How to resize Trisquel's default encrypted partitions
This guide assumes you have used the ubiquity Live USB/DVD ISO image installer choosing to encrypt you disk using the default recipe by just clicking "Next" until the system got installed.
For this guide we will be using:
Disk: 100GB
The disk is identified as: vda
After a couple of days or weeks and installing all your common programs, applying updates, the available space on your root partition may be rather low, while the home partition has enough space available. You can start removing unnecessary programs, but even that has a limit.
So let's check the case at hand:
DISK PARTITIONING DETAILS
$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS 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 23.3G 0 lvm / ├─vgtrisquel-swap_1 253:2 0 3.9G 0 lvm [SWAP] └─vgtrisquel-home 253:3 0 70.6G 0 lvm /home
This shows that
- vda4 contains an encrypted volume (TYPE: crypt)
- it contains 3 logical volumes (TYPE: lvm)
- there are separate volumes for / (root) and /home
This guide is only applicable if you can see this.
$ df -h -t ext4 Filesystem Size Used Avail Use% Mounted on /dev/mapper/vgtrisquel-root 23G 19G 3.5G 84% / /dev/vda3 1.7G 173M 1.4G 12% /boot /dev/mapper/vgtrisquel-home 69G 4.4M 66G 1% /home
If /home does not appear with this command, this guide is not applicable.
We see that:
/ (called "root) is 80% used and has only 3.5G available.
/home is nearly empty and has 65.4G available.
So we might take 10 GB from home for root.
GOAL
Move 10 GBs from the home volume to the root volume.
REQUIREMENTS
Get a Trisquel ISO, verify it, and prepare a Live USB 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 Live ISO, 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
2. Resize HOME
Make sure you get the right LV (logical volume) and VG (volume group) names:
$ sudo lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert home vgtrisquel -wi-a----- 70.64g root vgtrisquel -wi-a----- 23.28g swap_1 vgtrisquel -wi-a----- <3.86g
We need to specify the volume as VG/LV. Here, we want to shrink vgtrisquel/home by 10 GB and resize the file system:
$ sudo lvresize -r -L -10G vgtrisquel/home fsck from util-linux 2.37.2 /dev/mapper/vgtrisquel-home: 151/4636672 files (2.0% non-contiguous), 436537/18519040 blocks resize2fs 1.46.5 (30-Dec-2021) Resizing the filesystem on /dev/mapper/vgtrisquel-home to 15897600 (4k) blocks. The filesystem on /dev/mapper/vgtrisquel-home is now 15897600 (4k) blocks long. Size of logical volume vgtrisquel/home changed from 70.64 GiB (18085 extents) to 60.64 GiB (15525 extents). Logical volume vgtrisquel/home successfully resized.
Now
$ sudo lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert home vgtrisquel -wi-a----- 60.64g root vgtrisquel -wi-a----- 23.28g swap_1 vgtrisquel -wi-a----- <3.86g
We see that vgtrisquel/home was shrinked from 70.64g to 60.64g.
Looking at the volume group vgtrisquel:
$ sudo pvs PV VG Fmt Attr PSize PFree /dev/mapper/mydisk vgtrisquel lvm2 a-- <97.81g 10.02g
The last column show that vgtrisquel has 10.02g free.
3. Resize ROOT
The root volume is vgtrisquel/root. Let's increase its size to take all the free space available in the volume group:
$ sudo lvresize -r -l +100%FREE vgtrisquel/root fsck from util-linux 2.37.2 /dev/mapper/vgtrisquel-root: 303601/1525920 files (0.2% non-contiguous), 4888274/6103040 blocks Size of logical volume vgtrisquel/root changed from 23.28 GiB (5960 extents) to 33.30 GiB (8526 extents). Logical volume vgtrisquel/root successfully resized. resize2fs 1.46.5 (30-Dec-2021) Resizing the filesystem on /dev/mapper/vgtrisquel-root to 8730624 (4k) blocks. The filesystem on /dev/mapper/vgtrisquel-root is now 8730624 (4k) blocks long.
4. Confirm partition sizes
$ 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 33.3G 0 lvm ├─vgtrisquel-swap_1 253:2 0 3.9G 0 lvm └─vgtrisquel-home 253:3 0 60.6G 0 lvm
So root is now 33.3 GB instead of 23.3 GB.
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 33G 19G 13G 59% / 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 60G 4.4M 57G 1% /home tmpfs 392M 120K 392M 1% /run/user/1000/
Now we have 13 GB available for root, success !!
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 with the same VM, and sizes we left before:
$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS 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 33.3G 0 lvm / ├─vgtrisquel-swap_1 253:2 0 3.9G 0 lvm [SWAP] └─vgtrisquel-home 253:3 0 60.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 Live ISO, 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 33.3G 0 lvm ├─vgtrisquel-swap_1 253:2 0 3.9G 0 lvm └─vgtrisquel-home 253:3 0 60.6G 0 lvm
Let's shrink vgtrisquel/home by 4G:
$ sudo lvresize -r -L -4G vgtrisquel/home fsck from util-linux 2.37.2 /dev/mapper/vgtrisquel-home: 151/3981312 files (2.0% non-contiguous), 395404/15897600 blocks resize2fs 1.46.5 (30-Dec-2021) Resizing the filesystem on /dev/mapper/vgtrisquel-home to 14849024 (4k) blocks. The filesystem on /dev/mapper/vgtrisquel-home is now 14849024 (4k) blocks long. Size of logical volume vgtrisquel/home changed from 60.64 GiB (15525 extents) to 56.64 GiB (14501 extents). Logical volume vgtrisquel/home successfully resized.
Time to enlarge the swap volume,
$ sudo lvresize -l +100%FREE 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.
Then, 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 33.3G 0 lvm /mnt ├─vgtrisquel-swap_1 253:2 0 7.9G 0 lvm [SWAP] └─vgtrisquel-home 253:3 0 56.6G 0 lvm
The swap is now 7.9 GB, success !!
We still need to initialize the enlarged swap space:
$ sudo mkswap /dev/vgtrisquel/swap_1 mkswap: /dev/mapper/vgtrisquel-swap_1: warning: wiping old swap signature. Setting up swapspace version 1, size = 7.9 GiB (8438935552 bytes) no label, UUID=4fc8c0c8-03cd-42c9-8e9a-66396ca98636
Now, we check the fstab:
$ sudo mount /dev/mapper/vgtrisquel-root /mnt $ grep swap /mnt/etc/fstab
The output may be like one of the two:
1. /dev/mapper/vgtrisquel-swap_1 none swap sw 0 0
2. UUID=368f4c5d-6b94-48d5-b44c-f8cef74af6df none swap sw 0 0
Only if it is like 2. (otherwise, skip this):
$ sudo sed -i '/swap/d' /mnt/etc/fstab $ echo UUID=$(lsblk -n -o UUID /dev/vgtrisquel/swap_1) none swap sw 0 0 | sudo tee -a /mnt/etc/fstab 1>/dev/null
Now, we close:
$ sudo umount /mnt $ sudo vgchange -an 0 logical volume(s) in volume group "vgtrisquel" now active $ sudo cryptsetup luksClose mydisk
Time to reboot.