my disk is encrypted, but boot partition is by default 512MB how to increase boot partition?
also how to increase boot partition during fresh new install?
ubuntu 20.04
my disk is encrypted, but boot partition is by default 512MB how to increase boot partition?
also how to increase boot partition during fresh new install?
ubuntu 20.04
I originally installed Ubuntu 20.04, which unfortunately has a bug in that it creates a /boot partition that is much too small. Any time I would install updates, I would run into errors because /boot wouldn't have enough space in it.
I just did this ... but I don't recommend it. I'm rather technical, but it was very time consuming and at various points I was afraid I had completely wiped my data. I also wasn't able to find a current reference for how to do this.
Having said that, while I've never worked with encryption, I do think it was made easier by having some previous knowledge of LVMs and partitioning. It was also made easier by the fact that GParted did what I think is the most dangerous part: resizing the partition.
I'll try to add explanations as much as possible but if you don't understand the steps, again, I would recommend instead backing up your data and doing a clean install of Ubuntu (22.04 or later so the bug is fixed). It would be much easier.
Most of the steps below are specific to the system I ran them an and will need to be updated for your system, and they may contain errors as I typed them from another computer and was unable to copy and paste.
(Recommended) Clean up disk space
This will make some of the process quicker as there will be less data to back up and less to move
I like to use Disk Usage Analyzer:
sudo apt install baobab
Back up everything
⚠️ This is very risky and there's a strong possibility you'll lose all of your data. Back up anything you want to keep.
Open GParted (install if necessary) and identify partitions
For example, this is what I see:
| /dev/nvme0n1p1 | fat32 | /boot/efi |
| /dev/nvme0n1p2 | ext4 | /boot |
| /dev/nvme0n1p3 | [Encypted] lvm2 pv | vgubuntu |
You can also use lsblk, e.g.
nvme0n1 259:0 0 953.9G 0 disk
├─nvme0n1p1 259:1 0 512M 0 part /boot/efi
├─nvme0n1p2 259:2 0 732M 0 part /boot
└─nvme0n1p3 259:3 0 952.7G 0 part
└─nvme0n1p3_crypt
252:0 0 952.6G 0 crypt
├─vgubuntu-root
│ 252:1 0 920.6G 0 lvm /
└─vgubuntu-swap_1
252:2 0 32G 0 lvm [SWAP]
Create a live USB installation of Ubuntu and boot to it
(Optional) List partitions with lsblk
nvme0n1 259:0 0 953.9G 0 disk
├─nvme0n1p1 259:1 0 512M 0 part
├─nvme0n1p2 259:2 0 732M 0 part
└─nvme0n1p3 259:3 0 952.7G 0 part
Open the encrypted partition
sudo cryptsetup luksOpen /dev/nvme0n1p3 nvme0n1p3_crypt
ⓘ This allows modifying the LVM inside the encrypted partition
List partitions again with lsblk
Confirm you can see the partitions inside the encrypted partition (everything under nvme0n1p3 in this case):
nvme0n1 259:0 0 953.9G 0 disk
├─nvme0n1p1 259:1 0 512M 0 part
├─nvme0n1p2 259:2 0 732M 0 part
└─nvme0n1p3 259:3 0 952.7G 0 part
└─nvme0n1p3_crypt
252:0 0 952.6G 0 crypt
├─vgubuntu-root
│ 252:1 0 920.6G 0 lvm
└─vgubuntu-swap_1
252:2 0 32G 0 lvm
Activate LVM volumes
sudo vgscan --mknodes
sudo vgchange -ay
Make sure the volume group and logical volumes are visible
sudo pvdisplay
sudo lvdisplay
Calculate the new size of the root volume
The /boot partition should be 2.0 GB and is currently 732 MB (from my example), so I want to increase the size of the /boot partition by 1.3 and decrease the size of the root partition by the same amount, so the final size of the root partition will be 919.3 GB
Shrink the contents of the encrypted partition
ⓘ We'll be shrinking the file system, then shrinking the logical volume, then shrinking the physical volume, shrinking the LUKS, all so we can finally shrink the physical partition in a later step
Check filesystem integrity, e.g.
sudo e2fsck -f /dev/mapper/vgubuntu-root
Resize the filesystem
For example:
sudo resize2fs /dev/mapper/vgubuntu-root 827G
ⓘ To be save, use a size 90% smaller than the size you calculated above. This allows margin for error, and we will then expand the filesystem after to fill all available space.
Check the filesystem again, e.g.
sudo e2fsck -f /dev/mapper/vgubuntu-root
Resize the logical volume
Again, to be safe, we'll us a size smaller than we need for now and resize it later to fill the whole physical volume. This time we'll use a size 95% smaller:
sudo lvreduce -L 873G /dev/mapper/vgubuntu-root
Expand the filesystem to fit the logical volume, e.g.
sudo resize2fs /dev/mapper/vgubuntu-root
Shrink the physical volume
List the logical volumes again
sudo lvdisplay
Note the size of the swap partition
In my case, the swap partition was 32.00 GiB
Remove the swap partition
sudo lvremove /dev/vgubuntu/swap_1
ⓘ This is necessary because we shrank the root partition, leaving empty space in the volume group between the root partition and the swap partition
Shrink the physical volume
As above, we'll use a smaller size to be safe. Pick a size between the size of the logical volume we just resized and the final desired size, which in this example would be 951.34 GiB (919.34 GiB plus 32.00 GiB for swap)
sudo pvresize --setphysicalvolumesize 900G /dev/mapper/nvme0n1p3_crypt
Note the output, e.g. "Pretending size is 1887436800 not 1997826048 sectors."
Close the LVM
sudo vgchange -an
Close the encrypted volume
sudo cryptsetup luksClose nvme0n1p3_crypt
Resize LUKS mapping
⚠️ I'm not actually sure if this part is necessary (https://unix.stackexchange.com/a/416356)
Again, we're going to play it safe here. We're going to pick a number between the numbers of the last command, so (1887436800+1997826048)/2 = 1942631424
sudo cryptsetup -b 1942631424 resize nvme0n1p3_crypt
Resize the encrypted partition
Open GParted
Figure out how much to shrink the partition
Right-click the encrypted partition > Open Encryption
Right-click the encrypted partition > Resize/Move
Set the new size > Resize
Click the green Apply all operations button
Right-click the partition again > Deactivate
Right-click the partition again > Close Encryption
Move the encrypted partition
In GParted, right-click the partition again > Resize/Move
Adjust the partition so all the free space is at the beginning of the partition > Resize/Move
Click the green Apply all operations button
ⓘ This will take a while
Resize the boot partition
In GParted, right-click the boot partition > Resize/Move
Expand it to fill all of the available free space > Resize/Move
Click the green Apply all operations button
Exit GParted
Resize everything in the encrypted partition to fill the available space
ⓘ We'll be doing the opposite of what we did before: grow the physical volume, grow the logical volume, then grow the filesystem
Open the encrypted partition
sudo cryptsetup luksOpen /dev/nvme0n1p3 nvme0n1p3_crypt
(Optional) Check the status of the encrypted partition
sudo cryptsetup status nvme0n1p3_crypt
It should have automatically resized to the new size of the partition
Resize the physical volume to fill the available space
sudo pvresize /dev/mapper/nvme0n1p3_crypt
Resize the root logical volume
Take the size of the physical volume (951.3 GiB in our example) and subtract the size of the swap you will create (32.00 GiB in our example, so 919.3 GiB), and use that to resize the logical volume, e.g.
sudo lvresize -L 919.3G /dev/vgubuntu/root
Re-create the swap logical volume
We'll tell it to use all of the available free space in the volume group:
sudo lvcreate -l 100%FREE -n swap_1 vgubuntu
Format the swap partition
sudo mkswap /dev/mapper/vgubuntu-swap_1
Check the filesystem again, e.g.
sudo e2fsck -f /dev/mapper/vgubuntu-root
Expand the filesystem to fit the logical volume
sudo resize2fs /dev/mapper/vgubuntu-root
Check the filesystem again, e.g.
sudo e2fsck -f /dev/mapper/vgubuntu-root
Close the LVM
sudo vgchange -an
Close the encrypted volume
sudo cryptsetup luksClose nvme0n1p3_crypt
Reboot and pray your system still works and you don't need to restore from backup