Skip to content
Rolling Back Your Home Partition on a BTRFS System

Rolling Back Your Home Partition on a BTRFS System

Overview

This technical guide will walk you through the process of identifying your BTRFS partitions, exploring available snapshots for the home partition, and rolling back your home subvolume (@home) to a previous state using Snapper. It will also include troubleshooting steps in case you encounter issues along the way.

Garuda Linux KDE, which uses BTRFS as the default filesystem, supports snapshots via Snapper. This guide assumes you have Snapper set up for your home subvolume and want to perform a rollback to a previous snapshot.


Pre-requisites

  • Snapper: You should already have Snapper configured to take snapshots of the @home subvolume. If not, refer to the Snapper setup guide.
  • BTRFS Filesystem: Ensure that your /home partition uses the BTRFS filesystem and that Snapper is taking snapshots for it.
  • Backup: Always make sure you have a backup of critical data before performing a rollback.

Step 1: Identifying the Correct Partition

Before performing any rollback operations, you need to identify which partition contains your BTRFS subvolumes, including the @home subvolume.

Using lsblk to List Block Devices

lsblk -f

Example output:

NAME   FSTYPE      LABEL   UUID                                 MOUNTPOINT
sda
├─sda1 ext4                xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx  /boot
├─sda2 btrfs               yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy  /
sdb
└─sdb1 btrfs               zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz  /home

In this case:

  • /dev/sda2 is the root partition (BTRFS).
  • /dev/sdb1 is the home partition (BTRFS).

Look for FSTYPE="btrfs" and identify the partition for /home.

Using blkid to List Filesystems

sudo blkid

Example output:

/dev/sda1: UUID="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" TYPE="ext4"
/dev/sda2: UUID="yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy" TYPE="btrfs"
/dev/sdb1: UUID="zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz" TYPE="btrfs"

Identify the partition where TYPE="btrfs" is listed and matches the /home mount.

Using df -h to See Mounted Partitions

df -h

Example output:

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2       100G   30G   70G  30% /
/dev/sdb1       200G   50G  150G  25% /home

Check for /home and identify the associated device.

Using btrfs filesystem show to List BTRFS Filesystems

sudo btrfs filesystem show

Example output:

Label: none  uuid: yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy
    Total devices 1 FS bytes used 30.00GiB
    devid    1 size 100.00GiB used 50.00GiB path /dev/sda2

Label: none  uuid: zzzzzzzz-zzzz-zzzz-zzzz-zzzzzzzzzzzz
    Total devices 1 FS bytes used 50.00GiB
    devid    1 size 200.00GiB used 100.00GiB path /dev/sdb1

Here, /dev/sdb1 is the BTRFS volume containing your home subvolume.


Step 2: Listing Snapshots for the Home Subvolume

Once you’ve identified the partition, you can list the snapshots for the home subvolume (@home).

sudo snapper -c home list

Example output:

# | Type   | Pre # | Date        | User | Cleanup | Description        | Userdata
---+--------+-------+-------------+------+---------+--------------------+---------
0  | single |       |             | root |         | current             |
1  | single |       | 2024-10-01  | root | timeline| hourly snapshot    |
2  | single |       | 2024-10-02  | root | timeline| daily snapshot     |
...
  • Snapshot #: This is the snapshot identifier you will use for rollback.
  • Description: Identifies the snapshot (e.g., “hourly snapshot”).

Step 3: Exploring a Snapshot Before Rollback

You can explore a snapshot to verify its contents before rolling back. First, create a mount point:

sudo mkdir /mnt/snapshot

Mount the desired snapshot (e.g., snapshot 5):

sudo mount -o subvol=.snapshots/5/snapshot /dev/sdb1 /mnt/snapshot

Explore the mounted snapshot at /mnt/snapshot and verify its contents.

To unmount the snapshot:

sudo umount /mnt/snapshot

Step 4: Rolling Back the Home Subvolume

Option 1: Rolling Back Using a Live Environment

  1. Boot into a live environment (Garuda Live USB or similar).

  2. Mount the BTRFS filesystem:

    sudo mount /dev/sdb1 /mnt
  3. Delete the current home subvolume:

    sudo btrfs subvolume delete /mnt/@home
  4. Restore the home subvolume from the desired snapshot (e.g., snapshot 5):

    sudo btrfs subvolume snapshot /mnt/.snapshots/5/snapshot /mnt/@home
  5. Unmount and reboot your system.

Option 2: Rolling Back from a Running System

  1. Switch to a root shell:

    sudo su
  2. Unmount the home partition:

    umount /home
  3. Delete the current home subvolume:

    btrfs subvolume delete /home
  4. Restore the subvolume from the snapshot:

    btrfs subvolume snapshot /.snapshots/5/snapshot /home
  5. Remount the home partition:

    mount /home
  6. Exit the root shell:

    exit

Step 5: Verifying the Rollback

Once the rollback is complete, reboot your system and log in. Verify that your home directory is in the state it was at the time of the snapshot you restored.

You can list the snapshots again using:

sudo snapper -c home list

This should show you the current and previous snapshots, confirming the rollback.


Troubleshooting and Common Issues

  1. Snapshot Not Found:
    • If you don’t see the snapshot in the list, ensure that Snapper is correctly configured for the home subvolume by checking /etc/snapper/configs/home.
  2. Unable to Unmount /home:
    • Make sure you are logged in as root, and no user processes are using /home. You may need to log in via a different TTY or boot into a live environment.
  3. Insufficient Disk Space:
    • If the rollback fails due to insufficient space, free up space by deleting unnecessary files or older snapshots.
  4. Snapshot Restore Failed:
    • If restoring the snapshot fails, check the system logs (journalctl) for detailed error messages. You may need to manually clean up and retry.

Conclusion

Rolling back a BTRFS subvolume such as @home using Snapper is a powerful way to restore your system to a previous state. This guide covered how to:

  • Identify the correct partition.
  • List and explore available snapshots.
  • Roll back using either a live environment or from a running system.
  • Verify the rollback and troubleshoot common issues.

By following this guide, you can confidently manage your home subvolume snapshots and perform rollbacks when needed. Snapper and BTRFS provide a robust and efficient snapshot management system for Linux systems like Garuda KDE.