I am using ssh to remotely access some machines. These machines have a custom kernel installed (based on the 2.6.28 source). However, whenever I try to reboot the machines using sudo reboot, the system uses kexec and loads the 2.6.28-19-generic kernel, which is also intalled on the machine.

So how can I specify which kernel image to load after reboot?

EDIT: I have ubuntu 9.04 installed on the machine, with grub 1.something. The custom kernel is based on the 2.6.28 source with the name being Two other kernels are installed on the machine 2.6.28-19-generic and 2.6.28-6-386. I have checked that after calling reboot, the machine does not actually reboot but uses kexec to load the 19-generic kernel, even if the current kernel was the custom one.

  • 2
    Might be a good question for unix.stackexchange.com
    – Jakob
    Feb 16, 2011 at 8:46
  • Which bootloader are you running?
    – sjr
    Feb 16, 2011 at 8:48
  • @Jakob: Is not there a way to have the question on both the sites?
    – apoorv020
    Feb 16, 2011 at 8:58
  • Why would you bother? This isn't a programming question.
    – Ignacio Vazquez-Abrams
    Feb 16, 2011 at 8:58
  • Because I am developing a kernel module on the machine, and I need to reboot the machine at some points. I noticed that my makes were starting from scratch for some reason, and then I noticed that the kernels were being switched.
    – apoorv020
    Feb 16, 2011 at 9:02

2 Answers 2


Normally, when you reboot, the machine will return to grub and either allow you to select a kernel via the keyboard, or boot the default configured kernel. However if you have kexec-tools installed, the reboot command will short circuit this behaviour and directly kexec into a kernel. You can disable this behaviour, and return to grub in reboot, by uninstalling kexec tools or editing the file


and setting:


Alternatively, to keep kexec active and have it reboot into the kernel of your choice, try a command line like this to load your desired kernel:

 kexec -l /boot/vmlinux --append=root=/dev/hda1 --initrd=/boot/initrd

then when 'kexec -e' is later run, the configured kernel in the kexec line as well will be run. As I believe the reboot script eventually just calls 'kexec-e' I believe the kernel change should take effect then.

  • Just wanted to add that you should probably add parameters from the current kernel's commandline from /proc/cmdline after the -l flag.
    – apoorv020
    Feb 17, 2011 at 13:26

I found a pretty nifty post here. It contains a script to call kexec manually. Reposting script here:

    UNAMER=`uname -r` # this checks the version of the kernel 
            #just to save typing

    #This just puts all of the parameters for loading in one place

KPARAMS="-l " # tells kexec to load the kernel

# --append tells the kernel all of its parameters
# cat /proc/cmdline gets the current kernel's command line
KPARAMS=$KPARAMS"--append=\"`cat /proc/cmdline`\" "

# this tells the kernel what initrd image to use
KPARAMS=$KPARAMS"--initrd=/boot/initrd.img-$UNAMER "

# this tells the kexec what kernel to load

    # Message should end with a newline since kFreeBSD may
    # print more stuff (see #323749)
    log_action_msg "Will now restart"

    if [ -x `locate kexec | grep sbin` ]; then # check for the kexec executable
            kexec $KPARAMS  # load the kernel with the correct parameters
            sync            # sync all of the disks so as not to lose data
            umount -a       # make sure all disks are unmounted
            kexec -e        # reboot the kernel

    #This next line should never happen.

    reboot -d -f -i
  • To make this work in Ubuntu, you need to replace locate with which command and also remove log_action_msg line.
    – ARH
    Feb 22, 2015 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.