[Tip] fast reboots with kexec

morph027

Renowned Member
Mar 22, 2013
451
63
93
Leipzig
morph027.gitlab.io
Install the package:

Code:
echo "kexec-tools kexec-tools/load_kexec boolean false" | debconf-set-selections
apt-get -y install kexec-tools

Create /etc/systemd/system/kexec-pve.service with content:

Code:
[Unit]
Description=boot into into the current pve kernel
Documentation=man:kexec(8)
DefaultDependencies=no
Before=shutdown.target umount.target final.target

[Service]
Type=oneshot
ExecStart=/sbin/kexec -l /boot/pve/vmlinuz --initrd=/boot/pve/initrd.img --reuse-cmdline

[Install]
WantedBy=kexec.target

Enable:

Code:
systemctl enable kexec-pve.service

Now you can reboot without the whole UEFI/BIOS/OpROM stuff with

Code:
systemctl kexec
 
Last edited:
Really nice, thanks. The proxmox dev's should integrate it and make it as alternative reboot option to the "real" reboot with bios :)
Small nit: Is the "into into" in the description right?
 
Description=boot into into the current pve kernel

Just to make things clear: it does not boot into the current (running) kernel, but into the kernel defined as primary in boot-loader. So if kernel was updated, it boots into the new one...
 
Just to make things clear: it does not boot into the current (running) kernel, but into the kernel defined as primary in boot-loader. So if kernel was updated, it boots into the new one...
Not it boots into current kernel. Because there is no grub at kexec. Tested here on my two machines.
 
In fact, it is loading /boot/pve/vmlinuz with /boot/pve/initrd.img which is a symlink to the latest installed kernel.

Code:
root@proxmox:~# cat /etc/systemd/system/kexec-pve.service
[Unit]
Description=boot into into the current pve kernel
Documentation=man:kexec(8)
DefaultDependencies=no
Before=shutdown.target umount.target final.target

[Service]
Type=oneshot
ExecStart=/sbin/kexec -l /boot/pve/vmlinuz --initrd=/boot/pve/initrd.img --reuse-cmdline

[Install]
WantedBy=kexec.target
root@proxmox:~# ls -la /boot/pve/
total 20
drwxr-xr-x 2 root root  8 Apr  3 11:30 .
drwxr-xr-x 5 root root 15 Apr  5 08:50 ..
lrwxrwxrwx 1 root root 25 Apr  3 11:30 initrd.img -> /boot/pve/initrd.img-4.13
lrwxrwxrwx 1 root root 30 Apr  3 11:30 initrd.img-4.13 -> /boot/initrd.img-4.13.16-1-pve
lrwxrwxrwx 1 root root 30 Mar 27 08:20 initrd.img-4.15 -> /boot/initrd.img-4.15.10-1-pve
lrwxrwxrwx 1 root root 22 Apr  3 11:30 vmlinuz -> /boot/pve/vmlinuz-4.13
lrwxrwxrwx 1 root root 27 Apr  3 11:30 vmlinuz-4.13 -> /boot/vmlinuz-4.13.16-1-pve
lrwxrwxrwx 1 root root 27 Mar 27 08:20 vmlinuz-4.15 -> /boot/vmlinuz-4.15.10-1-pve
 
Strange, this day i've installed 4.15
Code:
total 20
drwxr-xr-x 2 root root  8 Apr  7 13:29 ./
drwxr-xr-x 5 root root 19 Apr  7 13:29 ../
lrwxrwxrwx 1 root root 25 Mar 26 23:16 initrd.img -> /boot/pve/initrd.img-4.13
lrwxrwxrwx 1 root root 30 Apr  4 21:21 initrd.img-4.13 -> /boot/initrd.img-4.13.16-1-pve
lrwxrwxrwx 1 root root 30 Apr  7 13:29 initrd.img-4.15 -> /boot/initrd.img-4.15.10-1-pve
lrwxrwxrwx 1 root root 22 Mar 26 23:16 vmlinuz -> /boot/pve/vmlinuz-4.13
lrwxrwxrwx 1 root root 27 Apr  4 21:21 vmlinuz-4.13 -> /boot/vmlinuz-4.13.16-1-pve
lrwxrwxrwx 1 root root 27 Apr  7 13:29 vmlinuz-4.15 -> /boot/vmlinuz-4.15.10-1-pve
You see default is 4.13. But yes i can force manualy with an other line
Code:
ExecStart=/sbin/kexec -l /boot/pve/vmlinuz-4.15 --initrd=/boot/pve/initrd.img-4.15 --reuse-cmdline
 
Hi, have you tried with Proxmox 6? I have tried but it says:

# systemctl kexec
Cannot find the ESP partition mount point.
 
Hi, it works when I start the service, but I have to start the service manually after reboot, even the service is enabled:

Code:
root@xxxxxxxx:~# uptime
 13:44:03 up 1 min,  2 users,  load average: 0.20, 0.12, 0.04

root@xxxxxxxx:~# systemctl kexec
Cannot find the ESP partition mount point.

root@cxxxxxxxx:~# systemctl is-enabled kexec-pve.service
enabled

root@xxxxxxxx:~# systemctl status kexec
● kexec.service - LSB: Execute the kexec -e command to reboot system
   Loaded: loaded (/etc/init.d/kexec; generated)
   Active: active (exited) since Wed 2019-07-31 13:42:13 CEST; 1min 33s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 1699 ExecStart=/etc/init.d/kexec start (code=exited, status=0/SUCCESS)

Jul 31 13:42:13 xxxxxxxx systemd[1]: Starting LSB: Execute the kexec -e command to reboot system...
Jul 31 13:42:13 xxxxxxxx systemd[1]: Started LSB: Execute the kexec -e command to reboot system.

root@xxxxxxxx:~# systemctl start kexec-pve.service

root@xxxxxxxx:~# systemctl status kexec
● kexec.service - LSB: Execute the kexec -e command to reboot system
   Loaded: loaded (/etc/init.d/kexec; generated)
   Active: active (exited) since Wed 2019-07-31 13:42:13 CEST; 2min 2s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 1699 ExecStart=/etc/init.d/kexec start (code=exited, status=0/SUCCESS)

Jul 31 13:42:13 xxxxxxxx systemd[1]: Starting LSB: Execute the kexec -e command to reboot system...
Jul 31 13:42:13 xxxxxxxx systemd[1]: Started LSB: Execute the kexec -e command to reboot system.

root@xxxxxxxx:~# systemctl kexec
Connection to xxxxxxxx closed by remote host.
Connection to xxxxxxxx closed.

Thank you for your help
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!