Moving /boot and MBR to a new drive

It turns out that using rsync or dump to copy the /boot partition was causing the problem. Based on erick's answer above, I booted a live CD into rescue mode and ran the following dd commands.

dd if=/dev/sda of=mbrbackup bs=512 count=1
dd if=mbrbackup of=/dev/sdb bs=446 count=1
dd if=/dev/sda1 of=/dev/sdb1

I ran the first two dd's again just to make sure everything was copied correctly and not corrupted with all the testing I've been doing. Then I ran the third dd to copy the boot partition from my old drive to my new one. After that I shut down, pulled out my old drive and booted without issue into my CentOS.

There must have been some issue caused by using dump on a mounted drive that caused the copy to not work correctly. Regardless, dd did the trick. Thanks for your help everyone.


If the two hard-disks are of the same size (or the new one is bigger), why didn’t you just copy the old disk to the new disk? I.e.

dd if=/dev/sda of=/dev/sdb

Now, if the new hard-disk is bigger, change the partition sizes with parted or gparted. All this done booting from a live CD/USB-stick.


Rather than dd, I built a new volume. More steps, but might fix problems rather than copy them over. I had a too small /boot that got corrupted. I also was using cento7 with grub2. So my instructions would require some adjustments or upgrade to grub2 as psusi suggested. I tried to note the changes.

NOTE: When I use "/dev/sdx", I am assuming that your know that the "sdx" needs to be changed to whatever the name of the disk/volume that you want to be /boot.

  • Use fdisk (not cfdisk) to Partition with type 83 (normal linux part), and mark as bootable.
    • Reason for fdisk: cfdisk starts the partition too soon, with no room for the boot loader. Remember, the boot loader needs to fit before the partition.
  • Make file system on partition. Ext[234], xfs. others?.
  • Mount at /boot
  • Copy *.img files from old /boot over into /boot… at least the ones you want to keep.
  • I also copied vmlinuz-* files from old /boot over into /boot… not sure if that is needed.
  • Run grub2-install /dev/sdx
    • Note 1: If you are using grub (rather than grub2), I believe the correct command is grub-install /dev/sdx
    • Note 2: This installs before the partition that we just formatted, so to NOT point it at /dev/sdx1!
  • Run grub2-mkconfig -o /boot/grub2/grub.cfg
    • Note: If you are using grub (rather than grub2), this is different. This might help, not sure: http://www.linuxandubuntu.com/home/how-to-change-boot-order-set-default-boot-os-in-ubuntu-14-10-15-04-linux-mint-or-other-derivatives
  • Don’t forget to update /etc/fstab for /boot

references: http://www.ocztechnologyforum.com/fo...226#post373226 http://www.patriotmemory.com/forums/...ead.php?t=3696 http://thunk.org/tytso/blog/2009/02/...se-block-size/ https://ubuntuforums.org/showthread.php?t=1528529 https://wiki.centos.org/HowTos/Grub2

Tags:

Dump

Mbr

Boot

Dd