Chroot Snippet

less than 1 minute read

The Story

Some time ago, my PC wouldn’t boot.
This was my fault, as I needed to resize some partition, and resizing in Linux really means deleting the partition and creating a new one in the same place. I forgot to assign the partition the same UUID, which caused Ubuntu to resent it.
I was lazy and tried using automated boot fixers, which made things worse, and eventually had to go and operate manually.
During the surgery, I learnt about chrooting and found this nifty snippet (from here). Since I’ve been using it a lot since then, I thought I’d upload it.

The script

Note that I’m first unlocking LUKS (disk encryption) and setting up the LVM.

sudo su
cryptsetup --type luks open /dev/sda3 sda3_crypt
vgchange -a y
mkdir /mnt/system
mount /dev/mapper/ubuntu--vg-root /mnt/system
for i in /dev/pts /dev /proc /sys; do mount -B $i /mnt/system$i; done
chroot /mnt/system

The Story pt.2

Eventaully, I figured out that /etc/crypttab, used by Ubuntu’s GRUB scripts to unlock LUKS disks, doesn’t support quoting. Unlike everywhere else, where UUIDs are referenced like UUID="da30f935-a684-4415-b6ca-e991cbcc52dc", this file has to look like:

sda3_crypt UUID=da30f935-a684-4415-b6ca-e991cbcc52dc none luks

So annoying.