mirror of
https://github.com/Antynea/grub-btrfs.git
synced 2026-03-04 21:15:02 +08:00
Compare commits
98 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
79ae25ea5d | ||
|
|
ee3c366fa4 | ||
|
|
4f1aa38604 | ||
|
|
1accd5e272 | ||
|
|
2500ce8d30 | ||
|
|
d9f54afcb7 | ||
|
|
33ad3273d3 | ||
|
|
3b0d0c4ff7 | ||
|
|
66a218356a | ||
|
|
7dc240faa7 | ||
|
|
75e6408510 | ||
|
|
fbc33391cb | ||
|
|
63c3493504 | ||
|
|
02b925e4b5 | ||
|
|
9d436adf95 | ||
|
|
301752f300 | ||
|
|
3b857348cb | ||
|
|
f3d8e99cb8 | ||
|
|
af80fe7993 | ||
|
|
c7f403d2a2 | ||
|
|
e6898c0de8 | ||
|
|
a790ff054e | ||
|
|
df643361cc | ||
|
|
b0408225c1 | ||
|
|
8142691be1 | ||
|
|
bab78d4ed8 | ||
|
|
544d2e84ac | ||
|
|
b346727219 | ||
|
|
f1ca0db36d | ||
|
|
c4d0df3a97 | ||
|
|
c1cadccd1f | ||
|
|
8cc214fd0e | ||
|
|
81bde02b03 | ||
|
|
14bf041ba6 | ||
|
|
863107588c | ||
|
|
2851ecd72b | ||
|
|
679d000446 | ||
|
|
981777d745 | ||
|
|
3433754c69 | ||
|
|
db753a9ac8 | ||
|
|
83bf1da01e | ||
|
|
2f22fd8630 | ||
|
|
88a0320d62 | ||
|
|
87b816345b | ||
|
|
d68fdf5fff | ||
|
|
87168d2d50 | ||
|
|
a437b80a35 | ||
|
|
9408231ecc | ||
|
|
9722f6732c | ||
|
|
0ed5adaf32 | ||
|
|
d4b97415b0 | ||
|
|
da36aa8847 | ||
|
|
d8df766554 | ||
|
|
9adce629f7 | ||
|
|
3c5e741641 | ||
|
|
fa65c3d6d9 | ||
|
|
4493bdc6e4 | ||
|
|
a7289b182a | ||
|
|
0fe512776a | ||
|
|
6af193c47a | ||
|
|
9a771d9842 | ||
|
|
64c08a0807 | ||
|
|
c9b605153b | ||
|
|
7e922abefb | ||
|
|
d20439554e | ||
|
|
ce8261395f | ||
|
|
133c8ebfdb | ||
|
|
2349282df5 | ||
|
|
041a9c6606 | ||
|
|
7e5bfa597f | ||
|
|
f0382536fb | ||
|
|
b50ad439d4 | ||
|
|
5f40f30985 | ||
|
|
d2c15acd72 | ||
|
|
77d69aaa81 | ||
|
|
44ee10f5ef | ||
|
|
9cb57dab40 | ||
|
|
6bfdf07bbf | ||
|
|
7f76eec16d | ||
|
|
a89834248c | ||
|
|
b49e19ce30 | ||
|
|
9b863f027b | ||
|
|
44771d9756 | ||
|
|
18c6eebf31 | ||
|
|
6ff1fc7127 | ||
|
|
92eef3079d | ||
|
|
4e1b628465 | ||
|
|
21df698e04 | ||
|
|
27335ffbaf | ||
|
|
6cd13037ce | ||
|
|
4a882e77dc | ||
|
|
cb0b55a6bb | ||
|
|
2c03d5f9e2 | ||
|
|
e286bf1a0d | ||
|
|
091ffc0ae9 | ||
|
|
28990c45bb | ||
|
|
4c57fcbbf4 | ||
|
|
e1532c0515 |
@@ -1,7 +0,0 @@
|
||||
[Service]
|
||||
# Set the possible paths for `grub-mkconfig`
|
||||
Environment="PATH=/sbin:/bin:/usr/sbin:/usr/bin"
|
||||
# Load environment variables from the configuration
|
||||
EnvironmentFile=/etc/grub.d/41_snapshots-btrfs_config
|
||||
# Regenerate just '/boot/grub/grub-btrfs.cfg' if it exists, else regenerate the whole grub menu
|
||||
ExecStartPost=/bin/bash -c 'if [ -s "/boot/${GRUB_BTRFS_DIRNAME:-grub}/grub-btrfs.cfg" ]; then /etc/grub.d/41_snapshots-btrfs; else ${GRUB_BTRFS_MKCONFIG:-/usr/bin/grub-mkconfig} -o /boot/${GRUB_BTRFS_DIRNAME:-grub}/grub.cfg; fi'
|
||||
902
41_snapshots-btrfs
Executable file → Normal file
902
41_snapshots-btrfs
Executable file → Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,19 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# GRUB_BTRFS_SUBMENUNAME="Arch Linux snapshots" # Name appearing in the Grub menu
|
||||
# GRUB_BTRFS_PREFIXENTRY="Snapshot:" # Add a name ahead your snapshots entries in the Grub menu
|
||||
# GRUB_BTRFS_DISPLAY_PATH_SNAPSHOT="true" # Show full path snapshot or only name in the Grub menu
|
||||
# GRUB_BTRFS_TITLE_FORMAT="p/d/n" # Custom title, shows/hides p"prefix" d"date" n"name" in the Grub menu, separator "/", custom order available
|
||||
# GRUB_BTRFS_LIMIT="50" # Limit the number of snapshots populated in the GRUB menu
|
||||
# GRUB_BTRFS_SUBVOLUME_SORT="descending" # Sort the found subvolumes by newest first ("descending") or oldest first ("ascending") and show $GRUB_BTRFS_LIMIT first entries.
|
||||
# GRUB_BTRFS_SHOW_SNAPSHOTS_FOUND="true" # Show snapshots found during run "grub-mkconfig"
|
||||
# GRUB_BTRFS_SHOW_TOTAL_SNAPSHOTS_FOUND="true" # Show Total of snapshots found during run "grub-mkconfig"
|
||||
# GRUB_BTRFS_NKERNEL=("vmlinuz-linux") # Use only if you have custom kernel name
|
||||
# GRUB_BTRFS_NINIT=("initramfs-linux.img" "initramfs-linux-fallback.img") # Use only if you have custom initramfs name
|
||||
# GRUB_BTRFS_INTEL_UCODE=("intel-ucode.img") # Use only if you have custom intel-ucode
|
||||
# GRUB_BTRFS_IGNORE_SPECIFIC_PATH=("var/lib/docker") # Ignore specific path during run "grub-mkconfig"
|
||||
# GRUB_BTRFS_SNAPPER_CONFIG="root" # Snapper's config name to use
|
||||
# GRUB_BTRFS_DISABLE="false" # Disable Grub-btrfs
|
||||
# GRUB_BTRFS_DIRNAME=grub # Might be grub2 on some systems ex. /boot/grub2/...
|
||||
# GRUB_BTRFS_OVERRIDE_BOOT_PARTITION_DETECTION="false" # Change to "true" if you have a boot partition in a different subvolume
|
||||
# GRUB_BTRFS_MKCONFIG=grub-mkconfig # Might be 'grub2-mkconfig' on some systems
|
||||
86
Makefile
Normal file
86
Makefile
Normal file
@@ -0,0 +1,86 @@
|
||||
PKGNAME ?= grub-btrfs
|
||||
PREFIX ?= /usr
|
||||
|
||||
INITCPIO ?= false
|
||||
SYSTEMD ?= true
|
||||
OPENRC ?= false
|
||||
|
||||
SHARE_DIR = $(DESTDIR)$(PREFIX)/share
|
||||
LIB_DIR = $(DESTDIR)$(PREFIX)/lib
|
||||
BIN_DIR = $(DESTDIR)$(PREFIX)/bin
|
||||
|
||||
.PHONY: install uninstall help
|
||||
|
||||
install:
|
||||
@if test "$(shell id -u)" != 0; then \
|
||||
echo "You are not root, run this target as root please."; \
|
||||
exit 1; \
|
||||
fi
|
||||
@install -Dm755 -t "$(DESTDIR)/etc/grub.d/" 41_snapshots-btrfs
|
||||
@install -Dm644 -t "$(DESTDIR)/etc/default/grub-btrfs/" config
|
||||
@# Systemd init system
|
||||
@if test "$(SYSTEMD)" = true; then \
|
||||
install -Dm644 -t "$(LIB_DIR)/systemd/system/" grub-btrfs.path; \
|
||||
install -Dm644 -t "$(LIB_DIR)/systemd/system/" grub-btrfs.service; \
|
||||
fi
|
||||
@# OpenRC init system
|
||||
@if test "$(OPENRC)" = true; then \
|
||||
install -Dm744 -t "$(BIN_DIR)/" grub-btrfs-openrc; \
|
||||
install -Dm744 -t "$(DESTDIR)/etc/init.d/" grub-btrfsd; \
|
||||
fi
|
||||
@# Arch Linux like distros only :
|
||||
@if test "$(INITCPIO)" = true; then \
|
||||
install -Dm644 "initramfs/Arch Linux/overlay_snap_ro-install" "$(LIB_DIR)/initcpio/install/grub-btrfs-overlayfs"; \
|
||||
install -Dm644 "initramfs/Arch Linux/overlay_snap_ro-hook" "$(LIB_DIR)/initcpio/hooks/grub-btrfs-overlayfs"; \
|
||||
fi
|
||||
@install -Dm644 -t "$(SHARE_DIR)/licenses/$(PKGNAME)/" LICENSE
|
||||
@install -Dm644 -t "$(SHARE_DIR)/doc/$(PKGNAME)/" README.md
|
||||
@install -Dm644 "initramfs/readme.md" "$(SHARE_DIR)/doc/$(PKGNAME)/initramfs-overlayfs.md"
|
||||
|
||||
uninstall:
|
||||
@if test "$(shell id -u)" != 0; then \
|
||||
echo "You are not root, run this target as root please."; \
|
||||
exit 1; \
|
||||
fi
|
||||
@grub_dirname="$$(grep -oP '^[[:space:]]*GRUB_BTRFS_GRUB_DIRNAME=\K.*' "$(DESTDIR)/etc/default/grub-btrfs/config" | sed "s|\s*#.*||;s|(\s*\(.\+\)\s*)|\1|;s|['\"]||g")"; \
|
||||
rm -f "$${grub_dirname:-/boot/grub}/grub-btrfs.cfg"
|
||||
@rm -f "$(DESTDIR)/etc/default/grub-btrfs/config"
|
||||
@rm -f "$(DESTDIR)/etc/grub.d/41_snapshots-btrfs"
|
||||
@rm -f "$(LIB_DIR)/systemd/system/grub-btrfs.path"
|
||||
@rm -f "$(LIB_DIR)/systemd/system/grub-btrfs.service"
|
||||
@rm -f "$(BIN_DIR)/grub-btrfs-openrc;"
|
||||
@rm -f "$(DESTDIR)/etc/init.d/grub-btrfsd;"
|
||||
@rm -f "$(LIB_DIR)/initcpio/install/grub-btrfs-overlayfs"
|
||||
@rm -f "$(LIB_DIR)/initcpio/hooks/grub-btrfs-overlayfs"
|
||||
@# Arch Linux UNlike distros only :
|
||||
@if test "$(INITCPIO)" != true && test -d "$(LIB_DIR)/initcpio"; then \
|
||||
rmdir --ignore-fail-on-non-empty "$(LIB_DIR)/initcpio/install" || :; \
|
||||
rmdir --ignore-fail-on-non-empty "$(LIB_DIR)/initcpio/hooks" || :; \
|
||||
rmdir --ignore-fail-on-non-empty "$(LIB_DIR)/initcpio" || :; \
|
||||
fi
|
||||
@rm -f "$(SHARE_DIR)/doc/$(PKGNAME)/README.md"
|
||||
@rm -f "$(SHARE_DIR)/doc/$(PKGNAME)/initramfs-overlayfs.md"
|
||||
@rm -f "$(SHARE_DIR)/licenses/$(PKGNAME)/LICENSE"
|
||||
@rmdir --ignore-fail-on-non-empty "$(SHARE_DIR)/doc/$(PKGNAME)/" || :
|
||||
@rmdir --ignore-fail-on-non-empty "$(SHARE_DIR)/licenses/$(PKGNAME)/" || :
|
||||
@rmdir --ignore-fail-on-non-empty "$(DESTDIR)/etc/default/grub-btrfs" || :
|
||||
|
||||
help:
|
||||
@echo
|
||||
@echo "Usage: $(MAKE) [ <parameter>=<value> ... ] [ <action> ]"
|
||||
@echo
|
||||
@echo " actions: install"
|
||||
@echo " uninstall"
|
||||
@echo " help"
|
||||
@echo
|
||||
@echo " parameter | type | description | defaults"
|
||||
@echo " ----------+------+--------------------------------+----------------------------"
|
||||
@echo " DESTDIR | path | install destination | <unset>"
|
||||
@echo " PREFIX | path | system tree prefix | '/usr'"
|
||||
@echo " SHARE_DIR | path | shared data location | '\$$(DESTDIR)\$$(PREFIX)/share'"
|
||||
@echo " LIB_DIR | path | system libraries location | '\$$(DESTDIR)\$$(PREFIX)/lib'"
|
||||
@echo " PKGNAME | name | name of the ditributed package | 'grub-btrfs'"
|
||||
@echo " INITCPIO | bool | include mkinitcpio hook | false"
|
||||
@echo " SYSTEMD | bool | include unit files | true"
|
||||
@echo " OPENRC | bool | include OpenRc daemon | false"
|
||||
@echo
|
||||
250
README.md
250
README.md
@@ -1,131 +1,155 @@
|
||||
[](https://github.com/Antynea/grub-btrfs)
|
||||
|
||||
## grub-btrfs
|
||||
[](https://github.com/Antynea/grub-btrfs/releases)
|
||||

|
||||
|
||||
This is a version 3.xx of grub-btrfs
|
||||
##### BTC donation address: 1Lbvz244WA8xbpHek9W2Y12cakM6rDe5Rt
|
||||
##
|
||||
### Description
|
||||
## grub-btrfs
|
||||
|
||||
grub-btrfs, Include btrfs snapshots at boot options. (grub menu)
|
||||
##
|
||||
### What does grub-btrfs v3.xx do :
|
||||
This is a version 4.xx of grub-btrfs
|
||||
##### BTC donation address: `1Lbvz244WA8xbpHek9W2Y12cakM6rDe5Rt`
|
||||
- - -
|
||||
### Description :
|
||||
Improves Grub by adding "btrfs snapshots" to the Grub menu.
|
||||
|
||||
Simple rollback using snapshots you made previously.
|
||||
You can boot your system on a "snapshot" from the Grub menu.
|
||||
Supports manual snapshots, snapper, timeshift ...
|
||||
|
||||
##### Warning: booting on read-only snapshots can be tricky
|
||||
|
||||
If you choose to do it, `/var/log` or even `/var` must be on a separate subvolume.
|
||||
Otherwise, make sure your snapshots are writeable.
|
||||
See [this ticket](https://github.com/Antynea/grub-btrfs/issues/92) for more info.
|
||||
|
||||
This project includes its own solution.
|
||||
Refer to the [documentation](https://github.com/Antynea/grub-btrfs/blob/master/initramfs/readme.md).
|
||||
|
||||
- - -
|
||||
### What does grub-btrfs v4.xx do :
|
||||
* Automatically List snapshots existing on root partition (btrfs).
|
||||
|
||||
* Automatically Detect if "/boot" is in separate partition.
|
||||
* Automatically Detect kernel, initramfs and intel/amd microcode in "/boot" directory on snapshots.
|
||||
* Automatically Create corresponding "menuentry" in `grub.cfg`
|
||||
* Automatically detect the type/tags and descriptions/comments of snapper/timeshift snapshots.
|
||||
* Automatically generate `grub.cfg` if you use the provided systemd service.
|
||||
|
||||
* Automatically Detect kernel, initramfs and intel microcode in "/boot" directory on snapshots.
|
||||
- - -
|
||||
### Installation :
|
||||
#### Arch Linux
|
||||
The package is available in the community repository [grub-btrfs](https://archlinux.org/packages/community/any/grub-btrfs/)
|
||||
```
|
||||
pacman -S grub-btrfs
|
||||
```
|
||||
|
||||
* Automatically Create corresponding "menuentry" in grub.cfg , which ensures a very easy rollback.
|
||||
#### 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
|
||||
emerge --sync
|
||||
```
|
||||
|
||||
* Automatically detect snapper and use snapper's snapshot description if available.
|
||||
Now merge grub-btrfs via
|
||||
`emerge app-backup/grub-btrfs`
|
||||
|
||||
#### Manual
|
||||
* Run `make install` or look into Makefile for instructions on where to put each file.
|
||||
* Run `make help` to check what options are available.
|
||||
* Dependencies:
|
||||
* [btrfs-progs](https://archlinux.org/packages/core/x86_64/btrfs-progs/)
|
||||
* [grub](https://archlinux.org/packages/core/x86_64/grub/)
|
||||
* [bash >4](https://archlinux.org/packages/core/x86_64/bash/)
|
||||
* [gawk ](https://archlinux.org/packages/core/x86_64/gawk/)
|
||||
|
||||
#### NOTE: All distros
|
||||
Generate your Grub menu after installation for the changes to take effect.
|
||||
For example:
|
||||
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-like** distribution `update-grub` is an alias to `grub-mkconfig ...`
|
||||
- - -
|
||||
### Customization :
|
||||
|
||||
You have the possibility to modify many parameters in `/etc/default/grub-btrfs/config`.
|
||||
See [config file](https://github.com/Antynea/grub-btrfs/blob/master/config) for more information.
|
||||
|
||||
- - -
|
||||
### Automatically update grub :
|
||||
#### Systemd
|
||||
1. If you would like grub-btrfs menu to automatically update when a snapshot is created or deleted:
|
||||
* Use `systemctl enable grub-btrfs.path`.
|
||||
* `grub-btrfs.path` automatically (re)generates `grub-btrfs.cfg` when a modification appears in `/.snapshots` mount point (by default).
|
||||
* If the `/.snapshots` mount point is already mounted, then use `systemctl start grub-btrfs.path` to start monitoring.
|
||||
Otherwise, the unit will automatically start monitoring when the mount point will be available.
|
||||
* If your snapshots location aren't mounted in `/.snapshots`, you must modify `grub-btrfs.path` unit using
|
||||
`systemctl edit --full grub-btrfs.path` and run `systemctl reenable grub-btrfs.path` for changes take effect.
|
||||
To find out the name of the `.mount` unit
|
||||
use `systemctl list-units -t mount`.
|
||||
* For example: Timeshift mounts its snapshot folder in `/run/timeshift/backup/timeshift-btrfs/snapshots`.
|
||||
|
||||
Use `systemctl edit --full grub-btrfs.path`.
|
||||
Then replace the whole block by:
|
||||
```
|
||||
[Unit]
|
||||
Description=Monitors for new snapshots
|
||||
DefaultDependencies=no
|
||||
Requires=run-timeshift-backup.mount
|
||||
After=run-timeshift-backup.mount
|
||||
BindsTo=run-timeshift-backup.mount
|
||||
|
||||
[Path]
|
||||
PathModified=/run/timeshift/backup/timeshift-btrfs/snapshots
|
||||
|
||||
[Install]
|
||||
WantedBy=run-timeshift-backup.mount
|
||||
```
|
||||
Then save and finally run `systemctl reenable grub-btrfs.path` for changes take effect.
|
||||
Optional:
|
||||
If the `/run/timeshift/backup/timeshift-btrfs/snapshots` mount point is already mounted,
|
||||
then use `systemctl start grub-btrfs.path` to start monitoring.
|
||||
Otherwise, the unit will automatically start monitoring when the mount point will be available.
|
||||
* You can view your change to `systemctl cat grub-btrfs.path`.
|
||||
* To revert change use `systemctl revert grub-btrfs.path`.
|
||||
|
||||
2. If you would like grub-btrfs menu to automatically update on system restart/ shutdown:
|
||||
[Look at this comment](https://github.com/Antynea/grub-btrfs/issues/138#issuecomment-766918328)
|
||||
Currently not implemented
|
||||
##
|
||||
### How to customize it:
|
||||
#### OpenRC
|
||||
1. If you would like grub-btrfs menu to automatically update when a snapshot is created or deleted:
|
||||
* Use `rc-config add grub-btrfsd default`, to start the grub-btrfsd daemon the next time the system boots.
|
||||
* To start `grub-btrfsd` right now, run `rc-service grub-btrfsd start`
|
||||
* `grub-btrfsd` automatically watches the snapshot directory of timeshift (/run/timeshift/backup/timeshift-btrfs/snapshots)
|
||||
and updates the grub-menu when a change occurs.
|
||||
* Currently untested for snapper
|
||||
|
||||
You have the possibility to modify many parameters.
|
||||
Add this lines to /etc/default/grub:
|
||||
|
||||
* GRUB_BTRFS_SUBMENUNAME="Arch Linux Snapshots"
|
||||
|
||||
(Name menu appearing in grub.)
|
||||
|
||||
* GRUB_BTRFS_PREFIXENTRY="Snapshot:"
|
||||
|
||||
(Add a name ahead your snapshots entries.)
|
||||
2. If you would like grub-btrfs menu to automatically update on system restart/ shutdown:
|
||||
Just add the following script as `/etc/local.d/grub-btrfs-update.stop`
|
||||
```
|
||||
#!/bin/bash
|
||||
|
||||
* GRUB_BTRFS_DISPLAY_PATH_SNAPSHOT="true"
|
||||
description="Update the grub btrfs snapshots menu"
|
||||
name="grub-btrfs-update"
|
||||
|
||||
(Show full path snapshot or only name, weird reaction with snapper)
|
||||
depend()
|
||||
{
|
||||
use localmount
|
||||
}
|
||||
|
||||
* GRUB_BTRFS_TITLE_FORMAT="p/d/n"
|
||||
|
||||
(Custom title, shows/hides p"prefix" d"date" n"name" in grub-menu, separator "/", custom order available)
|
||||
|
||||
* GRUB_BTRFS_NKERNEL=("kernel-custom")
|
||||
|
||||
(Use it only if you have a custom kernel name)
|
||||
|
||||
* GRUB_BTRFS_NINIT=("initramfs-custom.img" "initrd.img-custom")
|
||||
|
||||
(Use it only if you have a custom initramfs name)
|
||||
|
||||
* GRUB_BTRFS_INTEL_UCODE=("intel-ucode.img")
|
||||
|
||||
(Use it only if you have custom intel-ucode)
|
||||
|
||||
* GRUB_BTRFS_LIMIT="50"
|
||||
|
||||
(Limit the number of snapshots populated in the GRUB menu.)
|
||||
|
||||
* GRUB_BTRFS_SUBVOLUME_SORT="descending"
|
||||
|
||||
(Sort the found subvolumes by newest first ("descending") or oldest first ("ascending").
|
||||
If "ascending" is chosen then the $GRUB_BTRFS_LIMIT oldest
|
||||
subvolumes will populate the menu.)
|
||||
|
||||
* GRUB_BTRFS_SHOW_SNAPSHOTS_FOUND="true"
|
||||
bash -c 'if [ -s "${GRUB_BTRFS_GRUB_DIRNAME:-/boot/grub}/grub-btrfs.cfg" ]; then /etc/grub.d/41_snapshots-btrfs; else {GRUB_BTRFS_MKCONFIG:-grub-mkconfig} -o {GRUB_BTRFS_GRUB_DIRNAME:-/boot/grub}/grub.cfg; fi'
|
||||
```
|
||||
|
||||
(Show snapshots found during run "grub-mkconfig")
|
||||
|
||||
* GRUB_BTRFS_SHOW_TOTAL_SNAPSHOTS_FOUND="true"
|
||||
|
||||
(Show Total number of snapshots found during run "grub-mkconfig")
|
||||
Make your script executeable with `chmod a+x /etc/local.d/grub-btrfs-update.stop`.
|
||||
|
||||
* GRUB_BTRFS_IGNORE_SPECIFIC_PATH=("var/lib/docker")
|
||||
* The extension ".stop" at the end of the filename indicates to locald that this script should be run at shutdown.
|
||||
If you want to run the menu update on startup instead, rename the file to `grub-btrfs-update.start`
|
||||
* Works for snapper and timeshift
|
||||
|
||||
(Ignore specific path during run "grub-mkconfig")
|
||||
|
||||
* GRUB_BTRFS_SNAPPER_CONFIG="root"
|
||||
|
||||
(Snapper's config name to use)
|
||||
|
||||
* GRUB_BTRFS_DISABLE="true"
|
||||
|
||||
(Disable grub-btrfs)
|
||||
|
||||
* GRUB_BTRFS_DIRNAME="grub"
|
||||
|
||||
(Name of the grub folder on /boot/)
|
||||
|
||||
* GRUB_BTRFS_OVERRIDE_BOOT_PARTITION_DETECTION="false"
|
||||
(Change to "true" if you have a boot partition in a different subvolume)
|
||||
|
||||
* GRUB_BTRFS_MKCONFIG=grub-mkconfig
|
||||
|
||||
(Name or path of the 'grub-mkconfig' executable; this is 'grub2-mkconfig' on some systems)
|
||||
|
||||
Generate grub.cfg (on Arch linux use grub-mkconfig -o /boot/grub/grub.cfg )
|
||||
|
||||
grub-btrfs automatically generates snapshots entries.
|
||||
|
||||
You will see it appear differents entries (e.g : Snapshot: 2018-01-03 15:08:41 @test1 )
|
||||
##
|
||||
### Automatically update grub
|
||||
|
||||
If you would like grub to automatically update when Snapper timeline snapshots and cleanups occur, simply install `10-update_grub.conf` in the following locations:
|
||||
|
||||
- `/etc/systemd/system/snapper-timeline.service.d/`
|
||||
- `/etc/systemd/system/snapper-cleanup.service.d/`
|
||||
|
||||
Or copy `grub-btrfs.path` and `grub-btrfs.service` to `/etc/systemd/system/`
|
||||
|
||||
Once the configuration files are in place, `systemctl daemon-reload` should be run to reload the units and make the changes active.
|
||||
|
||||
##
|
||||
### Discussion
|
||||
Pour les francophones : https://forums.archlinux.fr/viewtopic.php?f=18&t=17177
|
||||
##
|
||||
##### Warning :
|
||||
by default, `grub-mkconfig` command is used.
|
||||
Might be `grub2-mkconfig` on some systems (Fedora ...).
|
||||
Edit `GRUB_BTRFS_MKCONFIG` variable in `/etc/default/grub-btrfs/config` file to reflect this.
|
||||
- - -
|
||||
### Special thanks for assistance and contributions
|
||||
|
||||
* [maximbaz](https://github.com/maximbaz)
|
||||
* [crossroads1112](https://github.com/crossroads1112)
|
||||
* [penetal](https://github.com/penetal)
|
||||
* [wesbarnett](https://github.com/wesbarnett)
|
||||
* [Psykar](https://github.com/Psykar)
|
||||
* [anyc](https://github.com/anyc)
|
||||
* [daftaupe](https://github.com/daftaupe)
|
||||
* [N-Parsons](https://github.com/N-Parsons)
|
||||
##
|
||||
* [Maxim Baz](https://github.com/maximbaz)
|
||||
* [Schievel1](https://github.com/Antynea/grub-btrfs/discussions/173#discussioncomment-1438790)
|
||||
* [All contributors](https://github.com/Antynea/grub-btrfs/graphs/contributors)
|
||||
- - -
|
||||
|
||||
132
config
Normal file
132
config
Normal file
@@ -0,0 +1,132 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Disable grub-btrfs.
|
||||
# Default: "false"
|
||||
#GRUB_BTRFS_DISABLE="true"
|
||||
|
||||
# Name appearing in the Grub menu.
|
||||
# Default: "Use distribution information from /etc/os-release."
|
||||
#GRUB_BTRFS_SUBMENUNAME="Arch Linux snapshots"
|
||||
|
||||
# Custom title.
|
||||
# Shows/Hides "date" "snapshot" "type" "description" in the Grub menu, custom order available.
|
||||
# Default: ("date" "snapshot" "type" "description")
|
||||
#GRUB_BTRFS_TITLE_FORMAT=("date" "snapshot" "type" "description")
|
||||
|
||||
# Limit the number of snapshots populated in the GRUB menu.
|
||||
# Default: "50"
|
||||
#GRUB_BTRFS_LIMIT="50"
|
||||
|
||||
# Sort the found subvolumes by "ogeneration" or "generation" or "path" or "rootid".
|
||||
# # See Sorting section to https://btrfs.wiki.kernel.org/index.php/Manpage/btrfs-subvolume#SUBCOMMAND
|
||||
# "-rootid" means list snapshot by new ones first.
|
||||
# Default: "-rootid"
|
||||
#GRUB_BTRFS_SUBVOLUME_SORT="+ogen,-gen,path,rootid"
|
||||
|
||||
# Show snapshots found during run "grub-mkconfig"
|
||||
# Default: "true"
|
||||
#GRUB_BTRFS_SHOW_SNAPSHOTS_FOUND="false"
|
||||
|
||||
# Show Total of snapshots found during run "grub-mkconfig"
|
||||
# Default: "true"
|
||||
#GRUB_BTRFS_SHOW_TOTAL_SNAPSHOTS_FOUND="true"
|
||||
|
||||
# By default, "grub-btrfs" automatically detects most existing kernels.
|
||||
# If you have one or more custom kernels, you can add them here.
|
||||
# Default: ("")
|
||||
#GRUB_BTRFS_NKERNEL=("kernel-custom" "vmlinux-custom")
|
||||
|
||||
# By default, "grub-btrfs" automatically detects most existing initramfs.
|
||||
# If you have one or more custom initramfs, you can add them here.
|
||||
# Default: ("")
|
||||
#GRUB_BTRFS_NINIT=("initramfs-custom.img" "initrd-custom.img" "otherinit-custom.gz")
|
||||
|
||||
# By default, "grub-btrfs" automatically detects most existing microcodes.
|
||||
# If you have one or more custom microcodes, you can add them here.
|
||||
# Default: ("")
|
||||
#GRUB_BTRFS_CUSTOM_MICROCODE=("custom-ucode.img" "custom-uc.img "custom_ucode.cpio")
|
||||
|
||||
# Comma seperated mount options to be used when booting a snapshot.
|
||||
# They can be defined here as well as in the "/" line inside the respective snapshots'
|
||||
# "/etc/fstab" files. Mount options found in both places are combined, and this variable
|
||||
# takes priority over `fstab` entries.
|
||||
# NB: Do NOT include "subvol=..." or "subvolid=..." here.
|
||||
# Default: ""
|
||||
#GRUB_BTRFS_ROOTFLAGS="space_cache,commit=10,norecovery"
|
||||
|
||||
# Ignore specific path during run "grub-mkconfig".
|
||||
# Only exact paths are ignored.
|
||||
# e.g : if `specific path` = @, only `@` snapshot will be ignored.
|
||||
# Default: ("@")
|
||||
GRUB_BTRFS_IGNORE_SPECIFIC_PATH=("@")
|
||||
|
||||
# Ignore prefix path during run "grub-mkconfig".
|
||||
# Any path starting with the specified string will be ignored.
|
||||
# e.g : if `prefix path` = @, all snapshots beginning with "@/..." will be ignored.
|
||||
# Default: ("var/lib/docker" "@var/lib/docker" "@/var/lib/docker")
|
||||
GRUB_BTRFS_IGNORE_PREFIX_PATH=("var/lib/docker" "@var/lib/docker" "@/var/lib/docker")
|
||||
|
||||
# Ignore specific type/tag of snapshot during run "grub-mkconfig".
|
||||
# For snapper:
|
||||
# Type = single, pre, post.
|
||||
# For Timeshift:
|
||||
# Tag = boot, ondemand, hourly, daily, weekly, monthly.
|
||||
# Default: ("")
|
||||
#GRUB_BTRFS_IGNORE_SNAPSHOT_TYPE=("")
|
||||
|
||||
# Ignore specific description of snapshot during run "grub-mkconfig".
|
||||
# e.g: timeline
|
||||
# Default: ("")
|
||||
#GRUB_BTRFS_IGNORE_SNAPSHOT_DESCRIPTION=("")
|
||||
|
||||
# By default "grub-btrfs" automatically detects your boot partition,
|
||||
# either located at the system root or on a separate partition or in a subvolume,
|
||||
# Change to "true" if your boot partition isn't detected as separate.
|
||||
# Default: "false"
|
||||
#GRUB_BTRFS_OVERRIDE_BOOT_PARTITION_DETECTION="true"
|
||||
|
||||
# Location of the folder containing the "grub.cfg" file.
|
||||
# Use by grub-btrfs to save the file "grub-btrfs.cfg".
|
||||
# Might be grub2 on some systems.
|
||||
# For example, on Fedora with EFI : "/boot/efi/EFI/fedora"
|
||||
# Default: "/boot/grub"
|
||||
#GRUB_BTRFS_GRUB_DIRNAME="/boot/grub2"
|
||||
|
||||
# Location of kernels/initramfs/microcode.
|
||||
# Use by "grub-btrfs" to detect the boot partition and the location of kernels/initrafms/microcodes.
|
||||
# Default: "/boot"
|
||||
#GRUB_BTRFS_BOOT_DIRNAME="/boot"
|
||||
|
||||
# Name/path of grub-mkconfig command, use by "grub-btrfs.service"
|
||||
# Might be 'grub2-mkconfig' on some systems (Fedora ...)
|
||||
# Default paths are /sbin:/bin:/usr/sbin:/usr/bin,
|
||||
# if your path is missing, report it on the upstream project.
|
||||
# For example, on Fedora : "/sbin/grub2-mkconfig"
|
||||
# You can use only name or full path.
|
||||
# Default: grub-mkconfig
|
||||
#GRUB_BTRFS_MKCONFIG=/usr/bin/grub2-mkconfig
|
||||
|
||||
# Name of grub-script-check command, use by "grub-btrfs"
|
||||
# Might be 'grub2-script-check' on some systems (Fedora ...)
|
||||
# For example, on Fedora : "grub2-script-check"
|
||||
# Default: grub-script-check
|
||||
#GRUB_BTRFS_SCRIPT_CHECK=grub2-script-check
|
||||
|
||||
# Path of grub-mkconfig_lib file, use by "grub-btrfs"
|
||||
# Might be '/usr/share/grub2/grub-mkconfig_lib' on some systems (Opensuse ...)
|
||||
# Default: /usr/share/grub/grub-mkconfig_lib
|
||||
#GRUB_BTRFS_MKCONFIG_LIB=/usr/share/grub2/grub-mkconfig_lib
|
||||
|
||||
# Password protection management for submenu,snapshots
|
||||
# Refer to the Grub documentation https://www.gnu.org/software/grub/manual/grub/grub.html#Authentication-and-authorisation
|
||||
# and this comment https://github.com/Antynea/grub-btrfs/issues/95#issuecomment-682295660
|
||||
#
|
||||
# Add authorized usernames separate by comma (foo,bar)
|
||||
# When Grub's password protection is enabled, the superuser is authorized by default, it isn't necessary to add it
|
||||
# Default: ""
|
||||
#GRUB_BTRFS_PROTECTION_AUTHORIZED_USERS="foo,bar"
|
||||
#
|
||||
# Disable authentication support for submenu of Grub-btrfs only (--unrestricted)
|
||||
# doesn't work if GRUB_BTRFS_PROTECTION_AUTHORIZED_USERS isn't empty
|
||||
# Default: "false"
|
||||
#GRUB_BTRFS_DISABLE_PROTECTION_SUBMENU="true"
|
||||
6
grub-btrfs-openrc
Executable file
6
grub-btrfs-openrc
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
echo $$ > /run/grub-btrfsd.pid
|
||||
|
||||
while true; do sleep 1 && inotifywait -e create -e delete /run/timeshift/backup/timeshift-btrfs/snapshots && sleep 5 && if [ -s "${GRUB_BTRFS_GRUB_DIRNAME:-/boot/grub}/grub-btrfs.cfg" ]; then /etc/grub.d/41_snapshots-btrfs; else ${GRUB_BTRFS_MKCONFIG:-grub-mkconfig} -o ${GRUB_BTRFS_GRUB_DIRNAME:-/boot/grub}/grub.cfg; fi ; done
|
||||
|
||||
|
||||
6
grub-btrfs.path
Executable file → Normal file
6
grub-btrfs.path
Executable file → Normal file
@@ -1,8 +1,12 @@
|
||||
[Unit]
|
||||
Description=Monitors for new snapshots
|
||||
DefaultDependencies=no
|
||||
Requires=\x2esnapshots.mount
|
||||
After=\x2esnapshots.mount
|
||||
BindsTo=\x2esnapshots.mount
|
||||
|
||||
[Path]
|
||||
PathModified=/.snapshots
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
WantedBy=\x2esnapshots.mount
|
||||
|
||||
4
grub-btrfs.service
Executable file → Normal file
4
grub-btrfs.service
Executable file → Normal file
@@ -6,6 +6,6 @@ Type=oneshot
|
||||
# Set the possible paths for `grub-mkconfig`
|
||||
Environment="PATH=/sbin:/bin:/usr/sbin:/usr/bin"
|
||||
# Load environment variables from the configuration
|
||||
EnvironmentFile=/etc/grub.d/41_snapshots-btrfs_config
|
||||
EnvironmentFile=/etc/default/grub-btrfs/config
|
||||
# Regenerate just '/boot/grub/grub-btrfs.cfg' if it exists and is not empty, else regenerate the whole grub menu
|
||||
ExecStart=/bin/bash -c 'if [ -s "/boot/${GRUB_BTRFS_DIRNAME:-grub}/grub-btrfs.cfg" ]; then /etc/grub.d/41_snapshots-btrfs; else ${GRUB_BTRFS_MKCONFIG:-/usr/bin/grub-mkconfig} -o /boot/${GRUB_BTRFS_DIRNAME:-grub}/grub.cfg; fi'
|
||||
ExecStart=bash -c 'if [ -s "${GRUB_BTRFS_GRUB_DIRNAME:-/boot/grub}/grub-btrfs.cfg" ]; then /etc/grub.d/41_snapshots-btrfs; else ${GRUB_BTRFS_MKCONFIG:-grub-mkconfig} -o ${GRUB_BTRFS_GRUB_DIRNAME:-/boot/grub}/grub.cfg; fi'
|
||||
|
||||
14
grub-btrfsd
Executable file
14
grub-btrfsd
Executable file
@@ -0,0 +1,14 @@
|
||||
#!/sbin/openrc-run
|
||||
# Copyright 1999-2021 Gentoo Foundation
|
||||
# Distributed under the terms of the GNU General Public License v2
|
||||
|
||||
name="grub-btrfs daemon"
|
||||
command="/usr/bin/grub-btrfs-openrc"
|
||||
pidfile="/run/{RC_SVCNAME}.pid"
|
||||
command_background=true
|
||||
|
||||
depend() {
|
||||
use localmount
|
||||
}
|
||||
|
||||
|
||||
15
initramfs/Arch Linux/overlay_snap_ro-hook
Normal file
15
initramfs/Arch Linux/overlay_snap_ro-hook
Normal file
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/ash
|
||||
|
||||
run_latehook() {
|
||||
local root_mnt="/new_root"
|
||||
local current_dev=$(resolve_device "$root"); # resolve devices for blkid
|
||||
if [[ $(blkid "${current_dev}" -s TYPE -o value) = "btrfs" ]] && [[ $(btrfs property get ${root_mnt} ro) != "ro=false" ]]; then # run only on a read only snapshot
|
||||
local lower_dir=$(mktemp -d -p /)
|
||||
local ram_dir=$(mktemp -d -p /)
|
||||
mount --move ${root_mnt} ${lower_dir} # move new_root to lower_dir
|
||||
mount -t tmpfs cowspace ${ram_dir} #meuh!!! space, you can't test !
|
||||
mkdir -p ${ram_dir}/upper
|
||||
mkdir -p ${ram_dir}/work
|
||||
mount -t overlay -o lowerdir=${lower_dir},upperdir=${ram_dir}/upper,workdir=${ram_dir}/work rootfs ${root_mnt}
|
||||
fi
|
||||
}
|
||||
18
initramfs/Arch Linux/overlay_snap_ro-install
Normal file
18
initramfs/Arch Linux/overlay_snap_ro-install
Normal file
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
|
||||
build() {
|
||||
add_module btrfs
|
||||
add_module overlay
|
||||
add_binary btrfs
|
||||
add_binary btrfsck
|
||||
add_binary blkid
|
||||
add_runscript
|
||||
}
|
||||
|
||||
help() {
|
||||
cat <<HELPEOF
|
||||
This hook uses overlayfs to boot on a read only snapshot.
|
||||
HELPEOF
|
||||
}
|
||||
|
||||
# vim: set ft=sh ts=4 sw=4 et:
|
||||
45
initramfs/readme.md
Normal file
45
initramfs/readme.md
Normal file
@@ -0,0 +1,45 @@
|
||||
### Description :
|
||||
|
||||
Booting on a snapshot in read-only mode can be tricky.
|
||||
An elegant way is to boot this snapshot using overlayfs (included in the kernel ≥ 3.18).
|
||||
|
||||
Using overlayfs, the booted snapshot will behave like a live-cd in non-persistent mode.
|
||||
The snapshot will not be modified, the system will be able to boot correctly, because a writeable folder will be included in the ram.
|
||||
(no more problems due to `/var` not open for writing)
|
||||
|
||||
Any changes in this system thus started will be lost when the system is rebooted/shutdown.
|
||||
|
||||
To do this, it is necessary to modify the initramfs.
|
||||
This means that any snapshot that does not include this modified initramfs will not be able to benefit from it.
|
||||
(except for separate boot partitions)
|
||||
#
|
||||
### Installation :
|
||||
#### Arch Linux
|
||||
1.
|
||||
`Pacman -S grub-btrfs`
|
||||
Or if you use git
|
||||
copy the `overlay_snap_ro-install` file to `/etc/initcpio/install/grub-btrfs-overlayfs`
|
||||
copy the `overlay_snap_ro-hook` file to `/etc/initcpio/hooks/grub-btrfs-overlayfs`
|
||||
You must rename the files. (I did it above)
|
||||
|
||||
For example :
|
||||
`overlay_snap_ro-install` to `grub-btrfs-overlayfs`
|
||||
`overlay_snap_ro-hook` to `grub-btrfs-overlayfs`
|
||||
Keep in mind that the files must have exactly the same name to ensure a match.
|
||||
|
||||
2.
|
||||
Edit the file `/etc/mkinitcpio.conf`
|
||||
Added hook `grub-btrfs-overlayfs` at the end of the line `HOOKS`.
|
||||
|
||||
For example :
|
||||
`HOOKS=(base udev autodetect modconf block filesystems keyboard fsck grub-btrfs-overlayfs)`
|
||||
You notice that the name of the `hook` must match the name of the 2 installed files. (don't forget it)
|
||||
|
||||
3.
|
||||
Re-generate your initramfs
|
||||
`mkinitcpio -P` (option -P means, all preset present in `/etc/mkinitcpio.d`)
|
||||
|
||||
#### Other distribution
|
||||
Refer to your distribution's documentation
|
||||
or contribute to this project to add a paragraph.
|
||||
#
|
||||
Binary file not shown.
Reference in New Issue
Block a user