mirror of
https://github.com/Antynea/grub-btrfs.git
synced 2026-03-09 16:04:32 +08:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f17ce68fb3 | ||
|
|
7720cec5f9 | ||
|
|
b4bd7b952c | ||
|
|
56c11b8e2a | ||
|
|
d469db0a2d | ||
|
|
6ae56dbaf6 | ||
|
|
f820de4759 | ||
|
|
59164367e7 | ||
|
|
f256338074 |
@@ -16,19 +16,30 @@
|
|||||||
# - Add this lines to /etc/default/grub: #
|
# - Add this lines to /etc/default/grub: #
|
||||||
# #
|
# #
|
||||||
# * GRUB_BTRFS_SUBMENUNAME="ArchLinux Snapshots" #
|
# * GRUB_BTRFS_SUBMENUNAME="ArchLinux Snapshots" #
|
||||||
# (Name menu appearing in grub.) #
|
# (Name appearing in the Grub menu.) #
|
||||||
# * GRUB_BTRFS_PREFIXENTRY="Snapshot:" #
|
# * 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" #
|
# * 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" #
|
# * 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" #
|
||||||
|
# (Sort the found subvolumes by newest first ("descending") or oldest first ("ascending"). #
|
||||||
|
# If "ascending" is chosen then the $GRUB_BTRFS_LIMIT oldest subvolumes will populate the menu.) #
|
||||||
|
# * 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") #
|
# * 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 or auto-detect failed.) #
|
||||||
# * 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 or auto-detect failed.) #
|
||||||
# * 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 or auto-detect failed.) #
|
||||||
|
# * GRUB_BTRFS_IGNORE_SPECIFIC_PATH=("var/lib/docker" "nosapshot") #
|
||||||
|
# (Ignore specific path during run "grub-mkconfig") #
|
||||||
# #
|
# #
|
||||||
# - Generate grub.cfg (on Archlinux use grub-mkconfig -o /boot/grub/grub.cfg) #
|
# - Generate grub.cfg (on Archlinux use grub-mkconfig -o /boot/grub/grub.cfg) #
|
||||||
# #
|
# #
|
||||||
@@ -37,7 +48,7 @@
|
|||||||
# #
|
# #
|
||||||
# #
|
# #
|
||||||
# To do: #
|
# To do: #
|
||||||
# # #
|
# #
|
||||||
# * Display name of microcode in menuentry when available #
|
# * Display name of microcode in menuentry when available #
|
||||||
# #
|
# #
|
||||||
#################################################################################################################################################
|
#################################################################################################################################################
|
||||||
@@ -56,8 +67,6 @@ sysconfdir="/etc"
|
|||||||
######################################
|
######################################
|
||||||
### Variables in /etc/default/grub ###
|
### Variables in /etc/default/grub ###
|
||||||
######################################
|
######################################
|
||||||
## Choice of method
|
|
||||||
choise_of_method=${GRUB_BTRFS_METHOD:-"1"}
|
|
||||||
## Submenu name
|
## Submenu name
|
||||||
submenuname=${GRUB_BTRFS_SUBMENUNAME:-"ArchLinux Snapshots"}
|
submenuname=${GRUB_BTRFS_SUBMENUNAME:-"ArchLinux Snapshots"}
|
||||||
## Prefix entry
|
## Prefix entry
|
||||||
@@ -72,6 +81,21 @@ nkernel=("${GRUB_BTRFS_NKERNEL[@]}")
|
|||||||
ninit=("${GRUB_BTRFS_NINIT[@]}")
|
ninit=("${GRUB_BTRFS_NINIT[@]}")
|
||||||
## Microcode(s) name(s)
|
## Microcode(s) name(s)
|
||||||
microcode=("${GRUB_BTRFS_INTEL_UCODE[@]}")
|
microcode=("${GRUB_BTRFS_INTEL_UCODE[@]}")
|
||||||
|
## Limit to show in the Grub menu
|
||||||
|
limit_snap_show="${GRUB_BTRFS_LIMIT:-100}"
|
||||||
|
## How to sort snapshots list
|
||||||
|
snap_list_sort=${GRUB_BTRFS_SUBVOLUME_SORT:-"descending"}
|
||||||
|
case "${snap_list_sort}" in
|
||||||
|
ascending) btrfssubvolsort=("--sort=+rootid");;
|
||||||
|
*) btrfssubvolsort=("--sort=-rootid")
|
||||||
|
esac
|
||||||
|
## Show snapshots found during run "grub-mkconfig"
|
||||||
|
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[@]}")
|
||||||
|
|
||||||
|
|
||||||
########################
|
########################
|
||||||
### variables script ###
|
### variables script ###
|
||||||
@@ -156,7 +180,7 @@ snapshots_entry()
|
|||||||
## List of snapshots on filesystem
|
## List of snapshots on filesystem
|
||||||
snapshot_list()
|
snapshot_list()
|
||||||
{
|
{
|
||||||
for snap in $(btrfs subvolume list -sa /); do
|
for snap in $(btrfs subvolume list -sa "${btrfssubvolsort}" /); do
|
||||||
IFS=$oldIFS
|
IFS=$oldIFS
|
||||||
snap=($snap)
|
snap=($snap)
|
||||||
local snap_path_name=${snap[@]:13:${#snap[@]}}
|
local snap_path_name=${snap[@]:13:${#snap[@]}}
|
||||||
@@ -227,7 +251,6 @@ path_snapshot()
|
|||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
## Title format in grub-menu
|
## Title format in grub-menu
|
||||||
title_format()
|
title_format()
|
||||||
{
|
{
|
||||||
@@ -249,47 +272,77 @@ title_format()
|
|||||||
list_kernels_initramfs()
|
list_kernels_initramfs()
|
||||||
{
|
{
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
|
count_limit_snap=0
|
||||||
for item in $(snapshot_list); do
|
for item in $(snapshot_list); do
|
||||||
IFS=$oldIFS
|
IFS=$oldIFS
|
||||||
item=($item)
|
item=($item)
|
||||||
snap_dir_name=${item[@]:2:${#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;
|
[[ ! -d "$gbgmp/$snap_dir_name/boot" ]] && continue;
|
||||||
|
### show snapshot found during run "grub-mkconfig"
|
||||||
snap_date_time=${item[@]:0:2}
|
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 ;
|
gettext_printf $"# Found Snapshot: %s\n" "${snap_date_time} ${snap_dir_name}" >&2 ;
|
||||||
|
fi
|
||||||
|
### Kernel (auto-detect + custom kernel)
|
||||||
unset list_kernel
|
unset list_kernel
|
||||||
detect_kernel
|
detect_kernel
|
||||||
name_kernel=("${list_kernel[@]##*"/"}")
|
name_kernel=("${list_kernel[@]##*"/"}")
|
||||||
# echo "kernel = ${name_kernel[*]}"
|
# echo "kernel = ${name_kernel[*]}"
|
||||||
|
### Initramfs (autodetect + custom initramfs)
|
||||||
unset list_initramfs
|
unset list_initramfs
|
||||||
detect_initramfs
|
detect_initramfs
|
||||||
name_initramfs=("${list_initramfs[@]##*"/"}")
|
name_initramfs=("${list_initramfs[@]##*"/"}")
|
||||||
# echo "initramfs = ${name_initramfs[*]}"
|
# echo "initramfs = ${name_initramfs[*]}"
|
||||||
|
### microcode (auto-detect + custom microcode)
|
||||||
unset list_ucode
|
unset list_ucode
|
||||||
detect_microcode
|
detect_microcode
|
||||||
name_microcode=("${list_ucode[@]##*"/"}")
|
name_microcode=("${list_ucode[@]##*"/"}")
|
||||||
# echo "ucode = ${name_microcode[*]}"
|
# echo "ucode = ${name_microcode[*]}"
|
||||||
|
### real path to boot
|
||||||
boot_dir_real_path="$(make_system_path_relative_to_its_root "$(boot_dir)")"
|
boot_dir_real_path="$(make_system_path_relative_to_its_root "$(boot_dir)")"
|
||||||
## Create menu entries
|
### Create menu entries
|
||||||
# name snpashot
|
## name snpashot
|
||||||
path_snapshot
|
path_snapshot
|
||||||
# title menu custom
|
## title menu custom
|
||||||
title_format
|
title_format
|
||||||
# echo "${title_menu[*]}"
|
# echo "${title_menu[*]}"
|
||||||
snapshots_entry
|
snapshots_entry
|
||||||
|
### Limit snapshots found during run "grub-mkconfig"
|
||||||
|
count_limit_snap=$((1+$count_limit_snap))
|
||||||
|
if [[ $count_limit_snap -gt $limit_snap_show ]]; then
|
||||||
|
break;
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
IFS=$oldIFS
|
IFS=$oldIFS
|
||||||
}
|
}
|
||||||
### END auto detect ###
|
### END auto detect ###
|
||||||
|
|
||||||
### Choice of method ###
|
### Start ###
|
||||||
if [ ${choise_of_method} = "1" ] ; then
|
gettext_printf "###### - Grub-btrfs: Auto-detect Start - ######\n" >&2 ;
|
||||||
gettext_printf "###### - Grub-btrfs: Auto-detect - ######\n" >&2 ;
|
### create mount point and mounts
|
||||||
[[ ! -d $gbgmp ]] && mkdir -p $gbgmp
|
[[ ! -d $gbgmp ]] && mkdir -p $gbgmp
|
||||||
mount -o subvolid=0 /dev/disk/by-uuid/$root_uuid $gbgmp/
|
mount -o subvolid=0 /dev/disk/by-uuid/$root_uuid $gbgmp/
|
||||||
|
### Create a menu in grub
|
||||||
echo "submenu '${submenuname}' {"
|
echo "submenu '${submenuname}' {"
|
||||||
list_kernels_initramfs ;
|
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 "}"
|
echo "}"
|
||||||
|
## unmount mount point
|
||||||
umount $gbgmp
|
umount $gbgmp
|
||||||
gettext_printf "###### - Grub-btrfs: Auto-detect - ######\n" >&2 ;
|
gettext_printf "###### - Grub-btrfs: Auto-detect End - ######\n" >&2 ;
|
||||||
fi
|
### End ###
|
||||||
### End choice of method ###
|
|
||||||
20
README.md
20
README.md
@@ -54,6 +54,24 @@ Add this lines to /etc/default/grub:
|
|||||||
|
|
||||||
(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_LIMIT="100"
|
||||||
|
|
||||||
|
(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").
|
||||||
|
If "ascending" is chosen then the $GRUB_BTRFS_LIMIT oldest
|
||||||
|
subvolumes will populate the menu.)
|
||||||
|
|
||||||
|
* 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")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Generate grub.cfg (on Archlinux use grub-mkconfig -o /boot/grub/grub.cfg )
|
Generate grub.cfg (on Archlinux use grub-mkconfig -o /boot/grub/grub.cfg )
|
||||||
@@ -66,7 +84,7 @@ You will see it appear differents entries (e.g : Snapshot: [2014-02-12 11:24:37]
|
|||||||
#### TO DO
|
#### TO DO
|
||||||
|
|
||||||
* Display name of microcode in menuentry when available
|
* Display name of microcode in menuentry when available
|
||||||
|
* ignore specific path
|
||||||
|
|
||||||
|
|
||||||
## discussion
|
## discussion
|
||||||
|
|||||||
Reference in New Issue
Block a user