X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=bootcensus;a=blobdiff_plain;f=instmbr;fp=instmbr;h=15a9696a535b3237bb2594805cc532e1a5ac2d79;hp=0000000000000000000000000000000000000000;hb=19e033a35e0f312848fdcf81d9b4f07cc156f2e6;hpb=84d954eff1e78353c2d17a9ad5e057e5a07aee5e diff --git a/instmbr b/instmbr new file mode 100755 index 0000000..15a9696 --- /dev/null +++ b/instmbr @@ -0,0 +1,31 @@ +#!/bin/sh + +dev=$1 +if [ -z "$dev" ]; then + echo 'pass the device on which to install' >&2 + exit 1 +fi + +# try to remake boot.img if it's missing +if [ ! -f boot.img ]; then + make || exit 1 +fi + +# safety check +if mount | grep ^$dev >/dev/null 2>&1; then + echo "device $dev seems to be in use." >&2 + echo "Make sure it's the correct device, and unmount the following filesystems first:" >&2 + echo "" >&2 + mount | grep ^$dev >&2 + exit 1 +fi + +# copy the existing MBR to preserve the partition table +echo "saving copy of existing MBR to preserve partition table ..." +dd if=$dev of=/tmp/instmbr.mbr bs=512 count=1 status=none +echo "writing boot image to $dev ..." +dd if=boot.img of=$dev bs=512 status=none conv=notrunc +echo "patching boot sector with saved partition table ..." +dd if=/tmp/instmbr.mbr of=$dev bs=1 seek=440 skip=440 count=70 status=none conv=notrunc + +sync