• Embed Doc
  • Readcast
  • Collections
  • CommentGo Back
Download
 
MBR tricks with Linux
Courtesy to-- www.tuxation.com
By
Bipul
 
The funny thing about the MBR is that it really isn'tcovered much in tutorials about installing Linux, however,it is a very crucial thing on your hard disk, and learninghow to manipulate it is a very good skill indeed.
What is the MBR?
The MBR is an acronym that stands for Master Boot Record.It has two main functions: firstly, it holds the partitiontable of a disk, and secondly it can optionally containexecutable code that the BIOS runs when the computer firststarts up. If there's no executable code in the MBR, theBIOS simply moves on to the first bootable partition.
MBR structure
The MBR is located in the first 512 bytes of the disk (thefirst sector). It's organized as follows (taken fromWikipedia):Size (bytes) Description446 Executable code section4 Optional Disk signature2 Usually nulls64 Partition table2 MBR signatureSo what does this tell us? The most important thing to noteis the overall size (512 bytes) and the executable code
 
section (the first 446 bytes). Using this information youcan do some fairly useful tasks.
Uses
Backing up a partition table
Probably one of the most useful things to do is to backupyour partition table. This could be useful if you'replanning to edit your partition table but don't want tolose the entire thing. To back it up, we're going to usethe dd utility. To back up the MBR, enter the following ata Linux prompt:
dd if=/dev/hda of=/mbrbackup.bin bs=512 count=1
How does this work?
if=
refers to the input file. In thiscase it's your hard drive device,/dev/hda. (If you harddrive isn't /dev/hda for some reason, substitute it withthe correct device.)of=refers to -- you guessed it -- theoutput file. In this caseddwill create a new file in theroot directory of the filesystem and save the contents ofthe MBR to this. bs refers to the block size (sector).Since the MBR is512 bytes, you want to set it to that.Finally,countrefers to the number of sectors to copy.There's only one MBR, so the count is set to 1. Now youshould copy this file to an external device, because if thepartition table gets damaged or erased, you won't be ableto access the partition where you saved the file!Restoringthe MBR is equally easy:
dd if=/mbrbackup.bin of=/dev/hda bs=512 count=1
 (This guide assumes you've already copied the mbrbackup.binfile from your backup media onto the current rootpartition.)
Erasing the executable code area
When Linux gets installed, chances are it installssomething called GRUB or LILO. These are bootloaders thatallow you to boot Linux, and if you've got other operatingsystems such as Windows installed, boot them as well. Thisworks great for most people until they decide that they
of 00

Leave a Comment

You must be to leave a comment.
Submit
Characters: ...
You must be to leave a comment.
Submit
Characters: ...