Make 'grub-mkconfig' command name configurable (#56)

* Make 'grub-mkconfig' command name configurable

- Use 'grub-mkconfig' as the default
- Note that some systems use 'grub2-mkconfig'
- Update 10-update_grub.conf to use the configurable grub directory name
- Refactor the systemd commands for clarity and to avoid duplicate regeneration on first run

* Update check_uuid_required() to work for partial regeneration of the GRUB menu
This commit is contained in:
Nathan Parsons
2018-08-15 14:02:13 +02:00
committed by Antynea
parent a1a48d26b7
commit 35703e71c1
5 changed files with 37 additions and 20 deletions
+6 -1
View File
@@ -1,2 +1,7 @@
[Service] [Service]
ExecStartPost=/usr/sbin/grub-mkconfig -o /boot/grub/grub.cfg # 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'
+20 -14
View File
@@ -5,7 +5,7 @@
# Written by: Antynea # Written by: Antynea
# BTC donation address: 1Lbvz244WA8xbpHek9W2Y12cakM6rDe5Rt # BTC donation address: 1Lbvz244WA8xbpHek9W2Y12cakM6rDe5Rt
# Github: https://github.com/Antynea/grub-btrfs # Github: https://github.com/Antynea/grub-btrfs
# #
# Purpose: Include btrfs snapshots at boot options (grub-menu). # Purpose: Include btrfs snapshots at boot options (grub-menu).
# #
# What this script does: # What this script does:
@@ -96,14 +96,20 @@ grub_directory=${GRUB_BTRFS_DIRNAME:-"grub"}
## Internationalization (default : english) ## Internationalization (default : english)
export TEXTDOMAIN=grub-btrfs-git export TEXTDOMAIN=grub-btrfs-git
export TEXTDOMAINDIR="/usr/share/locale" export TEXTDOMAINDIR="/usr/share/locale"
## hints string ## Probe info "Boot partition"
hs_boot=$(${grub_probe} --target="hints_string" "/boot" 2>/dev/null) # Boot device
## UUID of the boot partition boot_device=$(${grub_probe} --target=device "/boot")
boot_uuid=$(${grub_probe} --target="fs_uuid" "/boot" 2>/dev/null) # hints string
## Type filesystem of boot partition boot_hs=$(${grub_probe} --device "${boot_device}" --target="hints_string" 2>/dev/null)
# UUID of the boot partition
boot_uuid=$(${grub_probe} --device "${boot_device}" --target="fs_uuid" 2>/dev/null)
# Type filesystem of boot partition
boot_fs=$(${grub_probe} --target="fs" "/boot" 2>/dev/null) boot_fs=$(${grub_probe} --target="fs" "/boot" 2>/dev/null)
## UUID of the root partition ## Probe info "Root partition"
root_uuid=$(${grub_probe} "/" --target="fs_uuid" 2>/dev/null) # Root device
root_device=$(${grub_probe} --target=device "/")
# UUID of the root partition
root_uuid=$(${grub_probe} --device "${root_device}" --target="fs_uuid" 2>/dev/null)
## Parameters passed to the kernel ## Parameters passed to the kernel
kernel_parameters="$GRUB_CMDLINE_LINUX $GRUB_CMDLINE_LINUX_DEFAULT" kernel_parameters="$GRUB_CMDLINE_LINUX $GRUB_CMDLINE_LINUX_DEFAULT"
## Mount point location ## Mount point location
@@ -114,12 +120,12 @@ CLASS="--class snapshots --class gnu-linux --class gnu --class os"
oldIFS=$IFS oldIFS=$IFS
## Detect uuid requirement (lvm,btrfs...) ## Detect uuid requirement (lvm,btrfs...)
check_uuid_required() { check_uuid_required() {
if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \ if [ "x${root_uuid}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
|| ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \ || ! test -e "/dev/disk/by-uuid/${root_uuid}" \
|| ( test -e "${GRUB_DEVICE}" && uses_abstraction "${GRUB_DEVICE}" lvm ); then || ( test -e "${root_device}" && uses_abstraction "${root_device}" lvm ); then
LINUX_ROOT_DEVICE=${GRUB_DEVICE} LINUX_ROOT_DEVICE=${root_device}
else else
LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID} LINUX_ROOT_DEVICE=UUID=${root_uuid}
fi fi
} }
@@ -193,7 +199,7 @@ make_menu_entries()
set gfxpayload=keep set gfxpayload=keep
insmod ${boot_fs} insmod ${boot_fs}
if [ x\$feature_platform_search_hint = xy ]; then if [ x\$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root ${hs_boot} ${boot_uuid} search --no-floppy --fs-uuid --set=root ${boot_hs} ${boot_uuid}
else else
search --no-floppy --fs-uuid --set=root ${boot_uuid} search --no-floppy --fs-uuid --set=root ${boot_uuid}
fi fi
+2 -1
View File
@@ -14,5 +14,6 @@
# GRUB_BTRFS_IGNORE_SPECIFIC_PATH=("var/lib/docker") # Ignore specific path during run "grub-mkconfig" # 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_SNAPPER_CONFIG="root" # Snapper's config name to use
# GRUB_BTRFS_DISABLE="false" # Disable Grub-btrfs # GRUB_BTRFS_DISABLE="false" # Disable Grub-btrfs
# GRUB_BTRFS_DIRNAME=grub # Might be grub2 on some systems ex. /boot/grub2/... # 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_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
+4
View File
@@ -93,6 +93,10 @@ Add this lines to /etc/default/grub:
* GRUB_BTRFS_OVERRIDE_BOOT_PARTITION_DETECTION="false" * GRUB_BTRFS_OVERRIDE_BOOT_PARTITION_DETECTION="false"
(Change to "true" if you have a boot partition in a different subvolume) (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 ) Generate grub.cfg (on Arch linux use grub-mkconfig -o /boot/grub/grub.cfg )
grub-btrfs automatically generates snapshots entries. grub-btrfs automatically generates snapshots entries.
+5 -4
View File
@@ -3,8 +3,9 @@ Description=Regenerate grub-btrfs.cfg
[Service] [Service]
Type=oneshot Type=oneshot
#Inital setup # 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/grub.d/41_snapshots-btrfs_config
ExecStartPre=-/bin/bash -c '[ ! -f "/boot/${GRUB_BTRFS_DIRNAME:-grub}/grub-btrfs.cfg" ] && grub2-mkconfig -o /boot/${GRUB_BTRFS_DIRNAME:-grub}/grub.cfg' # Regenerate just '/boot/grub/grub-btrfs.cfg' if it exists and is not empty, else regenerate the whole grub menu
#Regenerate grub-btrfs.cfg instead of 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=/etc/grub.d/41_snapshots-btrfs