Heres a simple script for using kexec to do a quick reboot. The script properly kills all running processes, unmounts all local filesystem, remounts root read-only and then loads the current running kernel ( /boot/vmlinuz-$(uname -r) ) and executes it with kexec -e
If it is supplied with the "-i" command line option it also includes the matching initrd
Since a partial shutdown is done... and root is remounted read-only. fsck doesnt complainCode:#!/bin/bash ######## Settings ######## KERNEL=/boot/vmlinuz-$(uname -r) # Edit this to the format of your initrd filenames INITRD="/boot/initrd.img" # Set env and do some sanity checks CMDLINE=$(cat /proc/cmdline) KEXEC_STATUS=$(dpkg --get-selections kexec-tools | awk '{ print $2 }') [ "$1" = "-i" ] && INITRD="--initrd=$INITRD-$(uname -r)" || INITRD="" [ "$UID" != "0" ] && echo "This script must be run as root!" && exit 1 [ ! "$KEXEC_STATUS" = "install" ] && echo "kexec not found! Please install the package 'kexec-tools'" && exit 1 # Function to blank the screen... cosmedic screen_dump() { # Edit CYCLES if you like. Less cycles means the script will be faster # but may leave garbage on the screen from the previous kernel CYCLES=1000 PASS=0 clear while [[ $PASS -lt $CYCLES ]] do echo "" >/dev/console ; echo "" >/dev/tty0 echo "" >/dev/tty1 ; echo "" >/dev/tty2 echo "" >/dev/tty3 ; echo "" >/dev/tty4 echo "" >/dev/tty5 ; echo "" >/dev/tty6 PASS=$(($PASS + 1)) done clear } FATAL_ERROR() { echo "" echo "FATAL: $1 not found." exit 1 } # Deactivate current system and go read-only ## Make sure no other kernel has been loaded kexec -u sync echo -n "Killing all running processes ..." [ -x /etc/init.d/sendsigs ] && /etc/init.d/sendsigs stop >/dev/null 2>&1 || FATAL_ERROR "/etc/init.d/umountroot" echo "Done" echo -n "Mounting root read-only ..." [ -x /etc/init.d/umountfs ] && /etc/init.d/umountfs stop >/dev/null 2>&1 || FATAL_ERROR "/etc/init.d/umountroot" [ -x /etc/init.d/umountroot ] && /etc/init.d/umountroot stop >/dev/null 2>&1 || FATAL_ERROR "/etc/init.d/umountroot" echo "Done" # Clear the screen once again and boot the new kernel # Load the system kexec -l $KERNEL $INITRD --append="$CMDLINE" echo "Booting the system...." screen_dump kexec -e
Enjoy!
-Justin
One Mynds Eye
1U Supermicro Server 10 Bay 2x Intel Xeon 3.3Ghz 8C 128GB RAM 480GB SSD 2x 10GBE
$297.00
HPE ProLiant MicroServer Gen8 Intel Xeon E3-1265L 16GB ECC PCIe x16 4x1TB HDD
$249.99
HP ProLiant Xeon E3-1220L V2 MicroServer Gen8 2.30 GHz 16 GB RAM NO DRIVES
$199.99
HPE ProLiant MicroServer Gen10 Plus v2 Ultra Micro Tower Server - 1 x Intel Xeon
$846.19
HP ProLiant HSTNS-5151 Micro Server 8GB RAM No Drives/Key/Caddies *READ*
$94.99
SuperMicro Server 505-2 Intel Atom 2.4GHz 8GB RAM SYS-5018A-FTN4 1U Rackmount
$202.49
Supermicro 5018A-FTN4 Rack Server - Black
$125.00
HP ProLiant Microserver Micro Server HSTNS-5151 untested NO DRIVE CADDIES
$60.75
SUPERMICRO CSE-512 AMD Opteron Processor 6128, 32GB DDR3 RAM NO HDD
$90.00
1U Supermicro Server X10DRU-i+ 2x Xeon E5-2690 V4 28 Cores 64GB 4x 10GBE-T 2PS
$324.00