Thursday 17 March 2016

Erasing / copying MBR and GPT partition tables within Linux


The MBR typically takes up the first 512 bytes of your disk - it is broken down as follows:

446 bytes – Bootstrap.
64 bytes – Partition table.
2 bytes – Signature.

(446 + 64 + 2 = 512 bytes.)

We can make use of the dd command to copy your MBR to another drive:

dd if=/dev/sda of=/dev/sdb bs=512 count=1

or even delete your MBR:

dd if=/dev/zero of=/dev/sdc bs=512 count=1


GPT addresses a lot of MBR's shortcomings - specifically the partition size / disk sizes.

You can erase a GPT partition table using gdisk:

gdisk /dev/sda

Command (? for help): x 

Expert command (? for help): z
About to wipe out GPT on /dev/sdx. Proceed? (Y/N): y
GPT data structures destroyed! You may now partition the disk using fdisk or
other utilities.
Blank out MBR? (Y/N): y

You can copy a GPT partition table using the sgdisk (apt-get install gdisk):

sgdisk -R /dev/sda /dev/sdb
sgdisk -G /dev/sdb

 Note: The second command generalizes the disk and partition GUIDs. 


Post a Comment