Add Recovery To Your Pop!_OS

For anyone who already has a none default install of Pop!_OS, there exist a way for you to get the recovery partition of System76's distribution.

I didn't know about the recovery recovery partition until I ended up purchasing a System76 laptop and using the clean install procedure. Pop!_OS has its own Recovery mode. The recovery mode is essentially a partition with a live install version of the beautiful distribution. It allows you to do full install changes, upgrades, and any other recovery requirements you may have.

If you like me, fellow reader, you may be using a more custom partition setup. Unfortunately, anything other than the default clean install on Pop!_OS means you do not get the automatically generated recovery partition of goodness. Here's a small guide over how to get the setup on an already existing install.

First, make sure you have all the tools required here:

Make the recovery partition

You now need to make sure you have 4.4 GiB of unallocated storage available on your primary disk drive. The unallocated storage space will be used to make a new FAT32 partition on your partition table.

Note, if you are using btrfs, make sure to resize the filesystem before shrinking the storage available. A required step as you may have allocations used in locations you will be removing. Hence a small rebalance for those data blocks:

btrfs filesystem resize -4.4g /

Use your favorite tool to resize the disk. Personally, I tend to just use gdisk, but you can use parted or any other tool for the task. Once you have resized, make the 4.4 GiB partition, if you haven't already, and create the FAT32 filesystem on the new partition:

# the label RECOVERY is to make easier to define later
mkfs.vfat -n RECOVERY /dev/{{ recovery_parition_id }}

Next, you need the new partition mounted on /recovery.

mount -L RECOVERY /recovery

Now comes the tricky part. You need to run pop-upgrade tool to install the Pop!_OS ISO into the recovery partition. Before you do, make sure you have open on a tail of the logs for pop-upgrade:

journalctl -flu pop-upgrade

The pop-upgrade tool has a tendency to fail and the error messages are not exactly descriptive. Having the logs available can be quite helpful in debugging what went wrong. Once you do have the logs tailed, on a separate terminal run the following:

# use 20.04 as of this writing for Focal version
pop-upgrade recovery upgrade from-release 20.04

If you have a /tmp directory with less storage available than the full ISO image size of POP!_OS, you will have troubles installing. Before this becomes an issue, make sure you have available at least 2.5 GiB of disk storage on /tmp. If you don't, you can always do a bind mount to filesystem that does temporarily. Allowing you to download the ISO. Once pop-upgrade procedure is complete, simply unbind the bind mount.

If by any chance your recovery installation fails on pop-upgrade, head over to your /etc/fstab and comment out the auto generated entry for you /recovery partition. The tool currently has an issue where it will fail if the entry exists on your filesystem table file.

Add the recovery.conf file

Ok, so now that you have the recovery partition, you need to add the recovery.conf file. First run the command below to create the file in /recovery/recovery.conf filepath with the following template:

 EFI_UUID={{ boot_efi_uuid }}
HOSTNAME=pop-os
KBD_LAYOUT=us
KBD_MODEL=
KBD_VARIANT=
LANG=en_US.UTF-8
LUKS_UUID=
OEM_MODE=0
RECOVERY_UUID={{ pop_recovery_uuid }}
ROOT_UUID=UUID={{ pop_root_uuid }}
UPGRADE=1

Edit all the {{ }} with the correct partition's UUID. To keep this easier to identify, use the PARTUUID of your partitions for all of the entries like the example below:

ROOT_UUID=PARTUUID=6fee8edb-1e18-485b-95aa-4e36f1abaa4e

Create the systemd-boot entry

Congrats, you now up to the final stretch. You only need two things here, the actual ID for your recovery partition and the partuuid of the partition. Make an entry on your systemd-boot loader entry:

title Pop!_OS recovery
linux /EFI/Recovery-{{ recovery_partition_uuid }}/vmlinuz.efi
initrd /EFI/Recovery-{{ recovery_partition_uuid }}/initrd.gz
options boot=casper hostname=recovery userfullname=Recovery username=recovery live-media-path=/casper-{{ recovery_partition_uuid }} live-media=/dev/disk/by-partuuid/{{ recovery_partition_partuuid }} noprompt

All that's left is to test the new boot entry. Simply do a restart and see if you can actually boot into the new Pop!OS recovery entry. If all went well, you now you should have a fully functioning Pop!OS recovery mode available on boot. If you had any troubles during this setup, you can look through the journal logs for pop-upgrade to see if you can resolve.

While this may seem like a lot, it is due to the fact pop-upgrade tool doesn't yet support setting up post install. If you had the luxury of doing your custom setup before any of this, you can simply add a 4.4 GiB FAT32 partition and Pop!_OS install will take care of the rest.

#100DaysToOffload #Day8 #PopOS #System76