Re-install Linux Mint 21 to an existing LVM Logical Volume on LUKS

Last updated on 2022-10-29 Tagged under  #mint   #linux   #luks   #lvm 

When installing Linux Mint, I like to create storage space to hold the contents of my home directory that is separate from the space that contains the root filesystem. If for any reason I wish to re-install Mint in the future, this setup will preserve user data when installing a fresh copy of the operating system.

My setup

My previous install used a combination of Linux Unified Key Setup (LUKS) and Logical Volume Manager (LVM) to encrypt the storage space and create "virtual partitions" (Logical Volumes or LVs) for separate root and home file systems.

Current layout for (example) disk vda:

Goal: Re-install Linux Mint to root LV while leaving home LV untouched.

This is how I do it ...

1. Before running the installer: Unlock LUKS

Open the terminal and switch to root with sudo -i.

Identify the encrypted LUKS partition ...

lsblk -f | grep LUKS

For the purposes of this HOWTO, the example used will be the drive vda and LUKS partition vda4.

Unlock the partition ...

cryptsetup open /dev/vda4 vda4_crypt

2. Installation type

Start the installer.

At Installation type choose Something else.

mint-something-else

Partitions and the LVM LV's will appear in the installer.

2.1 Home

Configure /dev/mapper/vgmint-home and do NOT format (keep our user data intact).

mint-vgmint-home

mint-edit-home.png

2.2 Root

Configure /dev/mapper/vgmint-root for installation and format the LV.

mint-vgmint-root

mint-edit-root

2.3 Boot

Configure and format /dev/vda3 as the unencrypted boot partition.

mint-boot

mint-edit-boot

3. Write changes

Confirm that home is skipped and left unmentioned, then save changes to disk.

mint-write-changes

Proceed with the rest of the install as per normal.

When the Mint installer finishes, select Continue Testing.

mint-continue-testing

4. Mount

Switch back to the terminal and mount file systems ...

mount /dev/mapper/vgmint-root /mnt/
mount /dev/vda3 /mnt/boot/
mount --rbind /dev/ /mnt/dev/
mount --rbind /sys/ /mnt/sys/
mount --rbind /run/ /mnt/run/
mount --rbind /proc/ /mnt/proc/

5. Chroot

chroot /mnt /bin/bash -l

6. Crypttab

User will be prompted at boot to enter the existing passphrase that unlocks the encrypted LUKS partition.

Create /etc/crypttab (for our example LUKS partition vda4) ...

LUKSPART=vda4
UUID=$(blkid -s UUID -o value /dev/${LUKSPART})
echo "${LUKSPART}_crypt UUID=${UUID} none luks,discard" > /etc/crypttab  

7. Initramfs

update-initramfs -u -k all

8. Finish

Exit the chroot ...

exit

Unmount ...

umount -l /mnt

Deactivate swap and volume group ...

swapoff -a
lvchange -an vgmint

Remove the encrypted device mapping (example: vda4_crypt) ...

cryptsetup close vda4_crypt

Close terminal and reboot!

Helpful: ubiquity does not support existing LUKS encrypted partitions

Thanks for reading! Read other posts?

» Later: MintyFresh

« Earlier: Install Linux Mint 21 with custom LVM on LUKS