Rearrange LVM after installing Linux Mint

Last updated on 2021-05-15 Tagged under  # linux  # mint

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 20.1 "Ulyssa" Cinnamon - 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 overlayed with LVM containing multiple LVs and mountpoints.

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

Let's go!

1. 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. Run lsblk -f and view the partition layout generated by the Mint installer. Example: In my case, 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 LV 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. Set the size of the existing root LV to 30 GiB and resize its file system all at once ...

lvresize -L 30G --resizefs vgmint/root

4. 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. 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. Create entry for home in /mnt/root/etc/fstab ...

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

7. 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!

» Later: Create a multiboot USB installer with Ventoy

« Earlier: Transfer files between phone and computer via USB