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
@homesubvolume. If not, refer to the Snapper setup guide. - BTRFS Filesystem: Ensure that your
/homepartition 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 -fExample 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 /homeIn this case:
/dev/sda2is the root partition (BTRFS)./dev/sdb1is the home partition (BTRFS).
Look for FSTYPE="btrfs" and identify the partition for /home.
Using blkid to List Filesystems
sudo blkidExample 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 -hExample output:
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 100G 30G 70G 30% /
/dev/sdb1 200G 50G 150G 25% /homeCheck for /home and identify the associated device.
Using btrfs filesystem show to List BTRFS Filesystems
sudo btrfs filesystem showExample 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/sdb1Here, /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 listExample 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/snapshotMount the desired snapshot (e.g., snapshot 5):
sudo mount -o subvol=.snapshots/5/snapshot /dev/sdb1 /mnt/snapshotExplore the mounted snapshot at /mnt/snapshot and verify its contents.
To unmount the snapshot:
sudo umount /mnt/snapshotStep 4: Rolling Back the Home Subvolume
Option 1: Rolling Back Using a Live Environment
Boot into a live environment (Garuda Live USB or similar).
Mount the BTRFS filesystem:
sudo mount /dev/sdb1 /mntDelete the current home subvolume:
sudo btrfs subvolume delete /mnt/@homeRestore the home subvolume from the desired snapshot (e.g., snapshot
5):sudo btrfs subvolume snapshot /mnt/.snapshots/5/snapshot /mnt/@homeUnmount and reboot your system.
Option 2: Rolling Back from a Running System
Switch to a root shell:
sudo suUnmount the home partition:
umount /homeDelete the current home subvolume:
btrfs subvolume delete /homeRestore the subvolume from the snapshot:
btrfs subvolume snapshot /.snapshots/5/snapshot /homeRemount the home partition:
mount /homeExit 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 listThis should show you the current and previous snapshots, confirming the rollback.
Troubleshooting and Common Issues
- Snapshot Not Found:
- If you don’t see the snapshot in the list, ensure that Snapper is correctly configured for the
homesubvolume by checking/etc/snapper/configs/home.
- If you don’t see the snapshot in the list, ensure that Snapper is correctly configured for the
- 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.
- Make sure you are logged in as root, and no user processes are using
- Insufficient Disk Space:
- If the rollback fails due to insufficient space, free up space by deleting unnecessary files or older snapshots.
- 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.
- If restoring the snapshot fails, check the system logs (
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.