Posts Tagged 'kexec'

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?


Top artists this week from Last.fm

My Twitter feed