blog.shukriadams.com

Game devops and other things

Installing Ubuntu26 on Btrfs for Timeshift snapshots

Update: In the original post from May 26 I didn't catch that in Ubuntu 26.04 the btrfs subvolumes weren't properly created. I didn't install Timeshift after install to verify it worked. The script used for this has been updated, and Timeshift is now verified working. Now back the original post.

Timeshift is a handy application for taking snapshots of your system - this lets you roll back regrettable configuration choices. Sometimes you do risky, compound system changes that go wrong, and you wish you could clean them up and make them disappear, entirely. Timeshift lets you do this properly by using atomic filesystem forks that are guaranteed to work. If you want to roll back a hundred different things, it will undo all of them, not 99 plus a single exception, leaving your system hanging in a weird intermediate state. Timeshift achieves this by forking the filesystem and then reverted the fork, meaning all changes after the fork disappear. Forking doesn't copy files so it's instant and doesn't take extra space.

Timeshift, at least at the time of writing, works on only one filesystem, BTRFS. Timeshift also requires that your boot and efi partitions are kept seperate from the root partition and are mounted as BTRSFS subvolumes, meaning you likely need to reinstall Linux from scratch to get it working. Many distros support BTRFS subvolume setup during installation, but Ubuntu removed that functionality as of 24.04. It is still possible to get it working, but you need to hack around in your new Linux setup during installation. After a lot of failed attempts from incomplete guides I stumbled on an unmaintained script that on Ubuntu 24.04 finalized the setup for me. Normally I don't run strange scripts on my system, but this one was simple enough to read and understand, so much so that I forked and updated it to work with 26.04.

This process is now confirmed working for Ubuntu 26.04, and assumes you're going to do a full install onto a single disk and completely overwrite everything on it. Lets get into it.

  • Boot your system from the Ubuntu install ISO.
  • Proceed as you normally would, when you get to disk setup choose "manual installation".
  • Delete all existing partitions on the disk you intend to install to.
  • In the "Device for boot loader" menu select the target install disk, this should automatically create a FAT32 paritition that mounts /boot/efi. If this doesn't happen, your system is likely not set up with EFI support, check your VM/BIOS settings, then restart the install process until this works.
  • Create an additional EXT4 partition, 1GB in size (change size units in dropdown to GB), select /boot in the mounts dropdown.
  • Finally create your root data partition using all remaining disk space, the filesystem should be btrfs, and selct / from the mounts dropdown.
  • Disk setup is done, click Next and continue installing. Your should get a confirmation prompt that you're installing to three partitions, /boot/efi, /boot and / respectively. If you see anything else, the install will almost certainly fail later.
  • Assuming success, you'll get a prompt to reboot or continue testing - select the latter. This drops you onto the Ubuntu installer desktop.
  • Open Firefox, go to https://github.com/shukriadams/btrfs-encrypt-root, select the btrfs-encrypt-root.sh script and download it to your system. Read the script contents to see what it's doing. You did read it, right?
  • Open a terminal, make the script executable with chmod +x btrfs-encrypt-root.sh.
  • Run the script as root with no arguments - sudo ./btrfs-encrypt-root.sh. It will explain what it can do and which arguments it wants - in this case, it wants the short device names for the three mount points from the previous install. You can get these by running lsblk. Note the order of the arguments - root, then boot, then efi.
  • Run sudo ./btrfs-encrypt-root.sh --only-subvols <root-dev> <boot-dev> <efi-dev>, substituting your values. It needs short names only, so for egs sudo ./btrfs-encrypt-root.sh --only-subvols sda3 sda2 sda1. You should see several lines of output as it unmounts, remounts and creates BTRFS subvolumes.
  • Reboot, and when you're in your new Ubuntu install list root subvolumes with sudo btrfs su li /, this should list back several things including path @ and path @home. If it lists nothing, an error occurred during the script run.
  • You can now install Timeshift and set it use BTRFS instead of rsync.

I want to give a big thanks to the original script author, Torsten Bronger, for replacing functionality that Canonical removed for no good reason. I would have preferred merging my fix into his project but it's no longer being maintained, so I opted to continue with my fork.