Kexec quick reboot

John Richard Moser nigelenki at comcast.net
Fri Aug 18 19:15:19 BST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I'm looking at kexec and thinking it could be used for fast rebooting in
some situations; I've had a machine that makes it to Grub in 18 seconds,
and I know someone who's got his going 25 seconds, both Athlon 64s.
Someone else I know has a couple RAID/SCSI cards that give him a nice
long wait.

I've tested this on dapper (using an edgy kernel, which has kexec on);
the results are pleasing.  The line I used to load went like this:

 sudo kexec -l --initrd=/boot/initrd.img-2.6.15-26-686 \
 --append="`cat /proc/cmdline`" /boot/vmlinuz-2.6.15-26-686

NOTE:  Rather than do `cat /proc/cmdline` you can do:
   $(cat /boot/grub/menu.lst | grep $(uname -r) | grep "^kernel" | \
     head -n 1 | xargs | cut -f 3 -d ' ')

This loaded the latest Dapper kernel (I was on 2.6.17-6-686 from Edgy)
for kexec, and I went merrily on my way.

Later (20 seconds later, after toying with a few more programs) I tried
to reboot; this failed.  The solution was to modify /etc/init.d/reboot
to have the following block:

do_stop () {
	log_action_msg "Will now reboot"
	# if we have kexec, try to execute a loaded kernel
	which kexec > /dev/null && kexec -e
	# failing that, reboot normally
	reboot -d -f -i
}

I loaded the Dapper kernel again; hit reboot; and, amazingly, it worked!
 uname showed I'd downgraded from 2.6.17 to 2.6.15, and everything works.

I'm thinking there's three scenarios this can be used in:

1.  "System Restart Required."  The dialog has a "Reboot" button in it.
    If we're expecting the user to be restarting Linux, then it makes
    sense to kexec -l the latest Linux kernel before rebooting.

2.  Shutdown->Restart.  We COULD assume the user is restarting Linux,
    and automatically load the latest kernel.  This has issues of
    course, because the user has to power down to get back to the boot
    loader.

2a. Shutdown->Restart.  Again, we could get the normal actions to carry
    out our bidding; but this time, disable the functionality if we
    detect a non-Ubuntu OS.  Unfortunately we can't detect multiboot
    with 100% certainty.

2b. Shutdown->Restart.  Just make it configurable and disable it by
    default.  We may turn it on by default later, but that decision is
    easy to delay.

3.  Shutdown->Quick Restart.  We COULD add a new Quit/Shut Down option
    for a "Quick Restart" that loads the latest kernel.  This is
    harmless; except that it will clutter that dialog with an extra
    button.


The steps that need to be taken for this to be enabled are as follows:

 - Patch /etc/init.d/reboot to call kexec before reboot; a failure with
   kexec will fall through to normal reboot.  (Hint:  Read up)

 - Write a script (A) to figure out the latest kernel.

 - Write a script (B) to divine the command line for a specific kernel.

 - Write a script (C) to call script (A) and script (B) and load kexec
   as appropriate.

 - Set the "System Restart Required" dialog up to call script (C) before
   rebooting.

 - Address any configuration issues with (2a) or (2b) if you want to
   implement (2).

 - Add the button for (3) and have it call script (C) before rebooting,
   if you want to implement (3).

- --
All content of all messages exchanged herein are left in the
Public Domain, unless otherwise explicitly stated.

    Creative brains are a valuable, limited resource. They shouldn't be
    wasted on re-inventing the wheel when there are so many fascinating
    new problems waiting out there.
                                                 -- Eric Steven Raymond

    We will enslave their women, eat their children and rape their
    cattle!
                  -- Bosc, Evil alien overlord from the fifth dimension
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQIVAwUBROYDtQs1xW0HCTEFAQJGWw//aPtjWSYh884QAx6m9DBdWX4oC1gGGdg1
SUzWD+LaTKHlnRQhjAe9AzqFiNnyLUVxKogbhaMf2jizHo5ANRP/AwOV0+85Hr/T
wpXeJwJ5tI5uADCitLW9d1P+W3hNgwqBbcAw+r98vxVAfS+lAbL4GwVHMdVFykNh
AQSCuvmlDV9uryefU+tABPh9kMxPsqfIW6nFC7ikIpdrR1Q9EIGevyhrNUlbL8rG
e6dxOS/5ULcIyToTpAlccGXs3pxGQsWBmvomA4e+3eKk5MHJqLDbBUkMIliJ6I/Y
Gf7z/vz3axG3z2n3laypk5SR9kw4vfwv1SFGtgo78vkpsMknZLxMPb/EbXOmTC9l
Dn+9CkSv67bbTOQEDIDakDhab+GaNjT3eae9ri5H/gXfUgs10XKcVfq0sBa/+xEq
1W8pXFeouqEnDkD9AyKH26ghC+PIrPOk7kZngkuc6bBTEUBvT7WG87o/kxMo2Uui
9n0LIc1o70qbTVzBjvbp7q/GWkyBtu3crCYKTTHSAPuvxcfEQkXQbW2jUHoVYrFb
1WUjrt18y4gEZtYQVdFCyaKttK6BsQllMc0JtJh8FcQ6jICnQftwlx82iEb7gUUX
jVOw2IXt4/OHRlSk5g2uKiWX/Q4W71sZXiUE9E723E8dyGcWToWnBMFnEvFUfdAo
DEi7/DQcsic=
=eO2h
-----END PGP SIGNATURE-----



More information about the ubuntu-devel mailing list