How to move boot and root partitions to another drive
You'll need to boot from a live cd. Add partitions for them to disk 1, copy all the contents over, and then use sudo blkid
to get the UUID of each partition. On disk 1's new /, edit the /etc/fstab to use the new UUIDs you just looked up.
Updating GRUB depends on whether it's GRUB1 or GRUB2. If GRUB1, you need to edit /boot/grub/device.map
If GRUB2, I think you need to mount your partitions as they would be in a real situation. For example:
sudo mkdir /media/root
sudo mount /dev/sda1 /media/root
sudo mount /dev/sda2 /media/root/boot
sudo mount /dev/sda3 /media/root/home
(Filling in whatever the actual partitions are that you copied things to, of course)
Then bind mount /proc and /dev in the /media/root:
sudo mount -B /proc /media/root/proc
sudo mount -B /dev /media/root/dev
sudo mount -B /sys /media/root/sys
Now chroot into the drive so you can force GRUB to update itself according to the new layout:
sudo chroot /media/root
sudo update-grub
The second command will make one complaint (I forget what it is though...), but that's ok to ignore.
Test it by removing the bad drive. If it doesn't work, the bad drive should still be able to boot the system, but I believe these are all the necessary steps.
If you replace the drive right away you can use dd
(tried it on my server some months ago, and it worked like a charm).
You'll need a boot-CD for this as well.
- Start boot-CD
- Only mount Drive 1
- Run
dd if=/dev/sdb1 of=/media/drive1/backuproot.img
- sdb1 being your root (/
) partition. This will save the whole partition in a file.- same for
/boot
- same for
- Power off, replace disk, power on
- Run
dd if=/media/drive1/backuproot.img of=/dev/sdb1
- write it back.- same for
/boot
- same for
The above will create 2 partitions with the exact same size as they had before. You might need to adjust grub (check macos post).
If you want to resize your partitions (as i did):
- Create 2 Partitions on the new drive (for
/
and/boot
; size whatever you want) - Mount the backup-image:
mount /media/drive1/backuproot.img /media/backuproot/
- Mount the empty
/
partition:mount /dev/sdb1 /media/sdb1/
- Copy its contents to the new partition (i'm unsure about this command, it's really important to preserve ownership,
cp -R
won't do it!)cp -R --preserve=all /media/backuproot/* /media/sdb1
- same for
/boot/
- same for
This should do it.
My final solution to this was a combination of a number of techniques:
- I connected the dying drive and its replacement to the computer simultaneously.
- The new drive was smaller than the old, so I shrank the partitions on the old using GParted.
- After doing that, I copied the partitions on the old drive, and pasted them on the new (also using GParted).
- Next, I added the boot flag to the correct partition on the new drive, so it was effectively a mirror of the old drive.
This all worked well, but I needed to update grub2 per the instructions here.
After all this was done, things seem to work.