diff -pruN a/man/halt.8 b/man/halt.8 --- a/man/halt.8 2001-11-21 21:11:22.000000000 +0000 +++ b/man/halt.8 2004-10-10 12:28:11.000000000 +0000 @@ -23,6 +23,7 @@ halt, reboot, poweroff \- stop the syste .RB [ \-d ] .RB [ \-f ] .RB [ \-i ] +.RB [ \-k ] .br .B /sbin/poweroff .RB [ \-n ] @@ -65,6 +66,8 @@ Put all harddrives on the system in stan .IP \fB\-p\fP When halting the system, do a poweroff. This is the default when halt is called as \fBpoweroff\fP. +.IP \fB\-k\fP +Try to reboot using \fBkexec\fP, if kernel supports it. .\"}}} .\"{{{ Diagnostics .SH DIAGNOSTICS diff -pruN a/src/halt.c b/src/halt.c --- a/src/halt.c 2004-07-30 12:16:18.000000000 +0000 +++ b/src/halt.c 2004-10-10 12:28:11.000000000 +0000 @@ -8,7 +8,7 @@ * execute an "shutdown -r". This is for compatibility with * sysvinit 2.4. * - * Usage: halt [-n] [-w] [-d] [-f] [-h] [-i] [-p] + * Usage: halt [-n] [-w] [-d] [-f] [-h] [-i] [-p] [-k] * -n: don't sync before halting the system * -w: only write a wtmp reboot record and exit. * -d: don't write a wtmp record. @@ -16,6 +16,7 @@ * -h: put harddisks in standby mode * -i: shut down all network interfaces. * -p: power down the system (if possible, otherwise halt). + * -k: reboot the system using kexec. * * Reboot and halt are both this program. Reboot * is just a link to halt. Invoking the program @@ -64,8 +65,10 @@ extern void write_wtmp(char *user, char */ void usage(void) { - fprintf(stderr, "usage: %s [-n] [-w] [-d] [-f] [-h] [-i]%s\n", - progname, strcmp(progname, "halt") ? "" : " [-p]"); + fprintf(stderr, "usage: %s [-n] [-w] [-d] [-f] [-h] [-i]%s%s\n", + progname, + strcmp(progname, "halt") ? "" : " [-p]", + strcmp(progname, "reboot") ? "" : " [-k]"); fprintf(stderr, "\t-n: don't sync before halting the system\n"); fprintf(stderr, "\t-w: only write a wtmp reboot record and exit.\n"); fprintf(stderr, "\t-d: don't write a wtmp record.\n"); @@ -74,6 +77,8 @@ void usage(void) fprintf(stderr, "\t-i: shut down all network interfaces.\n"); if (!strcmp(progname, "halt")) fprintf(stderr, "\t-p: power down the system (if possible, otherwise halt).\n"); + if (!strcmp(progname, "reboot")) + fprintf(stderr, "\t-k: reboot the system using kexec.\n"); exit(1); } @@ -172,6 +177,7 @@ int main(int argc, char **argv) int do_ifdown = 0; int do_hddown = 0; int do_poweroff = 0; + int do_kexec = 0; int c; char *tm = NULL; @@ -189,7 +195,7 @@ int main(int argc, char **argv) /* * Get flags */ - while((c = getopt(argc, argv, ":ihdfnpwt:")) != EOF) { + while((c = getopt(argc, argv, ":ihdfnpwkt:")) != EOF) { switch(c) { case 'n': do_sync = 0; @@ -213,6 +219,9 @@ int main(int argc, char **argv) case 'p': do_poweroff = 1; break; + case 'k': + do_kexec = 1; + break; case 't': tm = optarg; break; @@ -230,10 +239,24 @@ int main(int argc, char **argv) (void)chdir("/"); if (!do_hard && !do_nothing) { + c = get_runlevel(); + + /* + * We can't reboot using kexec through this path. + */ + if (c != '6' && do_reboot && do_kexec) { + fprintf(stderr, "ERROR: using -k at this" + " runlevel requires also -f\n" + " (You probably want instead to reboot" + " normally and let your reboot\n" + " script, usually /etc/init.d/reboot," + " specify -k)\n"); + exit(1); + } + /* * See if we are in runlevel 0 or 6. */ - c = get_runlevel(); if (c != '0' && c != '6') do_shutdown(do_reboot ? "-r" : "-h", tm); } @@ -263,6 +286,16 @@ int main(int argc, char **argv) if (do_nothing) exit(0); if (do_reboot) { + /* + * kexec or reboot + */ + if (do_kexec) { + init_reboot(BMAGIC_KEXEC); + } + + /* + * Fall through if failed + */ init_reboot(BMAGIC_REBOOT); } else { /* diff -pruN a/src/reboot.h b/src/reboot.h --- a/src/reboot.h 2004-06-09 12:47:45.000000000 +0000 +++ b/src/reboot.h 2004-10-10 12:28:11.000000000 +0000 @@ -32,5 +32,8 @@ # define BMAGIC_POWEROFF BMAGIC_HALT #endif +/* for kexec support */ +#define BMAGIC_KEXEC 0x45584543 + #define init_reboot(magic) reboot(magic)