Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Made a btrfs snapshot mess, destroyed fabric of the universe
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
Schievel
n00b
n00b


Joined: 13 Sep 2021
Posts: 27

PostPosted: Tue Nov 02, 2021 2:07 pm    Post subject: Made a btrfs snapshot mess, destroyed fabric of the universe Reply with quote

Hi,

on my system I use one fat partition for efi, mounted on /boot and one big btrfs partition for everything else, which is devided into the subvolumes @ (for /) @home (for /home) and @cache for /var/cache.

Now I use timeshift to make snapshots of that system and roll them back, which worked well in the past.
Anyway, so yesterday evening something strange happened. I wasnt even doing something system wide, just surfing the internet a bit and working on stuff in my homefolder, when I noticed my zsh-autosuggestion that are usually /usr/share went missing. I tried cd ing to /usr/share, but could not. When I did a 'ls /', it said command not found!
It was as if I, or something else, ran a rm -rf / on my system.

I rebooted, and gdm failed to start. I have had that recently, and it was because of some mismatch with versions of the gentoo-bin kernel, nvidia driver and gentoo-sources when gentoo-kernel-bin-5.14.15 was released, but gentoo-sources-5.14.15 wasnt yet. So this was a few days ago and to fix this, I rolled back my system with timeshift to a point before the update with gentoo-kernel-bin-5.14.14 and gentoo-sources-5.14.14 and I masked the packages of gentoo-sources and gentoo-kernel-bin bigger than 5.14.14 in my package.mask.
Anyway, I did some fiddling with the nvidia driver and it worked, I looked up package.mask and my masks I put in a few days ago were gone!
Apparently I booted into a snapshot that was taken right when the update to gentoo-kernel-bin-5.14.15 happened, and before I put in the package masks.

Well, maybe I am a bit tired, rebooted, made sure I am 100% that I boot a snapshot from a few hours ago (remember the update to 5.14.15 was a few days ago, so this snapshot must have 5.14.14 in them and the packages masked) but I ended up in the same snapshot from after the update to 5.14.15! I made a few other snapshots to test, and I always end up in the same one again regardless of which one I am booting. Even though I deleted it from timeshift.
It seems like something went wrong when I booted that snapshot before the update a few days ago.

It also happened again a few times, that my whole system is gone and all commands arent recognized.

So no matter what I do, I am always back to that system state from a few days ago. I do not really know where to start and what to look for.
I feel like I am Bill Murray in Grundhog Day, send help!
Back to top
View user's profile Send private message
alamahant
Advocate
Advocate


Joined: 23 Mar 2019
Posts: 3879

PostPosted: Tue Nov 02, 2021 2:27 pm    Post subject: Reply with quote

Is your system existent in some form and functional?
If yes, rsync it to another non-btrfs partition, reinstall grub,update your fstab grub and initrd.
And maybe avoid using timeshift or even btrfs.
Good old plain ext4 and rsync is much better.
IMHO.
This is what i would do.
_________________
:)
Back to top
View user's profile Send private message
Schievel
n00b
n00b


Joined: 13 Sep 2021
Posts: 27

PostPosted: Tue Nov 02, 2021 2:39 pm    Post subject: Reply with quote

alamahant wrote:
Is your system existent in some form and functional?
If yes, rsync it to another non-btrfs partition, reinstall grub,update your fstab grub and initrd.
And maybe avoid using timeshift or even btrfs.
Good old plain ext4 and rsync is much better.
IMHO.
This is what i would do.


Well yes it is, I am writing this post on it right now.
I have got kernel log, dmesg and syslog open to have a chance to see what is happening, when everything vanishes from the disk.

I was thinking about going back to ext4 already, but btrfs and snapshots seemed like a good thing.
Back to top
View user's profile Send private message
Schievel
n00b
n00b


Joined: 13 Sep 2021
Posts: 27

PostPosted: Tue Nov 02, 2021 7:10 pm    Post subject: Reply with quote

I took me a while but after all I am back to a system that is not set back after the next reboot. I don't know if this strange wiping of root comes back.

Heres what I have figured out:
In order to fix the root partition being set back to a snapshot, I mounted the actual hardware partition (so no subvolume, I mounted /dev/sda3) to /mnt.
So I can see all of my subvolumes in /mnt now: @, @home and @cache and timeshift-btrfs, this is where timeshift keeps the snapshots.
Now btrfs subvolumes behave like folders in a certain way, so I just did
Code:

cd /mnt
mv -i @ @bak
mv ./timeshift-btrfs/snapshots/2021-11-02_16-21-10/@ ./@


The kernel command line in my grub identifies the subvolumes it wants to boot with
Code:
rootflags=subvol=@
, so it is easily possible to exchange the folder that is called '@' in the /dev/sda3 root. If a subvolid is used instead, this might be more complicated.

So this did the trick, I am back to a system that is actually persistent during reboots and out of the groundhog day loop. :D

I haven't figured out what caused this mayhem in the first place. It has something to do with how timeshift and grub and grub-btrfs handled it when I booted the snapshot in the first place. Because this also changed the kernel command line to something like "subvol="timeshift-btrfs/snapshots/2021-11-02_14-59-16/@". This makes somewhat sense that I always ended up in an earlier snapshot from the system. But even though I booted any snapshot and was in the system from a few days ago, then I changed something, made a new snapshot at say 2021-11-02_12-00-00 and booted this particular snapshot I just created (by making sure the kernel command line in grub says 2021-11-02_12-00-00) I would still end up in the system from a few days ago.
So after booting a snapshot in order to stay on this snapshot, mv it to @.

Maybe this has something todo with my initramfs. Although grub has the kernel command line with the snapshot, the initramfs is maybe always mounting @ on /dev/sda3, regardless what grub says. But this is only a shot in the dark.
Back to top
View user's profile Send private message
figueroa
Advocate
Advocate


Joined: 14 Aug 2005
Posts: 2964
Location: Edge of marsh USA

PostPosted: Wed Nov 03, 2021 3:02 am    Post subject: Reply with quote

Spooky; just in time for the Halloween lights to go out. Who wants a spooky file system, anyway?
_________________
Andy Figueroa
hp pavilion hpe h8-1260t/2AB5; spinning rust x3
i7-2600 @ 3.40GHz; 16 gb; Radeon HD 7570
amd64/23.0/split-usr/desktop (stable), OpenRC, -systemd -pulseaudio -uefi
Back to top
View user's profile Send private message
Schievel
n00b
n00b


Joined: 13 Sep 2021
Posts: 27

PostPosted: Wed Nov 03, 2021 8:38 am    Post subject: Reply with quote

I think the problem here is not the filesystem in itself, but rather timeshift and how it handles snapshots that the system is currently bootet in or possible the person in front of the computer.

When I bootet into that snapshot, no programs does shift the snapshot into @. It just changes the subvol= in grub to that snapshot and it stays there, so I kept booting to that snapshot.
Timeshift also deletes old snapshots, if there are enough new ones. So maybe it tried to delete the snapshot I had currently booted.

Anyway, I will do some research here and maybe make a bug report upstream
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3343
Location: Rasi, Finland

PostPosted: Wed Nov 03, 2021 8:50 am    Post subject: Reply with quote

My wild guess is that your root subvolume is a read-only snapshot or a rw snapshot that is created from some earlier snapshot on boot.

Code:
btrfs subvol list
... might give you some clues.

Your best bet to get booted into working system is then to manually edit kernel command line when booting and specifically adjust your rootfsflags so that subvol= points to the actual working root subvolume.

EDIT: I wanted to add a tip how to easily manage btrfs, without the hassle of mounting every subvolume separately:
    When you have formatted your btrfs partition/disk then let kernel just mount it without specifying any subvolumes.
    That mounted filesystem is now your system root. Then you can later create subvolumes inside your root. For example
    Code:
    btrfs subvolume create /var/cache/portage
    ... and /var/cache/portage directory is now a subvolume inside your root. (You may need to move the contents of /var/cache/portage to some temporary location first.)
    This way you don't need to list every subvolume in /etc/fstab. Your subvolumes will be there after your root is mounted.

_________________
..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
Schievel
n00b
n00b


Joined: 13 Sep 2021
Posts: 27

PostPosted: Wed Nov 03, 2021 2:28 pm    Post subject: Reply with quote

Well I found out about it. Its just timeshift rolling back to a wrong snapshot.

I just made a snapshot at 15:00. Then i created some testfiles and then chose to restore to that snapshot at 15:00. I rebooted and the kernel command line in grub says subvol=/timeshift-btrfs/blabla/2021-11-03_15:16.
That snapshot from 15:16 is the one timeshift creates automatically before doing a restore. So of course the testfiles where still in there.

The spooky thing is, timeshift doesnt move that snapshot over to the @ subvolume. Instead it leaves you booted into that snapshot.
But it TAKES new snapshots from that @ subvolume. That means when I change something in the currently bootet snapshot from 15:16 and make a new snapshot in timeshift, it wont have what I changed in there.

Now if thats not an upstream bug, I dont know what is.

To sum up what happened here yesterday:
I messed up the kernel and nvidia drivers a few days ago, and booted into snapshot A.
I did not check the kernel command line in grub and let timeshift do its thing instead. Timeshift kept me booted into snapshot A.
Timeshift happilfy took its snapshots B, C and D at boot time, hourly, daily, etc. but it took all of them from the @ snapshot, not from snapshot A and the @ snapshot was from a few days ago. So snapshots B, C and D are all not from the currently booted system, but from a few days ago, because @ was kept in that state.
When I tried to boot any of them yesterday, they all where the same, regardless of what I was booting. (except the snapshot A)

now, that explains it. What I cant explain yet is why my whole system was deleted while it was running. But I got an itch this has something to do with timeshift cleaning up old snapshots and therefore deleting snapshot A.
Back to top
View user's profile Send private message
alamahant
Advocate
Advocate


Joined: 23 Mar 2019
Posts: 3879

PostPosted: Wed Nov 03, 2021 4:14 pm    Post subject: Reply with quote

So maybe do NOT use timeshift.
Prefer rsync or tar instead to backup your WHOLE system rather than individual btrfs sub volumes.
_________________
:)
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3343
Location: Rasi, Finland

PostPosted: Wed Nov 03, 2021 9:44 pm    Post subject: Reply with quote

alamahant wrote:
So maybe do NOT use timeshift.
Yup.
Timeshift is quite picky on what system configurations it'll work.
Although, I applaud for the developer for supporting different configurations and nice ui.

My solution has been to schedule rsync every two hours and once a day snapshot that directory to /var/backups/<DATE>
So a completely custom script.
I'm thinking of testing restic for backups, but that'll take some time... I prefer backups that are accessible (in case of emergency) with normal fs and/or linux tools.
_________________
..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum