Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Can somebody please tell me how can I format a hard drive at a low enough level that the boot sector is re-written? I guess the equivalent of fdisk /mbr.

share|improve this question
2  
Welcome to Ask Ubuntu! I believe what you're asking is erasing the partition table/MBR. It's not the same as formatting (applying a file system) –  gertvdijk Feb 9 '13 at 12:34
1  
Is it the hard drive you have in your computer or is it an external one? –  green7 Feb 9 '13 at 12:34
add comment

4 Answers

Please note that Low-Level formatting a hard drive refers to something completely different and should never be done by an end user. Also note that the notion of formatting a drive comes from the old DOS days. In Unix/Linux creating file systems and partition tables is more common and precise.


Rewriting the MBR doesn't require any formatting. If you just want to wipe the MBR (making that drive unbootable, and all data on all partitions on that disk unrecoverable), you can run this command:

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

replace xxxxxx with the actual device name of the device you want to lose all data on.

Supplemental: There is also the possibility of keeping the partition table and just erasing the boot loader code in the MBR, but you should make a backup first and then try zeroing the boot loader code:

dd if=/dev/XXXXXX of=mbr-backup.img bs=512 count=1
dd if=/dev/zero of=/dev/XXXXXX bs=446 count=1

Note that some boot loaders utilize the space between the MBR and the first partition to safe additional data. This is likely not to cause issues in this case, but if you want to do a complete boot loader backup, you should be aware of this.

share|improve this answer
    
Well, that's not completely true. You don't make all data on all partitions on that disk unrecoverable. With that command, you can't find your partitions again, unless you recreate the partition table or recover it somehow (for example, with testdisk). –  Jorge Suárez de Lis Feb 9 '13 at 12:39
1  
@JorgeSuárezdeLis While you can attempt data recovery, it's not something "easy" after removing the MBR. –  gertvdijk Feb 9 '13 at 12:40
add comment

Use GParted Install GParted. By creating a new partition table, this will effectively overwrite the MBR (boot sector).

enter image description here

Then a new window will pop up:

enter image description here

share|improve this answer
add comment

Step 1:

Boot from a live USB

Step 2:

Using fdisk -l, find out which drive you want to wipe. I shall assume that you want to wipe /dev/sda

Now, run

dd if=/dev/zero of=/dev/sda

That will wipe the hard drive.

If you want to wipe just the MBR (which has a blocksize of around 446), use

dd if=/dev/zero of=/dev/sda bs=446 count=1

To remove the partition table as well, use

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

Source for sizes of MBR/MBR+partition table

share|improve this answer
add comment

In Disks (find this application, it's installed by default), formerly known as Disk Utility, you can perform the same format as I explained using GParted.

enter image description here

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.