Backing up your MBR
MBR stands for Master Boot Record. It is the part of your hard drive that tells where the partitions on that drive are located. It is also the part of your drive that becomes worthless if you try to install Windows on your hard drive after Linux. Of course, i have never done this … more than twice.
So i came across a poor soul that had done this and wished he had kept a backup of his MBR and it got me thinking “i could automate that,” because I hate to do something like this more than once. So I wrote a quick bash script to handle the issue.
#!/bin/sh
SAVETO=”/etc”
# Do ATA drives
for DRIVE in `ls -l /dev/hd* 2>/dev/null | grep -v [0-9]$ | grep disk | cut -d”/” -f3`
do
dd if=/dev/$DRIVE of=$SAVETO/mbr-$DRIVE bs=512 count=1
done# Do SCSI drives
for DRIVE in `ls -l /dev/sd* 2>/dev/null | grep -v [0-9]$ | grep disk | cut -d”/” -f3`
do
dd if=/dev/$DRIVE of=$SAVETO/mbr-$DRIVE bs=512 count=1
done
Obviously, there is a whole lot that could be done to improve the script (error checking, user notification, overkill), but if you aren’t already backing up your MBR, start here. Throw it into a cronjob and forget it – cron.monthly not cron.hourly.
