3

I wish to clone a 500gb MBR source disk to a 250gb MBR destination disk manually by making each corresponding partition on the destination disk and restoring just the data contents of each. This way, if a 100GB partition is only 5% full, I am only dealing with 5GB and not all 100 when using dd. I believe I am restoring the contents of each partition correctly, including the partition labels. The only thing that changes is the partition sizes, but that should not matter.

My understanding of MBR disks is that the first 446 bytes is the bootstrap code area. And with the subsequent 64 bytes being the partition table makes up the familiar 512 bytes of MBR. But I have already handled these 64 bytes (partition table) manually on the destination disk.

  • How does one deal with the bootstrap code area, the first 446 bytes of the first sector of the disk?
  • Is it as simple as dd if=/dev/sdb of=/dev/sdc bs=446 count=1 ?
  • Will bootstrap code be the same on every MBR disk, or does it need to be modified to work on the destination disk? If modified, then how?
  • What does the bootstrap code do?

I want to know how to clone different size MBR disks, myself manually, and not rely on some 3rd party free software. I have already successfully dd if=/dev/sdb of=/dev/sdc bs=32M between same sized disks and had the destination disk work. Everything is mount by disklabel. And I am dealing with Fedora 18 (Spherical Cow), and I believe grub2 and all my partitions are ext3.

  • Something is missing here: how do you intend to distinguish "data" bytes in a partition from the others? DD has no such capability. – kreemoweet Nov 15 '19 at 4:04
  • mount source partitions as /dev/sdb# and destination partitions as/dev/sdc# and as root do a cp -rp * – ron Nov 15 '19 at 18:32
  • i have been doing mount /dev/sdb# /z; cd z; tar -cf /root/sdb#.tar * then doing a mount /dev/sdc# /zz; cd zz; tar -xf /root/sdb#.tar. Replace # with partition number – ron Nov 15 '19 at 18:34
0

My understanding of MBR disks is that the first 446 bytes is the bootstrap code area. And with the subsequent 64 bytes being the partition table makes up the familiar 512 bytes of MBR.

Yes, almost. 446 + 64 = 510 bytes, you forgot two bytes for the disk signature, i.e.0x55aa at offset 510 for MBR style disks.

Is it as simple as dd if=/dev/sdb of=/dev/sdc bs=446 count=1 ?

Yes. Make sure to make a backup of the whole 512 bytes to a file on a different disk before doing so. This can save you a lot of trouble.

Will bootstrap code be the same on every MBR disk, or does it need to be modified to work on the destination disk? If modified, then how?

It depends on the OS and the bootloader (Grub, syslinux, Windows,...), so the code might differ. In your case it shouldn't matter as you clone the disk, just with different partition offsets and sizes.

What does the bootstrap code do?

It's usually used to determine the active partition and load a second stage boot loader off the boot sector of the active partition since the whole boot code doesn't fit into the MBR.

Just as an example: On an old laptop I'm triple booting Win10, Debian and OSX. If I set the the first partition active, it boots Windows, if the second partition is active it loads Grub (installed on the boot sector of the partition, not on the MBR), if the third partition is active it loads a hackintosh bootloader. I'm not sure if the bootstrap code is the original Windows code or from the hackintosh bootloader. They both used to work.

Note: I don't know how you copy the partitions to the destination disk, but I would suggest you resize the partitions on the source disk to their destination sizes (gparted).

Then
a) create a partition table on the destination disk with the same sizes and copy the partitions with dd
or
b) use gparted, create a clean MBR partition table on the destination disk and copy the partitions.

When done, copy the bootstrap code to the destination disk. This way you make sure that all data is copied and the filesystems stay intact. When done, you can resize the partitions on the source disk back to their original sizes.

Related:

  • before I had blank screen blinking cursor when trying to boot new disk. I then did a dd if=/dev/sdb of=/dev/sdc bs=446 count=1 to it and now it gets to a grub> prompt but stops there. I know I'm close, I think it has something to do with LBA in core.img – ron Nov 15 '19 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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