Revision of How to resize Trisquel's default encrypted partitions from Sun, 09/22/2024 - 11:22
The revisions let you track differences between multiple versions of a post.
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
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.