mirror of
https://github.com/Antynea/grub-btrfs.git
synced 2026-03-05 21:55:01 +08:00
Compare commits
18 Commits
improve-ve
...
feature/ub
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6bc0ee806f | ||
|
|
2b9c1d2730 | ||
|
|
1749789f9a | ||
|
|
695f4b06ba | ||
|
|
d5541253d3 | ||
|
|
4e4e853f2d | ||
|
|
89ef805e81 | ||
|
|
e03e87dd64 | ||
|
|
29ec43e9a6 | ||
|
|
6980771cd2 | ||
|
|
bc167ffe00 | ||
|
|
b661e4e03f | ||
|
|
f594a56232 | ||
|
|
efc4657aab | ||
|
|
9e34f53ef8 | ||
|
|
6f154329c7 | ||
|
|
4942989d7f | ||
|
|
91c4aac82c |
@@ -569,7 +569,7 @@ rm -f "$grub_btrfs_directory/grub-btrfs.new"
|
|||||||
> "$grub_btrfs_directory/grub-btrfs.new" # Create a "grub-btrfs.new" file in "grub_btrfs_directory"
|
> "$grub_btrfs_directory/grub-btrfs.new" # Create a "grub-btrfs.new" file in "grub_btrfs_directory"
|
||||||
# Create mount point then mounting
|
# Create mount point then mounting
|
||||||
[[ ! -d $grub_btrfs_mount_point ]] && mkdir -p "$grub_btrfs_mount_point"
|
[[ ! -d $grub_btrfs_mount_point ]] && mkdir -p "$grub_btrfs_mount_point"
|
||||||
mount -o ro,subvolid=5 /dev/disk/by-uuid/"$root_uuid" "$grub_btrfs_mount_point/"
|
mount -o ro,subvolid=5 /dev/disk/by-uuid/"$root_uuid" "$grub_btrfs_mount_point/" > /dev/null
|
||||||
trap "unmount_grub_btrfs_mount_point" EXIT # unmounting mount point on EXIT signal
|
trap "unmount_grub_btrfs_mount_point" EXIT # unmounting mount point on EXIT signal
|
||||||
count_warning_menuentries=0 # Count menuentries
|
count_warning_menuentries=0 # Count menuentries
|
||||||
count_limit_snap=0 # Count snapshots
|
count_limit_snap=0 # Count snapshots
|
||||||
|
|||||||
28
Makefile
28
Makefile
@@ -2,6 +2,7 @@ PKGNAME ?= grub-btrfs
|
|||||||
PREFIX ?= /usr
|
PREFIX ?= /usr
|
||||||
|
|
||||||
INITCPIO ?= false
|
INITCPIO ?= false
|
||||||
|
MKINITRAMFS ?= false
|
||||||
SYSTEMD ?= true
|
SYSTEMD ?= true
|
||||||
OPENRC ?= false
|
OPENRC ?= false
|
||||||
|
|
||||||
@@ -59,6 +60,11 @@ install:
|
|||||||
install -Dm644 "initramfs/Arch Linux/overlay_snap_ro-install" "$(LIB_DIR)/initcpio/install/grub-btrfs-overlayfs"; \
|
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"; \
|
install -Dm644 "initramfs/Arch Linux/overlay_snap_ro-hook" "$(LIB_DIR)/initcpio/hooks/grub-btrfs-overlayfs"; \
|
||||||
fi
|
fi
|
||||||
|
@# Ubuntu like distros only :
|
||||||
|
@if test "$(MKINITRAMFS)" = true; then \
|
||||||
|
echo "Installing mkinitramfs hook"; \
|
||||||
|
initramfs/ubuntu/setup install; \
|
||||||
|
fi
|
||||||
@install -Dm644 -t "$(SHARE_DIR)/licenses/$(PKGNAME)/" LICENSE
|
@install -Dm644 -t "$(SHARE_DIR)/licenses/$(PKGNAME)/" LICENSE
|
||||||
@install -Dm644 -t "$(SHARE_DIR)/doc/$(PKGNAME)/" README.md
|
@install -Dm644 -t "$(SHARE_DIR)/doc/$(PKGNAME)/" README.md
|
||||||
@install -Dm644 "initramfs/readme.md" "$(SHARE_DIR)/doc/$(PKGNAME)/initramfs-overlayfs.md"
|
@install -Dm644 "initramfs/readme.md" "$(SHARE_DIR)/doc/$(PKGNAME)/initramfs-overlayfs.md"
|
||||||
@@ -80,6 +86,7 @@ uninstall:
|
|||||||
@rm -f "$(DESTDIR)/etc/conf.d/grub-btrfsd;"
|
@rm -f "$(DESTDIR)/etc/conf.d/grub-btrfsd;"
|
||||||
@rm -f "$(LIB_DIR)/initcpio/install/grub-btrfs-overlayfs"
|
@rm -f "$(LIB_DIR)/initcpio/install/grub-btrfs-overlayfs"
|
||||||
@rm -f "$(LIB_DIR)/initcpio/hooks/grub-btrfs-overlayfs"
|
@rm -f "$(LIB_DIR)/initcpio/hooks/grub-btrfs-overlayfs"
|
||||||
|
@initramfs/ubuntu/setup uninstall || true
|
||||||
@rm -f "$(MAN_DIR)/man8/grub-btrfs.8.bz2"
|
@rm -f "$(MAN_DIR)/man8/grub-btrfs.8.bz2"
|
||||||
@rm -f "$(MAN_DIR)/man8/grub-btrfsd.8.bz2"
|
@rm -f "$(MAN_DIR)/man8/grub-btrfsd.8.bz2"
|
||||||
@# Arch Linux UNlike distros only :
|
@# Arch Linux UNlike distros only :
|
||||||
@@ -108,14 +115,15 @@ help:
|
|||||||
@echo " uninstall"
|
@echo " uninstall"
|
||||||
@echo " help"
|
@echo " help"
|
||||||
@echo
|
@echo
|
||||||
@echo " parameter | type | description | defaults"
|
@echo " parameter | type | description | defaults"
|
||||||
@echo " ----------+------+--------------------------------+----------------------------"
|
@echo " ------------+------+--------------------------------+----------------------------"
|
||||||
@echo " DESTDIR | path | install destination | <unset>"
|
@echo " DESTDIR | path | install destination | <unset>"
|
||||||
@echo " PREFIX | path | system tree prefix | '/usr'"
|
@echo " PREFIX | path | system tree prefix | '/usr'"
|
||||||
@echo " SHARE_DIR | path | shared data location | '\$$(DESTDIR)\$$(PREFIX)/share'"
|
@echo " SHARE_DIR | path | shared data location | '\$$(DESTDIR)\$$(PREFIX)/share'"
|
||||||
@echo " LIB_DIR | path | system libraries location | '\$$(DESTDIR)\$$(PREFIX)/lib'"
|
@echo " LIB_DIR | path | system libraries location | '\$$(DESTDIR)\$$(PREFIX)/lib'"
|
||||||
@echo " PKGNAME | name | name of the ditributed package | 'grub-btrfs'"
|
@echo " PKGNAME | name | name of the ditributed package | 'grub-btrfs'"
|
||||||
@echo " INITCPIO | bool | include mkinitcpio hook | false"
|
@echo " INITCPIO | bool | include mkinitcpio hook | false"
|
||||||
@echo " SYSTEMD | bool | include unit files | true"
|
@echo " MKINITRAMFS | bool | include mkinitramfs hook | false"
|
||||||
@echo " OPENRC | bool | include OpenRc daemon | false"
|
@echo " SYSTEMD | bool | include unit files | true"
|
||||||
|
@echo " OPENRC | bool | include OpenRc daemon | false"
|
||||||
@echo
|
@echo
|
||||||
|
|||||||
36
README.md
36
README.md
@@ -104,6 +104,8 @@ Disable colors in output.
|
|||||||
* `-l / --log-file`
|
* `-l / --log-file`
|
||||||
This arguments specifies a file where grub-btrfsd should write log messages.
|
This arguments specifies a file where grub-btrfsd should write log messages.
|
||||||
* `-s / --syslog`
|
* `-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.
|
||||||
* `-t / --timeshift-auto`
|
* `-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 is changing 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_DIR` has no effect.
|
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 is changing 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_DIR` has no effect.
|
||||||
* `-v / --verbose`
|
* `-v / --verbose`
|
||||||
@@ -160,8 +162,6 @@ sudo systemctl enable grub-btrfsd
|
|||||||
```
|
```
|
||||||
|
|
||||||
##### 💼 Snapshots not in `/.snapshots`
|
##### 💼 Snapshots not in `/.snapshots`
|
||||||
NOTE: This works also for Timeshift versions < 22.06, the path to watch would be `/run/timeshift/backup/timeshift-btrfs/snapshots`.
|
|
||||||
|
|
||||||
By default the daemon is watching the directory `/.snapshots`. If the daemon should watch a different directory, it can be edited with
|
By default the daemon is watching the directory `/.snapshots`. If the daemon should watch a different directory, it can be edited with
|
||||||
```bash
|
```bash
|
||||||
sudo systemctl edit --full grub-btrfsd
|
sudo systemctl edit --full grub-btrfsd
|
||||||
@@ -184,10 +184,11 @@ EnvironmentFile=/etc/default/grub-btrfs/config
|
|||||||
# SNAPSHOTS_DIR Snapshot directory to watch, without effect when --timeshift-auto
|
# SNAPSHOTS_DIR Snapshot directory to watch, without effect when --timeshift-auto
|
||||||
# Optional arguments:
|
# Optional arguments:
|
||||||
# -t, --timeshift-auto Automatically detect Timeshifts snapshot directory
|
# -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
|
# -l, --log-file Specify a logfile to write to
|
||||||
# -v, --verbose Let the log of the daemon be more verbose
|
# -v, --verbose Let the log of the daemon be more verbose
|
||||||
# -s, --syslog Write to syslog
|
# -s, --syslog Write to syslog
|
||||||
ExecStart=/usr/bin/grub-btrfsd --syslog /path/to/your/snapshot/directory
|
ExecStart=/usr/bin/grub-btrfsd --syslog /.snapshots
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
@@ -282,21 +283,19 @@ After editing, the file should look like this:
|
|||||||
# Distributed under the terms of the GNU General Public License v3
|
# Distributed under the terms of the GNU General Public License v3
|
||||||
|
|
||||||
## Where to locate the root snapshots
|
## Where to locate the root snapshots
|
||||||
#snapshots="/.snapshots" # Snapper in the root directory
|
snapshots="/.snapshots" # Snapper in the root directory
|
||||||
#snapshots="/run/timeshift/backup/timeshift-btrfs/snapshots" # Timeshift < v22.06
|
#snapshots="/run/timeshift/backup/timeshift-btrfs/snapshots" # Timeshift < v22.06
|
||||||
snapshots="/path/to/your/snapshot/directory"
|
|
||||||
|
|
||||||
## Optional arguments to run with the daemon
|
## Optional arguments to run with the daemon
|
||||||
|
# Append options to this like this:
|
||||||
|
# optional_args="--syslog --timeshift-auto --verbose"
|
||||||
# Possible options are:
|
# Possible options are:
|
||||||
# -t, --timeshift-auto Automatically detect Timeshifts snapshot directory for timeshift >= 22.06
|
# -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
|
# -l, --log-file Specify a logfile to write to
|
||||||
# -v, --verbose Let the log of the daemon be more verbose
|
# -v, --verbose Let the log of the daemon be more verbose
|
||||||
# -s, --syslog Write to syslog
|
# -s, --syslog Write to syslog
|
||||||
# Uncomment the line to activate the option
|
optional_args="--syslog"
|
||||||
optional_args+="--syslog " # write to syslog by default
|
|
||||||
#optional_args+="--timeshift-auto "
|
|
||||||
#optional_args+="--log-file /var/log/grub-btrfsd.log "
|
|
||||||
#optional_args+="--verbose "
|
|
||||||
```
|
```
|
||||||
|
|
||||||
After that, the daemon should be restarted with
|
After that, the daemon should be restarted with
|
||||||
@@ -383,6 +382,23 @@ sudo /usr/bin/grub-btrfsd /.snapshots --verbose` (for snapper)
|
|||||||
Or pass `--verbose` to the daemon using the Systemd .service-file or the OpenRC conf.d file respectively. (see Daemon installation instructions how to do that)
|
Or pass `--verbose` to the daemon using the Systemd .service-file or the OpenRC conf.d file respectively. (see Daemon installation instructions how to do that)
|
||||||
|
|
||||||
- - -
|
- - -
|
||||||
|
### 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`:
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
#!/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
|
### Special thanks for assistance and contributions
|
||||||
* [Maxim Baz](https://github.com/maximbaz)
|
* [Maxim Baz](https://github.com/maximbaz)
|
||||||
* [Schievel1](https://github.com/Antynea/grub-btrfs/discussions/173#discussioncomment-1438790)
|
* [Schievel1](https://github.com/Antynea/grub-btrfs/discussions/173#discussioncomment-1438790)
|
||||||
|
|||||||
2
config
2
config
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
GRUB_BTRFS_VERSION=4.12-master-2022-11-26T16:38:15+00:00
|
GRUB_BTRFS_VERSION=4.12-master-2022-12-10T21:20:15+00:00
|
||||||
|
|
||||||
# Disable grub-btrfs.
|
# Disable grub-btrfs.
|
||||||
# Default: "false"
|
# Default: "false"
|
||||||
|
|||||||
35
grub-btrfsd
35
grub-btrfsd
@@ -1,4 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/usr/bin/env bash
|
||||||
# Copyright 2022 Pascal Jaeger
|
# Copyright 2022 Pascal Jaeger
|
||||||
# Distributed under the terms of the GNU General Public License v3
|
# Distributed under the terms of the GNU General Public License v3
|
||||||
# Update GRUB when new BTRFS snapshots are created.
|
# Update GRUB when new BTRFS snapshots are created.
|
||||||
@@ -9,6 +9,7 @@ watchtime=0
|
|||||||
logfile=0
|
logfile=0
|
||||||
snapshots=-1
|
snapshots=-1
|
||||||
timeshift_auto=false
|
timeshift_auto=false
|
||||||
|
timeshift_old=false
|
||||||
verbose=false
|
verbose=false
|
||||||
syslog=false
|
syslog=false
|
||||||
|
|
||||||
@@ -31,8 +32,8 @@ setcolors true # normally we want colors
|
|||||||
sysconfdir="/etc"
|
sysconfdir="/etc"
|
||||||
grub_btrfs_config="${sysconfdir}/default/grub-btrfs/config"
|
grub_btrfs_config="${sysconfdir}/default/grub-btrfs/config"
|
||||||
# source config file
|
# source config file
|
||||||
[[ -f "$grub_btrfs_config" ]] && . "$grub_btrfs_config"
|
[ -f "$grub_btrfs_config" ] && . "$grub_btrfs_config"
|
||||||
[[ -f "${sysconfdir}/default/grub" ]] && . "${sysconfdir}/default/grub"
|
[ -f "${sysconfdir}/default/grub" ] && . "${sysconfdir}/default/grub"
|
||||||
|
|
||||||
print_help() {
|
print_help() {
|
||||||
echo "${CYAN}[?] Usage:"
|
echo "${CYAN}[?] Usage:"
|
||||||
@@ -44,6 +45,7 @@ print_help() {
|
|||||||
echo "-c, --no-color Disable colors in output"
|
echo "-c, --no-color Disable colors in output"
|
||||||
echo "-l, --log-file Specify a logfile to write to"
|
echo "-l, --log-file Specify a logfile to write to"
|
||||||
echo "-s, --syslog Write to syslog"
|
echo "-s, --syslog Write to syslog"
|
||||||
|
echo "-o, --timeshift-old Look for snapshots in directory of Timeshift <v22.06 (requires --timeshift-auto)"
|
||||||
echo "-t, --timeshift-auto Automatically detect Timeshifts snapshot directory"
|
echo "-t, --timeshift-auto Automatically detect Timeshifts snapshot directory"
|
||||||
echo "-v, --verbose Let the log of the daemon be more verbose"
|
echo "-v, --verbose Let the log of the daemon be more verbose"
|
||||||
echo "-h, --help Display this message"
|
echo "-h, --help Display this message"
|
||||||
@@ -97,6 +99,9 @@ while getopts :l:ctvsh-: opt; do
|
|||||||
timeshift-auto)
|
timeshift-auto)
|
||||||
timeshift_auto=true
|
timeshift_auto=true
|
||||||
;;
|
;;
|
||||||
|
timeshift-old)
|
||||||
|
timeshift_old=true
|
||||||
|
;;
|
||||||
verbose)
|
verbose)
|
||||||
verbose=true
|
verbose=true
|
||||||
;;
|
;;
|
||||||
@@ -125,6 +130,9 @@ while getopts :l:ctvsh-: opt; do
|
|||||||
t)
|
t)
|
||||||
timeshift_auto=true
|
timeshift_auto=true
|
||||||
;;
|
;;
|
||||||
|
o)
|
||||||
|
timeshift_old=true
|
||||||
|
;;
|
||||||
v)
|
v)
|
||||||
verbose=true
|
verbose=true
|
||||||
;;
|
;;
|
||||||
@@ -150,7 +158,7 @@ shift $(( OPTIND - 1 ))
|
|||||||
snapshots="${1}"
|
snapshots="${1}"
|
||||||
|
|
||||||
# check if inotify exists, see issue #227
|
# check if inotify exists, see issue #227
|
||||||
if ! command -v inotifywait &> /dev/null; then
|
if ! command -v inotifywait >/dev/null 2>&1; then
|
||||||
err "[!] inotifywait was not found, exiting. Is inotify-tools installed?" "${RED}" >&2
|
err "[!] inotifywait was not found, exiting. Is inotify-tools installed?" "${RED}" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@@ -168,9 +176,15 @@ else
|
|||||||
inotify_qiet_flag=" -q -q "
|
inotify_qiet_flag=" -q -q "
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ ${timeshift_auto} = false ] && [ ${timeshift_old} = true ]; then
|
||||||
|
err "[!] Flag --timeshift-old requires flag --timeshift-auto" "${RED}" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
vlog "Arguments:"
|
vlog "Arguments:"
|
||||||
vlog "Snapshot directory: $snapshots"
|
vlog "Snapshot directory: $snapshots"
|
||||||
vlog "Timestift autodetection: $timeshift_auto"
|
vlog "Timestift autodetection: $timeshift_auto"
|
||||||
|
vlog "Timeshift old: $timeshift_old"
|
||||||
vlog "Logfile: $logfile"
|
vlog "Logfile: $logfile"
|
||||||
|
|
||||||
if ! [ -d "$snapshots" ] && ! [ ${timeshift_auto} = true ]; then
|
if ! [ -d "$snapshots" ] && ! [ ${timeshift_auto} = true ]; then
|
||||||
@@ -204,6 +218,15 @@ create_grub_menu() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set_snapshot_dir() {
|
||||||
|
# old timeshift has it's snapshot dir in a different location
|
||||||
|
if [ "${timeshift_old}" = true ]; then
|
||||||
|
snapshots="/run/timeshift/backup/timeshift-btrfs/snapshots"
|
||||||
|
else
|
||||||
|
snapshots="/run/timeshift/${timeshift_pid}/backup/timeshift-btrfs/snapshots"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# start the actual daemon
|
# start the actual daemon
|
||||||
vlog "Snapshot dir watchtimeout: $watchtime"
|
vlog "Snapshot dir watchtimeout: $watchtime"
|
||||||
vlog "Entering infinite while" "${GREEN}"
|
vlog "Entering infinite while" "${GREEN}"
|
||||||
@@ -217,7 +240,7 @@ while true; do
|
|||||||
fi
|
fi
|
||||||
timeshift_pid=$(ps ax | awk '{sub(/.*\//, "", $5)} $5 ~ /timeshift/ {print $1}')
|
timeshift_pid=$(ps ax | awk '{sub(/.*\//, "", $5)} $5 ~ /timeshift/ {print $1}')
|
||||||
if [ "${#timeshift_pid}" -gt 0 ]; then
|
if [ "${#timeshift_pid}" -gt 0 ]; then
|
||||||
snapshots="/run/timeshift/${timeshift_pid}/backup/timeshift-btrfs/snapshots"
|
set_snapshot_dir
|
||||||
log "detected running Timeshift at daemon startup, PID is: $timeshift_pid"
|
log "detected running Timeshift at daemon startup, PID is: $timeshift_pid"
|
||||||
vlog "new snapshots directory is $snapshots"
|
vlog "new snapshots directory is $snapshots"
|
||||||
else
|
else
|
||||||
@@ -225,7 +248,7 @@ while true; do
|
|||||||
inotifywait ${inotify_qiet_flag} -e create -e delete /run/timeshift && {
|
inotifywait ${inotify_qiet_flag} -e create -e delete /run/timeshift && {
|
||||||
sleep 1
|
sleep 1
|
||||||
timeshift_pid=$(ps ax | awk '{sub(/.*\//, "", $5)} $5 ~ /timeshift/ {print $1}')
|
timeshift_pid=$(ps ax | awk '{sub(/.*\//, "", $5)} $5 ~ /timeshift/ {print $1}')
|
||||||
snapshots="/run/timeshift/${timeshift_pid}/backup/timeshift-btrfs/snapshots"
|
set_snapshot_dir
|
||||||
log "detected Timeshift startup, PID is: $timeshift_pid" "${CYAN}"
|
log "detected Timeshift startup, PID is: $timeshift_pid" "${CYAN}"
|
||||||
vlog "new snapshots directory is $snapshots" "${CYAN}"
|
vlog "new snapshots directory is $snapshots" "${CYAN}"
|
||||||
(create_grub_menu) # create the grub menu once immidiatly in a forking process. Snapshots from commandline using timeshift --create need this
|
(create_grub_menu) # create the grub menu once immidiatly in a forking process. Snapshots from commandline using timeshift --create need this
|
||||||
|
|||||||
@@ -6,13 +6,12 @@ snapshots="/.snapshots" # Snapper in the root directory
|
|||||||
#snapshots="/run/timeshift/backup/timeshift-btrfs/snapshots" # Timeshift < v22.06
|
#snapshots="/run/timeshift/backup/timeshift-btrfs/snapshots" # Timeshift < v22.06
|
||||||
|
|
||||||
## Optional arguments to run with the daemon
|
## Optional arguments to run with the daemon
|
||||||
|
# Append options to this like this:
|
||||||
|
# optional_args="--syslog --timeshift-auto --verbose"
|
||||||
# Possible options are:
|
# Possible options are:
|
||||||
# -t, --timeshift-auto Automatically detect Timeshifts snapshot directory for timeshift >= 22.06
|
# -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
|
# -l, --log-file Specify a logfile to write to
|
||||||
# -v, --verbose Let the log of the daemon be more verbose
|
# -v, --verbose Let the log of the daemon be more verbose
|
||||||
# -s, --syslog Write to syslog
|
# -s, --syslog Write to syslog
|
||||||
# Uncomment the line to activate the option
|
optional_args="--syslog"
|
||||||
optional_args+="--syslog " # write to syslog by default
|
|
||||||
#optional_args+="--timeshift-auto "
|
|
||||||
#optional_args+="--log-file /var/log/grub-btrfsd.log "
|
|
||||||
#optional_args+="--verbose "
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ EnvironmentFile=/etc/default/grub-btrfs/config
|
|||||||
# SNAPSHOTS_DIR Snapshot directory to watch, without effect when --timeshift-auto
|
# SNAPSHOTS_DIR Snapshot directory to watch, without effect when --timeshift-auto
|
||||||
# Optional arguments:
|
# Optional arguments:
|
||||||
# -t, --timeshift-auto Automatically detect Timeshifts snapshot directory
|
# -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
|
# -l, --log-file Specify a logfile to write to
|
||||||
# -v, --verbose Let the log of the daemon be more verbose
|
# -v, --verbose Let the log of the daemon be more verbose
|
||||||
# -s, --syslog Write to syslog
|
# -s, --syslog Write to syslog
|
||||||
|
|||||||
@@ -39,6 +39,13 @@ You notice that the name of the `hook` must match the name of the 2 installed fi
|
|||||||
Re-generate your initramfs
|
Re-generate your initramfs
|
||||||
`mkinitcpio -P` (option -P means, all preset present in `/etc/mkinitcpio.d`)
|
`mkinitcpio -P` (option -P means, all preset present in `/etc/mkinitcpio.d`)
|
||||||
|
|
||||||
|
#### Ubuntu
|
||||||
|
Install initramfs scripts & re-generate initramfs.
|
||||||
|
|
||||||
|
``` shell
|
||||||
|
sudo initramfs/ubuntu/setup install
|
||||||
|
```
|
||||||
|
|
||||||
#### Other distribution
|
#### Other distribution
|
||||||
Refer to your distribution's documentation
|
Refer to your distribution's documentation
|
||||||
or contribute to this project to add a paragraph.
|
or contribute to this project to add a paragraph.
|
||||||
|
|||||||
15
initramfs/ubuntu/hooks/grub-btrfs-overlay
Executable file
15
initramfs/ubuntu/hooks/grub-btrfs-overlay
Executable file
@@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/sh -e
|
||||||
|
PREREQ=
|
||||||
|
prereqs() {
|
||||||
|
echo "$PREREQ"
|
||||||
|
}
|
||||||
|
case "$1" in
|
||||||
|
prereqs)
|
||||||
|
prereqs
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
. /usr/share/initramfs-tools/hook-functions
|
||||||
|
manual_add_modules overlay
|
||||||
|
copy_exec /usr/bin/findmnt /usr/bin
|
||||||
32
initramfs/ubuntu/scripts/local-bottom/grub-btrfs-overlay
Executable file
32
initramfs/ubuntu/scripts/local-bottom/grub-btrfs-overlay
Executable file
@@ -0,0 +1,32 @@
|
|||||||
|
#!/bin/sh -e
|
||||||
|
PREREQ=
|
||||||
|
prereqs() {
|
||||||
|
echo "$PREREQ"
|
||||||
|
}
|
||||||
|
case $1 in
|
||||||
|
prereqs)
|
||||||
|
prereqs
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
. /scripts/functions
|
||||||
|
on_err() {
|
||||||
|
log_failure_msg 'error setting up overlay'
|
||||||
|
}
|
||||||
|
trap on_err ERR
|
||||||
|
if [ -x /usr/bin/btrfs -a -x /usr/bin/findmnt ] &&
|
||||||
|
[ "$(findmnt -no FSTYPE -M "$rootmnt")" = btrfs ] &&
|
||||||
|
[ "$(btrfs property get $rootmnt ro)" != ro=false ]
|
||||||
|
then
|
||||||
|
log_begin_msg 'remount read-only subvolume as read-only layer in non-persistent, writable overlay'
|
||||||
|
trap log_end_msg EXIT
|
||||||
|
lower_dir="$(mktemp -dp /)"
|
||||||
|
ram_dir="$(mktemp -dp /)"
|
||||||
|
upper_dir="$ram_dir"/upper
|
||||||
|
work_dir="$ram_dir"/work
|
||||||
|
mount --move "$rootmnt" "$lower_dir"
|
||||||
|
mount -t tmpfs cowspace "$ram_dir"
|
||||||
|
mkdir -p "$upper_dir" "$work_dir"
|
||||||
|
mount -t overlay -o lowerdir="$lower_dir",upperdir="$upper_dir",workdir="$work_dir" rootfs "$rootmnt"
|
||||||
|
fi
|
||||||
70
initramfs/ubuntu/setup
Executable file
70
initramfs/ubuntu/setup
Executable file
@@ -0,0 +1,70 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
log() {
|
||||||
|
local CODE=$?
|
||||||
|
echo >&2 "$*"
|
||||||
|
return $CODE
|
||||||
|
}
|
||||||
|
print-help() {
|
||||||
|
log "\
|
||||||
|
usage: ${0##*/} [-h] [--] (install|uninstall)
|
||||||
|
Install initramfs scripts for Ubuntu.
|
||||||
|
|
||||||
|
# Options
|
||||||
|
-h display this help & exit
|
||||||
|
|
||||||
|
# Subcommands
|
||||||
|
install install initramfs scripts
|
||||||
|
uninstall remove initramfs scripts"
|
||||||
|
}
|
||||||
|
usage-error() {
|
||||||
|
print-help
|
||||||
|
exit 2
|
||||||
|
}
|
||||||
|
action-install() {
|
||||||
|
local SCRIPT_DIR="$(cd -P -- "$(dirname -- "$BASH_SOURCE")" && pwd)"
|
||||||
|
install {"$SCRIPT_DIR",/etc/initramfs-tools}/hooks/grub-btrfs-overlay
|
||||||
|
install {"$SCRIPT_DIR",/etc/initramfs-tools}/scripts/local-bottom/grub-btrfs-overlay
|
||||||
|
}
|
||||||
|
action-uninstall() {
|
||||||
|
rm -f /etc/initramfs-tools/{hooks,scripts/local-bottom}/grub-btrfs-overlay
|
||||||
|
}
|
||||||
|
set -e
|
||||||
|
while getopts h OPT
|
||||||
|
do case "$OPT" in
|
||||||
|
h)
|
||||||
|
print-help
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
usage-error
|
||||||
|
esac done
|
||||||
|
shift $(( OPTIND - 1 ))
|
||||||
|
OPTIND=1
|
||||||
|
ACTION=
|
||||||
|
case "$#" in
|
||||||
|
0)
|
||||||
|
log event: a subcommand is required
|
||||||
|
usage-error
|
||||||
|
;;
|
||||||
|
1)
|
||||||
|
case "$1" in
|
||||||
|
install|uninstall)
|
||||||
|
ACTION="action-$1"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
log "\
|
||||||
|
event: unknown subcommand
|
||||||
|
subcommand: $1"
|
||||||
|
usage-error
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
log "\
|
||||||
|
event: too many arguments
|
||||||
|
arguments: $*"
|
||||||
|
usage-error
|
||||||
|
esac
|
||||||
|
"$ACTION" || log "\
|
||||||
|
event: execution failure
|
||||||
|
suggestion: rerun with sudo"
|
||||||
|
exec update-initramfs -u
|
||||||
@@ -9,7 +9,7 @@ when a new btrfs snapshot is created.
|
|||||||
|
|
||||||
.SH "SYNOPSIS"
|
.SH "SYNOPSIS"
|
||||||
.PP
|
.PP
|
||||||
\fCgrub\-btrfsd [\-h, \-\-help] [\-c, \-\-no\-color] [\-l, \-\-log\-file LOG_FILE] [\-s, \-\-syslog] [\-t, \-\-timeshift\-auto] [\-v, \-\-verbose] SNAPSHOTS_DIR\fP
|
\fCgrub\-btrfsd [\-h, \-\-help] [\-c, \-\-no\-color] [\-l, \-\-log\-file LOG_FILE] [\-s, \-\-syslog] [\-t, \-\-timeshift\-auto] [\-o, \-\-timeshift\-old] [\-v, \-\-verbose] SNAPSHOTS_DIR\fP
|
||||||
|
|
||||||
.SH "DESCRIPTION"
|
.SH "DESCRIPTION"
|
||||||
.PP
|
.PP
|
||||||
@@ -38,6 +38,10 @@ Write to syslog
|
|||||||
.PP
|
.PP
|
||||||
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 \fC/run/timeshift/$PID/backup/timeshift\-btrfs\fP. Where \fC$PID\fP is the process ID of the currently running Timeshift session. The PID is changing 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 \fCSNAPSHOTS_DIR\fP has no effect.
|
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 \fC/run/timeshift/$PID/backup/timeshift\-btrfs\fP. Where \fC$PID\fP is the process ID of the currently running Timeshift session. The PID is changing 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 \fCSNAPSHOTS_DIR\fP has no effect.
|
||||||
|
|
||||||
|
.SS "\fC\-o / \-\-timeshift\-old\fP"
|
||||||
|
.PP
|
||||||
|
Look for snapshots in \fC/run/timeshift/backup/timeshift\-btrfs\fP instead of \fC/run/timeshift/$PID/backup/timeshift\-btrfs\fP. This is to be used for Timeshift versions <22.06.
|
||||||
|
|
||||||
.SS "\fC\-v / \-\-verbose\fP"
|
.SS "\fC\-v / \-\-verbose\fP"
|
||||||
.PP
|
.PP
|
||||||
Let the log of the daemon be more verbose
|
Let the log of the daemon be more verbose
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ grub-btrfsd - An OpenRC daemon to automatically update the grub menu with
|
|||||||
when a new btrfs snapshot is created.
|
when a new btrfs snapshot is created.
|
||||||
|
|
||||||
* SYNOPSIS
|
* SYNOPSIS
|
||||||
~grub-btrfsd [-h, --help] [-c, --no-color] [-l, --log-file LOG_FILE] [-s, --syslog] [-t, --timeshift-auto] [-v, --verbose] SNAPSHOTS_DIR~
|
~grub-btrfsd [-h, --help] [-c, --no-color] [-l, --log-file LOG_FILE] [-s, --syslog] [-t, --timeshift-auto] [-o, --timeshift-old] [-v, --verbose] SNAPSHOTS_DIR~
|
||||||
|
|
||||||
* DESCRIPTION
|
* DESCRIPTION
|
||||||
Grub-btrfsd is a shell script which is meant to be run as a daemon.
|
Grub-btrfsd is a shell script which is meant to be run as a daemon.
|
||||||
@@ -33,6 +33,9 @@ Write to syslog
|
|||||||
** ~-t / --timeshift-auto~
|
** ~-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 is changing 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_DIR~ has no effect.
|
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 is changing 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_DIR~ has no effect.
|
||||||
|
|
||||||
|
** ~-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.
|
||||||
|
|
||||||
** ~-v / --verbose~
|
** ~-v / --verbose~
|
||||||
Let the log of the daemon be more verbose
|
Let the log of the daemon be more verbose
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user