Procedure:HostDiskMigration
The host disk migration procedure is to be used in the event that
- a host's disk is failing and it must be moved to a good disk
- expanded host storage on the root disk is needed
WARNING: This procedure is obviously not without risks, backups should be available first!
If everything is done correctly, this process will be read-only from the original disk's perspective, however mistakes can be made and if grub is reinstalled wrong (or the wrong disk gets repartitioned) the results would be gruesome.
New disk preparation
- Hot install new disk in the host; It is recognized and appears in the /dev/sd* table
- Format the new disk to have the same set of partitions as the old disk
- If the new disk is larger, feel free to enlarge
- make sure to mark the /boot partition as bootable
- mark the partition types as the same
Filesystem copy
- mkdir /mnt/tmp -p
Once the copy of the partitions is ready, copy everything over at the filesystem level. Generically, one rsync will be needed for each partition
- mount /dev/sdbX /mnt/tmp
- rsync -avxHAXS /boot /mnt/tmp
- umount /mnt/tmp
# Next is the master filesystem copy # IMPORTANT: # Theoretically this should be done using a liveusb to assure that the source FS is static, # however if the system is completely idle, all important services are stopped, etc, # then only /var/log/* is likely to change. YMMV!
- mount /dev/sdbY /mnt/tmp
- rsync -avxHAXS / /mnt/tmp
- -> be sure that /mnt/tmp is mounted, baby, otherwise rsync will keep going until it crashes into the filesystem recursion limit
Boot preparation
Prepare for chroot:
- umount /mnt/tmp
- mount /dev/sdbX /mnt/tmp
- mount /dev/sdbY /mnt/tmp/boot
- mount --bind /sys /mnt/tmp/sys
- mount --bind /proc /mnt/tmp/proc
- mount --bind /sys /mnt/tmp/sys
Grab all the block device IDs and drop them in fstab. At this point, the UUIDs of the new disk must be slipped in for the mount points of the old disk in the new filesystem,
- blkid >> /mnt/tmp/etc/fstab
- vi /mnt/tmp/etc/fstab
If the disk arrangement is simple (just sda) it may be possible to leave /dev/sd* unchanged in fstab, as upon removal of the old disk the new disk will become sda at next boot.
- chroot /mnt/tmp
- grub2-install /dev/sdb
- grub2-mkconfig -o /boot/grub2/grub.cfg
- dracut -f
- Make absolutely sure that the new disk /boot is mounted before entering chroot!