Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

I'm unable to revert to a Btrfs snapshot.

Linux Kernel, Network, and Services configuration.
Post Reply
Message
Author
User avatar
s3a
Posts: 831
Joined: 2008-07-17 22:13
Has thanked: 6 times
Been thanked: 2 times

I'm unable to revert to a Btrfs snapshot.

#1 Post by s3a »

Hello to everyone that's reading this. :)

I took a snapshot with a test folder on the desktop, and I then deleted it, and I want to restore it by booting to the snapshot that has the folder.

Code: Select all

root@debian-btrfs-snapshot-testing:~# btrfs subvolume list /
ID 262 gen 11647 top level 5 path home/user/btrfs_snapshots_dir/snap
ID 267 gen 18957 top level 5 path home/user/My_Btrfs_Snapshots_Yo/one
root@debian-btrfs-snapshot-testing:~#

root@debian-btrfs-snapshot-testing:~# cat /etc/fstab 
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# systemd generates mount units based on this file, see systemd.mount(5).
# Please run 'systemctl daemon-reload' after making changes here.
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/vda1 during installation
UUID=I_removed_the_UUID_from_the_forum_post_just_in_case /               btrfs   defaults,compress=zstd,autodefrag,subvolid=267        0       0
/dev/sr0        /media/cdrom0   udf,iso9660 user,noauto     0       0
root@debian-btrfs-snapshot-testing:~#

root@debian-btrfs-snapshot-testing:~# cat /etc/mtab | grep -i vd
/dev/vda1 / btrfs rw,relatime,compress=zstd:3,space_cache,autodefrag,subvolid=5,subvol=/ 0 0
root@debian-btrfs-snapshot-testing:~#
I'm trying to mount the subvolume with subvolume ID 267 (via the /etc/fstab file), but as can be seen in /etc/mtab, the operating system keeps mounting the default subvolume (with subvolume ID 5).

What am I doing wrong, and how can I fix it?

Any input would be greatly appreciated!

P.S.
I'm using bullseye / testing.
Use Mnemosyne to Study for School!

User avatar
bester69
Posts: 2072
Joined: 2015-04-02 13:15
Has thanked: 24 times
Been thanked: 14 times

Re: I'm unable to revert to a Btrfs snapshot.

#2 Post by bester69 »

s3a wrote:Hello to everyone that's reading this. :)

I took a snapshot with a test folder on the desktop, and I then deleted it, and I want to restore it by booting to the snapshot that has the folder.

Code: Select all

root@debian-btrfs-snapshot-testing:~# btrfs subvolume list /
ID 262 gen 11647 top level 5 path home/user/btrfs_snapshots_dir/snap
ID 267 gen 18957 top level 5 path home/user/My_Btrfs_Snapshots_Yo/one
root@debian-btrfs-snapshot-testing:~#

root@debian-btrfs-snapshot-testing:~# cat /etc/fstab 
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# systemd generates mount units based on this file, see systemd.mount(5).
# Please run 'systemctl daemon-reload' after making changes here.
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/vda1 during installation
UUID=I_removed_the_UUID_from_the_forum_post_just_in_case /               btrfs   defaults,compress=zstd,autodefrag,subvolid=267        0       0
/dev/sr0        /media/cdrom0   udf,iso9660 user,noauto     0       0
root@debian-btrfs-snapshot-testing:~#

root@debian-btrfs-snapshot-testing:~# cat /etc/mtab | grep -i vd
/dev/vda1 / btrfs rw,relatime,compress=zstd:3,space_cache,autodefrag,subvolid=5,subvol=/ 0 0
root@debian-btrfs-snapshot-testing:~#
I'm trying to mount the subvolume with subvolume ID 267 (via the /etc/fstab file), but as can be seen in /etc/mtab, the operating system keeps mounting the default subvolume (with subvolume ID 5).

What am I doing wrong, and how can I fix it?

Any input would be greatly appreciated!

P.S.
I'm using bullseye / testing.
I think you need to update-grub to point to new id subvolume snapshot.. to avoid this is better to use subvolme name in fstab suchs as rootsys (subvol=rootsys).. for that you need to use always that subvolder subvolume name.. and when you want to rollback you need to mount root and replace old subvolume with one you want to rollbacj such like this.:

sudo mount -t btrfs /dev/sdX /mnt
cd /mnt
sudo mv rootsys rootsys.old
sudo btrfs subvolume snapshot rootsys.old/.snapshots/1/snapshot rootsys
sudo btrfs mv rootsys.old/.snapshots rootsys/
sudo btrfs subvolume delete rootsys.old
reboot

this way fstab will always be able to find the new snapshot ....

-------------

I forgot to tell, for doing this you should put root subvolume folder one level above root partition... if you didnt :!:
you will have to change default id for root partition to recover that snapshot...:
something like:
sudo mount -t btrfs -o subvolid=<<NewDefault>> /dev/sdaX /mnt
sudo brtrfs subvolume set-default /mnt (pathforNewdefault)

In Resuem, to avoid troubles: :idea:
- root subvolume must be within a subvolume folder (named rootsys)
- fstab must call that root subvolume by option idname. (subvol=/rootsys)
- when you want to recover an ID numver subvolume, you will rename rootsys to rootsys.del (you can rename with root mounted with no troubles)
and create a snapshot of ID number subvolume with rootsys name, and reboot.



,
Last edited by bester69 on 2021-06-26 12:51, edited 4 times in total.
bester69 wrote:STOP 2030 globalists demons, keep the fight for humanity freedom against NWO...

p.H
Global Moderator
Global Moderator
Posts: 3049
Joined: 2017-09-17 07:12
Has thanked: 5 times
Been thanked: 132 times

Re: I'm unable to revert to a Btrfs snapshot.

#3 Post by p.H »

/etc/fstab is in the root filesystem, so it obviously cannot be used when mounting the root filesystem.

Root mount options may be set either
- in the rootflags= parameter passed by GRUB to the kernel command line
- in the filesystem default mount options if it supports such feature (ext4 does, don't know about btrfs)

In the case of btrfs, it may also be possible to change the default subvolume. I did not check.

User avatar
s3a
Posts: 831
Joined: 2008-07-17 22:13
Has thanked: 6 times
Been thanked: 2 times

Re: I'm unable to revert to a Btrfs snapshot.

#4 Post by s3a »

Sorry for the huge delay, and thanks for the responses.

I read what was said several times, and I'm still confused.

bester69, in particular, I'm confused about how to get rootsys. How can I get the currently-used subvolume to be a snapshot in the snapshot directory (which I have in /home/user/My_Btrfs_Snapshots_Yo)?


If I mount the filesystem that's already mounted on "/" (without the quotes) on "/mnt" (without the quotes) as well (such that it's mounted on both "/" (without the quotes) and "/mnt" (without the quotes)), I just see this (so nothing unusual).:

Code: Select all

user@debian-btrfs-testing:~$ ls -a /mnt
.    boot  home            lib    libx32  opt   run   sys  var
..   dev   initrd.img      lib32  media   proc  sbin  tmp  vmlinuz
bin  etc   initrd.img.old  lib64  mnt     root  srv   usr  vmlinuz.old
user@debian-btrfs-testing:~$
As stated in a previous post and above in this post, my snapshot directory is in "/home/user" (without the quotes), which is below "/" (without the quotes). Isn't "/" (without the quotes) the root / uppermost folder? :P How am I supposed to have the snapshot folder be above it? If it's mounted on "/mnt" (without the quotes), then I suppose if I had a snapshot folder in "/" (without the quotes), that could work, assuming that that is what you meant.

Still, I don't understand what rootsys is (in a specific, non-abstract way) and how to get it.

Could you please help clarify the situation for me? If I know what rootsys is exactly and how to get it, then it seems like the rest is just a bunch of moving / renaming with the mv command-line utility, followed by a reboot.
Use Mnemosyne to Study for School!

User avatar
bester69
Posts: 2072
Joined: 2015-04-02 13:15
Has thanked: 24 times
Been thanked: 14 times

Re: I'm unable to revert to a Btrfs snapshot.

#5 Post by bester69 »

s3a wrote: 2021-07-01 06:22 ....
Still, I don't understand what rootsys is (in a specific, non-abstract way) and how to get it.

Could you please help clarify the situation for me? If I know what rootsys is exactly and how to get it, then it seems like the rest is just a bunch of moving / renaming with the mv command-line utility, followed by a reboot.
what I do is to move system installation within a subvolume folder named rootsys to avoid problems ..normally you get installation in default subvolume
and that is a headdache..

best thing is create in default suvolume all subvolumes like this.:

/home
/rootsys (linux installation)
/media

to achieve that, you just need create a subvolume called rootsys and move system installation within it with Steps:
1- reboot into livecd
2- mount default subvolume: sudo mount -t btrfs /dev/sda1 /mnt
3- create rootsys subvolume and move there system installation:
3.1 cd /mnt && sudo btrfs subvolume create rootsys
3.2 sudo mv dev sys etc bin usr ..... rootsys/ (move all system directories and files to rootsys subvolume folder)
4- edit fstab and update grub in order to grub find new location in rootstys:
4.1

Code: Select all

UUID=c649c9a7-6ed6-482b-9326-026837988bb7 /              btrfs   subvol=rootsys,defaults,noatime,ssd,space_cache,inode_cache 0 1
4.2- chroot and update grub
sudo mount -t btrfs -o subvol=rootsys /dev/sda1 /mntc
sudo mount --bind /dev /mnt/dev
sudo mount --bind /dev/pts /mnt/dev/pts
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys
sudo chroot /mnt
update-grub

this way you will have it properlly and easy to manage.. to manage snapshots is better to use snapper-gui..it creates snapshots for each subvolume in a hidden subvolume called .snapshots such like this.:

when you mount drive (default subvolume), you will see this structure:

sudo mount -t btrfs /dev/sda1 /mnt
sudo btrfs subvolume list /mnt
/home/.snapshots/1/snapshot
/home/.snapshots/2/snapshot
/rootsys/.snapshots/1/snapshot
/rootsys/.snapshots/2/snapshot
/media/.snapshots/2/snapshot
bester69 wrote:STOP 2030 globalists demons, keep the fight for humanity freedom against NWO...

User avatar
s3a
Posts: 831
Joined: 2008-07-17 22:13
Has thanked: 6 times
Been thanked: 2 times

Re: I'm unable to revert to a Btrfs snapshot.

#6 Post by s3a »

Thanks for the answer, but even if I chroot into subvol=rootsys (instead of subvol=@rootfs) (after the mount and mount --bind commands) (in the case of the VM where it has @rootfs as the default subvolume name) and try to do update grub and update-initramfs -u, I get the following upon trying to boot.:

Code: Select all

Welcome to GRUB!

error: file `/@rootfs/boot/grub/i386-pc/normal.mod` not found.
grub rescue>
The consistent thing that makes that happen is if I do "btrfs subvolume delete" or "mv" the @rootfs subvolume, when I do

Code: Select all

mount /dev/vda1 /mnt
.

Edit (#1):
Actually, if I remember correctly, I think I did the chrooting and everything else both as mount -o subvol=@rootfs and mount -o subvol=rootsys. Edit #3: I also made the /etc/fstab file say subvol=rootsys on both the @rootfs and rootsys subvolumes.

Edit #2:
By the way, when I installed Debian testing / bullseye, I was able to get the rolling back of snapshots to work. On my host OS, it's not like that, probably because I converted the filesystem to btrfs from when it used to be ext4.
Use Mnemosyne to Study for School!

p.H
Global Moderator
Global Moderator
Posts: 3049
Joined: 2017-09-17 07:12
Has thanked: 5 times
Been thanked: 132 times

Re: I'm unable to revert to a Btrfs snapshot.

#7 Post by p.H »

s3a wrote: 2021-07-23 04:33 even if I chroot into subvol=rootsys (instead of subvol=@rootfs) (after the mount and mount --bind commands) (in the case of the VM where it has @rootfs as the default subvolume name) and try to do update grub and update-initramfs -u, I get the following upon trying to boot.:

Code: Select all

error: file `/@rootfs/boot/grub/i386-pc/normal.mod` not found.
Neither update-grub nor update-initramfs will change the location where GRUB's boot image looks for /boot/grub stuff.
You need to run grub-install for this. In the meantime, you can just set the proper prefix value at the grub prompt.

Code: Select all

set prefix=(hdX,Y)/rootsys/boot/grub # or whatever the syntax is for your subvolume
insmod normal
normal

User avatar
s3a
Posts: 831
Joined: 2008-07-17 22:13
Has thanked: 6 times
Been thanked: 2 times

Re: I'm unable to revert to a Btrfs snapshot.

#8 Post by s3a »

That seems to have done it!

Thank you (both) very much!
Use Mnemosyne to Study for School!

User avatar
bester69
Posts: 2072
Joined: 2015-04-02 13:15
Has thanked: 24 times
Been thanked: 14 times

Re: I'm unable to revert to a Btrfs snapshot.

#9 Post by bester69 »

perhaps It had to be with EFI grub partition, I gave into same problems when I migrated from stretch to bullseye... To me, It has been very difficult to find where was the problem, and grub alwat pointed to /@ ... after some own researching .. I found changing grub.cfg paths to altered default root name subvolume within EFI partition woukd make it...

these were the files I need to modify (I guess one of them was the right one).:
root@hall:~# cat /boot/efi/EFI/debian/grub.cfg
search.fs_uuid 1950c700-95f3-4e89-a408-8a08d7b9d312 root
set prefix=($root)'/rootsys/boot/grub'
configfile $prefix/grub.cfg

root@hall:~# cat /boot/efi/EFI/sparky/grub.cfg
search.fs_uuid 1950c700-95f3-4e89-a408-8a08d7b9d312 root
set prefix=($root)'/rootsys/boot/grub'
configfile $prefix/grub.cfg
bester69 wrote:STOP 2030 globalists demons, keep the fight for humanity freedom against NWO...

Post Reply