Using kexec for a fast reboot in Archlinux

If you ever wondered how some distros achieve the trick of bypassing the BIOS when rebooting, it’s done using something called kexec, which wikipedia defines as:

[…]a mechanism of the Linux kernel that allows “live” booting of a new kernel “over” the currently running kernel. kexec skips the bootloader stage (hardware initialization phase by the firmware or BIOS) and directly loads the new kernel into memory, where it starts executing immediately.

In archlinux, you can achieve this with the package kexec-tools, which you can install as usual with:
pacman -S kexec-tools

kexec-tools is integrated with the archlinux initscripts, so that the kexec command line tool will by default go through the normal shutdown procedure before rebooting. You can find more information as ever on the excellent Archlinux Wiki. There are some scripts there which look pretty useful, but I started using kexec direct from the command line after reading the man page, and then wrote a short script to cover the form I was using each time.

#!/bin/dash

imgname=/boot/kernel26${1:+-$1}
krnname=/boot/vmlinuz26${1:+-$1}

exec kexec --type=bzImage --reuse-cmdline --initrd=$imgname.img $krnname

I saved this as ~/bin/kxreboot. You can either just use this without parameters to boot the default kernel, or you can add a single parameter – for example, if you do kxreboot mainline it will boot vmlinuz26-mainline with initrd kernel26-mainline.img

You might also ask, “Why would I want a fast reboot? I never reboot!”. Fair comment. I run the testing repos, so kernel and udev upgrades come along quite frequently. Also, my motherboard doesn’t recognise my USB keyboard on boot, which makes a BIOS boot a bit of a pain as I have to find a PS/2 keyboard. Last but not least, everyone loves faster, right?

Advertisements

3 Responses to “Using kexec for a fast reboot in Archlinux”


  1. 1 Ralph Corderoy 21/05/2011 at 13:07

    For that bit of extra “faster” you could switch to /bin/sh and exec kexec. šŸ™‚

  2. 2 John Carlyle-Clarke 21/05/2011 at 13:15

    Very true! Although it would have to /bin/dash since /bin/sh in Arch links to bash šŸ™‚

    I always thought that those parameter expansions were bashisms too, but apparently not…

  3. 3 John Carlyle-Clarke 21/05/2011 at 13:23

    Updated to include your suggestions.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s





%d bloggers like this: