Install Linux Mint 21.1 with custom LVM on LUKS
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. This makes it easier if I decide to re-install Linux in the future while preserving user data.
Using a combination of Linux Unified Key Setup (LUKS) and Logical Volume Manager (LVM), I encrypt the storage space and create “virtual partitions” (Logical Volumes or LVs) for separate root and home file systems. Installing LVM on top of the encrypted partition allows the creation of multiple LVs protected by a single passphrase, and the ability to create and resize LVs as needed.
Let's go!
During an install of Linux Mint 21.1 "Vera" Cinnamon Edition - if you select the option to automatically erase and partition the disk using LUKS and LVM - the installer creates a single encrypted partition with two LVs: a swap
LV, and a root
LV that uses all remaining disk storage. There is no option to add a home
LV to the automatic schema.
My setup
Linux Mint is installed as the sole OS on the device. I use Mint's installer to erase, partition, and encrypt the storage space, and configure LVM.
After the installer finishes - but before rebooting - I shrink the root
LV to free up storage, then create a new home
LV.
This is how I do it ...
1. During the install: Installation type
Choose Erase disk and install Linux Mint
, click on Advanced features...
, and opt to use LVM and encryption.
A password to secure the storage is entered and confirmed.
Proceed with the rest of the install as per usual.
2. After the install: Continue Testing
When the Mint installer finishes, select Continue Testing
.
3. Switch to root
Open a terminal. Switch to root using sudo -i
.
Run mount | grep /dev/mapper/vgmint
and ensure nothing is returned (LVs need to be unmounted).
4. 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.
5. Resize root
Shrink the root
LV to free up space for a new home
LV.
Set the desired size of root
(example: 40G
) and resize its file system all at once ...
lvresize -L 40G --resizefs vgmint/root
6. Create home
Create the new home
LV.
Option 1
Use fixed amount of storage (example: 300G
) ...
lvcreate -L 300G vgmint -n home
Option 2
Or use percentage of free capacity (example: 80%
) ...
lvcreate -l +80%FREE vgmint -n home
7. Format 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
8. Move home
Mount the LVs ...
mkdir /mnt/{root,home}
mount /dev/vgmint/root /mnt/root/
mount /dev/vgmint/home /mnt/home/
Move the contents of /home
from the root
LV to the new home
LV ...
mv /mnt/root/home/* /mnt/home/
9. Fstab
Create an entry for home
in /mnt/root/etc/fstab
...
echo "/dev/mapper/vgmint-home /home ext4 defaults 0 2" >> /mnt/root/etc/fstab
10. Finish
Unmount LVs ...
umount /mnt/root
umount /mnt/home
Deactivate swap and volume group ...
swapoff -a
lvchange -an vgmint
Remove the encrypted device mapping (example: sda3_crypt
) ...
cryptsetup close sda3_crypt
Done. Reboot and enjoy!
» Next: Re-install Linux Mint 21.1 to an existing LVM Logical Volume on LUKS
« Previous: Nostromo boot noise