Skip to content

tetam01/snapper-rollback-guide

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 

Repository files navigation

Manual Snapshot Rollback Reference

Why?

This is a reference file for rolling back a snapshot the manual (Arch?) way. Check to see if your system has a Snapper-Rollback.py script installed. If so, use the script instead. If not, follow this guide. Directions for the python script can be found here.

My system uses the BTRFS subvolume layout suggested here.

Caution!

Read the guide fully before you begin, as you will want to know what each command is doing. I am not liable for any damage done to your system. This is simply a command reference guide, so many commands will have to be modified to match the uniqueness of your system compared to mine.

Prerequisites:

  • Bootable Arch Installer
  • Snapshot Number to rollback to

If you are not sure which snapshot number is your most recent, I will include a command later in this guide to help you find it.

Encrypted Drive?

If you have an encrypted drive, this command will prompt for your passphrase and will decrypt the drive.

[root@host ~]# cryptsetup luksOpen /dev/nvme0n1p2 cryptdrive

Steps:

1. Boot your Arch Linux installer.

2. Mount the toplevel subvolume by ID.

[root@host ~]# mount -o subvolid=5 /dev/mapper/cryptdrive /mnt

In my case, the subvolume ID is 5. If it was not specified 0 is usually the default.

3. Find your the snapshot number and date of snapshot using the following command.

[root@host ~]# grep -r '<date>' /mnt/@snapshots/*/info.xml	- Take note of the snapshot numbers found at the asterisk

4. Move the root directory to another location.

[root@host ~]# mv /mnt/@ /mnt/@.broken

You can move this root to any temporary location you want. I chose this location (@.broken) for simplicity.

5. Create a new root directory from the snapshot you want to restore.

This new root directory will have read-write permissions while the snapshot is originally read-only.

[root@host ~]# btrfs subvolume snapshot /mnt/@snapshots/<number>/snapshot /mnt/@

6. Check your fstab and bootloader configurations to make sure the subvolid is correct.

Check your fstab file and bootloader that can be found here:

File Path
fstab /mnt/@/etc/fstab
bootloader /mnt/boot

The subvolid can also be found by running the following command: btrfs subvolume list /mnt | grep @$

Remember: the default should be subvolid=0. The bootloader can be checked a later point when the ESP is mounted here at that path.

7. Use chroot in the new root directory to regenerate the kernel image.

[root@host ~]# umount /mnt
[root@host ~]# mount -o subvol=@ /dev/mapper/cryptdrive /mnt
[root@host ~]# mount -o subvol=@home /dev/mapper/cryptdrive /mnt/home
[root@host ~]# mount -o subvol=@var_pkgs /dev/mapper/cryptdrive /mnt/var/cache/pacman/pkg
[root@host ~]# mount -o subvol=@var_log /dev/mapper/cryptdrive /mnt/var/log
[root@host ~]# mount -o subvol=@srv /dev/mapper/cryptdrive /mnt/srv
[root@host ~]# mount -o subvol=@root /dev/mapper/cryptdrive /mnt/root
[root@host ~]# mount -o subvol=@snapshots /dev/mapper/cryptdrive /mnt/.snapshots
[root@host ~]# mount /dev/nvme0n1p1 /mnt/boot

[root@host ~]# arch-chroot /mnt

[root@host ~]# mkinitcpio -p linux

[root@host ~]# exit

Complete: Time to reboot and find out if you win or lose...

About

Guide to manually rolling back snapshots on Linux

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published