Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 90zfsbootmenu/zfsbootmenu-exec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export force_import
export menu_timeout
export loglevel
export root
export zbm_sort

# store current kernel log level
read -r PRINTK < /proc/sys/kernel/printk
Expand Down
22 changes: 22 additions & 0 deletions 90zfsbootmenu/zfsbootmenu-help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,17 @@ This is not possible if any of the following conditions are met:

Upon successful re-import in $( colorize red "read/write") mode, each of the boot environments on this pool will be highlighted in $( colorize red "red") at the top of the screen.


$( mod_header O "sort order" )

Cycle the sorting key through the following list:

$( colorize orange "name") Use the filesystem or snapshot name
$( colorize orange "creation") Use the filesystem or snapshot creation time
$( colorize orange "used") Use the filesystem or snapshot size

The default sort key is $( colorize orange "name") .

EOF
SECTIONS+=("MAIN Main Menu")

Expand Down Expand Up @@ -178,6 +189,17 @@ $( mod_header I "interactive chroot" )

Enter a chroot of the selected boot environment snapshot. The snapshot is always mounted read-only.


$( mod_header O "sort order" )

Cycle the sorting key through the following list:

$( colorize orange "name") Use the filesystem or snapshot name
$( colorize orange "creation") Use the filesystem or snapshot creation time
$( colorize orange "used") Use the filesystem or snapshot size

The default sort key is $( colorize orange "name") .

EOF
SECTIONS+=("SNAPSHOT Snapshot Management")

Expand Down
38 changes: 32 additions & 6 deletions 90zfsbootmenu/zfsbootmenu-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ mount_zfs() {
return ${ret}
}

# prints: first sort key
# returns: nothing

get_sort_key() {
local sort_key
sort_key="${zbm_sort%%;*}"
zdebug "Using sorting key ${sort_key}"
echo -n "${sort_key}"
}

# arg1: value to substitute for empty first line (default: "enter")
# prints: concatenated lines of stdin, joined by commas

Expand Down Expand Up @@ -196,7 +206,7 @@ draw_be() {
"[CTRL+E] edit kcl" "[CTRL+K] kernels" "[CTRL+D] set bootfs" "[CTRL+S] snapshots" "" \
"[CTRL+I] interactive chroot" "[CTRL+R] recovery shell" "[CTRL+P] pool status" )"

expects="--expect=alt-e,alt-k,alt-d,alt-s,alt-c,alt-r,alt-p,alt-w,alt-i"
expects="--expect=alt-e,alt-k,alt-d,alt-s,alt-c,alt-r,alt-p,alt-w,alt-i,alt-o"

if ! selected="$( ${FUZZYSEL} -0 --prompt "BE > " \
${expects} ${expects//alt-/ctrl-} ${expects//alt-/ctrl-alt-} \
Expand Down Expand Up @@ -253,20 +263,22 @@ draw_kernel() {
# returns: 130 on error, 0 otherwise

draw_snapshots() {
local benv selected header expects
local benv selected header expects sort_key

benv="${1}"

zdebug "using boot environment: ${benv}"

sort_key="$( get_sort_key )"

header="$( header_wrap \
"[ENTER] duplicate" "[ESC] back" "[CTRL+H] help" "" \
"[CTRL+X] clone and promote" "[CTRL+C] clone only" "" \
"[CTRL+I] interactive chroot" "[CTRL+D] show diff" )"

expects="--expect=alt-x,alt-c,alt-d,alt-i"
expects="--expect=alt-x,alt-c,alt-d,alt-i,alt-o"

if ! selected="$( zfs list -t snapshot -H -o name "${benv}" |
if ! selected="$( zfs list -t snapshot -H -o name "${benv}" -S "${sort_key}" |
HELP_SECTION=SNAPSHOT ${FUZZYSEL} \
--prompt "Snapshot > " --header="${header}" --tac \
${expects} ${expects//alt-/ctrl-} ${expects//alt-/ctrl-alt-} \
Expand Down Expand Up @@ -1418,11 +1430,13 @@ load_key() {
# returns: 0 iff at least one valid BE was found

populate_be_list() {
local be_list fs mnt active candidates ret
local be_list fs mnt active candidates ret sort_key

be_list="${1}"
[ -n "${be_list}" ] || return 1

sort_key="$( get_sort_key )"

# Truncate the list to avoid stale entries
: > "${be_list}"

Expand All @@ -1444,7 +1458,7 @@ populate_be_list() {
fi

candidates+=( "${fs}" )
done <<< "$(zfs list -H -o name,mountpoint,org.zfsbootmenu:active | sort -r)"
done <<< "$(zfs list -H -o name,mountpoint,org.zfsbootmenu:active -S "${sort_key}")"

# put bootfs on the end, so it is shown first with --tac
[ -n "${BOOTFS}" ] && candidates+=( "${BOOTFS}" )
Expand Down Expand Up @@ -1495,3 +1509,15 @@ emergency_shell() {
echo -e "${message}\n"
/bin/bash
}

# prints: nothing
# returns: nothing

change_sort() {
local zsa zrem

zsa="${zbm_sort%%;*}"
zrem="${zbm_sort#*;}"
zbm_sort="${zrem};${zsa}"
zdebug "Setting zbm_sort to ${zbm_sort}"
}
32 changes: 32 additions & 0 deletions 90zfsbootmenu/zfsbootmenu-parse-commandline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,38 @@ zbm_lines=$( getarg zbm.lines=)
# shellcheck disable=SC2034
zbm_columns=$( getarg zbm.columns=)

# Allow sorting based on a key
zbm_sort=
sort_key=$( getarg zbm.sort_key=)
if [ -n "${sort_key}" ] ; then
valid_keys=( "name" "creation" "used" )
for key in "${valid_keys[@]}"; do
if [ "${key}" == "${sort_key}" ]; then
zbm_sort="${key}"
fi
done

# If zbm_sort is empty (invalid user provided key)
# Default the starting sort key to 'name'
if [ -z "${zbm_sort}" ] ; then
sort_key="name"
zbm_sort="name"
fi

# Append any other sort keys to the selected one
for key in "${valid_keys[@]}"; do
if [ "${key}" != "${sort_key}" ]; then
zbm_sort="${zbm_sort};${key}"
fi
done

info "ZFSBootMenu: Setting sort key order to ${zbm_sort}"
else
zbm_sort="name;creation;used"
info "ZFSBootMenu: Defaulting sort key order to ${zbm_sort}"
fi


# Turn on tmux integrations
# shellcheck disable=SC2034
if getargbool 0 zbm.tmux ; then
Expand Down
8 changes: 8 additions & 0 deletions 90zfsbootmenu/zfsbootmenu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ while true; do
BE_SELECTED=1
continue
;;
"mod-o")
change_sort
BE_SELECTED=1
continue
;;
# Check available space early in the process
"enter")
avail_space_exact="$( zfs list -p -H -o available "${parent_ds}" )"
Expand Down Expand Up @@ -292,5 +297,8 @@ while true; do
"mod-i")
zfs_chroot "${selected_be}"
;;
"mod-o")
change_sort
;;
esac
done
2 changes: 1 addition & 1 deletion man/generate-zbm.5
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
.\" ========================================================================
.\"
.IX Title "generate-zbm 5"
.TH generate-zbm 5 "2020-09-30" "1.8.1" "config.yaml"
.TH generate-zbm 5 "2020-11-05" "1.8.1" "config.yaml"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
Expand Down
2 changes: 1 addition & 1 deletion man/generate-zbm.8
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
.\" ========================================================================
.\"
.IX Title "generate-zbm 8"
.TH generate-zbm 8 "2021-01-06" "1.8.1" "generate-zbm"
.TH generate-zbm 8 "2021-02-03" "1.8.1" "generate-zbm"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
Expand Down
18 changes: 17 additions & 1 deletion man/zfsbootmenu.7
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
.\" ========================================================================
.\"
.IX Title "zfsbootmenu 7"
.TH zfsbootmenu 7 "2020-12-21" "1.8.1" "ZFSBootMenu"
.TH zfsbootmenu 7 "2021-02-06" "1.8.1" "ZFSBootMenu"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
Expand Down Expand Up @@ -162,6 +162,22 @@ Omit this option or explicitly specify \fBzbm.force_import=0\fR to disable force
.IP "\fBforce_import=1\fR" 4
.IX Item "force_import=1"
Deprecated; use \fBzbm.force_import\fR.
.IP "\fBzbm.sort_key\fR" 4
.IX Item "zbm.sort_key"
This option accepts a \s-1ZFS\s0 property name by which the boot environment and snapshot lists should be sorted.
.RS 4
.IP "\fBzbm.sort_key=name\fR" 2
.IX Item "zbm.sort_key=name"
Sort the lists by \fIname\fR. This is the default sorting method.
.IP "\fBzbm.sort_key=creation\fR" 2
.IX Item "zbm.sort_key=creation"
Sort the lists by \fIcreation\fR date.
.IP "\fBzbm.sort_key=used\fR" 2
.IX Item "zbm.sort_key=used"
Sort the lists by size \fIused\fR.
.RE
.RS 4
.RE
.IP "\fBzbm.timeout\fR" 4
.IX Item "zbm.timeout"
This option accepts numeric values that control whether and when the
Expand Down
20 changes: 20 additions & 0 deletions pod/zfsbootmenu.7.pod
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,26 @@ Omit this option or explicitly specify B<zbm.force_import=0> to disable forced i

Deprecated; use B<zbm.force_import>.

=item B<zbm.sort_key>

This option accepts a ZFS property name by which the boot environment and snapshot lists will be sorted.

=over 2

=item B<zbm.sort_key=name>

Sort the lists by I<name>. This is the default sorting method.

=item B<zbm.sort_key=creation>

Sort the lists by I<creation> date.

=item B<zbm.sort_key=used>

Sort the lists by size I<used>.

=back

=item B<zbm.timeout>

This option accepts numeric values that control whether and when the
Expand Down