0

I'm playing with Master boot record. I decided to delete and restore it on my vmware machine.

With Ubuntu LiveCD I'm trying to erase partition entries and signature with command:

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

or:

dd if=/dev/urandom of=/dev/sda bs=1 skip=446 count=66

To verify my changes I check with command:

dd if=/dev/sda bs=1 skip=446 count=66 | hexdump -C

but I do not see zeros or random characters. Everything is unchanged.

I rebooted my machine. As expected I could not boot my os. Again I booted LiveCD and again I see no changes to MBR partitions and signature, old data are preserved. What is wrong?

user3345632
  • 103
  • 3

1 Answers1

1

bs=1 and count=66 you are delete only 66 bytes, the mbr code is 446 and the signatures is the last 2 bytes

the MBR is not a partition but the first block of the disk, block 0 of size 512 bytes and is divided as follow:

446(bood code) + 64(partition table) + 2 (magic number)

your problem is you are using skip

man dd

skip=N skip N ibs-sized blocks at start of input

but you need to use seek to go to bytes 446 for /dev/sda

seek=N skip N obs-sized blocks at start of output
c4f4t0r
  • 5,149
  • 3
  • 28
  • 41
  • He only wants to delete the partition entries and preserve the boot code, hence the `skip=446`. – Oliver Jul 02 '15 at 10:40
  • @Oliver yes, but isn't clear, if my boot is /dev/sda1 and I delete the partition table, the /boot will not mount, I did a test and my kvm guest cannot boot. – c4f4t0r Jul 02 '15 at 10:47
  • My machine also cannot boot as expected. But... when I use Ubuntu LiveCD, data are preserved -> I can see previous deleted partitions – user3345632 Jul 02 '15 at 11:02
  • I do not understand why my 66 bytes are not erased and not overwritten with zeros/ – user3345632 Jul 02 '15 at 11:03
  • try to use oflag=direct and after that sfdisk -R /dev/sda and fdisk -l /dev/sda and tell us if you still see the partitions. – c4f4t0r Jul 02 '15 at 11:08
  • With oflag=direct I get: dd: writing to ‘/dev/sda’: Invalid argument 1+0 records in 0+0 records out 0 bytes (0 B) copied, 0.0174621 s, 0.0 kB/s. I checked that /dev/sda is not mounted. After sfdisk -R /dev/sda, I get: BLKRRPART: Device or resource busy. This disk is currently in use. – user3345632 Jul 02 '15 at 13:10
  • I don't why if use the with IO direct for writing a few bytes the error Invalid argument come out, but for writing 1M no problem :( – c4f4t0r Jul 02 '15 at 13:42
  • Is there difference between dd if=/dev/zero of=/dev/sda bs=1 skip=446 count=66 and dd if=/dev/zero of=/dev/sda bs=66 skip=446 count=1 ??? – user3345632 Jul 02 '15 at 14:12
  • your problem is you need to use dd if=/dev/zero of=/dev/sda bs=1 seek=446 count=66 – c4f4t0r Jul 02 '15 at 14:19
  • @c4f4t0r nice catch! – Oliver Jul 03 '15 at 05:43