Created
December 2, 2018 16:26
-
-
Save thebsdbox/77a328bf5c2605db8af010bad924abfb to your computer and use it in GitHub Desktop.
This will pivot to a copied tmpfs wipe the underlying disk and force a reboot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo Unmounting any filesystem not needed | |
umount -a | |
echo Beginning building of tmp root | |
mkdir /tmp/tmproot | |
mount -t tmpfs none /tmp/tmproot | |
mkdir /tmp/tmproot/{proc,sys,dev,run,usr,var,tmp,oldroot} | |
cp -ax /{bin,etc,mnt,sbin,lib64} /tmp/tmproot/ | |
mkdir /tmp/tmproot/lib | |
cp -ax /lib/x86_64-linux-gnu /tmp/tmproot/lib | |
cp -ax /usr/{bin,sbin,lib,lib64} /tmp/tmproot/usr/ | |
cp -ax /var/{account,empty,lib,local,lock,nis,opt,preserve,run,spool,tmp,yp} /tmp/tmproot/var/ | |
mount --make-rprivate / # necessary for pivot_root to work | |
pivot_root /tmp/tmproot /tmp/tmproot/oldroot | |
for i in dev proc sys run; do mount --move /oldroot/$i /$i; done | |
echo Wiping out the first 1GB of data | |
dd if=/dev/zero of=/dev/sda bs=1M count=1024 | |
echo Forcing a kernel sysrq reboot | |
echo 1 > /proc/sys/kernel/sysrq | |
echo b > /proc/sysrq-trigger |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment