Customize LVM on LUKS after installing Linux Mint 21

Last updated on 2022-08-01 Tagged under  #mint   #linux   #luks 

I like to create a separate partition to hold the contents of my home directory from the partition that contains the operating system. It makes it easier to re-install Linux in the future without overwriting user files.

During an install of Linux Mint 21 "Vanessa" Cinnamon Edition - if you select the option to erase the disk and auto-partition with Logical Volume Management (LVM) + encryption enabled - the install tool creates a single LUKS encrypted partition with 2 logical volumes (LV): a swap LV, and a root LV that uses all remaining disk storage.

Another option - manually partition the disk - has graphical partitioning tools, but they do not allow making an encrypted partition, overlay LVM, then add multiple LVs and mount points.

The plan: After the Mint installer finishes - but before rebooting - I shrink the root LV to free up storage, then create a dedicated home LV.

This is how I do it ...

1. Continue testing

When the Mint installer finishes, select Continue testing.

Open a terminal. Switch to root sudo -i.

Run mount | grep /dev/mapper and ensure nothing is returned (LVs are unmounted).

2. View layout

Run lsblk -f and view the partition layout generated by the Mint installer.

Example: In my install, the partition used for encryption is sda3 and the encrypted LUKS device is sda3_crypt.

List physical volumes (PV) with the command vgs. There is a single PV labelled vgmint.

List the LVs with lvs. There are two: root LV, and swap_1 LV.

Note: Only LVs with ext2, ext3, ext4, ReiserFS, and XFS file systems are supported for resizing.

3. Resize root

Set the size of the existing root LV to 40 GiB and resize its file system all at once ...

lvresize -L 40G --resizefs vgmint/root

4. Create home

Create a new LV labelled home with either a fixed amount of storage (example: 300GB) ...

lvcreate -L 300G vgmint -n home

... or, create using a percentage of free capacity (example: 80%) ...

lvcreate -l +80%FREE vgmint -n home

5. Prepare home

The new LV will appear as /dev/vgmint/home. Format the LV with an appropriate file system (example: ext4) ...

mkfs.ext4 /dev/vgmint/home

Move the contents of /home from the root LV to the new home LV ...

mkdir /mnt/{root,home}
mount /dev/vgmint/root /mnt/root/
mount /dev/vgmint/home /mnt/home/
mv /mnt/root/home/* /mnt/home/

6. Fstab

Create entry for home in /mnt/root/etc/fstab ...

/dev/mapper/vgmint-home /home           ext4    defaults        0       2

7. Finish

Unmount LVs ...

umount /mnt/root
umount /mnt/home

Deactivate swap and volume group ...

swapoff -a
lvchange -an vgmint

Remove the encrypted device mapping ...

cryptsetup close /dev/mapper/sda3_crypt

Done! Reboot and enjoy!

See also: Install Linux Mint with custom partition layout for an alternate method.

Thanks for reading! Read other posts?

» Later: Mint-after-install

« Earlier: Keep Arch updated and pinky clean