* ZFS boot environment patch
@ 2017-09-01 11:31 Paul Lagerweij
2017-09-13 15:02 ` Konrad Rzeszutek Wilk
0 siblings, 1 reply; 8+ messages in thread
From: Paul Lagerweij @ 2017-09-01 11:31 UTC (permalink / raw)
To: grub-devel
[-- Attachment #1.1: Type: text/plain, Size: 536 bytes --]
Hello,
I've created a patch for util/grub.d/10_linux.in for dynamic ZFS boot
environment entries. I've only tested the patch in Ubuntu 16.04.2 with GRUB
2.02~beta2, ZFS on Linux 0.6.5.6, Linux 4.4.0-83 and 4.4.0-81, but the
patch should work with any root ZFS configuration, because it only changes
the 10_linux shell script. It is designed to work with FreeBSD's beadm
tool, for which I'm currently making a Debian package, but isn't dependent
on beadm. I added the patch as an attachment and would like to request a
review.
Thanks.
[-- Attachment #1.2: Type: text/html, Size: 662 bytes --]
[-- Attachment #2: zfs-be-entries.patch --]
[-- Type: text/x-patch, Size: 4294 bytes --]
diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
index de9044c..c9a318e 100644
--- a/util/grub.d/10_linux.in
+++ b/util/grub.d/10_linux.in
@@ -20,6 +20,7 @@ set -e
prefix="@prefix@"
exec_prefix="@exec_prefix@"
datarootdir="@datarootdir@"
+zfs_be="0"
. "$pkgdatadir/grub-mkconfig_lib"
@@ -62,9 +63,15 @@ case x"$GRUB_FS" in
fi;;
xzfs)
rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`
- bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"
- LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}"
- ;;
+ zfs_active_bootfs="`zpool list -H -o bootfs ${rpool} || true`"
+ if [ -n "${zfs_active_bootfs}" ] && [ "${zfs_active_bootfs}" != "-" ] && \
+ [ `echo ${zfs_active_bootfs} | grep -o '/' | wc -l` -gt 1 ]; then
+ zfs_be="1"
+ LINUX_ROOT_DEVICE="ZFS=${zfs_active_bootfs}"
+ else
+ bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"
+ LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}"
+ fi;;
esac
title_correction_code=
@@ -177,6 +184,16 @@ title_correction_code=
# yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
submenu_indentation=""
+if [ "${zfs_be}" = 1 ]; then
+ while read ZFS_BE_NAME ZFS_ORIGIN; do
+ if [ "${ZFS_ORIGIN}" != "-" ]; then
+ zfs_be_list="${zfs_be_list} ${ZFS_BE_NAME}"
+ fi
+ done << EOF
+`zfs list -H -t filesystem -S creation -o name,origin -d 1 ${zfs_active_bootfs%/*} || true`
+EOF
+fi
+
is_top_level=true
while [ "x$list" != "x" ] ; do
linux=`version_find_latest $list`
@@ -184,6 +201,10 @@ while [ "x$list" != "x" ] ; do
basename=`basename $linux`
dirname=`dirname $linux`
rel_dirname=`make_system_path_relative_to_its_root $dirname`
+ # If ZFS BE support and /boot is in ZFS.
+ if [ "${zfs_be}" = 1 ] && [ -n "${rel_dirname}" ]; then
+ rel_dirname="/""${zfs_active_bootfs#*/}""@/boot"
+ fi
version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
alt_version=`echo $version | sed -e "s,\.old$,,g"`
linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
@@ -238,12 +259,53 @@ while [ "x$list" != "x" ] ; do
is_top_level=false
fi
- linux_entry "${OS}" "${version}" advanced \
- "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
- if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
- linux_entry "${OS}" "${version}" recovery \
- "single ${GRUB_CMDLINE_LINUX}"
- fi
+ for menu_entries_group in default ${zfs_be_list}; do
+ found_entry="0"
+ if [ "${menu_entries_group}" = "default" ]; then
+ found_entry="1"
+ os_title="${OS}"
+ else
+ found_zfs_be="0"
+ zfs_be_name=${menu_entries_group}
+ # If /boot is not in ZFS.
+ if [ -z "${rel_dirname}" ]; then
+ found_zfs_be="1"
+ else
+ zfs_be_mounted="`zfs list -H -o mounted ${zfs_be_name}`"
+ if [ "${zfs_be_mounted}" = "yes" ]; then
+ ZFSMNT=`mount | grep -m 1 "^${zfs_be_name} " | cut -d' ' -f3)`
+ else
+ ZFSMNT=`mktemp -d "/tmp/$(echo ${zfs_be_name} | sed 's^/^-^g').XXX" || true`
+ zfs set mountpoint=legacy ${zfs_be_name} || true
+ mount -t zfs -o ro ${zfs_be_name} ${ZFSMNT} || true
+ fi
+ if [ -n "${ZFSMNT}" ] && [ -f "${ZFSMNT}/boot/vmlinuz-${version}" ]; then
+ found_zfs_be="1"
+ rel_dirname="/""${zfs_be_name#*/}""@/boot"
+ fi
+ if [ "${zfs_be_mounted}" != "yes" ]; then
+ umount ${ZFSMNT} && rm -rf ${ZFSMNT} || true
+ zfs set mountpoint=/ ${zfs_be_name} || true
+ fi
+ fi
+
+ if [ "${found_zfs_be}" = 1 ]; then
+ found_entry="1"
+ os_title="${OS} (${zfs_be_name##*/} BE)"
+ gettext_printf "Found ZFS boot environment: (%s BE) %s\n" "${zfs_be_name##*/}" "$linux" >&2
+ linux_root_device_thisversion="ZFS=${zfs_be_name}"
+ fi
+ fi
+
+ if [ "${found_entry}" = 1 ]; then
+ linux_entry "${os_title}" "${version}" advanced \
+ "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
+ if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
+ linux_entry "${os_title}" "${version}" recovery \
+ "single ${GRUB_CMDLINE_LINUX}"
+ fi
+ fi
+ done
list=`echo $list | tr ' ' '\n' | fgrep -vx "$linux" | tr '\n' ' '`
done
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: ZFS boot environment patch
2017-09-01 11:31 Paul Lagerweij
@ 2017-09-13 15:02 ` Konrad Rzeszutek Wilk
2017-09-13 20:17 ` Colin Watson
0 siblings, 1 reply; 8+ messages in thread
From: Konrad Rzeszutek Wilk @ 2017-09-13 15:02 UTC (permalink / raw)
To: The development of GNU GRUB
On Fri, Sep 01, 2017 at 01:31:28PM +0200, Paul Lagerweij wrote:
> Hello,
>
> I've created a patch for util/grub.d/10_linux.in for dynamic ZFS boot
> environment entries. I've only tested the patch in Ubuntu 16.04.2 with GRUB
> 2.02~beta2, ZFS on Linux 0.6.5.6, Linux 4.4.0-83 and 4.4.0-81, but the
> patch should work with any root ZFS configuration, because it only changes
> the 10_linux shell script. It is designed to work with FreeBSD's beadm
> tool, for which I'm currently making a Debian package, but isn't dependent
> on beadm. I added the patch as an attachment and would like to request a
> review.
You seem to be missing an Signed off?
And perhaps an commit description?
>
> Thanks.
> diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
> index de9044c..c9a318e 100644
> --- a/util/grub.d/10_linux.in
> +++ b/util/grub.d/10_linux.in
> @@ -20,6 +20,7 @@ set -e
> prefix="@prefix@"
> exec_prefix="@exec_prefix@"
> datarootdir="@datarootdir@"
> +zfs_be="0"
Why not just
zfs_be=
And then you can just check for zfs_be having an value instead of for 1 or 0?
Or alternatively,
zfs_be=0
and then you can do if [ $zfs_be -ne 0 ]; .. or such?
>
> . "$pkgdatadir/grub-mkconfig_lib"
>
> @@ -62,9 +63,15 @@ case x"$GRUB_FS" in
> fi;;
> xzfs)
> rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`
> - bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"
> - LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}"
> - ;;
> + zfs_active_bootfs="`zpool list -H -o bootfs ${rpool} || true`"
Is zpool usually in /sbin or such? Perhaps a full path?
> + if [ -n "${zfs_active_bootfs}" ] && [ "${zfs_active_bootfs}" != "-" ] && \
> + [ `echo ${zfs_active_bootfs} | grep -o '/' | wc -l` -gt 1 ]; then
> + zfs_be="1"
> + LINUX_ROOT_DEVICE="ZFS=${zfs_active_bootfs}"
> + else
> + bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"
> + LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}"
> + fi;;
Did you test this where zpool is not installed?
> esac
>
> title_correction_code=
> @@ -177,6 +184,16 @@ title_correction_code=
> # yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
> submenu_indentation=""
>
> +if [ "${zfs_be}" = 1 ]; then
> + while read ZFS_BE_NAME ZFS_ORIGIN; do
> + if [ "${ZFS_ORIGIN}" != "-" ]; then
> + zfs_be_list="${zfs_be_list} ${ZFS_BE_NAME}"
> + fi
> + done << EOF
> +`zfs list -H -t filesystem -S creation -o name,origin -d 1 ${zfs_active_bootfs%/*} || true`
> +EOF
> +fi
> +
> is_top_level=true
> while [ "x$list" != "x" ] ; do
> linux=`version_find_latest $list`
> @@ -184,6 +201,10 @@ while [ "x$list" != "x" ] ; do
> basename=`basename $linux`
> dirname=`dirname $linux`
> rel_dirname=`make_system_path_relative_to_its_root $dirname`
> + # If ZFS BE support and /boot is in ZFS.
> + if [ "${zfs_be}" = 1 ] && [ -n "${rel_dirname}" ]; then
> + rel_dirname="/""${zfs_active_bootfs#*/}""@/boot"
> + fi
> version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
> alt_version=`echo $version | sed -e "s,\.old$,,g"`
> linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
> @@ -238,12 +259,53 @@ while [ "x$list" != "x" ] ; do
> is_top_level=false
> fi
>
> - linux_entry "${OS}" "${version}" advanced \
> - "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
> - if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
> - linux_entry "${OS}" "${version}" recovery \
> - "single ${GRUB_CMDLINE_LINUX}"
> - fi
> + for menu_entries_group in default ${zfs_be_list}; do
> + found_entry="0"
> + if [ "${menu_entries_group}" = "default" ]; then
> + found_entry="1"
> + os_title="${OS}"
> + else
> + found_zfs_be="0"
> + zfs_be_name=${menu_entries_group}
> + # If /boot is not in ZFS.
> + if [ -z "${rel_dirname}" ]; then
> + found_zfs_be="1"
> + else
> + zfs_be_mounted="`zfs list -H -o mounted ${zfs_be_name}`"
> + if [ "${zfs_be_mounted}" = "yes" ]; then
> + ZFSMNT=`mount | grep -m 1 "^${zfs_be_name} " | cut -d' ' -f3)`
> + else
> + ZFSMNT=`mktemp -d "/tmp/$(echo ${zfs_be_name} | sed 's^/^-^g').XXX" || true`
> + zfs set mountpoint=legacy ${zfs_be_name} || true
> + mount -t zfs -o ro ${zfs_be_name} ${ZFSMNT} || true
> + fi
> + if [ -n "${ZFSMNT}" ] && [ -f "${ZFSMNT}/boot/vmlinuz-${version}" ]; then
> + found_zfs_be="1"
> + rel_dirname="/""${zfs_be_name#*/}""@/boot"
> + fi
> + if [ "${zfs_be_mounted}" != "yes" ]; then
> + umount ${ZFSMNT} && rm -rf ${ZFSMNT} || true
> + zfs set mountpoint=/ ${zfs_be_name} || true
> + fi
> + fi
> +
> + if [ "${found_zfs_be}" = 1 ]; then
> + found_entry="1"
> + os_title="${OS} (${zfs_be_name##*/} BE)"
> + gettext_printf "Found ZFS boot environment: (%s BE) %s\n" "${zfs_be_name##*/}" "$linux" >&2
> + linux_root_device_thisversion="ZFS=${zfs_be_name}"
> + fi
> + fi
> +
> + if [ "${found_entry}" = 1 ]; then
> + linux_entry "${os_title}" "${version}" advanced \
> + "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
> + if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
> + linux_entry "${os_title}" "${version}" recovery \
> + "single ${GRUB_CMDLINE_LINUX}"
> + fi
> + fi
> + done
>
> list=`echo $list | tr ' ' '\n' | fgrep -vx "$linux" | tr '\n' ' '`
> done
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: ZFS boot environment patch
2017-09-13 15:02 ` Konrad Rzeszutek Wilk
@ 2017-09-13 20:17 ` Colin Watson
0 siblings, 0 replies; 8+ messages in thread
From: Colin Watson @ 2017-09-13 20:17 UTC (permalink / raw)
To: grub-devel
On Wed, Sep 13, 2017 at 11:02:48AM -0400, Konrad Rzeszutek Wilk wrote:
> On Fri, Sep 01, 2017 at 01:31:28PM +0200, Paul Lagerweij wrote:
> > +zfs_be="0"
>
> Why not just
>
> zfs_be=
>
> And then you can just check for zfs_be having an value instead of for 1 or 0?
>
> Or alternatively,
>
> zfs_be=0
>
> and then you can do if [ $zfs_be -ne 0 ]; .. or such?
If you're going to do the latter, it doesn't matter whether you assign
it as "0" or 0. Shell variables are untyped.
I think this is excessively nitpicky though. There's no single way to
do boolean shell variables that everyone agrees with, and [ "$foo" = 1 ]
is a perfectly reasonable idiomatic choice. There's very little to
choose between that and the other options you suggest, making it a
purely stylistic question. (I've been known to do 'foo=false' or
'foo=:' and then 'if "$foo"; then ...', but a lot of people have an
allergic reaction to that one.)
> > @@ -62,9 +63,15 @@ case x"$GRUB_FS" in
> > fi;;
> > xzfs)
> > rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`
> > - bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"
> > - LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}"
> > - ;;
> > + zfs_active_bootfs="`zpool list -H -o bootfs ${rpool} || true`"
>
> Is zpool usually in /sbin or such? Perhaps a full path?
Full paths are brittle when they refer to something installed by a
different package. If you need to do that kind of thing then it's
usually better to temporarily extend $PATH instead.
(I'm slightly surprised that the whole edifice of grub-mkconfig doesn't
currently appear to touch anything in /sbin or /usr/sbin, or if it does
it doesn't seem to have any particular handling for it.)
--
Colin Watson [cjwatson@ubuntu.com]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: ZFS boot environment patch
@ 2017-09-14 19:22 Paul Lagerweij
2017-09-14 23:57 ` Colin Watson
0 siblings, 1 reply; 8+ messages in thread
From: Paul Lagerweij @ 2017-09-14 19:22 UTC (permalink / raw)
To: grub-devel
[-- Attachment #1: Type: text/plain, Size: 2362 bytes --]
Thanks for answering.
On Wed, Sep 13, 2017 at 11:02:48AM -0400, Konrad Rzeszutek Wilk wrote:
> You seem to be missing an Signed off?
Signed-off-by: Paul Lagerweij <p.a.lagerweij@gmail.com>
I'm quite new with submitting code like this. I asked questions about where
to start at Ubuntu and they sent me here.
> And perhaps an commit description?
So first this makes grub-mkconfig use the bootfs property if set, because
the beadm tool changes that property to change the active boot environment.
Secondly for each kernel this adds bootable ZFS boot environment entries in
the advanced menu of grub.cfg by looking for valid boot environments and if
/boot resides in ZFS it checks if that boot environment has that kernel.
> > + zfs_active_bootfs="`zpool list -H -o bootfs ${rpool} || true`"
> > + if [ -n "${zfs_active_bootfs}" ] && [ "${zfs_active_bootfs}" !=
"-" ]
> > && \
> > + [ `echo ${zfs_active_bootfs} | grep -o '/' | wc -l` -gt 1 ];
then
> > + zfs_be="1"
> > + LINUX_ROOT_DEVICE="ZFS=${zfs_active_bootfs}"
> > + else
> > + bootfs="`make_system_path_relative_to_its_root / | sed -e
"s,@$,,"`"
> > + LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}"
> > + fi;;
>
> Did you test this where zpool is not installed?
I did and grub-mkconfig failed long before reaching this, because
grub-probe failed. Apparently grub-probe depends on the zpool command.
On Wed, 13 Sep 2017 at 09:17:42PM +0100, Colin Watson wrote:
> > On Wed, Sep 13, 2017 at 11:02:48AM -0400, Konrad Rzeszutek Wilk wrote:
> > > @@ -62,9 +63,15 @@ case x"$GRUB_FS" in
> > > fi;;
> > > xzfs)
> > > rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label
> > > 2>/dev/null || true`
> > > - bootfs="`make_system_path_relative_to_its_root / | sed -e
"s,@$,,"`"
> > > - LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}"
> > > - ;;
> > > + zfs_active_bootfs="`zpool list -H -o bootfs ${rpool} || true`"
> >
> > Is zpool usually in /sbin or such? Perhaps a full path?
>
> Full paths are brittle when they refer to something installed by a
> different package. If you need to do that kind of thing then it's
> usually better to temporarily extend $PATH instead.
Do you mean that grub-mkconfig has its own $PATH and that I should
temporarily change it to the user's $PATH? If so, can the 10_linux script
see the user's $PATH?
[-- Attachment #2: Type: text/html, Size: 3023 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: ZFS boot environment patch
2017-09-14 19:22 ZFS boot environment patch Paul Lagerweij
@ 2017-09-14 23:57 ` Colin Watson
2017-09-15 10:33 ` Vladimir 'phcoder' Serbinenko
2017-09-15 13:50 ` Konrad Rzeszutek Wilk
0 siblings, 2 replies; 8+ messages in thread
From: Colin Watson @ 2017-09-14 23:57 UTC (permalink / raw)
To: The development of GNU GRUB
On Thu, Sep 14, 2017 at 09:22:01PM +0200, Paul Lagerweij wrote:
> On Wed, 13 Sep 2017 at 09:17:42PM +0100, Colin Watson wrote:
> > > On Wed, Sep 13, 2017 at 11:02:48AM -0400, Konrad Rzeszutek Wilk wrote:
> > > > @@ -62,9 +63,15 @@ case x"$GRUB_FS" in
> > > > + zfs_active_bootfs="`zpool list -H -o bootfs ${rpool} || true`"
> > >
> > > Is zpool usually in /sbin or such? Perhaps a full path?
> >
> > Full paths are brittle when they refer to something installed by a
> > different package. If you need to do that kind of thing then it's
> > usually better to temporarily extend $PATH instead.
>
> Do you mean that grub-mkconfig has its own $PATH and that I should
> temporarily change it to the user's $PATH? If so, can the 10_linux script
> see the user's $PATH?
No, that's not what we mean. Konrad's point is that /sbin (and
/usr/sbin) may not be in $PATH when grub-mkconfig is invoked. (I'm not
sure I agree that this is likely because grub-mkconfig is normally
invoked as root and root's $PATH normally includes /sbin, but Konrad
seems to think it's a possibility worth worrying about.)
A reasonable solution to this kind of thing is to set
PATH="$PATH:/sbin:/usr/sbin" to ensure that utilities there are
available.
--
Colin Watson [cjwatson@ubuntu.com]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: ZFS boot environment patch
@ 2017-09-15 10:24 Paul Lagerweij
0 siblings, 0 replies; 8+ messages in thread
From: Paul Lagerweij @ 2017-09-15 10:24 UTC (permalink / raw)
To: grub-devel
[-- Attachment #1.1: Type: text/plain, Size: 403 bytes --]
On Fri, 15 Sep 2017 at 00:57:39AM +0100, Colin Watson wrote:
> A reasonable solution to this kind of thing is to set
> PATH="$PATH:/sbin:/usr/sbin" to ensure that utilities there are
> available.
I edited the patch and tested it. Now everywhere where I use the zpool or
zfs commands I temporarily extend $PATH with PATH="$PATH:/sbin:/usr/sbin".
Signed-off-by: Paul Lagerweij <p.a.lagerweij@gmail.com>
[-- Attachment #1.2: Type: text/html, Size: 530 bytes --]
[-- Attachment #2: zfs-be-entries-with-path.patch --]
[-- Type: text/x-patch, Size: 4525 bytes --]
diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
index de9044c..8be0acb 100644
--- a/util/grub.d/10_linux.in
+++ b/util/grub.d/10_linux.in
@@ -20,6 +20,7 @@ set -e
prefix="@prefix@"
exec_prefix="@exec_prefix@"
datarootdir="@datarootdir@"
+zfs_be="0"
. "$pkgdatadir/grub-mkconfig_lib"
@@ -62,9 +63,18 @@ case x"$GRUB_FS" in
fi;;
xzfs)
rpool=`${grub_probe} --device ${GRUB_DEVICE} --target=fs_label 2>/dev/null || true`
- bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"
- LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}"
- ;;
+ old_path="$PATH"
+ PATH="$PATH:/sbin:/usr/sbin"
+ zfs_active_bootfs="`zpool list -H -o bootfs ${rpool} || true`"
+ PATH="$old_path"
+ if [ -n "${zfs_active_bootfs}" ] && [ "${zfs_active_bootfs}" != "-" ] && \
+ [ `echo ${zfs_active_bootfs} | grep -o '/' | wc -l` -gt 1 ]; then
+ zfs_be="1"
+ LINUX_ROOT_DEVICE="ZFS=${zfs_active_bootfs}"
+ else
+ bootfs="`make_system_path_relative_to_its_root / | sed -e "s,@$,,"`"
+ LINUX_ROOT_DEVICE="ZFS=${rpool}${bootfs}"
+ fi;;
esac
title_correction_code=
@@ -177,6 +187,19 @@ title_correction_code=
# yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
submenu_indentation=""
+if [ "${zfs_be}" = 1 ]; then
+ old_path="$PATH"
+ PATH="$PATH:/sbin:/usr/sbin"
+ while read ZFS_BE_NAME ZFS_ORIGIN; do
+ if [ "${ZFS_ORIGIN}" != "-" ]; then
+ zfs_be_list="${zfs_be_list} ${ZFS_BE_NAME}"
+ fi
+ done << EOF
+`zfs list -H -t filesystem -S creation -o name,origin -d 1 ${zfs_active_bootfs%/*} || true`
+EOF
+ PATH="$old_path"
+fi
+
is_top_level=true
while [ "x$list" != "x" ] ; do
linux=`version_find_latest $list`
@@ -184,6 +207,10 @@ while [ "x$list" != "x" ] ; do
basename=`basename $linux`
dirname=`dirname $linux`
rel_dirname=`make_system_path_relative_to_its_root $dirname`
+ # If ZFS BE support and /boot is in ZFS.
+ if [ "${zfs_be}" = 1 ] && [ -n "${rel_dirname}" ]; then
+ rel_dirname="/""${zfs_active_bootfs#*/}""@/boot"
+ fi
version=`echo $basename | sed -e "s,^[^0-9]*-,,g"`
alt_version=`echo $version | sed -e "s,\.old$,,g"`
linux_root_device_thisversion="${LINUX_ROOT_DEVICE}"
@@ -238,12 +265,56 @@ while [ "x$list" != "x" ] ; do
is_top_level=false
fi
- linux_entry "${OS}" "${version}" advanced \
- "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
- if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
- linux_entry "${OS}" "${version}" recovery \
- "single ${GRUB_CMDLINE_LINUX}"
- fi
+ for menu_entries_group in default ${zfs_be_list}; do
+ found_entry="0"
+ if [ "${menu_entries_group}" = "default" ]; then
+ found_entry="1"
+ os_title="${OS}"
+ else
+ found_zfs_be="0"
+ zfs_be_name=${menu_entries_group}
+ # If /boot is not in ZFS.
+ if [ -z "${rel_dirname}" ]; then
+ found_zfs_be="1"
+ else
+ old_path="$PATH"
+ PATH="$PATH:/sbin:/usr/sbin"
+ zfs_be_mounted="`zfs list -H -o mounted ${zfs_be_name}`"
+ if [ "${zfs_be_mounted}" = "yes" ]; then
+ ZFSMNT=`mount | grep -m 1 "^${zfs_be_name} " | cut -d' ' -f3)`
+ else
+ ZFSMNT=`mktemp -d "/tmp/$(echo ${zfs_be_name} | sed 's^/^-^g').XXX" || true`
+ zfs set mountpoint=legacy ${zfs_be_name} || true
+ mount -t zfs -o ro ${zfs_be_name} ${ZFSMNT} || true
+ fi
+ if [ -n "${ZFSMNT}" ] && [ -f "${ZFSMNT}/boot/vmlinuz-${version}" ]; then
+ found_zfs_be="1"
+ rel_dirname="/""${zfs_be_name#*/}""@/boot"
+ fi
+ if [ "${zfs_be_mounted}" != "yes" ]; then
+ umount ${ZFSMNT} && rm -rf ${ZFSMNT} || true
+ zfs set mountpoint=/ ${zfs_be_name} || true
+ fi
+ PATH="$old_path"
+ fi
+
+ if [ "${found_zfs_be}" = 1 ]; then
+ found_entry="1"
+ os_title="${OS} (${zfs_be_name##*/} BE)"
+ gettext_printf "Found ZFS boot environment: (%s BE) %s\n" "${zfs_be_name##*/}" "$linux" >&2
+ linux_root_device_thisversion="ZFS=${zfs_be_name}"
+ fi
+ fi
+
+ if [ "${found_entry}" = 1 ]; then
+ linux_entry "${os_title}" "${version}" advanced \
+ "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
+ if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
+ linux_entry "${os_title}" "${version}" recovery \
+ "single ${GRUB_CMDLINE_LINUX}"
+ fi
+ fi
+ done
list=`echo $list | tr ' ' '\n' | fgrep -vx "$linux" | tr '\n' ' '`
done
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: ZFS boot environment patch
2017-09-14 23:57 ` Colin Watson
@ 2017-09-15 10:33 ` Vladimir 'phcoder' Serbinenko
2017-09-15 13:50 ` Konrad Rzeszutek Wilk
1 sibling, 0 replies; 8+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2017-09-15 10:33 UTC (permalink / raw)
To: The development of GNU GRUB
[-- Attachment #1: Type: text/plain, Size: 1704 bytes --]
On Fri, Sep 15, 2017, 01:58 Colin Watson <cjwatson@ubuntu.com> wrote:
> On Thu, Sep 14, 2017 at 09:22:01PM +0200, Paul Lagerweij wrote:
> > On Wed, 13 Sep 2017 at 09:17:42PM +0100, Colin Watson wrote:
> > > > On Wed, Sep 13, 2017 at 11:02:48AM -0400, Konrad Rzeszutek Wilk
> wrote:
> > > > > @@ -62,9 +63,15 @@ case x"$GRUB_FS" in
> > > > > + zfs_active_bootfs="`zpool list -H -o bootfs ${rpool} || true`"
> > > >
> > > > Is zpool usually in /sbin or such? Perhaps a full path?
> > >
> > > Full paths are brittle when they refer to something installed by a
> > > different package. If you need to do that kind of thing then it's
> > > usually better to temporarily extend $PATH instead.
> >
> > Do you mean that grub-mkconfig has its own $PATH and that I should
> > temporarily change it to the user's $PATH? If so, can the 10_linux script
> > see the user's $PATH?
>
> No, that's not what we mean. Konrad's point is that /sbin (and
> /usr/sbin) may not be in $PATH when grub-mkconfig is invoked. (I'm not
> sure I agree that this is likely because grub-mkconfig is normally
> invoked as root and root's $PATH normally includes /sbin, but Konrad
> seems to think it's a possibility worth worrying about.)
>
> A reasonable solution to this kind of thing is to set
> PATH="$PATH:/sbin:/usr/sbin" to ensure that utilities there are
> available.
>
If the user is not root mkconfig doesn't produce a useful output, so
manually extending path with sbin is unnecessary
>
> --
> Colin Watson [cjwatson@ubuntu.com]
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>
[-- Attachment #2: Type: text/html, Size: 2573 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: ZFS boot environment patch
2017-09-14 23:57 ` Colin Watson
2017-09-15 10:33 ` Vladimir 'phcoder' Serbinenko
@ 2017-09-15 13:50 ` Konrad Rzeszutek Wilk
1 sibling, 0 replies; 8+ messages in thread
From: Konrad Rzeszutek Wilk @ 2017-09-15 13:50 UTC (permalink / raw)
To: The development of GNU GRUB
On Fri, Sep 15, 2017 at 12:57:39AM +0100, Colin Watson wrote:
> On Thu, Sep 14, 2017 at 09:22:01PM +0200, Paul Lagerweij wrote:
> > On Wed, 13 Sep 2017 at 09:17:42PM +0100, Colin Watson wrote:
> > > > On Wed, Sep 13, 2017 at 11:02:48AM -0400, Konrad Rzeszutek Wilk wrote:
> > > > > @@ -62,9 +63,15 @@ case x"$GRUB_FS" in
> > > > > + zfs_active_bootfs="`zpool list -H -o bootfs ${rpool} || true`"
> > > >
> > > > Is zpool usually in /sbin or such? Perhaps a full path?
> > >
> > > Full paths are brittle when they refer to something installed by a
> > > different package. If you need to do that kind of thing then it's
> > > usually better to temporarily extend $PATH instead.
> >
> > Do you mean that grub-mkconfig has its own $PATH and that I should
> > temporarily change it to the user's $PATH? If so, can the 10_linux script
> > see the user's $PATH?
>
> No, that's not what we mean. Konrad's point is that /sbin (and
> /usr/sbin) may not be in $PATH when grub-mkconfig is invoked. (I'm not
> sure I agree that this is likely because grub-mkconfig is normally
> invoked as root and root's $PATH normally includes /sbin, but Konrad
> seems to think it's a possibility worth worrying about.)
>
> A reasonable solution to this kind of thing is to set
> PATH="$PATH:/sbin:/usr/sbin" to ensure that utilities there are
> available.
Which is much better than what I had mind. In other words, just
disregard my suggestion to add '/sbin' to the patch.
>
> --
> Colin Watson [cjwatson@ubuntu.com]
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2017-09-15 13:50 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-14 19:22 ZFS boot environment patch Paul Lagerweij
2017-09-14 23:57 ` Colin Watson
2017-09-15 10:33 ` Vladimir 'phcoder' Serbinenko
2017-09-15 13:50 ` Konrad Rzeszutek Wilk
-- strict thread matches above, loose matches on Subject: below --
2017-09-15 10:24 Paul Lagerweij
2017-09-01 11:31 Paul Lagerweij
2017-09-13 15:02 ` Konrad Rzeszutek Wilk
2017-09-13 20:17 ` Colin Watson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).