Revision of How to resize Trisquel's default encrypted partitions from Wed, 07/31/2024 - 23:30
The revisions let you track differences between multiple versions of a post.
So for this guide we assume you have used the ubiquity LiveISO image installer
Choosing to encrypt you disk partition, using the default LVM partition recipe by just clicking "Next", picking a encryption it will require the passphrase, following the installer options 'til the system got installed.
For this guide we will be using:
Disk: 100GB
The disk is identified as: vda
User: test
VM name: luks-vm
So the situation, after a couple of days or weeks you notice that after installing all your common programs, apply updates, you start to notice a important decrease on the size of your root partition, while the home partition has enough space available.
You can start removing unnecessary programs, but even that have a limit.
So let's check the case at hand:
PARTITION DETAILS
$ df -h
Filesystem Size Used Avail Use% Mounted on
tmpfs 392M 1.3M 390M 1% /run
/dev/mapper/vgtrisquel-root 23G 17G 4.9G 78% /
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
/dev/vda3 1.7G 173M 1.4G 12% /boot
/dev/vda2 512M 296K 512M 1% /boot/efi
/dev/mapper/vgtrisquel-home 69G 11G 56G 16% /home
tmpfs 392M 116K 392M 1% /run/user/1000
From that we can take,
/dev/mapper/vgtrisquel-root 23G 17G 4.9G 78% /
/dev/mapper/vgtrisquel-home 69G 11G 56G 16% /home
There are some 56GB available at home at this point, so we might take 20 GB of those for root.
GOAL
Move some 20GBs from the lvm home volume to the root volume group.
REQUIREMENTS
Get a Trisquel ISO, verify it, and prepare a LiveUSB to boot from, there are plenty of different ways to do so on the documentation.
PROCESS
1. Enable LVM encrypted partition
Let's start by booting into the LiveISO, and select "Try without installing", then let's get familiar with the disk details using the live system.
On a terminal,
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 2.8G 1 loop /rofs
sr0 11:0 1 2.9G 0 rom /cdrom
vda 252:0 0 100G 0 disk
├─vda1 252:1 0 1M 0 part
├─vda2 252:2 0 513M 0 part
├─vda3 252:3 0 1.7G 0 part
└─vda4 252:4 0 97.8G 0 part
We can identify that vda4 is the main encrypted partition with all the data; so we open the encrypted device, it will require the passphrase
$ sudo cryptsetup luksOpen /dev/vda4 mydisk
Enter passphrase for /dev/vda4:
now we can see the partitions inside the encrypted one in a detailed;
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 2.8G 1 loop /rofs
sr0 11:0 1 2.9G 0 rom /cdrom
vda 252:0 0 100G 0 disk
├─vda1 252:1 0 1M 0 part
├─vda2 252:2 0 513M 0 part
├─vda3 252:3 0 1.7G 0 part
└─vda4 252:4 0 97.8G 0 part
└─mydisk 253:0 0 97.8G 0 crypt
├─vgtrisquel-root 253:1 0 23.3G 0 lvm
├─vgtrisquel-swap_1 253:2 0 3.9G 0 lvm
└─vgtrisquel-home 253:3 0 70.6G 0 lvm
Pay attention to this two values: 23.3G and 70.6G for root and home respectively
├─vgtrisquel-root 253:1 0 23.3G 0 lvm
└─vgtrisquel-home 253:3 0 70.6G 0 lvm
as we'll do some basic math with them in a bit.
2. Resize HOME
We already know the amount of GBs we want to move from home to root, in this guide it's: 20GB
First, let's confirm the home integrity
$ sudo e2fsck -f /dev/vgtrisquel/home
e2fsck 1.46.5 (30-Dec-2021)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vgtrisquel/home: 130/4636672 files (4.6% non-contiguous), 3057880/18519040 blocks
All that seems ok, so we continue by reducing the filesystem by 20GB, so
70GB - 20GB = 50GB
leaving out decimal points, then:
$ sudo resize2fs -p /dev/vgtrisquel/home 50g
Test again for integrity,
$ sudo e2fsck -f /dev/vgtrisquel/home
e2fsck 1.46.5 (30-Dec-2021)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vgtrisquel/home: 130/3276800 files (4.6% non-contiguous), 2972530/13107200 blocks
All passed, so we're good.
Now we shrink the lvm volume to actually free the 20GB,
$ sudo lvreduce -L -20G /dev/vgtrisquel/home
when prompted to continue, answer yes.
$ sudo lvreduce -L -20G /dev/vgtrisquel/home
WARNING: Reducing active logical volume to 50.64 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vgtrisquel/home? [y/n]: y
Size of logical volume vgtrisquel/home changed from 70.64 GiB (18085 extents) to 50.64 GiB (12965 extents).
Logical volume vgtrisquel/home successfully resized.
3. Resize ROOT
Now that 20GB are available, let's increase the root volume,
$ sudo lvextend -L +20G /dev/vgtrisquel/root
Size of logical volume vgtrisquel/root changed from 23.28 GiB (5960 extents) to 43.28 GiB (11080 extents).
Logical volume vgtrisquel/root successfully resized.
Followed by checking the filesystem integrity:
$ sudo e2fsck -f /dev/vgtrisquel/root
e2fsck 1.46.5 (30-Dec-2021)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vgtrisquel/root: 296285/1525920 files (0.2% non-contiguous), 4528050/6103040 blocks
And finally expand the root filesystem,
$ sudo resize2fs /dev/vgtrisquel/root
resize2fs 1.46.5 (30-Dec-2021)
Resizing the filesystem on /dev/vgtrisquel/root to 11345920 (4k) blocks.
The filesystem on /dev/vgtrisquel/root is now 11345920 (4k) blocks long.
4. Confirm partition sizes
We just need to confirm the new partition size, let's recall the previous values,
├─vgtrisquel-root 253:1 0 23.3G 0 lvm
└─vgtrisquel-home 253:3 0 70.6G 0 lvm
Now compare with the newer ones,
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 2.8G 1 loop /rofs
sr0 11:0 1 2.9G 0 rom /cdrom
vda 252:0 0 100G 0 disk
├─vda1 252:1 0 1M 0 part
├─vda2 252:2 0 513M 0 part
├─vda3 252:3 0 1.7G 0 part
└─vda4 252:4 0 97.8G 0 part
└─mydisk 253:0 0 97.8G 0 crypt
├─vgtrisquel-root 253:1 0 43.3G 0 lvm
├─vgtrisquel-swap_1 253:2 0 3.9G 0 lvm
└─vgtrisquel-home 253:3 0 50.6G 0 lvm
So root, is now 20GB larger out of the home partition.
Success!!
5. Umount and reboot
At this point we can umount the active volumes
$ sudo vgchange -an
0 logical volume(s) in volume group "vgtrisquel" now active
We can see that there is something else missing,
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 2.8G 1 loop /rofs
sr0 11:0 1 2.9G 0 rom /cdrom
vda 252:0 0 100G 0 disk
├─vda1 252:1 0 1M 0 part
├─vda2 252:2 0 513M 0 part
├─vda3 252:3 0 1.7G 0 part
└─vda4 252:4 0 97.8G 0 part
└─mydisk 253:0 0 97.8G 0 crypt
So we proceed to close the encrypted device,
$ sudo cryptsetup luksClose mydisk
Now we it's safe to reboot the system, and confirm the new size:
$ df -h
Filesystem Size Used Avail Use% Mounted on
tmpfs 392M 1.3M 390M 1% /run
/dev/mapper/vgtrisquel-root 43G 17G 24G 42% /
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
/dev/vda3 1.7G 173M 1.4G 12% /boot
/dev/vda2 512M 296K 512M 1% /boot/efi
/dev/mapper/vgtrisquel-home 49G 11G 37G 22% /home
tmpfs 392M 120K 392M 1% /run/user/1000
So... what about SWAP?
There are plenty of discussions about how much swap we might need, if it's still useful to have a swap partition, etc.
Regardless, if you want to increase your swap partition size, you'll see that it is very similar to the above procedure.
In this guide, we'll continue witht he same VM, and sizes we left before:
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sr0 11:0 1 2.9G 0 rom /media/test/trisquel 11.0.1 amd64
vda 252:0 0 100G 0 disk
├─vda1 252:1 0 1M 0 part
├─vda2 252:2 0 513M 0 part /boot/efi
├─vda3 252:3 0 1.7G 0 part /boot
└─vda4 252:4 0 97.8G 0 part
└─vda4_crypt 253:0 0 97.8G 0 crypt
├─vgtrisquel-root 253:1 0 43.3G 0 lvm /
├─vgtrisquel-swap_1 253:2 0 3.9G 0 lvm [SWAP]
└─vgtrisquel-home 253:3 0 50.6G 0 lvm /home
The current swap size is ~4GB, let's add another 4GB from the home volume.
GOAL:
Move 4GB to swap from home.
Let's try to speed up things; as before, let's start by booting into the LiveISO, once on the live session,
Let's confirm the encrypted partition name, vda4
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 2.8G 1 loop /rofs
sr0 11:0 1 2.9G 0 rom /cdrom
vda 252:0 0 100G 0 disk
├─vda1 252:1 0 1M 0 part
├─vda2 252:2 0 513M 0 part
├─vda3 252:3 0 1.7G 0 part
└─vda4 252:4 0 97.8G 0 part
Open the encrypted device, it will require the passphrase,
$ sudo cryptsetup luksOpen /dev/vda4 mydisk
Enter passphrase for /dev/vda4:
Then,
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 2.8G 1 loop /rofs
sr0 11:0 1 2.9G 0 rom /cdrom
vda 252:0 0 100G 0 disk
├─vda1 252:1 0 1M 0 part
├─vda2 252:2 0 513M 0 part
├─vda3 252:3 0 1.7G 0 part
└─vda4 252:4 0 97.8G 0 part
└─mydisk 253:0 0 97.8G 0 crypt
├─vgtrisquel-root 253:1 0 43.3G 0 lvm
├─vgtrisquel-swap_1 253:2 0 3.9G 0 lvm
└─vgtrisquel-home 253:3 0 50.6G 0 lvm
We'll take 4Gb from home volume, that is,
50GB - 4GB = 46GB
So test integrity first,
$ sudo e2fsck -f /dev/vgtrisquel/home
then reduce the filesystem,
$ sudo resize2fs -p /dev/vgtrisquel/home 46g
resize2fs 1.46.5 (30-Dec-2021)
Resizing the filesystem on /dev/vgtrisquel/home to 12058624 (4k) blocks.
Begin pass 3 (max = 400)
Scanning inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/vgtrisquel/home is now 12058624 (4k) blocks long.
Now let's shrink the home volume,
$ sudo lvreduce -L -4G /dev/vgtrisquel/home
WARNING: Reducing active logical volume to 46.64 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vgtrisquel/home? [y/n]: y
Size of logical volume vgtrisquel/home changed from 50.64 GiB (12965 extents) to 46.64 GiB (11941 extents).
Logical volume vgtrisquel/home successfully resized.
Time to enlarge the swap volume,
$ sudo lvextend -L +4G /dev/vgtrisquel/swap_1
Size of logical volume vgtrisquel/swap_1 changed from <3.86 GiB (988 extents) to <7.86 GiB (2012 extents).
Logical volume vgtrisquel/swap_1 successfully resized.
Let's increase the swap size now,
$ sudo lvextend -l +100%FREE /dev/vgtrisquel/swap_1
Size of logical volume vgtrisquel/swap_1 changed from <7.86 GiB (2012 extents) to 7.88 GiB (2018 extents).
$ sudo mkswap /dev/vgtrisquel/swap_1
and now we mount it on the live session,
$ sudo swapon /dev/vgtrisquel/swap_1
We confirm,
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 2.8G 1 loop /rofs
sr0 11:0 1 2.9G 0 rom /cdrom
vda 252:0 0 100G 0 disk
├─vda1 252:1 0 1M 0 part
├─vda2 252:2 0 513M 0 part
├─vda3 252:3 0 1.7G 0 part
└─vda4 252:4 0 97.8G 0 part
└─mydisk 253:0 0 97.8G 0 crypt
├─vgtrisquel-root 253:1 0 43.3G 0 lvm
├─vgtrisquel-swap_1 253:2 0 7.9G 0 lvm
└─vgtrisquel-home 253:3 0 46.6G 0 lvm
$ free -m
total used free shared buff/cache available
Mem: 3911 521 2478 47 911 3121
Swap: 8071 0 8071
It's there ~8GB of swap. Now we can close, and reboot.
$ sudo vgchange -an
0 logical volume(s) in volume group "vgtrisquel" now active
$ sudo cryptsetup luksClose mydisk
Success!!
Time to reboot.