# [HOWTO] kexec

## Leffe

HOWTO kexec

kexec is a feature in some kernels (-mm for sure) that allows for

warm reboots, i.e. you do not have to go through the BIOS and

can load a kernel instantly. This HOWTO describes how to install,

setup and use kexec on a Gentoo system.

What is kexec?

kexec is a part of the Linux kernel that allows the running kernel to reboot into a new kernel. It can also be used to set up fallback kernels if a kernel panics, panic logging, and other things. This guide only covers rebooting.

Why kexec?

Rebooting using kexec is faster than rebooting normally because you do not have to go through the BIOS.

Installation

First of all, you will need a kernel with kexec support. The -mm patch series has that for example. The Gentoo package for the -mm kernel is sys-kernel/mm-sources. If you wanted to you could go and patch a kernel of your own by downloading patches from the kexec page.

To enable the kexec support in the kernel you must set the following options in the kernel menuconfig:

```
Code maturity level options  --->  Prompt for development and/or incomplete code/drivers  [y]

Processor type and features  --->  kexec system call  [y]
```

After doing that, compile the kernel, install it, and reboot.

Now you will need the userland kexec-tools package, it is currently ~x86 masked, so you will have to unmask it. 	These commands will unmask and install the package:

```
echo sys-apps/kexec-tools ~x86 &gt;&gt; /etc/portage/package.keywords

emerge -av sys-apps/kexec-tools
```

This will install the kexec binary, an init.d script and a conf.d configuration file.

Configuration

You might have to change some options in the configuration file, open up /etc/conf.d/kexec in your favorite editor. The defaults are (not what is commented out, see /etc/init.d/kexec):

```
BOOTPART="/boot"

BOOTMOUNT=1

KNAME="bzImage"

KPARAM=""

INITRD=""
```

ROOTPART is autodetected by scanning your /etc/fstab for the root partition. You will want to change the KPARAM to what you boot your kernel with from /etc/boot/grub/grub.conf, and perhaps put something in the INITRD variable too if you want/need that. (I have no experience with that.)

To have kexec automatically load your current kernel at boot, add kexec to the boot runlevel.

```
rc-update add kexec boot
```

To load the kernel run rc to let the initscripts handle everything (it will start all services you have manually stopped too).

```
rc
```

Or alternatively just launch it directly using the script.

```
/etc/init.d/kexec start
```

Loading a kernel does not actually boot it, it just loads it somewhere in memory. To actually load the kernel you can do kexec -e. Do not do that though, it will reboot right away without unmounting or killing processes. What you want to do is change /etc/init.d/reboot.sh to use kexec when rebooting. My script contains this:

```
/sbin/kexec -e

/sbin/reboot -idp
```

It uses the normal /sbin/reboot as a fallback if no kernel has been loaded. Your system is now ready to reboot using kexec, just issue the reboot command and your system will reboot using kexec!

You might want to know how to change the loaded kernel, for example if you want to reboot into a new kernel instead of what was loaded at boot. That is easy, just install the new kernel and restart kexec, /etc/init.d/kexec restart.

If you encounter any bugs in kexec, send them to the author ;)

Quick installation

Enable kexec in your kernel.

Install kexec-tools.

Configure kexec-tools.

Optionally add kexec to the boot runlevel.

Hack /init.d/reboot.sh.

reboot

--edited link to link to server processed xhtml document instead.

--added phpbb marked up version

--added FFox 1.0 bug workaroundLast edited by Leffe on Tue Feb 22, 2005 4:02 pm; edited 3 times in total

----------

## mayday147

I get an error from that link:

```
Error loading stylesheet: (null)http://nullref.se/xslt/config.xslt.xslt
```

----------

## Leffe

 *mayday147 wrote:*   

> I get an error from that link:
> 
> ```
> Error loading stylesheet: (null)http://nullref.se/xslt/config.xslt.xslt
> ```
> ...

 

What browser might you be using? I've only tried the site in ELinks (Linux), Internet Explorer (Windows), Firefox (Windows) and Opera (Windows).

No, wait, I will make a guess (from the logs), Konqueror? Hm, I must investigate. Google suggests Firefox :/

And you can try one of these links instead:

http://nullref.se/article/2005-02-13-howto-kexec.html

http://nullref.se/article/2005-02-13-howto-kexec.xhtml

http://nullref.se/article/2005-02-13-howto-kexec.txt

----------

## j-m

 *Leffe wrote:*   

>  *mayday147 wrote:*   I get an error from that link:
> 
> ```
> Error loading stylesheet: (null)http://nullref.se/xslt/config.xslt.xslt
> ```
> ...

 

Firefox 1.0 does not work for me (same error).   :Wink: 

----------

## Leffe

Okay, I dropped IE support for this article and serve it as text/xml instead of the (nonstandard but working) text/xsl.

If this doesn't work I'll blame the users using more than 2 days old browsers :p

----------

## cato`

No formating, how about using good old HTML?

----------

## j-m

 *Leffe wrote:*   

> Okay, I dropped IE support for this article and serve it as text/xml instead of the (nonstandard but working) text/xsl.
> 
> If this doesn't work I'll blame the users using more than 2 days old browsers :p

 

Regarding the original link, no - it is still broken.  :Laughing: 

----------

## Titeuf

Looks interesting, does it keep your uptime ?

----------

## Leffe

 *Titeuf wrote:*   

> Looks interesting, does it keep your uptime ?

 

I'm sorry to say it does not :p

I'm sure it could be hacked somehow though.

----------

## Titeuf

Too bad.

But the better boot times will make it good, that's now one of the reasons I don't update my kernel much: too lazy to reboot

----------

## pjp

DT&T is not intended for threads only linking to offsite documentation.

----------

## Leffe

 *pjp wrote:*   

> DT&T is not intended for threads only linking to offsite documentation.

 

 *Quote:*   

> # Provide detailed information about what your tip or trick does, and how it works.
> 
> Note: Please do not merely link to another website.

  === (equ)  *Quote:*   

> # Provide detailed information about what your tip or trick does and how it works if you merely link to another website.

 

:/

Oh well, I ported it.

----------

## Leffe

Yay, I figured out the FFox bug. XSLT stylesheets must be named *.xsl, not *.xslt.

----------

## idl

TIP: Don't build kexec-tools with a hardened toolchain, it won't work.

----------

## localghost

I run an AMD64 and have a gentoo-dev-sources 2.6.11-r2 kernel.

What file(s) should I download from http://www.xmission.com/~ebiederm/files/kexec/ and how do I apply them?

EDIT: never mind, I'm in the process of installing a pure 32 bit x86 installation on my AMD64.

----------

## Leffe

 *localghost wrote:*   

> I run an AMD64 and have a gentoo-dev-sources 2.6.11-r2 kernel.
> 
> What file(s) should I download from http://www.xmission.com/~ebiederm/files/kexec/ and how do I apply them?

 

I would imagine that <a href="http://www.xmission.com/~ebiederm/files/kexec/2.6.8.1-kexec3/">this</a> is your best choice. It seems to have support for x86_64 and ppc!

As for applying... put the file in your kernel directory, issue gzcat patch_file_name | patch -p1 --dry-run and pray that everything applies without problems, if that somehow is the case you can run that command again but without the --dry-run to actually apply the patch.

If you get problems... time to start hacking the kernel ;) I can't help you with that.

Using the -mm kernel is really the best idea. (you could try applying one of the <a href="http://www.xmission.com/~ebiederm/files/kexec/2.6.10-mm2-kexec3.tgz">-mm kexec patches</a>, but I would assume that they use -mm-specific functions)

----------

## dylan_stark

When I execute "kexec -e" I get message "kexec image is not loaded"???

I configured /etc/conf.d/kexec like this 

```
# Boot partition

BOOTPART="/boot"

# Kernel name

KNAME="kernel-2.6.20"

# Root partition (should be autodetected)

ROOTPART="/dev/hda4"

# Kernel parameters (should be autodetected)

#KPARAM="splash=silent,theme:emergence"

# Initrd

#INITRD="/boot/fbsplash-emergence-1024x768"

# Load kexec kernel image into memory during shutdown instead of bootup

# (default: yes)

LOAD_DURING_SHUTDOWN="yes"

```

----------

## nixnut

Moved from Gentoo Chat to Documentation, Tips & Tricks.

----------

## Lok

How to get dump kernel /proc/vmcore ?

# kexec -l /boot/kernel-genkernel-x86_64-4.12.12-gentoo --initrd=/boot/initramfs-genkernel-x86_64-4.12.12-gentoo --append="root=/dev/sda3 1 irqpoll maxcpus=1 reset_devices"

# kexec -e

load new kernel.

# cat /proc/cmdline

root=/dev/sda3 1 irqpoll maxcpus=1 reset_devices

But,

# kexec -p /boot/kernel-genkernel-x86_64-4.12.12-gentoo --initrd=/boot/initramfs-genkernel-x86_64-4.12.12-gentoo --append="root=/dev/sda3 1 irqpoll maxcpus=1 reset_devices"

Alt+SysRq+c = my system is freezing

if run

# kexec -p /boot/kernel-genkernel-x86_64-4.12.12-gentoo --initrd=/boot/initramfs-genkernel-x86_64-4.12.12-gentoo --append="root=/dev/sda3 1 irqpoll  reset_devices"

Alt+SysRq+c = system will reboot with grub2

/proc/vmcore missing.

----------

