Skip to content

Instantly share code, notes, and snippets.

@rc5hack
Created April 29, 2015 10:39
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 rc5hack/b8f130b4bc1ae26307df to your computer and use it in GitHub Desktop.
Save rc5hack/b8f130b4bc1ae26307df to your computer and use it in GitHub Desktop.
delete boot code from MBR
#!/bin/sh
if [ -z "$1" ] || [ ! -e $1 ] ; then
echo " !! Device '$1' not found" >&2
exit 1
fi
TMPFILE=`mktemp /tmp/mbr.XXXXXXXX`
if [ ! -e $TMPFILE ] ; then
echo " !! Unable to create temp file" >&2
exit 1
fi
sysctl kern.geom.debugflags=0x10
dd if=$1 of=$TMPFILE bs=512 count=1 > /dev/null 2>&1
echo -n "current MBR checksum is " && md5 -q -- $TMPFILE
dd if=/dev/zero of=$TMPFILE bs=1 count=446 conv=notrunc > /dev/null 2>&1
echo -n "new MBR checksum is " && md5 -q -- $TMPFILE
dd if=$TMPFILE of=/dev/ad0 > /dev/null 2>&1
echo "new MBR written"
rm $TMPFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment