Customize LVM on LUKS after installing 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.3 "Una" 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 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. Resize root
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 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!
» Later: Mint-after-install
« Earlier: Upgrade a home router with OpenWrt