Posted over 1 year ago. Visible to the public.

How to resize your boot partition when there is an encrypted partition after it

Boot partitions from installations prior to the 16.04 era are terribly small. When you install updates and encounter errors due to a full /boot partition, consider risizing it.

If you can't do the steps described below, ask someone experienced to help you out.
This has worked 100% so far. 1 out of 1 tries. ;)

Scenario A: There is unassigned space on your physical drive

When there is some unpartitioned space on your drive, increasing the size of /boot is actually very easy (even though the list below is rather long). It only takes a while.

  1. Back up your entire disk.
  2. Fetch a USB drive with an Ubuntu Live System (any flavor will do), a HDD/SSD that is at least the size of your encrypted partition, and a USB SATA adapter.
  3. Connect both the USB drive and the HDD via USB to your machine.
  4. Boot up the live system.
  5. Confirm that the external drive is empty. If it is not, wipe it (take care not to wipe your machine's drive!), and create a new partition. Format it to ext4.
  6. Mount the HDD and note its mount path. It starts with /media/.
  7. Open a terminal and sudo su to become root. We require root for everything.
  8. Use dd to create an image of your encrypted partition. It will not be decrypted, so it is okay to store the image on an unencrypted device.
    1. lsblk to list all drives.
      Your internal drive is probably sda and usually contains sda1 (where /boot lives), sda2 (an extended partition) and sda5 (your crypted partition) inside sda2.
      We will be using sda below; if yours is different, remember to use your drive label.
    2. dd if=/dev/sda5 of=/media/something/sda5.dd bs=1M to create an image of your encrypted partition.
      This will take a while. You can make dd print its status by opening a 2nd terminal and sending the USR1 signal via pkill -USR1 dd.
  9. Open gparted.
  10. In GParted, right-click sda5 and select "Information". Note the drive's UUID and total sectors count (you may take a screenshot and save it to the external drive).
  11. Right-click sda5 and select "Delete". Confirm, and actually the delete the partition by clicking the tick icon in the icon bar.
  12. Right-click sda2 (not the empty space inside id) and select "Resize/Move". You can drag the partition to the end of your drive using the bar representation, or copy and cut the "Free space following" value and paste it to "Free space preceding". The "New size" should stay the same. Confirm and apply via the tick icon.
  13. Click the free space inside the moved sda2 and create a new partition. It does not matter which file system you choose.
  14. Right-click your new sda5 and select "Information".
    • Confirm that the "Total sectors" count is at least the value from before. It may be higher. If it is lower, delete and check sda2's size. Re-create sda5 until there are enough sectors.
    • The UUID will be different. Restoring our image will fix that.
  15. Close GParted.
  16. In the root terminal, write your image back to the new sda5 partition: dd if=/media/something/sda5.dd of=/dev/sda5 bs=1M
  17. Open GParted again, and check sda5 to confirm its UUID has been restored. You should also see that sda5 is now a "crypt-luks" partition.
  18. Right-click sda1 and select "Resize/Move". You can now increase the size of /boot!
  19. Confirm and apply via the tick icon.
  20. Close GParted, shut down the live system, disconnect its USB pen drive, and the external HDD.
  21. Boot up your system again. It should start normally. A df -h /boot should now show your boot partition's new size!

If anything goes wrong, try again by re-creating sda2 and sda5 and restoring your dd image.
Should everything fail, restore your image from the NAS using our backup drive's restore procedure.

Scenario B: Your physical drive is fully partitioned

This is more painful. You first need to shrink your encrypted partition.
You can then follow procedure A.

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for old versions of Ruby on Rails (3.2 and 2.3).

Owner of this card:

Avatar
Arne Hartherz
Last edit:
3 months ago
by Arne Hartherz
Keywords:
linux, ubuntu, luks, crypt
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Arne Hartherz to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more