| 1 |
#! /bin/bash
|
| 2 |
# bash is important because for echo -e
|
| 3 |
|
| 4 |
# edit the magic number of boot sector (the last two bytes)
|
| 5 |
# (c) 2001, Thomas Lange, lange@informatik.uni-koeln.de
|
| 6 |
|
| 7 |
seek=510
|
| 8 |
|
| 9 |
usage() {
|
| 10 |
|
| 11 |
cat <<EOF
|
| 12 |
bootsector [-edlvh] device
|
| 13 |
|
| 14 |
Read or write the magic number (the last two bytes) of a boot
|
| 15 |
sector. Writing 0x0000 to it disables booting from this boot sector.
|
| 16 |
The value 0xAA55 enables booting from this boot sector.
|
| 17 |
|
| 18 |
-e enable the boot sector
|
| 19 |
-d disable the boot sector
|
| 20 |
-l list the magic number hexadecimal
|
| 21 |
-v list the magic number in a verbose way
|
| 22 |
-h print this help
|
| 23 |
|
| 24 |
Examples:
|
| 25 |
|
| 26 |
# bootsector -e /dev/hda
|
| 27 |
# bootsector -l /dev/hda
|
| 28 |
0000000 aa55
|
| 29 |
# bootsector -d /dev/hda
|
| 30 |
# bootsector -l /dev/hda
|
| 31 |
0000000 0000
|
| 32 |
# bootsector -v /dev/hda
|
| 33 |
Boot sector /dev/hda disabled.
|
| 34 |
|
| 35 |
bootsector is written by Thomas Lange, lange@informatik.uni-koeln.de, 2001.
|
| 36 |
|
| 37 |
EOF
|
| 38 |
exit 0
|
| 39 |
}
|
| 40 |
|
| 41 |
readbb() { # read last two bytes from boot block
|
| 42 |
|
| 43 |
dd bs=1c skip=$seek count=2 if=$1 2>/dev/null|od -x|grep -v 0000002
|
| 44 |
}
|
| 45 |
|
| 46 |
writebb() { # write last two bytes of boot block
|
| 47 |
|
| 48 |
dd bs=1c seek=$seek of=$1 2>/dev/null || echo "Can't write to boot block $1"
|
| 49 |
}
|
| 50 |
|
| 51 |
arch=`dpkg --print-installation-architecture`
|
| 52 |
[ "$arch" = "i386" ] || {
|
| 53 |
Currently, only i386 architecure is supported.
|
| 54 |
exit 1
|
| 55 |
}
|
| 56 |
|
| 57 |
getopts e:d:l:v:h opt
|
| 58 |
case $opt in
|
| 59 |
h) usage ;;
|
| 60 |
e) echo -ne "\x55\xaa" | writebb $OPTARG ;;
|
| 61 |
d) echo -ne "\x0\x0" | writebb $OPTARG ;;
|
| 62 |
l) readbb $OPTARG ;;
|
| 63 |
v) bs=`readbb $OPTARG`
|
| 64 |
case $bs in
|
| 65 |
"0000000 0000") echo "Boot sector $OPTARG is disabled." ;;
|
| 66 |
"0000000 aa55") echo "Boot sector $OPTARG is enabled." ;;
|
| 67 |
*) echo "Unknown boot sector $bs" ;;
|
| 68 |
esac
|
| 69 |
;;
|
| 70 |
*) usage; exit 1 ;;
|
| 71 |
esac
|