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, 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

  1. Copy /etc/mdadm/mdadm.conf to external storage
  2. Copy /root to external storage
  3. Copy /etc to external storage

File System & LUKS

  1. Unmount /home:
    sudo umount /home

    You might need to force unmount

  2. Close the LUKS container:
    sudo cryptsetup luksClose vg_data-lv_home_crypt
  3. 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

  1. Use vgdisplay and lvdisplay to understand your LVM configuration
  2. Deactivate logical volume(s): lvchange -an /dev/vg_data/lv_home
  3. Deactivate volume group: vgchange -an vg_data
  4. Export the volume group: vgexport vg_data

New Server

  1. Create a temporary /home mount point
  2. Install RAID, LVM, and cryptsetup into the new server
  3. Do not connect the data drives yet

RAID

  1. Copy the RAID configuration (mdadm.conf) from the old server to the new server
  2. Shut down the system, connect the data drives, then reboot the system
  3. Check with lsblk

LVM2

  1. Run pvscan to list the exported volume group(s)
  2. Import the volume group: vgimport vg_data
  3. Activate the volume group: vgchange -ay vg_data
  4. Activate the volume(s): lvchange -ay /dev/vg_data/lv_home

File System & LUKS

  1. Open the LUKS container and provide the passphrase:
    sudo cryptsetup luksOpen /dev/mapper/vg_data-lv_home vg_data-lv_home_crypt
  2. Mount the filesystem:
    mount /dev/mapper/vg_data-lv_home_crypt /home
  3. Modify fstab and give the temporary /home directory a new mount point
  4. Run update-initramfs -u