mirror of
https://github.com/Antynea/grub-btrfs.git
synced 2026-03-07 23:04:32 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9b73e0ac62 | ||
|
|
b17e7bd6a1 | ||
|
|
b8325cf134 | ||
|
|
c5da4014ae |
@@ -2,67 +2,39 @@
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
#########################################################################################################################################################################
|
#########################################################################################################################################################################
|
||||||
# Written by: Antynea #
|
# Written by: Antynea
|
||||||
# BTC donation address: 1Lbvz244WA8xbpHek9W2Y12cakM6rDe5Rt #
|
# BTC donation address: 1Lbvz244WA8xbpHek9W2Y12cakM6rDe5Rt
|
||||||
# #
|
# 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: #
|
#
|
||||||
# Simple rollback using snapshots you made previously. #
|
# What this script does:
|
||||||
# - Automatically List snapshots existing on root partition (btrfs). #
|
# Simple rollback using snapshots you made previously.
|
||||||
# - Automatically Detect if "/boot" is in separate partition. #
|
# - Automatically List snapshots existing on root partition (btrfs).
|
||||||
# - Automatically Detect kernel, initramfs and intel microcode in "/boot" directory on snapshots. (For custon name, see below.) #
|
# - Automatically Detect if "/boot" is in separate partition.
|
||||||
# - Automatically Create corresponding "menuentry" in grub.cfg , which ensures a very easy rollback. #
|
# - Automatically Detect kernel, initramfs and intel microcode in "/boot" directory on snapshots.
|
||||||
# - Automatically detect snapper and use snapper's snapshot description if available. #
|
# - Automatically Create corresponding "menuentry" in grub.cfg , which ensures a very easy rollback.
|
||||||
# #
|
# - Automatically detect snapper and use snapper's snapshot description if available.
|
||||||
# How to use it: #
|
#
|
||||||
# - Add this lines to /etc/default/grub: #
|
# How to customize it:
|
||||||
# #
|
# - Refer 41_snapshots-btrfs_config for the list of available options and their default values.
|
||||||
# * GRUB_BTRFS_SUBMENUNAME="Arch Linux snapshots" #
|
# - Place your configurations to either /etc/grub.d/41_snapshots-btrfs_config or /etc/default/grub.
|
||||||
# (Name appearing in the Grub menu.) #
|
#
|
||||||
# * GRUB_BTRFS_PREFIXENTRY="Snapshot:" #
|
# - Generate grub.cfg (on Arch Linux use grub-mkconfig -o /boot/grub/grub.cfg)
|
||||||
# (Add a name ahead your snapshots entries in the Grub menu.) #
|
#
|
||||||
# * GRUB_BTRFS_DISPLAY_PATH_SNAPSHOT="true" #
|
# - grub-btrfs automatically generates snapshots entries.
|
||||||
# (Show full path snapshot or only name in the Grub menu) #
|
# - You will see it appear different entries (e.g : Snapshot: [2014-02-12 11:24:37] my snapshot name overkill)
|
||||||
# * 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) #
|
# Automatically update grub
|
||||||
# * GRUB_BTRFS_LIMIT="50" #
|
# 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:
|
||||||
# (Limit the number of snapshots populated in the GRUB menu.) #
|
# - /etc/systemd/system/snapper-timeline.service.d/
|
||||||
# * GRUB_BTRFS_SUBVOLUME_SORT="descending" #
|
# - /etc/systemd/system/snapper-cleanup.service.d/
|
||||||
# (Sort the found subvolumes by newest first ("descending") or oldest first ("ascending"). #
|
# Once the configuration files are in place, systemctl daemon-reload should be run to reload the units and make the changes active.
|
||||||
# If "ascending" is chosen then the $GRUB_BTRFS_LIMIT oldest subvolumes will populate the menu.) #
|
#
|
||||||
# * GRUB_BTRFS_SHOW_SNAPSHOTS_FOUND="true" #
|
# Special thanks for assistance and contributions:
|
||||||
# (Show snapshots found during run "grub-mkconfig") #
|
# - My friends
|
||||||
# * GRUB_BTRFS_SHOW_TOTAL_SNAPSHOTS_FOUND="true" #
|
# - All contributors on Github
|
||||||
# (Show Total of snapshots found during run "grub-mkconfig") #
|
#
|
||||||
# * GRUB_BTRFS_NKERNEL=("vmlinuz-linux") #
|
|
||||||
# (Use only if you have custom kernel name or auto-detect failed.) #
|
|
||||||
# * GRUB_BTRFS_NINIT=("initramfs-linux.img" "initramfs-linux-fallback.img") #
|
|
||||||
# (Use only if you have custom initramfs name or auto-detect failed.) #
|
|
||||||
# * GRUB_BTRFS_INTEL_UCODE=("intel-ucode.img") #
|
|
||||||
# (Use only if you have custom intel-ucode or auto-detect failed.) #
|
|
||||||
# * GRUB_BTRFS_IGNORE_SPECIFIC_PATH=("var/lib/docker" "nosnapshot") #
|
|
||||||
# (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 (default=active) #
|
|
||||||
# #
|
|
||||||
# - 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 different entries (e.g : Snapshot: [2014-02-12 11:24:37] my snapshot name overkill) #
|
|
||||||
# #
|
|
||||||
# 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/ #
|
|
||||||
# Once the configuration files are in place, systemctl daemon-reload should be run to reload the units and make the changes active. #
|
|
||||||
# #
|
|
||||||
# Special thanks for assistance and contributions: #
|
|
||||||
# - My friends #
|
|
||||||
# - All contributors on Github #
|
|
||||||
# #
|
|
||||||
#########################################################################################################################################################################
|
#########################################################################################################################################################################
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
@@ -71,10 +43,11 @@ prefix="/usr"
|
|||||||
exec_prefix="/usr"
|
exec_prefix="/usr"
|
||||||
datarootdir="/usr/share"
|
datarootdir="/usr/share"
|
||||||
sysconfdir="/etc"
|
sysconfdir="/etc"
|
||||||
|
grub_btrfs_config="${sysconfdir}/grub.d/41_snapshots-btrfs_config"
|
||||||
|
|
||||||
. "${sysconfdir}/default/grub"
|
. "${sysconfdir}/default/grub"
|
||||||
. "$pkgdatadir/grub-mkconfig_lib"
|
[[ -f "$grub_btrfs_config" ]] && . "$grub_btrfs_config"
|
||||||
# . "$datarootdir/grub/grub-mkconfig_lib" # Uncomment if you run "bash -x"
|
. "$datarootdir/grub/grub-mkconfig_lib"
|
||||||
|
|
||||||
######################################
|
######################################
|
||||||
### Variables in /etc/default/grub ###
|
### Variables in /etc/default/grub ###
|
||||||
@@ -135,6 +108,16 @@ gbgmp=$(mktemp -d)
|
|||||||
CLASS="--class snapshots --class gnu-linux --class gnu --class os"
|
CLASS="--class snapshots --class gnu-linux --class gnu --class os"
|
||||||
## save IFS
|
## save IFS
|
||||||
oldIFS=$IFS
|
oldIFS=$IFS
|
||||||
|
## Detect uuid requirement (lvm,btrfs...)
|
||||||
|
check_uuid_required() {
|
||||||
|
if [ "x${GRUB_DEVICE_UUID}" = "x" ] || [ "x${GRUB_DISABLE_LINUX_UUID}" = "xtrue" ] \
|
||||||
|
|| ! test -e "/dev/disk/by-uuid/${GRUB_DEVICE_UUID}" \
|
||||||
|
|| ( test -e "${GRUB_DEVICE}" && uses_abstraction "${GRUB_DEVICE}" lvm ); then
|
||||||
|
LINUX_ROOT_DEVICE=${GRUB_DEVICE}
|
||||||
|
else
|
||||||
|
LINUX_ROOT_DEVICE=UUID=${GRUB_DEVICE_UUID}
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
######################
|
######################
|
||||||
@@ -182,16 +165,17 @@ make_menu_entries()
|
|||||||
[[ ! -f "${boot_dir}"/"${k}" ]] && continue;
|
[[ ! -f "${boot_dir}"/"${k}" ]] && continue;
|
||||||
kversion=${k#*"-"}
|
kversion=${k#*"-"}
|
||||||
for i in "${name_initramfs[@]}"; do
|
for i in "${name_initramfs[@]}"; do
|
||||||
prefix_i=${i[@]%%"-"*}
|
prefix_i=${i%%"-"*}
|
||||||
suffix_i=${i[@]##*"-"}
|
suffix_i=${i#*"-"}
|
||||||
if [ -f "${boot_dir}"/"${prefix_i}-${kversion}-${suffix_i}" ]; then i="${i}";
|
alt_suffix_i=${i##*"-"}
|
||||||
elif [ -f "${boot_dir}"/"${prefix_i}-${kversion}" ]; then i="${i}";
|
if [ "${kversion}" = "${suffix_i}" ]; then i="${i}";
|
||||||
elif [ -f "${boot_dir}"/"${prefix_i}-${kversion}.img" ]; then i="${i}";
|
elif [ "${kversion}.img" = "${suffix_i}" ]; then i="${i}";
|
||||||
elif [ -f "${boot_dir}"/"${prefix_i}-${kversion}.gz" ]; then i="${i}";
|
elif [ "${kversion}-fallback.img" = "${suffix_i}" ]; then i="${i}";
|
||||||
|
elif [ "${kversion}.gz" = "${suffix_i}" ]; then i="${i}";
|
||||||
else continue ;
|
else continue ;
|
||||||
fi
|
fi
|
||||||
for u in "${name_microcode[@]}"; do
|
for u in "${name_microcode[@]}"; do
|
||||||
if [[ -f "${boot_dir}"/"${u}" && "${i}" != initramfs-linux-fallback.img ]] ; then
|
if [[ -f "${boot_dir}"/"${u}" && "${i}" != "${prefix_i}-${kversion}-${alt_suffix_i}" ]] ; then
|
||||||
entry "
|
entry "
|
||||||
menuentry '"${k}" & "${i}" & "${u}"' ${CLASS} "\$menuentry_id_option" 'gnulinux-snapshots-$boot_uuid'{"
|
menuentry '"${k}" & "${i}" & "${u}"' ${CLASS} "\$menuentry_id_option" 'gnulinux-snapshots-$boot_uuid'{"
|
||||||
else
|
else
|
||||||
@@ -211,8 +195,8 @@ make_menu_entries()
|
|||||||
fi
|
fi
|
||||||
echo 'Loading Snapshot: "${snap_date_time}" "${snap_dir_name}"'
|
echo 'Loading Snapshot: "${snap_date_time}" "${snap_dir_name}"'
|
||||||
echo 'Loading Kernel: "${k}" ...'
|
echo 'Loading Kernel: "${k}" ...'
|
||||||
linux \"${boot_dir_root_grub}/"${k}"\" root=UUID=${root_uuid} rw rootflags=subvol=\""${snap_dir_name}"\" ${kernel_parameters}"
|
linux \"${boot_dir_root_grub}/"${k}"\" root="${LINUX_ROOT_DEVICE}" rw rootflags=subvol=\""${snap_dir_name}"\" ${kernel_parameters}"
|
||||||
if [[ -f "${boot_dir}"/"${u}" && "${i}" != initramfs-linux-fallback.img ]] ; then
|
if [[ -f "${boot_dir}"/"${u}" && "${i}" != "${prefix_i}-${kversion}-${alt_suffix_i}" ]] ; then
|
||||||
entry "\
|
entry "\
|
||||||
echo 'Loading Microcode & Initramfs: "${u}" "${i}" ...'
|
echo 'Loading Microcode & Initramfs: "${u}" "${i}" ...'
|
||||||
initrd \"${boot_dir_root_grub}/"${u}"\" \"${boot_dir_root_grub}/"${i}"\""
|
initrd \"${boot_dir_root_grub}/"${u}"\" \"${boot_dir_root_grub}/"${i}"\""
|
||||||
@@ -394,16 +378,15 @@ path_snapshot()
|
|||||||
title_format()
|
title_format()
|
||||||
{
|
{
|
||||||
case "${title_format}" in
|
case "${title_format}" in
|
||||||
p/d/n) title_menu="${prefixentry} ${snap_date_time} ${name_snapshot}";;
|
|
||||||
p/n/d) title_menu="${prefixentry} ${name_snapshot} ${snap_date_time}";;
|
p/n/d) title_menu="${prefixentry} ${name_snapshot} ${snap_date_time}";;
|
||||||
p/d) title_menu="${prefixentry} ${snap_date_time}";;
|
p/d) title_menu="${prefixentry} ${snap_date_time}";;
|
||||||
p/n) title_menu="${prefixentry} ${name_snapshot}";;
|
p/n) title_menu="${prefixentry} ${name_snapshot}";;
|
||||||
d/n) title_menu="${snap_date_time} ${name_snapshot}";;
|
d/n) title_menu="${snap_date_time} ${name_snapshot}";;
|
||||||
n/d) title_menu="${name_snapshot} ${snap_date_time}";;
|
n/d) title_menu="${name_snapshot} ${snap_date_time}";;
|
||||||
p) title_menu="${prefixentry}";;
|
p) title_menu="${prefixentry}";;
|
||||||
d) title_menu="${snap_date_time}";;
|
d) title_menu="${snap_date_time}";;
|
||||||
n) title_menu="${name_snapshot}";;
|
n) title_menu="${name_snapshot}";;
|
||||||
*) printf $"# Warning: GRUB_BTRFS_TITLE_FORMAT=${title_format}, syntax error \n" >&2
|
*) title_menu="${prefixentry} ${snap_date_time} ${name_snapshot}"
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -518,6 +501,8 @@ mount -o subvolid=5 /dev/disk/by-uuid/$root_uuid $gbgmp/
|
|||||||
count_warning_menuentries=0
|
count_warning_menuentries=0
|
||||||
# Count snapshots
|
# Count snapshots
|
||||||
count_limit_snap=0
|
count_limit_snap=0
|
||||||
|
# detect uuid requirement
|
||||||
|
check_uuid_required
|
||||||
# Detects if /boot is a separate partition
|
# Detects if /boot is a separate partition
|
||||||
if [[ "$root_uuid" != "$boot_uuid" ]]; then
|
if [[ "$root_uuid" != "$boot_uuid" ]]; then
|
||||||
printf "# Info: Separate boot partition detected \n" >&2 ;
|
printf "# Info: Separate boot partition detected \n" >&2 ;
|
||||||
|
|||||||
16
41_snapshots-btrfs_config
Normal file
16
41_snapshots-btrfs_config
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#!/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
|
||||||
29
README.md
29
README.md
@@ -2,14 +2,14 @@
|
|||||||
|
|
||||||
## grub-btrfs
|
## grub-btrfs
|
||||||
|
|
||||||
This is a version 2.xx of grub-btrfs
|
This is a version 3.xx of grub-btrfs
|
||||||
##### BTC donation address: 1Lbvz244WA8xbpHek9W2Y12cakM6rDe5Rt
|
##### BTC donation address: 1Lbvz244WA8xbpHek9W2Y12cakM6rDe5Rt
|
||||||
##
|
##
|
||||||
### Description
|
### Description
|
||||||
|
|
||||||
grub-btrfs, Include btrfs snapshots at boot options. (grub menu)
|
grub-btrfs, Include btrfs snapshots at boot options. (grub menu)
|
||||||
##
|
##
|
||||||
### What does grub-btrfs v2.xx do :
|
### What does grub-btrfs v3.xx do :
|
||||||
|
|
||||||
Simple rollback using snapshots you made previously.
|
Simple rollback using snapshots you made previously.
|
||||||
|
|
||||||
@@ -17,14 +17,15 @@ Simple rollback using snapshots you made previously.
|
|||||||
|
|
||||||
* Automatically Detect if "/boot" is in separate partition.
|
* Automatically Detect if "/boot" is in separate partition.
|
||||||
|
|
||||||
* Automatically Detect kernel, initramfs and intel microcode in "/boot" directory on snapshots. (For custom name, see below.)
|
* Automatically Detect kernel, initramfs and intel microcode in "/boot" directory on snapshots.
|
||||||
|
|
||||||
* Automatically Create corresponding "menuentry" in grub.cfg , which ensures a very easy rollback.
|
* Automatically Create corresponding "menuentry" in grub.cfg , which ensures a very easy rollback.
|
||||||
|
|
||||||
* Automatically detect snapper and use snapper's snapshot description if available.
|
* Automatically detect snapper and use snapper's snapshot description if available.
|
||||||
##
|
##
|
||||||
### How to use it:
|
### How to customize it:
|
||||||
|
|
||||||
|
You have the possibility to modify many parameters.
|
||||||
Add this lines to /etc/default/grub:
|
Add this lines to /etc/default/grub:
|
||||||
|
|
||||||
* GRUB_BTRFS_SUBMENUNAME="Arch Linux Snapshots"
|
* GRUB_BTRFS_SUBMENUNAME="Arch Linux Snapshots"
|
||||||
@@ -43,17 +44,17 @@ Add this lines to /etc/default/grub:
|
|||||||
|
|
||||||
(Custom title, shows/hides p"prefix" d"date" n"name" in grub-menu, separator "/", custom order available)
|
(Custom title, shows/hides p"prefix" d"date" n"name" in grub-menu, separator "/", custom order available)
|
||||||
|
|
||||||
* GRUB_BTRFS_NKERNEL=("vmlinuz-linux")
|
* GRUB_BTRFS_NKERNEL=("kernel-custom")
|
||||||
|
|
||||||
(Use only if you have a custom kernel name or auto-detect failed.)
|
(Use it only if you have a custom kernel name)
|
||||||
|
|
||||||
* GRUB_BTRFS_NINIT=("initramfs-linux.img" "initramfs-linux-fallback.img")
|
* GRUB_BTRFS_NINIT=("initramfs-custom.img" "initrd.img-custom")
|
||||||
|
|
||||||
(Use only if you have a custom initramfs name or auto-detect failed.)
|
(Use it only if you have a custom initramfs name)
|
||||||
|
|
||||||
* GRUB_BTRFS_INTEL_UCODE=("intel-ucode.img")
|
* GRUB_BTRFS_INTEL_UCODE=("intel-ucode.img")
|
||||||
|
|
||||||
(Use only if you have custom intel-ucode or auto-detect failed.)
|
(Use it only if you have custom intel-ucode)
|
||||||
|
|
||||||
* GRUB_BTRFS_LIMIT="50"
|
* GRUB_BTRFS_LIMIT="50"
|
||||||
|
|
||||||
@@ -73,18 +74,18 @@ Add this lines to /etc/default/grub:
|
|||||||
|
|
||||||
(Show Total number of snapshots found during run "grub-mkconfig")
|
(Show Total number of snapshots found during run "grub-mkconfig")
|
||||||
|
|
||||||
* GRUB_BTRFS_IGNORE_SPECIFIC_PATH=("var/lib/docker" "nosnapshot")
|
* GRUB_BTRFS_IGNORE_SPECIFIC_PATH=("var/lib/docker")
|
||||||
|
|
||||||
(Ignore specific path during run "grub-mkconfig")
|
(Ignore specific path during run "grub-mkconfig")
|
||||||
|
|
||||||
* GRUB_BTRFS_CREATE_ONLY_HARMONIZED_ENTRIES="true"
|
|
||||||
|
|
||||||
(Create entries with matching version number instead of all possible combinations of kernel and initramfs, very useful with debian-like distributions)
|
|
||||||
|
|
||||||
* GRUB_BTRFS_SNAPPER_CONFIG="root"
|
* GRUB_BTRFS_SNAPPER_CONFIG="root"
|
||||||
|
|
||||||
(Snapper's config name to use)
|
(Snapper's config name to use)
|
||||||
|
|
||||||
|
* GRUB_BTRFS_DISABLE="true"
|
||||||
|
|
||||||
|
(Disable grub-btrfs)
|
||||||
|
|
||||||
|
|
||||||
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 )
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user