mirror of
https://github.com/Antynea/grub-btrfs.git
synced 2026-03-08 07:14:38 +08:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b8325cf134 | ||
|
|
c5da4014ae |
@@ -4,18 +4,19 @@
|
|||||||
#########################################################################################################################################################################
|
#########################################################################################################################################################################
|
||||||
# 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: #
|
# What this script does: #
|
||||||
# Simple rollback using snapshots you made previously. #
|
# Simple rollback using snapshots you made previously. #
|
||||||
# - Automatically List snapshots existing on root partition (btrfs). #
|
# - Automatically List snapshots existing on root partition (btrfs). #
|
||||||
# - 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 custon 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: #
|
||||||
# - 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" #
|
||||||
@@ -36,12 +37,12 @@
|
|||||||
# * GRUB_BTRFS_SHOW_TOTAL_SNAPSHOTS_FOUND="true" #
|
# * GRUB_BTRFS_SHOW_TOTAL_SNAPSHOTS_FOUND="true" #
|
||||||
# (Show Total of snapshots found during run "grub-mkconfig") #
|
# (Show Total of snapshots found during run "grub-mkconfig") #
|
||||||
# * GRUB_BTRFS_NKERNEL=("vmlinuz-linux") #
|
# * GRUB_BTRFS_NKERNEL=("vmlinuz-linux") #
|
||||||
# (Use only if you have custom kernel name or auto-detect failed.) #
|
# (Use only if you have custom kernel name.) #
|
||||||
# * GRUB_BTRFS_NINIT=("initramfs-linux.img" "initramfs-linux-fallback.img") #
|
# * GRUB_BTRFS_NINIT=("initramfs-linux.img" "initramfs-linux-fallback.img") #
|
||||||
# (Use only if you have custom initramfs name or auto-detect failed.) #
|
# (Use only if you have 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 only if you have custom intel-ucode.) #
|
||||||
# * 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_SNAPPER_CONFIG="root" #
|
# * GRUB_BTRFS_SNAPPER_CONFIG="root" #
|
||||||
# (Snapper's config name to use) #
|
# (Snapper's config name to use) #
|
||||||
@@ -73,8 +74,7 @@ datarootdir="/usr/share"
|
|||||||
sysconfdir="/etc"
|
sysconfdir="/etc"
|
||||||
|
|
||||||
. "${sysconfdir}/default/grub"
|
. "${sysconfdir}/default/grub"
|
||||||
. "$pkgdatadir/grub-mkconfig_lib"
|
. "$datarootdir/grub/grub-mkconfig_lib"
|
||||||
# . "$datarootdir/grub/grub-mkconfig_lib" # Uncomment if you run "bash -x"
|
|
||||||
|
|
||||||
######################################
|
######################################
|
||||||
### Variables in /etc/default/grub ###
|
### Variables in /etc/default/grub ###
|
||||||
@@ -182,16 +182,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
|
||||||
@@ -212,7 +213,7 @@ make_menu_entries()
|
|||||||
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=UUID=${root_uuid} 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 +395,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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
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