Venom1991 / refind-btrfs

Generate rEFInd manual boot stanzas from Btrfs snapshots
GNU General Public License v3.0
144 stars 8 forks source link

Can't find a matched boot stanza with the root partition #31

Closed SprkPlug closed 2 years ago

SprkPlug commented 2 years ago

Hello there! I'm running OpenSUSE Tumbleweed version 20220619. I keep getting this really annoying error: ERROR (refind_btrfs.state_management.conditions/conditions.py/check_matched_boot_stanzas): Could not find a boot stanza matched with the root partition! This is despite the fact i already did a manual boot stanza in refind.conf:

menuentry "OpenSUSE Tumbleweed" {
    icon     /EFI/refind/icons/os_suse.png
    volume 4fe2e6a0-14ec-4fec-ae90-5436c7941a38
    loader   /boot/vmlinuz
    initrd   /boot/initrd
    options  "root=PARTUUID=4fe2e6a0-14ec-4fec-ae90-5436c7941a38 splash=0"
}

This is my fstab:

UID=567520fe-8503-4b1d-8ea2-54e8a350dc0e  /            btrfs  noatime,commit=120,space_cache=v2  0  0
UUID=567520fe-8503-4b1d-8ea2-54e8a350dc0e  /var         btrfs  subvol=/@/var         0  0
UUID=567520fe-8503-4b1d-8ea2-54e8a350dc0e  /usr/local   btrfs  subvol=/@/usr/local   0  0
UUID=567520fe-8503-4b1d-8ea2-54e8a350dc0e  /srv         btrfs  subvol=/@/srv         0  0
UUID=567520fe-8503-4b1d-8ea2-54e8a350dc0e  /root        btrfs  subvol=/@/root        0  0
UUID=567520fe-8503-4b1d-8ea2-54e8a350dc0e  /opt         btrfs  subvol=/@/opt         0  0
UUID=567520fe-8503-4b1d-8ea2-54e8a350dc0e  /home        btrfs  subvol=/@/home        0  0
UUID=567520fe-8503-4b1d-8ea2-54e8a350dc0e  /.snapshots  btrfs  subvol=/@/.snapshots  0  0
UUID=AB26-A6F6                             /boot/efi    vfat   utf8                  0  2

I tried to search in the source code why this happens but i cant understand what is really happening. In fact i cant understand python in general.

Reproduction steps:

  1. Have OpenSUSE Tumbleweed installed (in a VM) (https://get.opensuse.org/tumbleweed/#download)
  2. Install rEFInd from (http://sourceforge.net/projects/refind/files/0.13.3.1/refind-0.13.3.1-1.x86_64.rpm/download) because the version in the repos are outdated
  3. install btrfs-refind from pypi sudo /usr/bin/python3 -m pip install refind-btrfs. (Without running it with sudo it complains that it doesn't find module refind_btrfs. I dont know if there is a better way to do it properly.)
  4. Install the dependecies sudo zypper install python-btrfsutil libbtrfsutil1 python310-systemd
  5. Run sudo /usr/bin/python3 -m refind_btrfs Expect to return something similar:
    
    Initializing the block devices using lsblk.
    Initializing the physical partition table for device '/dev/sda' using lsblk.
    Initializing the live partition table for device '/dev/sda' using findmnt.
    Initializing the physical partition table for device '/dev/sr0' using lsblk.
    Initializing the live partition table for device '/dev/sr0' using findmnt.
    Found the ESP mounted at '/boot/efi' on '/dev/sda1'.
    Found the root partition on '/dev/sda2'.
    Searching for snapshots of the '@/.snapshots/1/snapshot' subvolume in the '/.snapshots' directory.
    Found subvolume '@/.snapshots/1/snapshot' mounted as the root partition.
    Found 11 snapshots of the '@/.snapshots/1/snapshot' subvolume.
    Searching for the 'refind.conf' file on '/dev/sda1'.
    ERROR (refind_btrfs.state_management.conditions/conditions.py/check_matched_boot_stanzas): Could not find a boot stanza matched with the root partition!

I also attached the [refind.conf](https://github.com/Venom1991/refind-btrfs/files/8958938/refind.conf.txt) with  `.txt` extension due github complaining about unsupported format. Just in case.
`refind-btrfs.conf` is not modified at all.
Venom1991 commented 2 years ago

Found subvolume '@/.snapshots/1/snapshot' mounted as the root partition.

That is pretty weird - it appears that you root partition is ("/") is mounted from a Snapper's snapshot or at least this tool somehow came to that conclusion.

I suppose you could try adding the "subvol" option here (first fstab line):

UUID=567520fe-8503-4b1d-8ea2-54e8a350dc0e / btrfs noatime,commit=120,space_cache=v2,subvol=@ 0 0

Also, it looks like you had a typo there - "UID" instead of "UUID".

Basically, the error is telling you that it cannot match the root subvolume with the options "root=PARTUUID=..." line defined in your boot stanza. Adding the "rootflags=subvol=@" option to the same "options" line could also help (as shown here). Make sure to check all of the prerequisites.

Finally, I'm interested in the output of: findmnt -t btrfs

SprkPlug commented 2 years ago

Sorry for the late response. Different timezones and school stuff.

Also, it looks like you had a typo there - "UID" instead of "UUID".

Somehow i did not included the first "U" in "UUID". Sometimes it happens since the vm is a bit sluggish.

I suppose you could try adding the "subvol" option here (first fstab line): UUID=567520fe-8503-4b1d-8ea2-54e8a350dc0e / btrfs noatime,commit=120,space_cache=v2,subvol=@ 0 0

The subvol=@ in the fstab did not do any difference. rootflags=subvol=@ threw me into emergency mode

Adding the "rootflags=subvol=@" option to the same "options" line could also help (...)

rootflags=subvol=@ threw me into emergency mode

Finally, I'm interested in the output of: findmnt -t btrfs

TARGET        SOURCE                              FSTYPE OPTIONS
/             /dev/sda2[/@/.snapshots/1/snapshot] btrfs  rw,noatime,space_cache=v2,commit=120,subvolid=264,subvol=/@/.snapshots/1/snapshot
├─/root       /dev/sda2[/@/root]                  btrfs  rw,relatime,space_cache=v2,commit=120,subvolid=260,subvol=/@/root
├─/.snapshots /dev/sda2[/@/.snapshots]            btrfs  rw,relatime,space_cache=v2,commit=120,subvolid=263,subvol=/@/.snapshots
├─/srv        /dev/sda2[/@/srv]                   btrfs  rw,relatime,space_cache=v2,commit=120,subvolid=259,subvol=/@/srv
├─/usr/local  /dev/sda2[/@/usr/local]             btrfs  rw,relatime,space_cache=v2,commit=120,subvolid=258,subvol=/@/usr/local
├─/var        /dev/sda2[/@/var]                   btrfs  rw,relatime,space_cache=v2,commit=120,subvolid=257,subvol=/@/var
├─/home       /dev/sda2[/@/home]                  btrfs  rw,relatime,space_cache=v2,commit=120,subvolid=262,subvol=/@/home
└─/opt        /dev/sda2[/@/opt]                   btrfs  rw,relatime,space_cache=v2,commit=120,subvolid=261,subvol=/@/opt

I think this last part with root partition mounted at /@/.snapshots/1/snapshot must be some specific OpenSUSE quirk with the snapshot configuration at setup because i cant delete this very specific snapshot.

(edit: fixed some spelling mistakes)

Venom1991 commented 2 years ago

Hm, I'm not using openSUSE but that first line of findmnt's output is definitely sketchy.
It could be that your default subvolume was somehow set to "/@/.snapshots/1/snapshot" but I'm not really sure how such a thing can even happen.

Run btrfs subvolume get-default / to see what the default one is - it should be (on a fresh install) the one with an id equal to 5.
If it isn't you could try setting it as the default but there could be some data loss in case "/@/.snapshots/1/snapshot subvolume" (I'm here assuming this is your current default subvolume) has certain changes which the subvolume with id 5 does not have.

Alternatively, you could try setting the fstab's "subvol" to "/@/.snapshots/1/snapshot" and the manual stanza's "rootflags=subvol" option to "@/.snapshots/1/snapshot" (notice the absence of an initial forward slash).
It could actually work and is worth a try. That is, if you don't mind that your default subvolume is somewhat "unorthodox".

SprkPlug commented 2 years ago

It could be that your default subvolume was somehow set to "/@/.snapshots/1/snapshot" but I'm not really sure how such a thing can even happen.

I will try to ask on the OpenSUSE forums to see if this is intentional or not. I will also try to see if this happens even without the snapshot function in the installer and set it manually after a install

Run btrfs subvolume get-default /

ID 264 gen 236 top level 263 path @/.snapshots/1/snapshot

Alternatively, you could try setting the fstab's "subvol" to "/@/.snapshots/1/snapshot" and the manual stanza's "rootflags=subvol" option to "@/.snapshots/1/snapshot"

Initializing the block devices using lsblk. Initializing the physical partition table for device '/dev/sda' using lsblk. Initializing the live partition table for device '/dev/sda' using findmnt. Initializing the physical partition table for device '/dev/sr0' using lsblk. Initializing the live partition table for device '/dev/sr0' using findmnt. Found the ESP mounted at '/boot/efi' on '/dev/sda1'. Found the root partition on '/dev/sda2'. Searching for snapshots of the '@/.snapshots/1/snapshot' subvolume in the '/.snapshots' directory. Found subvolume '@/.snapshots/1/snapshot' mounted as the root partition. Found 11 snapshots of the '@/.snapshots/1/snapshot' subvolume. Searching for the 'refind.conf' file on '/dev/sda1'. Found 1 boot stanza matched with the root partition. WARNING: Detected boot files required by the 'OpenSUSE Tumbleweed' boot stanza which are not matched with the '@/.snapshots/1/snapshot' subvolume: /boot/initrd, /boot/vmlinuz! ERROR (refind_btrfs.state_management.conditions/conditions.py/check_matched_boot_stanzas): None of the matched boot stanzas are usable!

I was curious to see whats is on `@`. There are some stuff missing??  

10:/ # mount -o subvolid=256 /dev/sda2 /mnt 10:/ # cd mnt/ 10:/mnt # ls .snapshots etc home opt root srv usr var



I got into the conclusion that the default behavior of the installer with the "Enable Snapshots" option might the reason why this is giving this problem. I will definitively try to reinstall with this option disabled and try again with a manually configured snapper and report back.
Venom1991 commented 2 years ago

That last error message means that the "loader" and/or "initrd" boot stanza's options are not matched with the currently booted system. See the example boot stanza. You could try setting them to:

loader   /@/.snapshots/1/snapshot/boot/vmlinuz
initrd   /@/.snapshots/1/snapshot/boot/initrd

The currently mounted root subvolume's logical path must appear as a substring in both the "loader" and "initrd" options' values.

SprkPlug commented 2 years ago

You could try setting them to:


loader   /@/.snapshots/1/snapshot/boot/vmlinuz
initrd   /@/.snapshots/1/snapshot/boot/initrd
Initializing the block devices using lsblk.
Initializing the physical partition table for device '/dev/sda' using lsblk.
Initializing the live partition table for device '/dev/sda' using findmnt.
Initializing the physical partition table for device '/dev/sr0' using lsblk.
Initializing the live partition table for device '/dev/sr0' using findmnt.
Found the ESP mounted at '/boot/efi' on '/dev/sda1'.
Found the root partition on '/dev/sda2'.
Searching for snapshots of the '@/.snapshots/1/snapshot' subvolume in the '/.snapshots' directory.
Found subvolume '@/.snapshots/1/snapshot' mounted as the root partition.
Found 11 snapshots of the '@/.snapshots/1/snapshot' subvolume.
Searching for the 'refind.conf' file on '/dev/sda1'.
Analyzing the 'refind.conf' file.
Found 1 boot stanza matched with the root partition.
Initializing the static partition table for subvolume '@/.snapshots/14/snapshot' from its fstab file.
Initializing the static partition table for subvolume '@/.snapshots/13/snapshot' from its fstab file.
Initializing the static partition table for subvolume '@/.snapshots/12/snapshot' from its fstab file.
Initializing the static partition table for subvolume '@/.snapshots/11/snapshot' from its fstab file.
Initializing the static partition table for subvolume '@/.snapshots/10/snapshot' from its fstab file.
Found 5 snapshots for addition.
WARNING: The '@/.snapshots/14/snapshot' subvolume's static partition table is not matched with the root subvolume (by 'subvol' or 'subvolid')!
WARNING: The '@/.snapshots/13/snapshot' subvolume's static partition table is not matched with the root subvolume (by 'subvol' or 'subvolid')!
WARNING: The '@/.snapshots/12/snapshot' subvolume's static partition table is not matched with the root subvolume (by 'subvol' or 'subvolid')!
WARNING: The '@/.snapshots/11/snapshot' subvolume's static partition table is not matched with the root subvolume (by 'subvol' or 'subvolid')!
WARNING: The '@/.snapshots/10/snapshot' subvolume's static partition table is not matched with the root subvolume (by 'subvol' or 'subvolid')!
WARNING: None of the snapshots for addition are usable!
WARNING: None of the prepared snapshots are matched with the 'OpenSUSE Tumbleweed' boot stanza!
ERROR (refind_btrfs.state_management.conditions/conditions.py/check_boot_stanzas_with_snapshots): None of the matched boot stanzas can be combined with any of the prepared snapshots!

Honestly this imo this is a lost case. I'm half way done with the installation on a separate VM and i will report if this weird case happens with manual snapper configuration

Venom1991 commented 2 years ago

The last thing you could try is changing your fstab's / line to:

UUID=567520fe-8503-4b1d-8ea2-54e8a350dc0e / btrfs noatime,commit=120,space_cache=v2,subvol=/@/.snapshots/1/snapshot,subvolid=264 0 0

Bear in mind that those five snapshots' fstab files will not be automatically fixed by this. Amend the main fstab file and create a new manual snapshot (with Snapper) of the current root subvolume.

SprkPlug commented 2 years ago

That seems to do the trick but now i cant get past rEFInd menu and boot into the system with either the snapshot submenu and the stanza i made. Thank you for your time! I also found that the /@/.snapshot/1/snapshot thing is normal https://libredd.it/r/openSUSE/comments/gsni5b/snapshot_1_the_first_root_filesystem_is_always/fs6z5id/?context=3