Skip to content

Instantly share code, notes, and snippets.

@thebsdbox
Created December 2, 2018 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thebsdbox/77a328bf5c2605db8af010bad924abfb to your computer and use it in GitHub Desktop.
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
#!/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