Replace primary drive how-to (2021)

Way back, I wrote a how-to on replacing a primary drive. I had to reference this with a recent server that had a primary failure, and want to update the process.

First, I followed the above how-to and ran into MAJOR issues with grub. Since that article, there has been an update to grub2, which complicated the process.

I installed the drive and the first issue with cfdisk is that I labeled it gpt. Don’t do that (if I read this), label it dos. This so you can get that bootable partition. Create the 1-3 primary partitions and the 4th logical container partition and load the rest. Set the boot flag.

In this case /dev/sda was failing, so this new drive is in /dev/sdc. I have enough life in /dev/sda to do the copies, but want to replace it.. it’s dying.

Create mount points in /mnt. For this server, I had separate partitions for /boot, /tmp, /usr, /home, and /var

cd /mnt
mkdir root boot tmp usr home var
mount /dev/sdc3 /mnt/root
mount /dev/sdc1 /mnt/boot
mount /dev/sdc6 /mnt/home
mount /dev/sdc7 /mnt/usr
mount /dev/sdc8 /mnt/var
rsync -auv --delete --exclude=/tmp --exclude=/files --exclude=/sys --exclude=/dev --exclude=/files --exclude=/files2 --exclude=/files3 --exclude=/var --exclude=/home --exclude=/usr --exclude=/tmp --exclude=/boot --exclude=/proc --exclude=/.swap --exclude=/mnt / /mnt/root/.
rsync -auv --delete /boot /mnt/.
rsync -auv --delete /usr /mnt/.
rsync -auv --delete /home /mnt/.
rsync -auv --delete --exclude=backup /var /mnt/.
cd /mnt/root
mkdir boot home var usr tmp

These mount points are there so we can mount the new drive partitions and to move the files. Leave fstab the same since we’ll remove the bad drive and this new drive will be the new sda.

Mount bind root so we can copy /dev

mkdir /mnt/test
mount -o bind / /mnt/test
rsync -auv --delete /mnt/test/dev /mnt/root/.

Make mount points in the new drive for /proc and /sys

cd /mnt/root
mkdir proc sys
chmod 555 proc

I then did a grub-install on /dev/sdc and it didn’t complain so I thought I was good. I powered down the machine and pulled out the bad disk and put the sdc drive in the sda slot. Fired it up, and thought it was good. Nope.

The problem is that grub is referencing the old sda1 Filesystem UUID. The only place I saw reference of this was in grub.cfg, so thought I would be clever and find all references of this and update to the new drive’s UUID. Still would not boot, still referenced the old UUID.

The only solution was to burn a new ISO gentoo min CD and chroot and run grub-install and grub-mkconfig. After the gentoo-nofb kernel is loaded from the Live CD

mount /dev/sda3 /mnt/gentoo
mount /dev/sda1 /mnt/gentoo/boot
mount /dev/sda5 /mnt/gentoo/tmp
mount /dev/sda6 /mnt/gentoo/usr
mount /dev/sda7 /mnt/gentoo/home
mount /dev/sda8 /mnt/gentoo/var
swapon /dev/sda2
cp -L /etc/resolv.conf /mnt/gentoo/etc/resolv.conf
mount -t proc none /mnt/gentoo/proc
mount -o bind /dev /mnt/gentoo/dev
chroot /mnt/gentoo /bin/bash
source /etc/profile
grub-install /dev/sda
grub-mkconfig -o /boot/grub/grub.cfg

After that, the system would boot.