|
: wyczyszczony MBR : oozie 26 February, 2007, 16:12:39 Cześć!
Ostatnio dużo eksperymentowałem z MBR na kompie w pracy, w końcu kompletnie go wyczyściłem. W nadzieji, że GRUB załatwi sprawę próbowałem wskrzesić swój MBR instalując kod gruba na różne sposoby. Jak się okazało, bez standardowego kodu MBR grub nie ruszy, bo jest od niego zależny. W [WIN]DO[W]Sach problem ten możnaby załatwić przy pomocy fdisk /mbr. W Linuxie tylko przy pomocy lilo -u, ale tylko jeżeli lilo zrobił backup MBRu. Dlatego też napisałem mały skrypcik, który przywraca funkcjonalność MBRa tak jak fdisk /mbr. Jeżeli tablica partycji przetrwała to zostanie zachowana. Mam nadzieję, że to komuś pomoże. : #!/bin/bash # # restore the standard MBR code to damaged hard drive # shellscript by oozie at poczta dot fm # # Used generic MBR code from MSDOS 3.30 fdisk /mbr # # #### if [ -z "$1" ]; then cat << _EOF_ Restore MBR with generic code ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Usage: $0 /dev/?d? where ?d? is one of your hard drives, e.g. /dev/sda _EOF_ exit 0 fi # 1. check for appropriate rights and existence of /dev/?d? DISK="$1" # check for appropriate rights if [ "$UID" -ne "0" ]; then echo "$0: you need to be root." exit 1 fi # checking for block device if [ ! -b "$DISK" ]; then echo "$0: $DISK is not a valid block device" exit 1 fi # let's start the fun - extact MBR generic code NEWMBR=$(mktemp) echo "[*] Extracting generic code to $NEWMBR" umask 077 MBRBACKUP="/root/mbr-backup.`date +%H-%M-%S`" printf \ "\xfa\x33\xc0\x8e\xd0\xbc\x00\x7c\x8b\xf4"\ "\x50\x07\x50\x1f\xfb\xfc\xbf\x00\x06\xb9"\ "\x00\x01\xf2\xa5\xea\x1d\x06\x00\x00\xbe"\ "\xbe\x07\xb3\x04\x80\x3c\x80\x74\x0e\x80"\ "\x3c\x00\x75\x1c\x83\xc6\x10\xfe\xcb\x75"\ "\xef\xcd\x18\x8b\x14\x8b\x4c\x02\x8b\xee"\ "\x83\xc6\x10\xfe\xcb\x74\x1a\x80\x3c\x00"\ "\x74\xf4\xbe\x8b\x06\xac\x3c\x00\x74\x0b"\ "\x56\xbb\x07\x00\xb4\x0e\xcd\x10\x5e\xeb"\ "\xf0\xeb\xfe\xbf\x05\x00\xbb\x00\x7c\xb8"\ "\x01\x02\x57\xcd\x13\x5f\x73\x0c\x33\xc0"\ "\xcd\x13\x4f\x75\xed\xbe\xa3\x06\xeb\xd3"\ "\xbe\xc2\x06\xbf\xfe\x7d\x81\x3d\x55\xaa"\ "\x75\xc7\x8b\xf5\xea\x00\x7c\x00\x00\x49"\ "\x6e\x76\x61\x6c\x69\x64\x20\x70\x61\x72"\ "\x74\x69\x74\x69\x6f\x6e\x20\x74\x61\x62"\ "\x6c\x65\x00\x45\x72\x72\x6f\x72\x20\x6c"\ "\x6f\x61\x64\x69\x6e\x67\x20\x6f\x70\x65"\ "\x72\x61\x74\x69\x6e\x67\x20\x73\x79\x73"\ "\x74\x65\x6d\x00\x4d\x69\x73\x73\x69\x6e"\ "\x67\x20\x6f\x70\x65\x72\x61\x74\x69\x6e"\ "\x67\x20\x73\x79\x73\x74\x65\x6d" > $NEWMBR perl -e '{print "\0"x228}' >> $NEWMBR printf \ "\x80\x01\x01\x00"\ "\x0b\x7f\xbf\xfd\x3f\x00\x00\x00\xc1\x40"\ "\x5e" >> $NEWMBR perl -e '{print "\0"x49}' >> $NEWMBR # 2. backup original MBR echo "[*] Backing up MBR to $MBRBACKUP" dd if=$DISK of=$MBRBACKUP count=1 bs=512 # > /dev/null 2>&1 # 3. rewrite original partition table from the harddrive to the # new mbr echo "[*] Rewriting original partition table to the new MBR " dd if=$MBRBACKUP of=$NEWMBR skip=446 seek=446 bs=1 count=64 #> /dev/null 2>&1 printf "\x55\xaa" >> $NEWMBR # 4. write new mbr to the disk echo -n "[?] Are you sure you want to write new MBR to the $DISK? [y/n] " read SURE if [ "$SURE" != "y" ]; then echo "[-] I guess not." exit 0 fi echo "[*] Re-Writing MBR to the disk" dd if=$NEWMBR of=$DISK bs=512 count=1 echo "-Done." rm $NEWMBR Online dostępny również tu: http://oozie.fm.interia.pl/src/restore-mbr.sh |