Git Product home page Git Product logo

grub-btrfs's Introduction

GitHub release

๐Ÿ’ป grub-btrfs

BTC donation address: 1Lbvz244WA8xbpHek9W2Y12cakM6rDe5Rt

๐Ÿ”Ž Description:

grub-btrfs improves the grub bootloader by adding a btrfs snapshots sub-menu, allowing the user to boot into snapshots.

grub-btrfs supports manual snapshots as well as snapper, timeshift, and yabsnap created snapshots.

Warning: booting read-only snapshots can be tricky

If you wish to use read-only snapshots, /var/log or even /var must be on a separate subvolume. Otherwise, make sure your snapshots are writable. See this ticket for more info.

This project includes its own solution. Refer to the documentation.


โœจ What features does grub-btrfs have?

  • Automatically lists snapshots existing on the btrfs root partition.
  • Automatically detect if /boot is in a separate partition.
  • Automatically detect kernel, initramfs and Intel/AMD microcode in /boot directory within snapshots.
  • Automatically create corresponding menu entries in grub.cfg
  • Automatically detect the type/tags/triggers and descriptions/comments of Snapper/Timeshift/Yabsnap snapshots.
  • Automatically generate grub.cfg if you use the provided Systemd/ OpenRC service.

๐Ÿ› ๏ธ Installation:

Arch Linux

The package is available in the extra repository grub-btrfs

pacman -S grub-btrfs

Gentoo

grub-btrfs is only available in the Gentoo User Repository (GURU) and not in the official Gentoo repository.
If you have not activated the GURU yet, do so by running:

emerge -av app-eselect/eselect-repository 
eselect repository enable guru 
emaint sync -r guru 

If you are using Systemd on Gentoo, make sure the USE-Flag systemd is set. (Either globally in make.conf or in package.use for the package app-backup/grub-btrfs) Without Systemd USE-Flag the OpenRC-daemon of grub-btrfs will be installed.

Emerge grub-btrfs via emerge app-backup/grub-btrfs

Kali Linux

grub-btrfs is available in the Kali Linux repository and can be installed with:

apt install grub-btrfs

Booting into read-only snapshots is fully supported when choosing btrfs as the file system during a standard Kali Linux installation following this walk-through.

Manual installation


๐Ÿ“š Manual usage of grub-btrfs

To manually generate grub snapshot entries you can run sudo /etc/grub.d/41_snapshots-btrfs which updates grub-btrfs.cfg. You then need to regenerate the GRUB configuration by running one of the following commands:

  • On Arch Linux or Gentoo use grub-mkconfig -o /boot/grub/grub.cfg.
  • On Fedora use grub2-mkconfig -o /boot/grub2/grub.cfg
  • On Debian and Ubuntu based distributions update-grub is a script that runs grub-mkconfig ...

This process can be automated to occur whenever you create or delete snapshots but this process is slightly different depending upon your distributions choice on init system. See the relevant instructions for your init system below.

โš™๏ธ Customization:

You have the possibility to modify many parameters in /etc/default/grub-btrfs/config. For further information see config file or man grub-btrfs

Warning:

Some file locations and command names differ from distribution to distribution. Initially the configuration is set up to work with Arch and Gentoo (and many other distributions) out of the box, which are using the grub-mkconfig command. However Fedora, for example, uses a different command, grub2-mkconfig. Edit the GRUB_BTRFS_MKCONFIG variable in /etc/default/grub-btrfs/config file to reflect this. (e.g. GRUB_BTRFS_MKCONFIG=/sbin/grub2-mkconfig for Fedora)

On most distributions, the grub installation resides in /boot/grub. If grub is installed in a different place, change the variable GRUB_BTRFS_MKCONFIG in the config file accordingly. For Fedora this is GRUB_BTRFS_GRUB_DIRNAME="/boot/grub2". The command to check the grub scripts is different on some system, for Fedora it is GRUB_BTRFS_SCRIPT_CHECK=grub2-script-check

Customization of the grub-btrfsd daemon

Grub-btrfs comes with a daemon script that automatically updates the grub menu when it sees a snapshot being created or deleted in a directory it is given via command line. You must install inotify-tools before you can use grub-btrfsd.

The daemon can be configured by passing different command line arguments to it. The available arguments are:

  • SNAPSHOTS_DIRS This argument specifies the (space separated) paths where grub-btrfsd looks for newly created snapshots and snapshot deletions. It is usually defined by the program used to make snapshots. E.g. for Snapper or Yabsnap this would be /.snapshots. It is possible to define more than one directory here, all directories will inherit the same settings (recursive etc.). This argument is not necessary to provide if --timeshift-auto is set.
  • -c / --no-color Disable colors in output.
  • -l / --log-file This arguments specifies a file where grub-btrfsd should write log messages.
  • -r / --recursive Watch the snapshots directory recursively
  • -s / --syslog
  • -o / --timeshift-old Look for snapshots in /run/timeshift/backup/timeshift-btrfs instead of /run/timeshift/$PID/backup/timeshift-btrfs. This is to be used for Timeshift versions <22.06. You must also use --timeshift-auto if using this option.
  • -t / --timeshift-auto This is a flag to activate the auto-detection of the path where Timeshift stores snapshots. Newer versions (>=22.06) of Timeshift mount their snapshots to /run/timeshift/$PID/backup/timeshift-btrfs. Where $PID is the process ID of the currently running Timeshift session. The PID changes every time Timeshift is opened. grub-btrfsd can automatically take care of the detection of the correct PID and directory if this flag is set. In this case the argument SNAPSHOTS_DIRS has no effect.
  • -v / --verbose Let the log of the daemon be more verbose
  • -h / --help Displays a short help message.

๐Ÿช€ Automatically update grub upon snapshot creation or deletion

Grub-btrfsd is a daemon that watches the snapshot directory for you and updates the grub menu automatically every time a snapshot is created or deleted. By default this daemon watches the directory /.snapshots for changes (creation or deletion of snapshots) and triggers the grub menu creation and re-installation of grub if any changes are noticed. Therefore, if Snapper or Yabsnap is used with its default directory, the daemon can just be started and nothing needs to be configured. See the instructions below to configure grub-btrfsd for use with Timeshift or when using an alternative snapshots directory with Snapper/Yabsnap.


grub-btrfsd systemd instructions

To start the daemon run:

sudo systemctl start grub-btrfsd

To activate it during system startup, run:

sudo systemctl enable grub-btrfsd
๐Ÿ’ผ Snapshots not in /.snapshots when using systemd

By default the daemon is watching the directory /.snapshots. If the daemon should watch a different directory, it can be edited with:

sudo systemctl edit --full grub-btrfsd 

You need to edit the /.snapshots part in the line that says ExecStart=/usr/bin/grub-btrfsd --syslog /.snapshots. This is what the file should look like afterwards:

[Unit]
Description=Regenerate grub-btrfs.cfg

[Service]
Type=simple
LogLevelMax=notice
# Set the possible paths for `grub-mkconfig`
Environment="PATH=/sbin:/bin:/usr/sbin:/usr/bin"
# Load environment variables from the configuration
EnvironmentFile=/etc/default/grub-btrfs/config
# Start the daemon, usage of it is:
# grub-btrfsd [-h, --help] [-t, --timeshift-auto] [-l, --log-file LOG_FILE] SNAPSHOTS_DIRS
# SNAPSHOTS_DIRS         Snapshot directories to watch, without effect when --timeshift-auto
# Optional arguments:
# -t, --timeshift-auto  Automatically detect Timeshifts snapshot directory
# -o, --timeshift-old   Activate for timeshift versions <22.06
# -l, --log-file        Specify a logfile to write to
# -v, --verbose         Let the log of the daemon be more verbose
# -s, --syslog          Write to syslog
ExecStart=/usr/bin/grub-btrfsd --syslog /.snapshots

[Install]
WantedBy=multi-user.target

When done, the service should be restarted with:

sudo systemctl restart grub-btrfsd 
๐ŸŒŸ Using Timeshift with systemd

Newer Timeshift versions (>= 22.06) create a new directory named after their process ID in /run/timeshift every time they are started. The PID will be different every time. Therefore the daemon cannot simply watch a directory. It monitors /run/timeshift and if a directory is created it gets Timeshifts current PID then watches a directory in that newly created directory from Timeshift. To activate this mode of the daemon, --timeshift-auto must be passed to the daemon as a command line argument.

To pass --timeshift-auto to grub-btrfsd, the .service file of grub-btrfsd can be edited with

sudo systemctl edit --full grub-btrfsd 

The line that contains:

ExecStart=/usr/bin/grub-btrfsd /.snapshots --syslog

Should be modified to read:

ExecStart=/usr/bin/grub-btrfsd --syslog --timeshift-auto

The modified file should look like this:

[Unit]
Description=Regenerate grub-btrfs.cfg

[Service]
Type=simple
LogLevelMax=notice
# Set the possible paths for `grub-mkconfig`
Environment="PATH=/sbin:/bin:/usr/sbin:/usr/bin"
# Load environment variables from the configuration
EnvironmentFile=/etc/default/grub-btrfs/config
# Start the daemon, usage of it is:
# grub-btrfsd [-h, --help] [-t, --timeshift-auto] [-l, --log-file LOG_FILE] SNAPSHOTS_DIRS
# SNAPSHOTS_DIRS         Snapshot directories to watch, without effect when --timeshift-auto
# Optional arguments:
# -t, --timeshift-auto  Automatically detect Timeshifts snapshot directory
# -l, --log-file        Specify a logfile to write to
# -v, --verbose         Let the log of the daemon be more verbose
# -s, --syslog          Write to syslog
ExecStart=/usr/bin/grub-btrfsd --syslog --timeshift-auto

[Install]
WantedBy=multi-user.target

If you are using an older release of Timeshift (before 22.06), you also need to add --timeshift-old so that your ExecStart line would look like:

ExecStart=/usr/bin/grub-btrfsd --syslog --timeshift-auto --timeshift-old

When done, the service must be restarted with:

sudo systemctl restart grub-btrfsd 

Note: You can view your change with systemctl cat grub-btrfsd. To revert all the changes use systemctl revert grub-btrfsd.


grub-btrfsd OpenRC instructions

To start the daemon run:

sudo rc-service grub-btrfsd start 

To activate it during system startup, run:

sudo rc-config add grub-btrfsd default 
๐Ÿ’ผ Snapshots not in /.snapshots for OpenRC

By default the daemon is watching the directory /.snapshots. If the daemon should watch a different directory, it can be edited by passing different arguments to it. Arguments are passed to grub-btrfsd via the file /etc/conf.d/grub-btrfsd. The variable snapshots defines the path the daemon will monitor for snapshots.

After editing, the file should look like this:

# Copyright 2022 Pascal Jaeger
# Distributed under the terms of the GNU General Public License v3

## Where to locate the root snapshots
snapshots="/.snapshots" # Snapper in the root directory
#snapshots="/run/timeshift/backup/timeshift-btrfs/snapshots" # Timeshift < v22.06

## Optional arguments to run with the daemon
# Append options to this like this:
# optional_args="--syslog --timeshift-auto --verbose"
# Possible options are:
# -t, --timeshift-auto  Automatically detect Timeshifts snapshot directory for timeshift >= 22.06
# -o, --timeshift-old   Look for snapshots in directory of Timeshift <v22.06 (requires --timeshift-auto)
# -l, --log-file        Specify a logfile to write to
# -v, --verbose         Let the log of the daemon be more verbose
# -s, --syslog          Write to syslog
optional_args="--syslog"

After that, the daemon should be restarted with:

sudo rc-service grub-btrfsd restart

Troubleshooting

If you experience problems with grub-btrfs don't hesitate to file an issue.

What version of grub-btrfs am I running?

When requesting help or reporting bugs in grub-btrfs, please run:

sudo /etc/grub.d/41_snapshots-btrfs --version

or

sudo /usr/bin/grub-btrfsd --help

to get the currently running version of grub-btrfs and include this information in your ticket.

Running grub-btrfsd in verbose mode

If you have problems with the daemon, you can run it with the --verbose-flag. To do so you can run:

sudo /usr/bin/grub-btrfsd --verbose --timeshift-auto` (for timeshift)
# or 
sudo /usr/bin/grub-btrfsd /.snapshots --verbose` (for snapper/yabsnap)

Or pass --verbose to the daemon using the Systemd .service file or the OpenRC conf.d file respectively.

For additional information on the daemon and its arguments, run grub-btrfsd -h or man grub-btrfsd


Development

Grub-btrfs uses a rudimentary system of automatic versioning to tell apart different commits. This is helpful when users report problems and it is not immediately clear what version they are using. We therefore have the following script in .git/hooks/pre-commit:

#!/bin/sh

echo "Doing pre commit hook with version bump"
version="$(git describe --tags --abbrev=0)-$(git rev-parse --abbrev-ref HEAD)-$(date -u -Iseconds)"
echo "New version is ${version}"
sed -i "s/GRUB_BTRFS_VERSION=.*/GRUB_BTRFS_VERSION=${version}/" config
git add config

This automatically sets the version in the config-file to [lasttag]-[branch-name]-[current-date-in-UTC]. In order to create a Tag we don't want to have this long version. In this case we set the version manually in config and commit with git commit --no-verify. This avoids running the hook.

Special thanks for assistance and contributions


grub-btrfs's People

Contributors

antynea avatar anyc avatar bastien-roucaries avatar budswa avatar ckotte avatar cmlsharp avatar cmrd-senya avatar crafter6432 avatar daftaupe avatar danboid avatar darkdragon-001 avatar expoodo avatar felixonmars avatar hrotkogabor avatar kevinchevreuil avatar kr1ss-xd avatar luflosi avatar maximbaz avatar megver83 avatar mrbliss avatar n-parsons avatar nephros avatar psykar avatar re4son avatar s-trace avatar schievel1 avatar semnodime avatar stolld avatar thomasfinstad avatar yarikoptic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grub-btrfs's Issues

Subvolume.IO Error

Hello,
I've configured grub-btrfs to boot my snapshot, but when I execute :
# snapper rollback
I've got this error
Creating read-only snapshot of default subvolume.IO Error (.snapshots is not a btrfs subvolume).
Also, I'm working with Kubuntu 17.10 and Plasma Desktop not loaded when booting any snapshots, only boot to text mode.
I'll appreciate if help me to fix this.
Thanks

report from a noob: "grub-probe: error: cannot find a GRUB drive for /dev/sda1. Check your device.map."

Hello Dev Team

I am completely new on Linux, and have just installed Manjaro after deleting my Win10 and hopping like 10 distros in these days. I ended up with Manjaro.

I encountered some seemingly errors after updating may Grub on a clean install and just wanted to report here as per the request within the terminal, so I just followed the instructions there with a link to here.

My OS is working perfectly and booting so I have no clue is there is any error or not so I just report it here for your information.

image

image

LUKS full disk encryption with Btrfs is the active, working setup.
Operating System: Manjaro Linux
KDE Plasma Version: 5.19.5
KDE Frameworks Version: 5.73.0
Qt Version: 5.15.0
Kernel Version: 5.7.19-2-MANJARO
OS Type: 64-bit
Processors: 12 ร— Intelยฎ Coreโ„ข i7-8700K CPU @ 3.70GHz
Memory: 15.6 GiB of RAM
Graphics Processor: GeForce RTX 2070/PCIe/SSE2

Update-Grub

 Generating grub configuration file
 Found theme: /usr/share/grub/themes/Vimix/theme.txt
 Found linux image: /boot/vmlinuz-5.4-x86_64
 Found initrd image: /boot/amd-ucode.img /boot/initramfs-5.4-x86_64.img
 Found initrd fallback image: /boot/initramfs-5.4-x86_64-fallback.img
 Found linux image: /boot/vmlinuz-5.4-rt-x86_64
Found initrd image: /boot/amd-ucode.img /boot/initramfs-5.4-rt-x86_64.img
 Found initrd fallback image: /boot/initramfs-5.4-rt-x86_64-fallback.img
 ###### - Grub-btrfs: Snapshot detection started - ######
# Info: Separate boot partition not detected 
 Config 'root' not found.
 Config 'root' not found.
 Config 'root' not found.
 # No snapshots found.
 # If you think an error has occurred , please file a bug report at " https://github.com/Antynea/grub-btrfs "
 # Nothing to do. Abort.
###### - Grub-btrfs: Snapshot detection ended   - ######
Found memtest86+ image: /boot/memtest86+/memtest.bin

Grub was not displayed
error sparse file not allowed

Compatible with UEFI boot

I have a problem where it incorrectly assumes initramfs is in /subvol name/boot
As of commit 8fffc13 at line 143:

initrd \"${boot_dir_real_path}/"${u}"\" \"/"${snap_dir_name}"/boot/"${i}"\""

I have my EFI system partition mounted at /boot and my current boot entry always loads the initramfs direct from the ESP root (not in any subdirectories). This is the recommended setup for Arch Linux if you boot using UEFI.
ex: initrd /intel-ucode.img /initramfs-linux.img

How could we best make sure this script recognizes this and use the appropriate path?

I'm happy to use GRUB_BTRFS_NINIT to override this but it doesn't seem like it does this mistake for the kernel.

More snapper friendly

Hey, love this script, but it would be even better if it was snapper friendly.
I am just going from using my own simple script to using snapper and would ask if you would add date and time to the menu entry.

Snapper only numbers them in the snapshot path, which will be pretty uninformative when looking at the menu.

My suggestion would just be to add something like the output of this $bindir/btrfs subvolume list -s / --sort=-ogen | $bindir/cut -d" " -f11-12 to the end of the menu entry line which is just a date and time: 2015-05-11 10:09:23

Systemd service fails to access config

๐Ÿ‘ Graz for making it into the Arch community repo !
Today I've got the update to 4.0, and I like the new design with the systemd path-unit and service.

Unfortunately, grub-btrfs.service tries to access the old config file, /etc/grub.d/41_snapshots-btrfs_config, rather than /etc/default/grub-btrfs/config, and fails.

Ignoring the /var/lib/docker directory has no effect.

Title. I ignored the /var/lib/docker directory on /etc/default/grub-btrfs/config and docker subvolumes still get detected as snapshots.

image

On grub-mkconfig (on the pacman hook, but running grub-mkconfig -o /boot/grub/grub.cfg yields the same)
image
image

Using /var/lib/docker or var/lib/docker has exactly the same effect.
edit: for the record, var is on a different subvolume

Debian: Failure when booting after rollback (Kernel panic)

Hi,
I have setup BTRFS snapshots successfully and can boot any snapshot from Grub.
However I have identified an issue related to snapshot rollback.

Steps to reproduce the issue (with Debian 9.6):

  1. Boot snapshot X
  2. After system is loaded it is read-only and not fully usable
  3. Rollback snapshot X with command snapper rollback X
  4. snapper rollback will create additional snapshots, of which one is a read-write snapshot Y of snapshot X; in addition this snapshot Y will be set as default snapshot (corresponding to btrfs subvolume set-default Y)
  5. reboot and select default entry

The system will not boot and run into Kernel panic.

A workaround to boot w/o errors is to edit the entry related to default by means of modifying the line starting with "linux"; here the string rootflags=... must be deleted.

Do you have an idea for a permanent fix?

grub.cfg failes to generate

Here is the output of:

grub-mkconfig -o /boot/grub/grub.cfg

###### - Grub-btrfs: Auto-detect - ######
###### - Grub-btrfs: Auto-detect - ######
error: syntax error.
error: Incorrect command.
error: syntax error.   
Syntax error at line 173
Syntax errors are detected in generated GRUB config file.
Ensure that there are no errors in /etc/default/grub
and /etc/grub.d/* files or please file a bug report with
/boot/grub/grub.cfg.new file attached.
done  

Create new release

Could you please create a new release and update the grub-btrfs Arch Linux package as well? The grub-btrfs-git AUR package is broken and ignoring @ doesn't work with 4.3.

Wrong data in 'Grub-btrfs: Snapshot detection'

Removing snapshot: 2020-07-28_12-18-36
Deleted directory: /run/timeshift/backup/timeshift-btrfs/snapshots/2020-07-28_12-18-36
Removed snapshot: 2020-07-28_12-18-36
------------------------------------------------------------------------------
Generating grub configuration file ...
Found theme: /usr/share/grub/themes/garuda/theme.txt
Found linux image: /boot/vmlinuz-linux-zen
Found initrd image: /boot/intel-ucode.img /boot/initramfs-linux-zen.img
Found fallback initrd image(s) in /boot: initramfs-linux-zen-fallback.img
###### - Grub-btrfs: Snapshot detection started - ######
# Info: Separate boot partition not detected 
# Found snapshot: 2020-07-28 04:00:22 | timeshift-btrfs/snapshots/2020-07-28_04-00-22/@
# Found snapshot: 2020-07-27 20:13:24 | timeshift-btrfs/snapshots/2020-07-27_20-13-24/@
# Found snapshot: 2020-07-26 18:57:59 | timeshift-btrfs/snapshots/2020-07-26_18-57-58/@
# Found snapshot: 2020-07-26 07:30:09 | timeshift-btrfs/snapshots/2020-07-26_07-30-09/@
# Found snapshot: 2020-07-26 06:57:10 | timeshift-btrfs/snapshots/2020-07-26_06-57-10/@
# Found snapshot: 2020-07-26 02:35:34 | timeshift-btrfs/snapshots/2020-07-26_02-35-34/@
# Found snapshot: 2020-07-18 02:51:57 | @
# Found 7 snapshot(s)


------------------------------------------------------------------------------------------
sudo timeshift --list
/dev/sda2 is mounted at: /run/timeshift/backup, options: rw,relatime,compress=zstd:3,ssd_spread,space_cache,autodefrag,subvolid=5,subvol=/

Device : /dev/sda2
UUID   : d6458fc5-cf8f-417a-8479-e8f6169c3604
Path   : /run/timeshift/backup
Mode   : BTRFS
Status : OK
6 snapshots, 194.1 GB free

Num     Name                 Tags  Description                                    
------------------------------------------------------------------------------
0    >  2020-07-26_02-35-34  O     {timeshift-autosnap} {created before upgrade}  
1    >  2020-07-26_06-57-10  O     sgs                                            
2    >  2020-07-26_07-30-09  O     {timeshift-autosnap} {created before upgrade}  
3    >  2020-07-26_18-57-58  O     {timeshift-autosnap} {created before upgrade}  
4    >  2020-07-27_20-13-24  O     {timeshift-autosnap} {created before upgrade}  
5    >  2020-07-28_04-00-22  O     {timeshift-autosnap} {created before upgrade}  

Where does the program get the wrong old data from?

What am I doing wrong?

When I delete all snapshots via TS-GUI, crashed TS and my PC has no more data. But this is not the problem of grub-btrfs :)

grub-btrfs should not parse pre-post snapshots

I use snap-pac which hooks into pacman to add transactions support: it creates a pre snapshot before running pacman and a post snapshot afterward. This makes possible to revert it or to diff the changes: https://wiki.archlinux.org/index.php/Snapper#Wrapping_pacman_transactions_in_snapshots

Unfortunately pre-post snapshots are not normal snapshots and should not be listed by brub-btrfs. You can show them with:
snapper -c @ list -t pre-post
or looking at the first column of
snapper -c @ list

Snapper id too long

Sadly I could not find more information on how and why the error occurs but while creating the grub config with grub-mkconfig -o /boot/grub/grub.cfg, /etc/grub.d/41_snapshots-btrfs tells me that on lines 296 and 309, 0882080592106262008919021151341962250 is too large for the current base and blames char \"0882080592106262008919021151341962250\".

Mentioned lines actually contain the same code:

296: if [[ "$snapper_id" -eq "$id" ]]; then
309: if [[ "$snapper_id" -eq "$id" ]]; then

System

OS: Arch Linux
Kernel: x86_64 Linux 4.14.10-1-ARCH
CPU: Intel Core i7-3630QM @ 8x 3.4GHz
Grub: grub-2:2.02-4
Snapper: snapper-0.5.0-3
Snap-Pac: snap-pac-1.1-1

`rootflags=subvol=` created twice

I have a specific subvolume I mount as root using rootflags=subvol=subvol_root. When I recreate the GRUB configuration file with this package installed, it creates another rootflags=subvol= entry, one for the one I've specified and then one for the snapshot.

UUID=X does not exist

I'm trying to use your script on ubuntu and the snapshots won't boot, the initrd does not finds the filesystem.

I replaced UUID with X, but the UUID of the partition and the UUID from the command line matches.

Here are some info:
/proc/cmdline with snapshot :
BOOT_IMAGE=/@/.snapshots/5/snapshot/boot/vmlinuz-4.15.0-15-generic root=UUID=X rw rootflags=suvbol=@/.snapshots/5/snapshot

/proc/cmdline on normal boot:
BOOT_IMAGE=/@/boot/vmlinuz-4.15.0-15-generic root=/dev/mapper/root-root ro rootflags=subvol=@

snapshots are not detected

Hi,
Snapshots are not detected on my system.
When I run grub-mkconfig -o /boot/grub/grub.cfg, I get the output below.

Generating grub configuration file ...
Found theme: /usr/share/grub/themes/starfield/theme.txt
Found linux image: /boot/vmlinuz-linux
Found initrd image: /boot/intel-ucode.img /boot/initramfs-linux.img
Found fallback initrd image(s) in /boot: initramfs-linux-fallback.img
###### - Grub-btrfs: Snapshot detection started - ######
# Info: Separate boot partition not detected 
# No snapshots found.
# If you think an error has occurred , please file a bug report at " https://github.com/Antynea/grub-btrfs "
# Nothing to do. Abort.
###### - Grub-btrfs: Snapshot detection ended   - ######
done

Could you please help me on that?
My system is Arch Linux. These are the related packages on my system:
grub 2:2.02-7
grub-btrfs 3.2-1
snap-pac-grub 1.0.4-1

Thanks in advance!

Adds docker snapshots to grub list, despite being ignored in config

On Arch Linux I am getting an issue where it will include snapshots of docker containers on my machine at
var/lib/docker/btrfs/subvolumes
despite it being included in /etc/default/grub-btrfs/config here:

57 GRUB_BTRFS_IGNORE_SPECIFIC_PATH=("var/lib/docker" "@var/lib/docker" "var/lib/docker/btrfs/subvolumes" "@/var/lib/docker/btrfs/subvolumes/")

Post pac-snap output:

Found snapshot: 2020-10-01 20:34:38 | @/.snapshots/5/snapshot | pre | pacman -Syu Found snapshot: 2020-10-01 16:30:38 | @/.snapshots/1/snapshot | single | timeline Found snapshot: 2020-09-21 13:56:05 | @/var/lib/docker/btrfs/subvolumes/12ee3841107f6a84f2dd8d27de3add46ac93be3ed05e9c4d38dbb505085b06ea-init Found snapshot: 2020-09-19 04:48:14 | @/var/lib/docker/btrfs/subvolumes/ca4982dd926876676465206d1ecd78f98af61d1e10cad81abae6e53e161c635c-init Found snapshot: 2020-09-12 18:31:19 | @/var/lib/docker/btrfs/subvolumes/976ac50fc3e045ba3011ae8409dd156b8e3879304766a2bc422e832ef386baeb Found snapshot: 2020-09-12 18:31:19 | @/var/lib/docker/btrfs/subvolumes/98a5c0240b308ccb3610459ac48acfcad9afd24a0a77e86c68b9eab5781096af Found snapshot: 2020-09-12 18:31:19 | @/var/lib/docker/btrfs/subvolumes/9def363859fbba065560c821a0be16b4b16f749d089690f68b8c5e11e9aab4c9 Found snapshot: 2020-09-12 18:31:16 | @/var/lib/docker/btrfs/subvolumes/6000b365c4369b1aea0bc2b38e2333c50f54c44e18da5972bb109867d52e8731 Found snapshot: 2020-09-12 18:12:54 | @/var/lib/docker/btrfs/subvolumes/3ceadc8495ce125b0d9b0c6ba045dc15927d516331ddd3597c350aef2620ceaa Found snapshot: 2020-09-12 18:12:54 | @/var/lib/docker/btrfs/subvolumes/3ceadc8495ce125b0d9b0c6ba045dc15927d516331ddd3597c350aef2620ceaa-init Found snapshot: 2020-09-12 02:19:25 | @/var/lib/docker/btrfs/subvolumes/462c1909d14af8d924849922ed4185525dabee22f8b35e17b6c58f951bca4eda Found snapshot: 2020-09-12 02:19:24 | @/var/lib/docker/btrfs/subvolumes/ac8542243671fcc2a057d21373be0fa8f0df1693b56edfc032595acb97ce360c Generated 400 total GRUB entries. You might experience issues loading snapshots menu in GRUB. Found 50 snapshot(s) done

Auto-move child subvolumes

Many applications (e.g. docker) create subvolumes (/var/lib/docker/btrfs/subvolumes/XXX) which are children of the root subvolume (The number after top level when running btrfs subvolume list /). These children must be moved the the selected snapshot to keep these applications running.

An approach could be to search for all subvolumes which are children of the default root subvolume. All these children are then moved to the selected subvolume on boot.

question

Hi, thanks for your script works just super!
Could you tell me how to implement your script works like this:
If I choose a snapshot in the menu of Grub then script should be to change a name of subvolume "subvolume_root" which is on "/" in "subvolume_root_bad" and selected snapshot move on "/" and rename it giving to him a name "subvolume_root"?

PS - Usually i do this with my hands, using a couple of commands
mv /mnt/subvolume_root /mnt/subvolume_root_bad
and
mv /mnt/backup /mnt/subvolume_root

Enhancement: GRUB_BTRFS_TITLE_FORMAT

Hi!
Could you consider to enhance the GRUB_BTRFS_TITLE_FORMAT to include snapper type "single, pre, post"?
This could simplify identification of relevant snapshot in Grub.

Regards
Thomas

Snapshot description is wrong

The description of some snapshots is wrong. In this specific example, the description of all snapshots is just timeline. Sometimes just a few snapshots aren't named correctly.

$ sudo snapper ls
Type   | # | Pre # | Date                          | User | Cleanup  | Description                                                                 | Userdata
-------+---+-------+-------------------------------+------+----------+-----------------------------------------------------------------------------+---------
single | 0 |       |                               | root |          | current                                                                     |         
single | 1 |       | Fri 30 Mar 2018 23:31:44 CEST | root |          | test123                                                                     |         
pre    | 2 |       | Fri 30 Mar 2018 23:46:15 CEST | root | number   | pacman -Ud /home/vagrant/.cache/pacaur/grub-btrfs/grub-btrfs-2.0.1-1-any... |         
post   | 3 | 2     | Fri 30 Mar 2018 23:46:17 CEST | root | number   | grub-btrfs                                                                  |         
single | 4 |       | Sat 31 Mar 2018 00:00:27 CEST | root | timeline | timeline                                                                    |         
single | 5 |       | Sat 31 Mar 2018 13:10:45 CEST | root | timeline | timeline                                                                    |         
pre    | 6 |       | Sun 01 Apr 2018 13:14:23 CEST | root | number   | pacman -Syu                                                                 |         
post   | 7 | 6     | Sun 01 Apr 2018 13:15:22 CEST | root | number   | gtk-update-icon-cache gtk3 linux linux-headers mpg123 openssl srt unrar ... |     
$ sudo grub-mkconfig -o /boot/grub/grub.cfg
Generating grub configuration file ...
Found theme: /boot/grub/themes/Vimix/theme.txt
Found linux image: /boot/vmlinuz-linux
Found initrd image: /boot/initramfs-linux.img
Found fallback initrd image(s) in /boot: initramfs-linux-fallback.img
###### - Grub-btrfs: Auto-detect Start - ######
# Found snapshot: 2018-04-01 13:15:22 | @/.snapshots/7/snapshot      | single | timeline
# Found snapshot: 2018-04-01 13:14:23 | @/.snapshots/6/snapshot      | single | timeline
# Found snapshot: 2018-03-31 13:10:45 | @/.snapshots/5/snapshot      | single | timeline
# Found snapshot: 2018-03-31 00:00:27 | @/.snapshots/4/snapshot      | single | timeline
# Found snapshot: 2018-03-30 23:46:17 | @/.snapshots/3/snapshot      | single | timeline
# Found snapshot: 2018-03-30 23:46:15 | @/.snapshots/2/snapshot      | single | timeline
# Found snapshot: 2018-03-30 23:31:44 | @/.snapshots/1/snapshot      | single | timeline
# Found 7 snapshot(s)
###### - Grub-btrfs: Auto-detect End   - ######
done

However, the assignment of the snapshots is correct. If I boot into snapshot #6 for example, the old kernel is loaded.

Use with manual snapshot

Hi all, can I use this with manual snapshot? I don't use snapper but I create my snapshot with btrfs command. Can I use this for booting my snapshots? If yes, how?

cant acess '/'

Getting this error on update-grub

Generating grub configuration file ...
Found theme: /boot/grub/themes/EndeavourOS/theme.txt
Found linux image: /boot/vmlinuz-linux-lts
Found initrd image: /boot/amd-ucode.img /boot/initramfs-linux-lts.img
Found fallback initrd image(s) in /boot: initramfs-linux-lts-fallback.img
Found linux image: /boot/vmlinuz-linux
Found initrd image: /boot/amd-ucode.img /boot/initramfs-linux.img
Found fallback initrd image(s) in /boot: initramfs-linux-fallback.img
###### - Grub-btrfs: Snapshot detection started - ######
# Info: Separate boot partition not detected 
ERROR: not a btrfs filesystem: /
ERROR: can't access '/'
# No snapshots found.
# If you think an error has occurred , please file a bug report at " https://github.com/Antynea/grub-btrfs "
# Nothing to do. Abort.
###### - Grub-btrfs: Snapshot detection ended   - ######
Found memtest86+ image: /boot/memtest86+/memtest.bin
done'

How to add grub-btrfs snapshot option with grub customizer?

hello guys, does anyone know how i can include btrfs snapshots in GRUB boot options? I usually use grub-customizer to add or edit boot entires.
Grub customizer has various options to add boot entries like Scripts,Linux,Linux-ISO,Chainloader,Memtest and other..
I guess i can add an entry with grub-customizer, i am not sure on how to do it tho
Thank you

unclutter the menu with AMD microcode

I modified grub-btrfs to work with AMD microcode only (comment out the business about the intel file {the microcode filename just has "amd" instead of "intel" prefixed }) and with timeshift. Maybe I make a pull-request one time.

It would be nice to have the config option to see AMD microcode only. So the menu gets uncluttered on a AMD machine.

for timeshift, just the path line must be changed from .snapshots to /mnt/timeshift/backup/timeshift-btrfs/snapshots/

snapper-gui work great in SUSE but breaks on most other distros unfortunately.

subvolume name problem with awk gsub regex

It a subvolume with the characters in the gsub(/^["<FS_TREE>/"]+/,"",$NF) exists, the subvolume name generated for grub is incorrect. In my case, the use of the underscore in a subvolume name required changing the expression to

gsub(/^.*<FS_TREE>/,"",$NF)

Submenu empty

Hi,
I have installed and configured grub-btrfs w/o issues.
And I can see in screen that existing BTRFS snapshots are found when new Grub Menu is generated.

However, when I check the submenu in Grub there are no entries.

Could you please advise how to troubleshoot this issue?

THX

[Enhancement] Allow config option for boot partition and kernel location

I have been trying to hack this in, but grub configuration is a bit over my head. I'll describe my usercase;

  • I have an ESP (/dev/nvme1n1p1), and a LUKS container (/dev/nvme1n1p2), with an LVM on top of the luks installation. My root partition is a btrfs logical partition on the LVM.
  • I have / as a btrfs snapshot
  • I have /boot as a regular folder
  • Arch installs the kernel to /boot/vmlinuz-*
  • I mount the ESP at /boot/efi, and my grub configuration folder is found in /boot/efi/grub
  • I have a tool that automatically signs my kernel after an update, and places them in /boot/efi/EFI/Arch (and grub)

I want to use grub only to boot into my other snapshots. Currently, grub-btrfs expects the kernel location to be /boot (as hard coded). It picks up the unsigned kernel at the root of my file-system, which then cannot be found because they are encrypted. I want to be able to change the kernel location to my signed copies under the ESP, in the directory EFI/Arch/vmlinuz-*. I was wondering how to add in a config option that can change the default boot partition location, and the location for the kernels.

Docker snapshots being detected.

Bit of a hairy one.
As the docker snapshots include linux kernels, autodetect is finding them and adding them to the boot menu.
Interestingly I actually think it might be possible to boot them (haven't checked yet) but it's very unlikely that you'd ever actually want to do this.

> Attempting to update grub-cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-linux
Found initrd image: /boot/initramfs-linux.img
Found fallback initramfs image: /boot/initramfs-linux-fallback.img
###### - Grub-btrfs: Auto-detect - ######
# Found Snapshot: 2016-03-31 10:26:52 var/lib/docker/btrfs/subvolumes/74040aee4fa98f7dc6bbdcd7df8e361352c7d9dc55440ee54f312eda1f52079c
# Found Snapshot: 2016-03-31 10:26:50 var/lib/docker/btrfs/subvolumes/74040aee4fa98f7dc6bbdcd7df8e361352c7d9dc55440ee54f312eda1f52079c-init
# Found Snapshot: 2016-03-31 10:26:46 var/lib/docker/btrfs/subvolumes/b61091160bd9583172cf1a4f81be99b244aefa0674f1e04cd5990928552e0825
# Found Snapshot: 2016-03-31 10:26:45 var/lib/docker/btrfs/subvolumes/b61091160bd9583172cf1a4f81be99b244aefa0674f1e04cd5990928552e0825-init
# Found Snapshot: 2016-03-31 10:26:42 var/lib/docker/btrfs/subvolumes/5bc5ce665173d6fbc356096f938e8ebf4b3b69e2aa6c779c88e5ba19edcacd66
# Found Snapshot: 2016-03-31 10:26:42 var/lib/docker/btrfs/subvolumes/5bc5ce665173d6fbc356096f938e8ebf4b3b69e2aa6c779c88e5ba19edcacd66-init
# Found Snapshot: 2016-03-31 10:25:00 .snapshots/913/snapshot
# Found Snapshot: 2016-03-31 10:24:41 var/lib/docker/btrfs/subvolumes/805c0ef9f093c6fc2685ec9592485c2bca478f3cd0b8716533d0e78a3f07aa20
# Found Snapshot: 2016-03-31 10:24:36 var/lib/docker/btrfs/subvolumes/805c0ef9f093c6fc2685ec9592485c2bca478f3cd0b8716533d0e78a3f07aa20-init
# Found Snapshot: 2016-03-31 10:22:22 .snapshots/912/snapshot
# Found Snapshot: 2016-03-31 10:00:27 .snapshots/911/snapshot
###### - Grub-btrfs: Auto-detect - ######

grub-btrfs by default can create astounding number of menu entries, making system unbootable

I have version 1.11-2 of grub-btrfs which I installed from an archlinux user repository PKGBUILD on my Manjaro linux installation on an EFI laptop. I left everything as-is, with the default 100 snapshot limit.

In the meantime, I installed a few kernels and used my system as I pleased. Today I had to reboot after a considerable uptime in which snapper had been dutifully storing lots of snapshots, and I ended up with a system that would not boot, or at least into GRUB. What I found after thrashing aimlessly for a couple of hours was that my grub.cfg had grown to over 22000 lines, almost entirely as a result of these snapshot entries.

At first I thought that there was no limit being applied at all, but I now realize that I did have exactly 100 "Snapshot" submenus in the bloated file. There are big problems, though:

grub-btrfs does not limit the number of raw menu entries it will create, which is what will ultimately kill your bootloader

While the number of snapshots under consideration is certainly correlated to the resultant number of entries, the latter is what makes the boot menu unwieldly, and ultimately inoperable.

grub-btrfs is very greedy in its generation of menu entries

My distribution (manjaro) has a bash script at /etc/grub.d/10_linux which dictates the logic to create menu entries from every valid pair of initramfs-* and vmlinu[z|x] files it finds in /boot. grub-btrfs by contrast just makes entries for every product of the two filetypes, whether or not they make sense.

My machine currently has two vmlinuz kernel files, one each for 4.14 and 4.15. It also has initramfs files for both of those, with fallback variants, and (for reasons I have yet to determine) a couple of leftover initramfs files for a kernel that I had removed. These files result in 1 default and 4 "advanced" entries in the 10_linux section, but 12 per snapshot (=1200 total) in the 41_snapshots-btrfs section, because grub-btrfs mashes, e.g., initramfs-4.14-rt-x86_64.img and vmlinuz-4.15-x86_64 together, even though that doesn't make sense. It's honestly questionable whether we need anything more than just the latest available kernel-ramdisk pair for these snapshot entries, but certainly very few people are could have any purpose for options to boot kernel version X with ramdisk version Y.


To close, I'd like to thank you for your contributions, but to also emphasize the seriousness of this kind of failure state. Inability to launch the bootloader is a really difficult problem for anyone without serious GRUB chops to diagnose; there was no interface, no output, and no logging. This way leads desperation.

Preventing the de facto corruption of grub.cfg should be priority number 1, over and above the functionality that you're trying to deliver here (which is very appreciated!).

Thanks for reading.

Grub-btrfs is not always valid.

I have a separate boot partition. It seems that due to some strange configuration of grub.cfg, grub's default working directory is not under the boot partition. Running the configfile "/grub/grub-btrfs.cfg" will not find the file. You should first run search -f --set=root --no-floppy to set the working working directory.
Example

submenu 'Arch Linux snapshots' {
        search -f --set=root --no-floppy /grub/grub-btrfs.cfg
        configfile "/grub/grub-btrfs.cfg"
}

This is my grub.cfg

# cat /boot/grub/grub.cfg 
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
insmod part_gpt
insmod part_msdos
if [ -s $prefix/grubenv ]; then
  load_env
fi
if [ "${next_entry}" ] ; then
   set default="${next_entry}"
   set next_entry=
   save_env next_entry
   set boot_once=true
else
   set default="unsaved"
fi

if [ x"${feature_menuentry_id}" = xy ]; then
  menuentry_id_option="--id"
else
  menuentry_id_option=""
fi

export menuentry_id_option

if [ "${prev_saved_entry}" ]; then
  set saved_entry="${prev_saved_entry}"
  save_env saved_entry
  set prev_saved_entry=
  save_env prev_saved_entry
  set boot_once=true
fi

function savedefault {
  if [ -z "${boot_once}" ]; then
    saved_entry="${chosen}"
    save_env saved_entry
  fi
}

function load_video {
  if [ x$feature_all_video_module = xy ]; then
    insmod all_video
  else
    insmod efi_gop
    insmod efi_uga
    insmod ieee1275_fb
    insmod vbe
    insmod vga
    insmod video_bochs
    insmod video_cirrus
  fi
}

set menu_color_normal=light-gray/black
set menu_color_highlight=green/black

if [ x$feature_default_font_path = xy ] ; then
   font=unicode
else
insmod part_gpt
insmod btrfs
set root='hd0,gpt3'
if [ x$feature_platform_search_hint = xy ]; then
  search --no-floppy --fs-uuid --set=root --hint-ieee1275='ieee1275//disk@0,gpt3' --hint-bios=hd0,gpt3 --hint-efi=hd0,gpt3 --hint-baremetal=ahci0,gpt3  0e854bcc-6bdc-424c-a46e-251afc2842cc
else
  search --no-floppy --fs-uuid --set=root 0e854bcc-6bdc-424c-a46e-251afc2842cc
fi
    font="/@/usr/share/grub/unicode.pf2"
fi

if loadfont $font ; then
  set gfxmode=auto
  load_video
  insmod gfxterm
  set locale_dir=$prefix/locale
  set lang=zh_CN
  insmod gettext
fi
terminal_input console
terminal_output gfxterm
insmod part_gpt
insmod btrfs
set root='hd0,gpt3'
if [ x$feature_platform_search_hint = xy ]; then
  search --no-floppy --fs-uuid --set=root --hint-ieee1275='ieee1275//disk@0,gpt3' --hint-bios=hd0,gpt3 --hint-efi=hd0,gpt3 --hint-baremetal=ahci0,gpt3  0e854bcc-6bdc-424c-a46e-251afc2842cc
else
  search --no-floppy --fs-uuid --set=root 0e854bcc-6bdc-424c-a46e-251afc2842cc
fi
insmod gfxmenu
loadfont ($root)/@/usr/share/grub/themes/manjaro/dejavu_sans_12.pf2
loadfont ($root)/@/usr/share/grub/themes/manjaro/dejavu_sans_14.pf2
loadfont ($root)/@/usr/share/grub/themes/manjaro/dejavu_sans_16.pf2
loadfont ($root)/@/usr/share/grub/themes/manjaro/dejavu_sans_24.pf2
loadfont ($root)/@/usr/share/grub/themes/manjaro/dejavu_sans_48.pf2
loadfont ($root)/@/usr/share/grub/themes/manjaro/dejavu_sans_bold_16.pf2
loadfont ($root)/@/usr/share/grub/themes/manjaro/dejavu_sans_mono_12.pf2
loadfont ($root)/@/usr/share/grub/themes/manjaro/terminus-12.pf2
loadfont ($root)/@/usr/share/grub/themes/manjaro/terminus-14.pf2
loadfont ($root)/@/usr/share/grub/themes/manjaro/terminus-16.pf2
loadfont ($root)/@/usr/share/grub/themes/manjaro/terminus-18.pf2
loadfont ($root)/@/usr/share/grub/themes/manjaro/terminus-b12.pf2
loadfont ($root)/@/usr/share/grub/themes/manjaro/terminus-b14.pf2
loadfont ($root)/@/usr/share/grub/themes/manjaro/terminus-b16.pf2
loadfont ($root)/@/usr/share/grub/themes/manjaro/terminus-b18.pf2
insmod png
set theme=($root)/@/usr/share/grub/themes/manjaro/theme.txt
export theme
if [ x$feature_timeout_style = xy ] ; then
  set timeout_style=menu
  set timeout=5
# Fallback normal timeout code in case the timeout_style feature is
# unavailable.
else
  set timeout=5
fi
### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/10_linux ###
menuentry 'Manjaro Linux' --class manjaro --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-0e854bcc-6bdc-424c-a46e-251afc2842cc' {
        load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_gpt
        insmod btrfs
        set root='hd0,gpt2'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-ieee1275='ieee1275//disk@0,gpt2' --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2  0002937f-36b7-48ec-9c04-181fe4f1cbfb
        else
          search --no-floppy --fs-uuid --set=root 0002937f-36b7-48ec-9c04-181fe4f1cbfb
        fi
        linux   /vmlinuz-5.3-x86_64 root=UUID=0e854bcc-6bdc-424c-a46e-251afc2842cc rw rootflags=subvol=@  quiet
        initrd  /amd-ucode.img /initramfs-5.3-x86_64.img
}
submenu 'Advanced options for Manjaro Linux' $menuentry_id_option 'gnulinux-advanced-0e854bcc-6bdc-424c-a46e-251afc2842cc' {
        menuentry 'Manjaro Linux (Kernel: 5.3rc7.d0901.g089cf7f-1-MANJARO x64)' --class manjaro --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.3rc7.d0901.g089cf7f-1-MANJARO x64-advanced-0e854bcc-6bdc-424c-a46e-251afc2842cc' {
                load_video
                set gfxpayload=keep
                insmod gzio
                insmod part_gpt
                insmod btrfs
                set root='hd0,gpt2'
                if [ x$feature_platform_search_hint = xy ]; then
                  search --no-floppy --fs-uuid --set=root --hint-ieee1275='ieee1275//disk@0,gpt2' --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2  0002937f-36b7-48ec-9c04-181fe4f1cbfb
                else
                  search --no-floppy --fs-uuid --set=root 0002937f-36b7-48ec-9c04-181fe4f1cbfb
                fi
                linux   /vmlinuz-5.3-x86_64 root=UUID=0e854bcc-6bdc-424c-a46e-251afc2842cc rw rootflags=subvol=@  quiet
                initrd  /amd-ucode.img /initramfs-5.3-x86_64.img
        }
        menuentry 'Manjaro Linux (Kernel: 5.3rc7.d0901.g089cf7f-1-MANJARO x64 - fallback initramfs)' --class manjaro --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-5.3rc7.d0901.g089cf7f-1-MANJARO x64-fallback-0e854bcc-6bdc-424c-a46e-251afc2842cc' {
                load_video
                set gfxpayload=keep
                insmod gzio
                insmod part_gpt
                insmod btrfs
                set root='hd0,gpt2'
                if [ x$feature_platform_search_hint = xy ]; then
                  search --no-floppy --fs-uuid --set=root --hint-ieee1275='ieee1275//disk@0,gpt2' --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2  0002937f-36b7-48ec-9c04-181fe4f1cbfb
                else
                  search --no-floppy --fs-uuid --set=root 0002937f-36b7-48ec-9c04-181fe4f1cbfb
                fi
                linux   /vmlinuz-5.3-x86_64 root=UUID=0e854bcc-6bdc-424c-a46e-251afc2842cc rw rootflags=subvol=@  quiet
                initrd  /initramfs-5.3-x86_64-fallback.img
        }
}

### END /etc/grub.d/10_linux ###

### BEGIN /etc/grub.d/20_linux_xen ###
### END /etc/grub.d/20_linux_xen ###

### BEGIN /etc/grub.d/30_os-prober ###


### END /etc/grub.d/30_os-prober ###

### BEGIN /etc/grub.d/40_custom ###
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
### END /etc/grub.d/40_custom ###

### BEGIN /etc/grub.d/41_custom ###
if [ -f  ${config_directory}/custom.cfg ]; then
  source ${config_directory}/custom.cfg
elif [ -z "${config_directory}" -a -f  $prefix/custom.cfg ]; then
  source $prefix/custom.cfg;
fi
### END /etc/grub.d/41_custom ###

### BEGIN /etc/grub.d/41_snapshots-btrfs ###
submenu 'Arch Linux snapshots' {
        configfile "/grub/grub-btrfs.cfg"
}
### END /etc/grub.d/41_snapshots-btrfs ###

### BEGIN /etc/grub.d/60_memtest86+ ###
if [ "${grub_platform}" == "pc" ]; then
    menuentry "Memory Tester (memtest86+)" --class memtest86 --class gnu --class tool {
        search --fs-uuid --no-floppy --set=root --hint-ieee1275='ieee1275//disk@0,gpt2' --hint-bios=hd0,gpt2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,gpt2  0002937f-36b7-48ec-9c04-181fe4f1cbfb
        linux16 /memtest86+/memtest.bin 
    }
fi
### END /etc/grub.d/60_memtest86+ ###

Services fail when booting into snapshot

I think this may be related to #64.
Debian 10 Stable

Whenever I boot into a snapshot from GRUB, a bunch of services don't boot and I end up in a TTY console instead of the GUI like normal. My /boot/efi is on a separate partition, and is not a BTRFS subvol, I wonder if this is related?

41_snapshots-btrfs dosen't run

Hi,

When I try to run "sh 41_snapshots-btrfs" nothing happens, no output, nothing :(

[demo@btrfs01 grub.d]$ sh 41_snapshots-btrfs
[demo@Abemisser grub.d]$

My EFI is mounted at /boot/efi and my grub.cfg is located in /boot/efi/grub/ I don't if this has something to say?

Linux 4.19.1-arch1-1-ARCH #1 SMP PREEMPT Sun Nov 4 16:49:26 UTC 2018 x86_64 GNU/Linux

Is it possible to enable some kind of debug log?

Best Regards
Soren

Feature Request: enable password protection for snapshots/snapshot submenu

Grub2 supports superuser and user access using passwords.

As snapshots are clearly the domain of a sysadmin and not a regular user, any entries allowing to boot from a snapshot should be (optionally, or even by default) protected by such passwords.

TL;DR this can be done by adding --user "" to the menuentry line, but there would need to be some plumbing in the config file and documentation to make it configurable.

https://help.ubuntu.com/community/Grub2/Passwords
https://www.gnu.org/software/grub/manual/grub/grub.html#Authentication-and-authorisation

TODOs:

  • Enable password protection for submenu
  • Enable password protection for menuentry
  • Enable enabling/disabling in config file
  • Enable specifying specific user(s) in the config file ( --users "" vs --users "user1, user2")
  • Update documentation

Change grub-btrfs output

I changed the output of grub-btrfs on my machine via a patch file in the past. Basically, I removed all leading # to have the same output as grub-mkconfig.

Before:

(5/5) Generate GRUB config to let grub-btrfs detect new snapshots
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-linux-lts
Found initrd image: /boot/initramfs-linux-lts.img
Found fallback initrd image(s) in /boot: initramfs-linux-lts-fallback.img
Found linux image: /boot/vmlinuz-linux
Found initrd image: /boot/initramfs-linux.img
Found fallback initrd image(s) in /boot: initramfs-linux-fallback.img
###### - Grub-btrfs: Snapshot detection started - ######
# Info: Separate boot partition not detected 
# Info: snapper detected, using config 'root'
# Found 13 snapshot(s)
###### - Grub-btrfs: Snapshot detection ended   - ######
done

After:

(5/5) Generating GRUB config and detecting new snapshots
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-linux-lts
Found initrd image: /boot/initramfs-linux-lts.img
Found fallback initrd image(s) in /boot: initramfs-linux-lts-fallback.img
Found linux image: /boot/vmlinuz-linux
Found initrd image: /boot/initramfs-linux.img
Found fallback initrd image(s) in /boot: initramfs-linux-fallback.img
Detecting snapshots ...
Info: Separate boot partition not detected 
Info: snapper detected, using config 'root'
Found 13 snapshot(s)

However, I need to update this with every new release.

Therefore, would you accept a pull request to just replace the output or do you prefer a new config variable to switch between different output formats?

Use snapper's snapshot description if available

This is one specific request for much nicer support of snapper's snapshots, originally mentioned in #23:

Make the script run snapper list, and use the description column for the snapshot in the GRUB menu instead of the current one. The script should not require any configuration (contrary to #28), just run snapper list and fallback to the current implementation if the command returned with a non-zero exit code or didn't produce a table of entries to parse. If only some of the discovered snapshots are not mentioned in the output of snapper list, again fallback and name those snapshots with the current naming scheme.

PR #28 should be closed because #23 is an invalid issue, but some bits and pieces of the PR can be reused to implement this feature.

I can make a PR, @Antynea are you still around to review and merge?

After changing root subvol name, can't boot

I changed my root subvol name from "arch_root" to "@", I got
image

I booted into arch live CD, and changed all "arch_root" to "@" in /boot/grub/grub-btrfs.cfg , and reboot.

But when I sudo grub-mkconfig -o /boot/grub/grub.cfg, I got this

Generating grub configuration file ...
Found theme: /boot/grub/themes/Griffin/theme.txt
Found linux image: /boot/vmlinuz-linux
Found initrd image: /boot/intel-ucode.img /boot/amd-ucode.img /boot/initramfs-linux.img
Found fallback initrd image(s) in /boot: initramfs-linux-fallback.img
###### - Grub-btrfs: Snapshot detection started - ######
# Info: Separate boot partition not detected 
# Info: snapper detected, using config 'root'
# No snapshots found.
# If you think an error has occurred , please file a bug report at " https://github.com/Antynea/grub-btrfs "
# Nothing to do. Abort.
###### - Grub-btrfs: Snapshot detection ended   - ######
done

No Snapshots found on Arch Linux

Hello,

After upgrading grub-btrfs on Arch it no longer seems to find my snap shots. I get the following error. I'm happy to help troubleshoot and poke around if you can point me in the right direction.

###### - Grub-btrfs: Snapshot detection started - ######
# Info: Separate boot partition detected 
# Info: snapper detected, using config 'root'
# No snapshots found.
# If you think an error has occurred , please file a bug report at " https://github.com/Antynea/grub-btrfs "
# Nothing to do. Abort.
###### - Grub-btrfs: Snapshot detection ended   - ######

Enhancement: speed up calls to the snapper tool

The script calls snapper list three times to collect information about the snapshots.
Depending on how the underlying filesystem and snapper is set up, this may take a long time.

Suggestions:

  • Whenever calling snapper list, add the --disable-used-space option. This will speed up the listing on configurations using btrfs quota.
  • Perhaps call snapper list once, store the output in e.g. an array or a temp file, and retrieve the information from there
  • Perhaps use the --columns option to retrieve all needed information in one go and nothing else

Parser errors while detecting snapshots

Hi,

I've been using grub-btrfs for a while now on manjaro without issues, but I recently noticed that whenever I rebuild my grub config the snapshot detection takes about 20min and uses a lot of CPU.

It also throws some errors:

###### - Grub-btrfs: Snapshot detection started - ######
# Info: Separate boot partition not detected 
loading 119 failed
:1: parser error : Document is empty

^
loading 526 failed
:1: parser error : Document is empty

^
loading 527 failed
loading 618 failed
loading 675 failed
IO error (open failed path://.snapshots/629 errno:2 (No such file or directory)).
loading 119 failed
:1: parser error : Document is empty

^
loading 526 failed
:1: parser error : Document is empty

^
loading 527 failed
loading 618 failed
loading 675 failed
loading 119 failed
:1: parser error : Document is empty

^
loading 526 failed
:1: parser error : Document is empty

^
loading 527 failed
loading 618 failed
loading 675 failed

It then moves on to correctly list snapshots and completes correctly.

Any suggestions how to fix this?

No initrd line when harmonized entries chosen

Hello,

I've noticed that the script doesn't generate initrd lines when the variable
GRUB_BTRFS_CREATE_ONLY_HARMONIZED_ENTRIES is set to "true" in my /etc/default/grub.

This makes the grub.cfg unusable for snapshots unfortunately.

Enhancement: subvolumes representing multiple Linux distribution available in GRUB

Hi,
this is certainly not an issue but rather an enhancement request, or at least a question to the developers.
So, I like the software you developed in the context of BTRFS + GRUB.

However, I don't know if GRUB menu will display multiple Linux installations in dedicated BTRFS subvolumes of the same BTRFS partition.

What is needed for this?

THX

git-latest oddity

I have similar Arch installs on several computers. For some reason, pacaur -Sua insists on listing

grub-btrfs-git-latest

for update on some installs, and not others. I've uninstalled the git package but after reinstallation, the problem persists even though the --devel flag is not enabled.

Any ideas how to track this down or fix the erroneous reporting?

Not a show stopper. I ignore it but it's puzzling.

initramfs-* not found

Currently, I've deployed with Ubuntu 17.10.
After reboot to from "Ubuntu Snapshot" I've got this error

Loading Snapshot: 2017-11-22 14:00:14 ~/.snapshots/2/snapshot
Loading Kernel: vmlinuz-4.13.0-16-generic ...
Loading Initfamfs: initramfs-* ...
error: file '/@/.snapshots/2/snapshot/boot/initramfs-*' not found.

Press any key to continue ...

Any help ??

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.