Replace the root disk
Recently the disk holding the root (/) filesystem on one of my linux systems started to report increased SMART raw read error rates, seek error rates and ECC recovered hardware errors.
As these are early indications of a failing disk, it became time to replace the disk.
Normally replacing a disk comes down to plugging in the new one, coyping over the data, umount the old disk, mount the new one in place, unplug the old disk.
But when it is the disk with the root filesystem a couple extra steps are needed.
The steps below worked for my Debian system without problems (even used the opportunity to upgrade to an SSD :-)
(source is this thread on StackExchange)
The following makes some assumptions:
- All commands ran as root when possible
- You are on a physical console to the host (need to type in grub commands to boot up the new disk!)
- You want an ext4 files system
- You are loosely familiar on a basic level with all commands run
- You are NOT booting from a RAID device
So here we go.
- Physically install new disk into computer and connect to available port leaving old disk in existing position.
- Boot computer into old OS.
- Prepare and mount new disk; first identify new disk
fdisk -l- Partition new disk
fdisk /dev/(newdisk)
Make partition primary partition with type "83" file system type.- Create filesystem
mkfs.ext4 /dev/(newpartition)- Mount new filesystem
mkdir /mnt/(newpartitionmountpoint)
mount /dev/(newpartition) /mnt/(newpartitionmountpoint)- Copy disk:
/sbin/init 1 (drop to single user mode)
rsync -avxHAX / /mnt/(newpartitionmountpoint)- Update FSTAB on newdisk
blkid (note UUID of new partition)
vi /mnt/(newpartitionmountpoint)/etc/fstab
Replace existing UUID of / in FSTAB to new disk UUID- Configure grub and install to new disk boot loader:
grub-mkconfig
update-grub
grub-install /dev/(newdisk)- Copy grub.cfg from old disk to new
cp -ax /boot/grub/grub.cfg /mnt/(newpartitionmountpoint)/boot/grub/grub.cfg- Open grub.cfg on new disk and replace all UUIDs with new disk
vi /mnt/(newpartitionmountpoint)/boot/grub/grub.cfg
Replace all old UUIDs with the UUID of the new disk- Shut down computer
shutdown- Physically move the new drive to the 1st drive location and remove old drive
- Start computer and grub should present:
error: no such device: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx GRUB rescue>- Manually boot new OS from grub; first identify the drive and partition of the boot files
ls [to identify your drive and partition options]
ls (hdx,p)/ [to identify which partition has the /boot folder]- Then, you can load the boot menu manually from the drive and partition you found above. Typically this would be (hd0,msdos1).
set prefix="(hdx,p)/boot/grub"
set root="(hdx,p)"
insmod normal
normal- Login to OS on new drive
- Configure grub again
fdisk -l (note dev of newdisk)
grub-mkconfig
update-grub
grub-install /dev/newdiskAnd that should be it!