Table of Contents

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.

Old Server

File System

  1. Unmount /home:
    sudo umount /home
  2. You might need to force unmount. Alternatively, you may want to reboot the machine without LUKS to open the encrypted container.

update-initramfs -u

LUKS

sudo cryptsetup luksHeaderBackup /dev/mapper/vg_data2-lv_home --header-backup-file /path/to/backup/header.img
sudo cryptsetup luksErase /dev/sdb1
sudo cryptsetup luksHeaderRestore /dev/sdb1 --header-backup-file /path/to/backup/header.img

https://superuser.com/questions/1596599/is-it-safe-to-move-a-luks-encrypted-partition-to-another-system-and-be-able-to-u

LVM2

  1. Make sure that no users are accessing files on the active volumes in the volume group, then unmount the logical volumes.
  2. Use the -a n argument of the vgchange command to mark the volume group as inactive, which prevents any further activity on the volume group.
  3. Use the vgexport command to export the volume group. This prevents it from being accessed by the system from which you are removing it.
  4. pvscan
  5. When the system is next shut down, you can unplug the disks that constitute the volume group and connect them to the new system.
  6. When the disks are plugged into the new system, use the vgimport command to import the volume group, making it accessible to the new system.
  7. Activate the volume group with the -a y argument of the vgchange command.
  8. Mount the file system to make it available for use.

https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/4/html/cluster_logical_volume_manager/vg_move

  1. Unmount filesystem(s): unmount /nfs (I also had an export mirror for a Samba share that I had to un-mount as well)
  2. Deactivate logical volume(s): lvchange -an /dev/NASRaid1/NAS_LVM
  3. Deactivate volume group: vgchange -an NASRaid1
  4. Export the volume group: vgexport NASRaid1
  5. Add RAID Array to new system and boot up. Running pvscan lists the exported volume group(s).
  6. Import the volume group: vgimport NASRaid1
  7. Activate the volume group: vgchange -ay NASRaid1
  8. Activate the volume(s): lvchange -ay /dev/NASRaid1/NAS_LVM
  9. Mount the filesystem(s): mkdir -p /nfs; mount /dev/NASRaid1/NAS_LVM /nfs

https://askubuntu.com/questions/529843/move-raid-1-array-to-new-system/529845#answers-header

RAID