[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Menu for booting BTRFS snapshots

From: Jordan Uggla
Subject: Re: Menu for booting BTRFS snapshots
Date: Thu, 2 Mar 2017 18:40:04 -0800

Grub's view of things at boot is necessarily different from the view
from your booted GNU/Linux environment, and indeed if you dual boot
two GNU/Linux OSs they will each mount each other's volumes to
different areas. Presumably /snaps/ is a mountpoint where you have
configured that your btrfs be mounted, with the right mount options
such that you can access your snapshots. Grub's grub.cfg is read
before any OS's fstab, so from grub's point of view "/snaps/" is most
likely just an empty directory. In addition, grub's view of a btrfs
filesystem starts at the top level subvolume so the path to that
"/snaps/" directory from grub is likely /@/snaps/ (though it depends
on the naming scheme you and your distribution have used). You will
most likely notice this when looking at other paths in your grub.cfg
(from parts generated by grub-mkconfig). Thankfully grub has a handy
utility for helping you find the path that grub will need to access a
file at boot, given the path to a file on your booted system:

TLDR: If you run "grub-mkrelpath /snaps/rxe-boot/grub2/grub.cfg" you
will get as output the path that grub will need to access your
grub.cfg at boot.

Also, if you're just reading from that grubenv to get a list of
subvolumes, you should know that grub can iterate over files and
directories using for loops and globbing just like bash, and so
(depending on your exact layout of snapshots) you can most likely
dynamically generate a menu with one entry per snapshot. And by
dynamically I don't mean "re-run grub-mkconfig to generate a new
grub.cfg", I mean they can literally be detected at boot by grub using

Jordan Uggla (Jordan_U on

On Thu, Mar 2, 2017 at 1:40 PM, Robert LeBlanc <address@hidden> wrote:
> I'm trying to add some menuentry items to move between btrfs
> snapshots. I've added the following in the non-snapshot
> /etc/grub.d/40_custom.
> menuentry 'RXE Snapshot' {
>        load_env -f /snaps/rxe-boot/grub2/grubenv
>        configfile /snaps/rxe-boot/grub2/grub.cfg
> }
> It loads the config for my RXE snapshot, but in doesn't select the
> default menuentry as specified in the snapshot's grubenv. This makes
> it so that it won't boot automatically into a snapshot kernel (I
> created a 09_header file to add a noop menuentry that tells me I'm
> using the RXE snapshot config and that is what is selected). It
> doesn't matter if load_env is before or after configfile. Other than
> this, it works as expected.
> I don't think I can use chainload because it is a 'directory' on the
> btrfs file system.
> Any ideas on how to accomplish what I want?
> Thank you,
> ----------------
> Robert LeBlanc
> PGP Fingerprint 79A2 9CA4 6CC4 45DD A904  C70E E654 3BB2 FA62 B9F1
> _______________________________________________
> Grub-devel mailing list
> address@hidden

reply via email to

[Prev in Thread] Current Thread [Next in Thread]