Skip to content

Commit 86c8d0a

Browse files
committed
Merge pull request #22 from anyc/master
Create only entries with matching version numbers and one small improvement
2 parents f0c50d1 + 9fcdab5 commit 86c8d0a

File tree

1 file changed

+80
-12
lines changed

1 file changed

+80
-12
lines changed

41_snapshots-btrfs

100644100755
Lines changed: 80 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
# (Use only if you have custom intel-ucode or auto-detect failed.) #
4141
# * GRUB_BTRFS_IGNORE_SPECIFIC_PATH=("var/lib/docker" "nosapshot") #
4242
# (Ignore specific path during run "grub-mkconfig") #
43+
# * GRUB_BTRFS_CREATE_ONLY_HARMONIZED_ENTRIES="false" #
44+
# (Create entries with matching version number instead of all possible combinations of kernel and initramfs) #
4345
# #
4446
# - Generate grub.cfg (on Archlinux use grub-mkconfig -o /boot/grub/grub.cfg) #
4547
# #
@@ -95,6 +97,8 @@ show_snap_found=${GRUB_BTRFS_SHOW_SNAPSHOTS_FOUND:-"true"}
9597
show_total_snap_found=${GRUB_BTRFS_SHOW_TOTAL_SNAPSHOTS_FOUND:-"true"}
9698
## Ignore specific path during run "grub-mkconfig"
9799
ignore_specific_path=("${GRUB_BTRFS_IGNORE_SPECIFIC_PATH[@]}")
100+
## create only entries with harmonized version numbers
101+
harmonized_entries=${GRUB_BTRFS_CREATE_ONLY_HARMONIZED_ENTRIES:-"false"}
98102

99103

100104
########################
@@ -114,7 +118,7 @@ root_uuid=$(${grub_probe} "/" --target="fs_uuid" 2>/dev/null)
114118
## Parameters passed to the kernel
115119
kernel_parameters="$GRUB_CMDLINE_LINUX $GRUB_CMDLINE_LINUX_DEFAULT"
116120
## Mount point location
117-
gbgmp="/tmp/gbgmp"
121+
gbgmp=$(mktemp -d)
118122
## Class for theme
119123
CLASS="--class snapshots --class gnu-linux --class gnu --class os"
120124
## save IFS
@@ -177,6 +181,63 @@ snapshots_entry()
177181
echo " }"
178182
}
179183

184+
harmonized_snapshots_entry()
185+
{
186+
## \" required for snap,kernels,init,microcode with space in their name
187+
echo " submenu '"${title_menu[*]}"' {
188+
submenu '---> "${title_menu[*]}" <---' { echo }
189+
"
190+
for k in "${name_kernel[@]}"; do
191+
version=${k#vmlinuz-}
192+
193+
i=""
194+
if [[ -e "$(boot_dir)"/initramfs-${version} ]]; then
195+
i=initramfs-${version}
196+
else
197+
if [[ -e "$(boot_dir)"/initrd.img-${version} ]]; then
198+
i=initrd.img-${version}
199+
fi
200+
fi
201+
202+
u=""
203+
if [ -f "$(boot_dir)"/intel-ucode.img ]; then
204+
u=intel-ucode.img
205+
fi
206+
207+
208+
echo "\
209+
menuentry '"${k}"' ${CLASS} "\$menuentry_id_option" 'gnulinux-snapshots-$boot_uuid'{
210+
$(save_default_entry)
211+
if [ x\$feature_all_video_module = xy ]; then
212+
insmod all_video
213+
fi
214+
set gfxpayload=keep
215+
insmod ${boot_fs}
216+
if [ x\$feature_platform_search_hint = xy ]; then
217+
search --no-floppy --fs-uuid --set=root ${hs_boot} ${boot_uuid}
218+
else
219+
search --no-floppy --fs-uuid --set=root ${boot_uuid}
220+
fi
221+
echo 'Loading Snapshot: "${snap_date_time}" "${snap_dir_name}"'
222+
echo 'Loading Kernel: "${k}" ...'
223+
linux \"${boot_dir_real_path}/"${k}"\" root=UUID=${root_uuid} rw rootflags=subvol=\""${snap_dir_name}"\" ${kernel_parameters}\
224+
"
225+
if [[ ! -z ${i} ]]; then
226+
if [ ! -z ${u} ] ; then
227+
echo "\
228+
echo 'Loading Microcode & Initramfs: "${u}" "${i}" ...'
229+
initrd \"${boot_dir_real_path}/"${u}"\" \"${boot_dir_real_path}/"${i}"\""
230+
else
231+
echo "\
232+
echo 'Loading Initramfs: "${i}" ...'
233+
initrd \"${boot_dir_real_path}/"${i}"\""
234+
fi
235+
fi
236+
echo " }"
237+
done
238+
echo " }"
239+
}
240+
180241
## List of snapshots on filesystem
181242
snapshot_list()
182243
{
@@ -297,16 +358,19 @@ list_kernels_initramfs()
297358
detect_kernel
298359
name_kernel=("${list_kernel[@]##*"/"}")
299360
# echo "kernel = ${name_kernel[*]}"
300-
### Initramfs (autodetect + custom initramfs)
301-
unset list_initramfs
302-
detect_initramfs
303-
name_initramfs=("${list_initramfs[@]##*"/"}")
304-
# echo "initramfs = ${name_initramfs[*]}"
305-
### microcode (auto-detect + custom microcode)
306-
unset list_ucode
307-
detect_microcode
308-
name_microcode=("${list_ucode[@]##*"/"}")
309-
# echo "ucode = ${name_microcode[*]}"
361+
362+
if [[ "${harmonized_entries}" = "false" ]]; then
363+
### Initramfs (autodetect + custom initramfs)
364+
unset list_initramfs
365+
detect_initramfs
366+
name_initramfs=("${list_initramfs[@]##*"/"}")
367+
# echo "initramfs = ${name_initramfs[*]}"
368+
### microcode (auto-detect + custom microcode)
369+
unset list_ucode
370+
detect_microcode
371+
name_microcode=("${list_ucode[@]##*"/"}")
372+
# echo "ucode = ${name_microcode[*]}"
373+
fi
310374
### real path to boot
311375
boot_dir_real_path="$(make_system_path_relative_to_its_root "$(boot_dir)")"
312376
### Create menu entries
@@ -315,7 +379,11 @@ list_kernels_initramfs()
315379
## title menu custom
316380
title_format
317381
# echo "${title_menu[*]}"
318-
snapshots_entry
382+
if [[ "${harmonized_entries}" = "false" ]]; then
383+
snapshots_entry
384+
else
385+
harmonized_snapshots_entry
386+
fi
319387
### Limit snapshots found during run "grub-mkconfig"
320388
count_limit_snap=$((1+$count_limit_snap))
321389
[[ $count_limit_snap -ge $limit_snap_show ]] && break;

0 commit comments

Comments
 (0)