Preface

Dear BTRFS folks, I’m using snapper in openSUSE.

For learning purpose I did % snapper rollback. It was more like a curiosity reason about snapper, but become a blunder.

BTRFS Mount Trapped in Snapper Rollback

After % snapper rollback, my % snapper list become empty.

% sudo snapper list
[sudo] password for root: 
Type   | # | Pre # | Date | User | Cleanup | Description | Userdata
-------+---+-------+------+------+---------+-------------+---------
single | 0 |       |      | root |         | current     |     

And this strange error message from snapper.

% sudo snapper rollback
IO error (.snapshots is not a btrfs subvolume).

It seems like root filesystem mounted to a snapshot volume as shown in command below.

% mount | grep '/dev/sda8 on / type'
/dev/sda8 on / type btrfs (rw,relatime,space_cache,subvolid=400,subvol=/@/.snapshots/75/snapshot)

Snapper: Rollback Issue

How do I solve the issue, undo the rollback to my normal filesystem ?

The answer is, add .snapshots entry in /etc/fstab.


Before The Issue

I actually had wonderful life with snapper.

Reading

Setup Subvolume for Root

% sudo snapper -c root create-config /
% sudo snapper list-configs
Config | Subvolume
-------+----------
root   | /

Configuration

% sudo cat /etc/snapper/configs/root
...
# limit for number cleanup
NUMBER_MIN_AGE="1800"
NUMBER_LIMIT="20"
NUMBER_LIMIT_IMPORTANT="7"
...

Some Cool Commands

% sudo snapper status 3..7
...
c..... /var/lib/systemd/random-seed
c..... /var/lib/wicked/lease-wlp3s0-dhcp-ipv4.xml
c..... /var/lib/wicked/lease-wlp3s0-dhcp-ipv6.xml
c..... /var/lib/zypp/AutoInstalled

Or if you wish, summary using line count.

% sudo snapper status 3..7 | wc -l
1805

snapper: status

Undo Change

% sudo snapper undochange 11..39

Even delete

% for i in `seq 11 39`; do sudo snapper delete --sync $i; done

Make a snapshot

% snapper -c config create --description backup.epsi

Solving The Issue

First I need to add this line to /etc/fstab

UUID=e901452a-b3ea-48d2-acdb-6687fad0be50 /.snapshots btrfs subvol=@/.snapshots   0 0

and mount it, no need to reboot.

% sudo mount /.snapshots

Get current snap

In my case, previously I have snapshot number 75. This is below just an example.

% sudo btrfs subvolume show /
@/.snapshots/45/snapshot
	Name: 			snapshot
	UUID: 			29d4436b-72d1-f14d-a9e9-f04b70c0ebe0
	Parent UUID: 		efa9f21b-f3b7-3543-9649-3897e083b39d
	Received UUID: 		-
	Creation time: 		2018-01-03 00:15:01 +0700
	Subvolume ID: 		355
	Generation: 		5677
	Gen at creation: 	3968
	Parent ID: 		301
	Top level ID: 		301
	Flags: 			-
	Snapshot(s):
				@/.snapshots/50/snapshot
				@/.snapshots/51/snapshot
% sudo btrfs subvolume get-default /
ID 355 gen 5682 top level 301 path @/.snapshots/45/snapshot 

BTRFS: get default subvolume

list snapper

% sudo snapper list
Type   | #  | Pre # | Date                            | User | Cleanup  | Description  | Userdata     
-------+----+-------+---------------------------------+------+----------+--------------+--------------
single | 0  |       |                                 | root |          | current      |              
single | 3  |       | Mon 01 Jan 2018 02:45:03 PM WIB | root | timeline | timeline     |              
single | 7  |       | Mon 01 Jan 2018 04:30:01 PM WIB | root | timeline | timeline     |              
single | 40 |       | Tue 02 Jan 2018 10:15:01 PM WIB | root | timeline | timeline     |              
single | 41 |       | Tue 02 Jan 2018 10:52:35 PM WIB | root |          | backup.epsi  |              
pre    | 42 |       | Tue 02 Jan 2018 11:01:48 PM WIB | root | number   | zypp(zypper) | important=yes
post   | 43 | 42    | Tue 02 Jan 2018 11:07:23 PM WIB | root | number   |              | important=yes
single | 44 |       | Tue 02 Jan 2018 11:15:01 PM WIB | root | timeline | timeline     |              
single | 45 |       | Wed 03 Jan 2018 12:15:01 AM WIB | root | timeline | timeline     |              
pre    | 46 |       | Wed 03 Jan 2018 12:16:34 AM WIB | root | number   | zypp(zypper) | important=no 
post   | 47 | 46    | Wed 03 Jan 2018 12:19:38 AM WIB | root | number   |              | important=no 
pre    | 48 |       | Wed 03 Jan 2018 12:47:47 AM WIB | root | number   | zypp(zypper) | important=no 
post   | 49 | 48    | Wed 03 Jan 2018 12:48:10 AM WIB | root | number   |              | important=no 
...

I decide to go back to 45.

Get BTRFS ID

% sudo btrfs subvolume list -a /
ID 257 gen 4804 top level 5 path <FS_TREE>/@
ID 258 gen 5096 top level 257 path <FS_TREE>/@/opt
ID 259 gen 4157 top level 257 path <FS_TREE>/@/srv
ID 260 gen 5672 top level 257 path <FS_TREE>/@/tmp
ID 261 gen 5538 top level 257 path <FS_TREE>/@/usr/local
ID 262 gen 5688 top level 257 path <FS_TREE>/@/var/cache
ID 263 gen 4157 top level 257 path <FS_TREE>/@/var/crash
ID 264 gen 4157 top level 257 path <FS_TREE>/@/var/lib/libvirt/images
ID 265 gen 4157 top level 257 path <FS_TREE>/@/var/lib/machines
ID 266 gen 4157 top level 257 path <FS_TREE>/@/var/lib/mailman
ID 267 gen 4157 top level 257 path <FS_TREE>/@/var/lib/mariadb
ID 268 gen 4157 top level 257 path <FS_TREE>/@/var/lib/mysql
ID 269 gen 4157 top level 257 path <FS_TREE>/@/var/lib/named
ID 270 gen 4157 top level 257 path <FS_TREE>/@/var/lib/pgsql
ID 271 gen 5688 top level 257 path <FS_TREE>/@/var/log
ID 272 gen 4157 top level 257 path <FS_TREE>/@/var/opt
ID 273 gen 5688 top level 257 path <FS_TREE>/@/var/spool
ID 274 gen 5672 top level 257 path <FS_TREE>/@/var/tmp
ID 301 gen 5674 top level 257 path <FS_TREE>/@/.snapshots
ID 304 gen 3008 top level 301 path <FS_TREE>/@/.snapshots/3/snapshot
ID 311 gen 3160 top level 301 path <FS_TREE>/@/.snapshots/7/snapshot
ID 345 gen 3737 top level 301 path <FS_TREE>/@/.snapshots/40/snapshot
ID 350 gen 3849 top level 301 path <FS_TREE>/@/.snapshots/41/snapshot
ID 351 gen 3862 top level 301 path <FS_TREE>/@/.snapshots/42/snapshot
ID 353 gen 3874 top level 301 path <FS_TREE>/@/.snapshots/43/snapshot
ID 354 gen 3887 top level 301 path <FS_TREE>/@/.snapshots/44/snapshot
ID 355 gen 5688 top level 301 path <FS_TREE>/@/.snapshots/45/snapshot
ID 356 gen 3972 top level 301 path <FS_TREE>/@/.snapshots/46/snapshot
ID 357 gen 3980 top level 301 path <FS_TREE>/@/.snapshots/47/snapshot
ID 358 gen 4021 top level 301 path <FS_TREE>/@/.snapshots/48/snapshot
ID 359 gen 4022 top level 301 path <FS_TREE>/@/.snapshots/49/snapshot

I find the ID of 45, it is 355.

Change default

To make it writable

% sudo btrfs property set -ts /.snapshots/45/snapshot ro false

And make it default

% sudo btrfs subvolume set-default 355 /

Then reboot

Remove the annoying snapshot.

% sudo snapper delete 75
% sudo snapper delete 76
% sudo snapper delete 77
% sudo snapper list

That’s all


Conclusion

I have to learn about the basic of BTRFS before going back to snapper !

Thank you for reading