====== Migrate data drives ======
This guide shows how to migrate data drives from an old server to a new machine. This works when the old server is still accessible. My setup is 2 HDD -> RAID 1 -> LVM2 -> LUKS -> ext4 so it is very important to do all the steps in the correct sequence as outlined below. In my setup all data is mounted as ''/home'', the volume group is ''vg_data'', the logical volume ''lv_home''.
In my configuration the crypt container and mounting of the filesystem are handled in a batch file. This is not reflected here, and I have also not included instructions how to mount the encrypted container to a mount point.
===== Old Server =====
==== Preparation ====
- Copy ''/etc/mdadm/mdadm.conf'' to external storage
- Copy ''/root'' to external storage
- Copy ''/etc'' to external storage
==== File System & LUKS ====
- Unmount /home:sudo umount /homeYou might need to force unmount
- Close the LUKS container:sudo cryptsetup luksClose vg_data-lv_home_crypt
- Alternatively, instead of step 2 & 3, you may want to reboot the machine without providing the encryption password to avoid LUKS opening the encrypted container.
==== LVM2 ====
- Use ''vgdisplay'' and ''lvdisplay'' to understand your LVM configuration
- Deactivate logical volume(s): ''lvchange -an /dev/vg_data/lv_home''
- Deactivate volume group: ''vgchange -an vg_data''
- Export the volume group: ''vgexport vg_data''
===== New Server =====
- Create a temporary ''/home'' mount point
- Install RAID, LVM, and cryptsetup into the new server
- Do not connect the data drives yet
==== RAID ====
- Copy the RAID configuration (''mdadm.conf'') from the old server to the new server
- Shut down the system, connect the data drives, then reboot the system
- Check with ''lsblk''
==== LVM2 ====
- Run ''pvscan'' to list the exported volume group(s)
- Import the volume group: ''vgimport vg_data''
- Activate the volume group: ''vgchange -ay vg_data''
- Activate the volume(s): ''lvchange -ay /dev/vg_data/lv_home''
==== File System & LUKS ====
- Open the LUKS container and provide the passphrase:sudo cryptsetup luksOpen /dev/mapper/vg_data-lv_home vg_data-lv_home_crypt
- Mount the filesystem:mount /dev/mapper/vg_data-lv_home_crypt /home
- Modify ''fstab'' and give the temporary ''/home'' directory a new mount point
- Run ''update-initramfs -u''
===== Links =====
* [[https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/4/html/cluster_logical_volume_manager/vg_move|Moving a Volume Group to Another System]]
* [[https://askubuntu.com/questions/529843/move-raid-1-array-to-new-system/529845#answers-header|Move RAID 1 Array to new system]]