5

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 2.6.28.10-custom-1.1. 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.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
apoorv020
  • 1,243
  • 3
  • 13
  • 19
  • 2
    Might be a good question for http://unix.stackexchange.com – Jakob Feb 16 '11 at 08:46
  • Which bootloader are you running? –  Feb 16 '11 at 08:48
  • @Jakob: Is not there a way to have the question on both the sites? – apoorv020 Feb 16 '11 at 08:58
  • Why would you bother? This isn't a programming question. –  Feb 16 '11 at 08: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 '11 at 09:02
  • It's still not a programming question. –  Feb 16 '11 at 09:03
  • @apoorv020 - Although there is no doubt a solution to your question, wouldn't you prefer that the system actually reboot rather than simply execute a different kernel? If so, init 6 with the proper bootloader settings should properly load your intended kernel. – Tok Feb 16 '11 at 15:10

2 Answers2

4

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

/etc/default/kexec 

and setting:

  LOAD_KEXEC=false 

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.

bdk
  • 390
  • 1
  • 7
  • 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 '11 at 13:26
2

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
KPARAMS=$KPARAMS"/boot/vmlinuz-$UNAMER"

    # 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
    fi

    #This next line should never happen.

    reboot -d -f -i
apoorv020
  • 1,243
  • 3
  • 13
  • 19
  • To make this work in Ubuntu, you need to replace `locate` with `which` command and also remove `log_action_msg` line. – ARH Feb 22 '15 at 17:32