mirror of
https://github.com/Antynea/grub-btrfs.git
synced 2026-03-04 21:15:02 +08:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
86c8d0a0e8 | ||
|
|
9fcdab5277 | ||
|
|
87932d900d | ||
|
|
f0c50d1d76 | ||
|
|
87a94c19c2 | ||
|
|
c8a7214e22 | ||
|
|
befb66e801 | ||
|
|
7213d04a42 | ||
|
|
5ea4c86400 | ||
|
|
f17ce68fb3 | ||
|
|
7720cec5f9 | ||
|
|
b4bd7b952c |
150
41_snapshots-btrfs
Normal file → Executable file
150
41_snapshots-btrfs
Normal file → Executable file
@@ -16,13 +16,13 @@
|
||||
# - Add this lines to /etc/default/grub: #
|
||||
# #
|
||||
# * GRUB_BTRFS_SUBMENUNAME="ArchLinux Snapshots" #
|
||||
# (Name menu appearing in grub.) #
|
||||
# (Name appearing in the Grub menu.) #
|
||||
# * GRUB_BTRFS_PREFIXENTRY="Snapshot:" #
|
||||
# (Add a name ahead your snapshots entries.) #
|
||||
# (Add a name ahead your snapshots entries in the Grub menu.) #
|
||||
# * GRUB_BTRFS_DISPLAY_PATH_SNAPSHOT="true" #
|
||||
# (Show full path snapshot or only name) #
|
||||
# (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 grub-menu, separator "/", custom order available) #
|
||||
# (Custom title, shows/hides p"prefix" d"date" n"name" in the Grub menu, separator "/", custom order available) #
|
||||
# * GRUB_BTRFS_LIMIT="100" #
|
||||
# (Limit the number of snapshots populated in the GRUB menu.) #
|
||||
# * GRUB_BTRFS_SUBVOLUME_SORT="descending" #
|
||||
@@ -37,7 +37,11 @@
|
||||
# * 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.) #
|
||||
# (Use only if you have custom intel-ucode or auto-detect failed.) #
|
||||
# * GRUB_BTRFS_IGNORE_SPECIFIC_PATH=("var/lib/docker" "nosapshot") #
|
||||
# (Ignore specific path during run "grub-mkconfig") #
|
||||
# * GRUB_BTRFS_CREATE_ONLY_HARMONIZED_ENTRIES="false" #
|
||||
# (Create entries with matching version number instead of all possible combinations of kernel and initramfs) #
|
||||
# #
|
||||
# - Generate grub.cfg (on Archlinux use grub-mkconfig -o /boot/grub/grub.cfg) #
|
||||
# #
|
||||
@@ -48,7 +52,6 @@
|
||||
# To do: #
|
||||
# #
|
||||
# * Display name of microcode in menuentry when available #
|
||||
# * ignore specific path #
|
||||
# #
|
||||
#################################################################################################################################################
|
||||
|
||||
@@ -80,9 +83,9 @@ nkernel=("${GRUB_BTRFS_NKERNEL[@]}")
|
||||
ninit=("${GRUB_BTRFS_NINIT[@]}")
|
||||
## Microcode(s) name(s)
|
||||
microcode=("${GRUB_BTRFS_INTEL_UCODE[@]}")
|
||||
## Limit to show in menu
|
||||
## Limit to show in the Grub menu
|
||||
limit_snap_show="${GRUB_BTRFS_LIMIT:-100}"
|
||||
## How to sort
|
||||
## How to sort snapshots list
|
||||
snap_list_sort=${GRUB_BTRFS_SUBVOLUME_SORT:-"descending"}
|
||||
case "${snap_list_sort}" in
|
||||
ascending) btrfssubvolsort=("--sort=+rootid");;
|
||||
@@ -92,6 +95,11 @@ esac
|
||||
show_snap_found=${GRUB_BTRFS_SHOW_SNAPSHOTS_FOUND:-"true"}
|
||||
## Show Total of snapshots found during run "grub-mkconfig"
|
||||
show_total_snap_found=${GRUB_BTRFS_SHOW_TOTAL_SNAPSHOTS_FOUND:-"true"}
|
||||
## Ignore specific path during run "grub-mkconfig"
|
||||
ignore_specific_path=("${GRUB_BTRFS_IGNORE_SPECIFIC_PATH[@]}")
|
||||
## create only entries with harmonized version numbers
|
||||
harmonized_entries=${GRUB_BTRFS_CREATE_ONLY_HARMONIZED_ENTRIES:-"false"}
|
||||
|
||||
|
||||
########################
|
||||
### variables script ###
|
||||
@@ -110,7 +118,7 @@ root_uuid=$(${grub_probe} "/" --target="fs_uuid" 2>/dev/null)
|
||||
## Parameters passed to the kernel
|
||||
kernel_parameters="$GRUB_CMDLINE_LINUX $GRUB_CMDLINE_LINUX_DEFAULT"
|
||||
## Mount point location
|
||||
gbgmp="/tmp/gbgmp"
|
||||
gbgmp=$(mktemp -d)
|
||||
## Class for theme
|
||||
CLASS="--class snapshots --class gnu-linux --class gnu --class os"
|
||||
## save IFS
|
||||
@@ -173,6 +181,63 @@ snapshots_entry()
|
||||
echo " }"
|
||||
}
|
||||
|
||||
harmonized_snapshots_entry()
|
||||
{
|
||||
## \" required for snap,kernels,init,microcode with space in their name
|
||||
echo " submenu '"${title_menu[*]}"' {
|
||||
submenu '---> "${title_menu[*]}" <---' { echo }
|
||||
"
|
||||
for k in "${name_kernel[@]}"; do
|
||||
version=${k#vmlinuz-}
|
||||
|
||||
i=""
|
||||
if [[ -e "$(boot_dir)"/initramfs-${version} ]]; then
|
||||
i=initramfs-${version}
|
||||
else
|
||||
if [[ -e "$(boot_dir)"/initrd.img-${version} ]]; then
|
||||
i=initrd.img-${version}
|
||||
fi
|
||||
fi
|
||||
|
||||
u=""
|
||||
if [ -f "$(boot_dir)"/intel-ucode.img ]; then
|
||||
u=intel-ucode.img
|
||||
fi
|
||||
|
||||
|
||||
echo "\
|
||||
menuentry '"${k}"' ${CLASS} "\$menuentry_id_option" 'gnulinux-snapshots-$boot_uuid'{
|
||||
$(save_default_entry)
|
||||
if [ x\$feature_all_video_module = xy ]; then
|
||||
insmod all_video
|
||||
fi
|
||||
set gfxpayload=keep
|
||||
insmod ${boot_fs}
|
||||
if [ x\$feature_platform_search_hint = xy ]; then
|
||||
search --no-floppy --fs-uuid --set=root ${hs_boot} ${boot_uuid}
|
||||
else
|
||||
search --no-floppy --fs-uuid --set=root ${boot_uuid}
|
||||
fi
|
||||
echo 'Loading Snapshot: "${snap_date_time}" "${snap_dir_name}"'
|
||||
echo 'Loading Kernel: "${k}" ...'
|
||||
linux \"${boot_dir_real_path}/"${k}"\" root=UUID=${root_uuid} rw rootflags=subvol=\""${snap_dir_name}"\" ${kernel_parameters}\
|
||||
"
|
||||
if [[ ! -z ${i} ]]; then
|
||||
if [ ! -z ${u} ] ; then
|
||||
echo "\
|
||||
echo 'Loading Microcode & Initramfs: "${u}" "${i}" ...'
|
||||
initrd \"${boot_dir_real_path}/"${u}"\" \"${boot_dir_real_path}/"${i}"\""
|
||||
else
|
||||
echo "\
|
||||
echo 'Loading Initramfs: "${i}" ...'
|
||||
initrd \"${boot_dir_real_path}/"${i}"\""
|
||||
fi
|
||||
fi
|
||||
echo " }"
|
||||
done
|
||||
echo " }"
|
||||
}
|
||||
|
||||
## List of snapshots on filesystem
|
||||
snapshot_list()
|
||||
{
|
||||
@@ -247,14 +312,6 @@ path_snapshot()
|
||||
esac
|
||||
}
|
||||
|
||||
# ## Show Total of snapshots found during run "grub-mkconfig"
|
||||
# show_total_snap_found()
|
||||
# {
|
||||
# case "${show_total_snap_found}" in
|
||||
# true)
|
||||
# *)
|
||||
# }
|
||||
|
||||
## Title format in grub-menu
|
||||
title_format()
|
||||
{
|
||||
@@ -277,60 +334,83 @@ list_kernels_initramfs()
|
||||
{
|
||||
IFS=$'\n'
|
||||
count_limit_snap=0
|
||||
# echo "tt = ${count_limit_snap}"
|
||||
for item in $(snapshot_list); do
|
||||
### fix: limit_snap_show=0
|
||||
[[ ${limit_snap_show} -le 0 ]] && break;
|
||||
IFS=$oldIFS
|
||||
item=($item)
|
||||
snap_dir_name=${item[@]:2:${#item[@]}}
|
||||
### ignore specific path during run "grub-mkconfig"
|
||||
if [ ! -z "${ignore_specific_path}" ] ; then
|
||||
for isp in ${ignore_specific_path[@]} ; do
|
||||
[[ "${gbgmp}"/"${snap_dir_name}" == "${gbgmp}"/"${isp}"/* ]] && continue 2;
|
||||
done
|
||||
fi
|
||||
### detect if /boot directory exist
|
||||
[[ ! -d "$gbgmp/$snap_dir_name/boot" ]] && continue;
|
||||
### show snapshot found during run "grub-mkconfig"
|
||||
snap_date_time=${item[@]:0:2}
|
||||
if [[ "${show_snap_found}" = "true" ]]; then
|
||||
gettext_printf $"# Found Snapshot: %s\n" "${snap_date_time} ${snap_dir_name}" >&2 ;
|
||||
fi
|
||||
### Kernel (auto-detect + custom kernel)
|
||||
unset list_kernel
|
||||
detect_kernel
|
||||
name_kernel=("${list_kernel[@]##*"/"}")
|
||||
# echo "kernel = ${name_kernel[*]}"
|
||||
unset list_initramfs
|
||||
detect_initramfs
|
||||
name_initramfs=("${list_initramfs[@]##*"/"}")
|
||||
# echo "initramfs = ${name_initramfs[*]}"
|
||||
unset list_ucode
|
||||
detect_microcode
|
||||
name_microcode=("${list_ucode[@]##*"/"}")
|
||||
# echo "ucode = ${name_microcode[*]}"
|
||||
|
||||
if [[ "${harmonized_entries}" = "false" ]]; then
|
||||
### Initramfs (autodetect + custom initramfs)
|
||||
unset list_initramfs
|
||||
detect_initramfs
|
||||
name_initramfs=("${list_initramfs[@]##*"/"}")
|
||||
# echo "initramfs = ${name_initramfs[*]}"
|
||||
### microcode (auto-detect + custom microcode)
|
||||
unset list_ucode
|
||||
detect_microcode
|
||||
name_microcode=("${list_ucode[@]##*"/"}")
|
||||
# echo "ucode = ${name_microcode[*]}"
|
||||
fi
|
||||
### real path to boot
|
||||
boot_dir_real_path="$(make_system_path_relative_to_its_root "$(boot_dir)")"
|
||||
## Create menu entries
|
||||
# name snpashot
|
||||
### Create menu entries
|
||||
## name snpashot
|
||||
path_snapshot
|
||||
# title menu custom
|
||||
## title menu custom
|
||||
title_format
|
||||
# echo "${title_menu[*]}"
|
||||
snapshots_entry
|
||||
count_limit_snap=$((1+$count_limit_snap))
|
||||
if [[ $count_limit_snap -gt $limit_snap_show ]]; then
|
||||
break;
|
||||
fi
|
||||
if [[ "${harmonized_entries}" = "false" ]]; then
|
||||
snapshots_entry
|
||||
else
|
||||
harmonized_snapshots_entry
|
||||
fi
|
||||
### Limit snapshots found during run "grub-mkconfig"
|
||||
count_limit_snap=$((1+$count_limit_snap))
|
||||
[[ $count_limit_snap -ge $limit_snap_show ]] && break;
|
||||
done
|
||||
# echo "ttt = ${count_limit_snap}"
|
||||
IFS=$oldIFS
|
||||
}
|
||||
### END auto detect ###
|
||||
|
||||
### Start ###
|
||||
gettext_printf "###### - Grub-btrfs: Auto-detect Start - ######\n" >&2 ;
|
||||
### create mount point and mounts
|
||||
[[ ! -d $gbgmp ]] && mkdir -p $gbgmp
|
||||
mount -o subvolid=0 /dev/disk/by-uuid/$root_uuid $gbgmp/
|
||||
### Create a menu in grub
|
||||
echo "submenu '${submenuname}' {"
|
||||
list_kernels_initramfs ;
|
||||
## show total found snapshots
|
||||
if [[ "${show_total_snap_found}" = "true" ]]; then
|
||||
gettext_printf "# found ${count_limit_snap} snapshot(s)\n" >&2 ;
|
||||
fi
|
||||
## if no snapshot found, show a warning
|
||||
if [[ "${count_limit_snap}" = "0" ]]; then
|
||||
echo " submenu '---> "No snapshot found : Press ESC to return previous menu" <---' { echo } ";
|
||||
gettext_printf "# No snapshot found \n# make sure you have at least one snapshot \n# or please file a bug report at \"https://github.com/Antynea/grub-btrfs\"\n" >&2 ;
|
||||
fi
|
||||
echo "}"
|
||||
## unmount mount point
|
||||
umount $gbgmp
|
||||
gettext_printf "###### - Grub-btrfs: Auto-detect End - ######\n" >&2 ;
|
||||
### End ###
|
||||
14
README.md
14
README.md
@@ -17,7 +17,7 @@ Simple rollback using snapshots you made previously.
|
||||
|
||||
* 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. (For custom name, see below.)
|
||||
|
||||
* Automatically Create corresponding "menuentry" in grub.cfg , which ensures a very easy rollback.
|
||||
|
||||
@@ -44,11 +44,11 @@ Add this lines to /etc/default/grub:
|
||||
|
||||
* GRUB_BTRFS_NKERNEL=("vmlinuz-linux")
|
||||
|
||||
(Use only if you have custom kernel name or auto-detect failed.)
|
||||
(Use only if you have a 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.)
|
||||
(Use only if you have a custom initramfs name or auto-detect failed.)
|
||||
|
||||
* GRUB_BTRFS_INTEL_UCODE=("intel-ucode.img")
|
||||
|
||||
@@ -70,7 +70,12 @@ Add this lines to /etc/default/grub:
|
||||
|
||||
* GRUB_BTRFS_SHOW_TOTAL_SNAPSHOTS_FOUND="true"
|
||||
|
||||
(Show Total 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")
|
||||
|
||||
(Ignore specific path during run "grub-mkconfig")
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -84,7 +89,6 @@ You will see it appear differents entries (e.g : Snapshot: [2014-02-12 11:24:37]
|
||||
#### TO DO
|
||||
|
||||
* Display name of microcode in menuentry when available
|
||||
* ignore specific path
|
||||
|
||||
|
||||
## discussion
|
||||
|
||||
Reference in New Issue
Block a user