From f25633807416f37bd6c3f456b0d2a3d2dd4b44d6 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Fri, 18 Mar 2016 16:46:11 -0500 Subject: [PATCH 1/3] Add GRUB_BTRFS_LIMIT Allow user to limit the number of snapshots listed in GRUB. This also reverses the order of the snapshots such that the more recent ones come first. That is, if a user specifies GRUB_BTRFS_LIMIT=10, then only the 10 most recent snapshots will be shown. The default limit is 100, which seems very large. The more snapshots in the GRUB menu, the longer the system takes to boot. --- 41_snapshots-btrfs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/41_snapshots-btrfs b/41_snapshots-btrfs index 8db1fb2..b18e045 100644 --- a/41_snapshots-btrfs +++ b/41_snapshots-btrfs @@ -72,6 +72,11 @@ nkernel=("${GRUB_BTRFS_NKERNEL[@]}") ninit=("${GRUB_BTRFS_NINIT[@]}") ## Microcode(s) name(s) microcode=("${GRUB_BTRFS_INTEL_UCODE[@]}") +## Limit to show in menu +limit=("${GRUB_BTRFS_LIMIT[@]}") +if [ -z "$limit" ]; then + limit=100 +fi ######################## ### variables script ### @@ -156,7 +161,7 @@ snapshots_entry() ## List of snapshots on filesystem snapshot_list() { - for snap in $(btrfs subvolume list -sa /); do + for snap in $(btrfs subvolume list -sa / | tac); do IFS=$oldIFS snap=($snap) local snap_path_name=${snap[@]:13:${#snap[@]}} @@ -249,6 +254,7 @@ title_format() list_kernels_initramfs() { IFS=$'\n' + c=0 for item in $(snapshot_list); do IFS=$oldIFS item=($item) @@ -276,6 +282,10 @@ list_kernels_initramfs() title_format # echo "${title_menu[*]}" snapshots_entry + c=$((1+$c)) + if [[ $c -gt $limit ]]; then + break; + fi done IFS=$oldIFS } @@ -292,4 +302,4 @@ if [ ${choise_of_method} = "1" ] ; then umount $gbgmp gettext_printf "###### - Grub-btrfs: Auto-detect - ######\n" >&2 ; fi -### End choice of method ### \ No newline at end of file +### End choice of method ### From 59164367e7fc05efd6845d2c815e2f73b0b51169 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Sat, 19 Mar 2016 08:11:47 -0500 Subject: [PATCH 2/3] cleanup --- 41_snapshots-btrfs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/41_snapshots-btrfs b/41_snapshots-btrfs index b18e045..aae0b35 100644 --- a/41_snapshots-btrfs +++ b/41_snapshots-btrfs @@ -73,10 +73,7 @@ ninit=("${GRUB_BTRFS_NINIT[@]}") ## Microcode(s) name(s) microcode=("${GRUB_BTRFS_INTEL_UCODE[@]}") ## Limit to show in menu -limit=("${GRUB_BTRFS_LIMIT[@]}") -if [ -z "$limit" ]; then - limit=100 -fi +limit=("${GRUB_BTRFS_LIMIT[@]:-100}") ######################## ### variables script ### @@ -161,7 +158,7 @@ snapshots_entry() ## List of snapshots on filesystem snapshot_list() { - for snap in $(btrfs subvolume list -sa / | tac); do + for snap in $(btrfs subvolume list -sa --sort=-rootid /); do IFS=$oldIFS snap=($snap) local snap_path_name=${snap[@]:13:${#snap[@]}} From f820de475962570ac0253b0f5b07538c2b689ff6 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Sat, 19 Mar 2016 08:19:10 -0500 Subject: [PATCH 3/3] add sorting options --- 41_snapshots-btrfs | 8 +++++++- README.md | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/41_snapshots-btrfs b/41_snapshots-btrfs index aae0b35..392f5f0 100644 --- a/41_snapshots-btrfs +++ b/41_snapshots-btrfs @@ -74,6 +74,12 @@ ninit=("${GRUB_BTRFS_NINIT[@]}") microcode=("${GRUB_BTRFS_INTEL_UCODE[@]}") ## Limit to show in menu limit=("${GRUB_BTRFS_LIMIT[@]:-100}") +## How to sort +subvolsort=${GRUB_BTRFS_SUBVOLUME_SORT:-"descending"} +case "${subvolsort}" in + ascending) btrfssubvolsort=("--sort=+rootid");; + *) btrfssubvolsort=("--sort=-rootid") +esac ######################## ### variables script ### @@ -158,7 +164,7 @@ snapshots_entry() ## List of snapshots on filesystem snapshot_list() { - for snap in $(btrfs subvolume list -sa --sort=-rootid /); do + for snap in $(btrfs subvolume list -sa "${btrfssubvolsort}" /); do IFS=$oldIFS snap=($snap) local snap_path_name=${snap[@]:13:${#snap[@]}} diff --git a/README.md b/README.md index cdc0dfa..69074e0 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,15 @@ Add this lines to /etc/default/grub: (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.) Generate grub.cfg (on Archlinux use grub-mkconfig -o /boot/grub/grub.cfg )