-
Senior Member
registered user
Quick reboot using kexec - The right way
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
Code:
#!/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
Since a partial shutdown is done... and root is remounted read-only. fsck doesnt complain 
Enjoy!
-Justin
One Mynds Eye
Similar Threads
-
By marhleet in forum General Support
Replies: 0
Last Post: 02-23-2007, 10:38 PM
-
By Mercer in forum General Support
Replies: 3
Last Post: 01-06-2006, 03:59 AM
-
By BNU-FaNtAsMa in forum Hdd Install / Debian / Apt
Replies: 4
Last Post: 08-23-2004, 04:14 AM
-
By mikey_man380 in forum Customising & Remastering
Replies: 3
Last Post: 11-06-2003, 10:56 PM
-
By jolimp in forum Networking
Replies: 2
Last Post: 06-19-2003, 07:48 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules

WAVLINK RAID 2 Bay Hard Drive Docking Station SATA 2.5/3.5'' SSD HDD Enclosure
$107.99

Broadcom 9600-24i Tri-Mode RAID Controller 4.0 NVMe SAS SATA NEW 05-50111-01003
$639.69

Intel VROC Premium RAID Controller Card PCIe Add-On Module VROCPREMMOD
$265.00

G-Technology G-SPEED Studio XL 48TB Thunderbolt 2 Storage
$200.00

Broadcom LSI 9305-16i 12Gbps SAS-3 PCIe x8 HBA 16-Ports Raid Controller
$64.99

2-Bay/4-Bay Hard Drive Enclosure for 3.5"/2.5'' SATA HDD/SSD 10Gbps USB-C 3.2
$75.99

Dell 3KDWX PERC H755 12G 8GB Cache Front RAID Controller
$999.99

TerraMaster D5-300C 5-Bay USB-C Hard Drive Enclosure
$115.00

Lacie 2big Quadra RAID 2 x 2 TB 4 TB Only 158 hours
$199.00

EMC VNXe3100 EPE 12-LFF 3.5" NAS Storage Array 12*3TB SAS HDD 2*303-137-000D
$224.99