Skip to content

Instantly share code, notes, and snippets.

@jvyden
Created September 1, 2023 05:15
Show Gist options
  • Save jvyden/649fe491987344fa783172da5e9492ac to your computer and use it in GitHub Desktop.
Save jvyden/649fe491987344fa783172da5e9492ac to your computer and use it in GitHub Desktop.
A script to softly reboot a Linux system with kexec
#!/bin/bash
if [ "$EUID" -ne 0 ]; then
echo "This script requires root."
sudo $0
exit
fi
if [ "$1" == "complete" ]; then
systemctl stop graphical.target
killall -9 -u jvyden
sleep 0.5
modprobe -r nvidia_drm
kexec -e
fi
# load kernel here, might as well do something before we switch away
kexec -l /boot/vmlinuz-linux-zen --initrd=/boot/initramfs-linux-zen.img --reuse-cmdline
# defer this to another systemd session so we don't get ourselves killed
systemd-run /usr/bin/soft-reboot complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment