Restore snapshot with timeshift from a live medium with LUKS and LVM

Today I learned to restore a snapshot with timeshift on a LUKS and LVM installation of Ubuntu.

Restore snapshot with timeshift from a live medium with LUKS and LVM

Today (Sunday) I messup up my Laptop and could not boot anymore. No idea why but I also did not want to tackle the problem. I just did not have the time for it and also need the laptop ready for work on Monday.

I am glad I just have Timeshift running for my root filesystem. Everything except my home directory is backed up and I can just restore a snapshot and boot again.

The restore process would be a very easy process but since I have an encrypted LUKS setup with LVM I had a few obstacles. I just write down my procedure for the next time and others.

Start a live distro

Boot from ubuntu live USB or what ever distro you can run Timeshift on:

Check your drives:

lsblk
nvme0n1                 259:0    0 465,8G  0 disk  
├─nvme0n1p1             259:1    0     1G  0 part
├─nvme0n1p2             259:2    0   512M  0 part
└─nvme0n1p3             259:3    0 464,3G  0 part  

Open the LUKS encrypted drive:

sudo cryptsetup open /dev/nvme0n1p3

Since LUKS and LVM do not play perfectly together you have to do a few steps now.

Identify volume group:

sudo vgdisplay --short
"system" 464,24 GiB [459,62 GiB used / 4,62 GiB free]

List your logical volumes:

sudo lvs
  LV   VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root system -wi-ao---- 451,62g                                                    
  swap system -wi-ao----   8,00g

Activate your logical volumes:

sudo lvchange -ay system

Mount your root filesystem in some folder:

mkdir nvme
sudo mount /dev/system/root

Found these instructions here:

How to mount encrypted LVM logical volume – sleeplessbeastie’s notes

There are almost still valid except that opening and closing a LUKS device has a change in syntax.

Restore data with timeshift

Install timeshift. Here are the instructions:

teejee2008/timeshift
System restore tool for Linux. Creates filesystem snapshots using rsync+hardlinks, or BTRFS snapshots. Supports scheduled snapshots, multiple backup levels, and exclude filters. Snapshots can be re...
sudo add-apt-repository -y ppa:teejee2008/timeshift
sudo apt-get update
sudo apt-get install timeshift

Open timeshift and Go to Settings -> Location and choose your root file system, or where ever you your backups.

This is a screenshot from my normal booted system. It looks slightly different when you boot from USB but you get the idea.

Now browse your snapshots and choose to restore:  

Timeshift will automatically find the /boot partition and /boot/efi partition.

Restoring now is just an order of following the wizard now.

Prepare for restart

Here comes the kicker. You should not just restart now because of LVM and LUKS.

Unmount your root system:

sudo umount root

Umount timeshift mount point:

lsblk
nvme0n1                 259:0    0 465,8G  0 disk  
├─nvme0n1p1             259:1    0     1G  0 part
├─nvme0n1p2             259:2    0   512M  0 part
└─nvme0n1p3             259:3    0 464,3G  0 part  
  └─crypt_dev_nvme0n1p3 253:0    0 464,3G  0 crypt 
    ├─system-root       253:1    0 451,6G  0 lvm   /run/timeshift/backup
sudo umount /run/timeshift/backup

Deactivate LVM:

sudo lvchange -an system

Close your LUKS device

sudo cryptsetup close /dev/nvme0n1p3

Restart your system

Now you should have a bootable system restored be happy about having backups.

Big thanks to Timeshift, one of the first programs I configure on my Desktop deivces.