This article is for advance user like kernel developer or a System Administrator. In a special occation you may need a backup copy of the boot sector of a PC or restore the boot sector.

Warning: If you’re running these commands on your PC, then there is high chance of corrupting your hard disk. So don’t tell that I didn’t warn you in advance.

For this example I will consider the hardisk is /dev/sda and its bootable drive. The boot information is in the first 512 BYTES of hardrive.

Backing up existing boot sector in /dev/sda hardrive.

$ dd if=/dev/sda of=bootsec.bin bs=512 count=1

Now to restore the boot sector to the hardisk use the following command.

$ dd if=bootsec.bin of=/dev/sda bs=512 count=1

Note: you need to run this command with root previliage.