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
DELL PowerEdge R730XD 24x 2.5" Server Dual 750W Dual Heatsink - BareBones TESTED
$269.99
Supermicro 4U 36 Bay Storage Server 2.2Ghz 16-C 128GB 1x1280W Rails TrueNAS ZFS
$725.06
Dell PowerEdge R630 8SFF 2.6Ghz 20-Core 128GB Mem 2x10G+2x1G NIC 2x750W PSU
$399.04
CSE-118 Supermicro 1U GPU Server 2.6Ghz 28-C 128GB 2x Nvidia K40 GPU 2x1600W PSU
$580.03
Intel Xeon E5-2680 v4 2.4GHz 35MB 14-Core 120W LGA2011-3 SR2N7
$17.99
Intel Xeon Gold 6140 SR3AX 2.3GHz 18-Core Processor CPU
$44.99
INTEL XEON GOLD 6148 2.40 GHz SR3B6 CPU
$98.99
Intel Xeon E5-2697 v2 2.7GHz 30M 12-Core LGA2011 CPU Processor SR19H
$27.99
HP ProLiant DL380 Gen9 16SFF 2x E5-2680v4 2.4GHz =28 Cores 64GB P840 4xRJ45
$353.00
DELL PowerEdge R730 Server 2x E5-2690v3 2.6GHz =24 Cores 32GB H730 4xRJ45
$274.00