commit: 4e46cfcd6f50560a9e8c31163663940a99875e0c Author: Thomas Deutschmann <whissi <AT> gentoo <DOT> org> AuthorDate: Wed Mar 27 11:53:54 2019 +0000 Commit: Thomas Deutschmann <whissi <AT> gentoo <DOT> org> CommitDate: Wed Mar 27 11:53:54 2019 +0000 URL: https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=4e46cfcd
ZFS: Change hostid handling No need to deal with hostid value: We assume that /etc/hostid exists if ZFS is used. So just copy that existing file. If file is missing tell user that kernel command-line parameter "spl_hostid=<hostid>" must be used. Same is true when generated initramfs is used for multiple systems. Closes: https://bugs.gentoo.org/531192 Closes: https://bugs.gentoo.org/616738 Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org> gen_initramfs.sh | 26 ++++++++++++-------------- genkernel | 23 +++++++++++++++++++---- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/gen_initramfs.sh b/gen_initramfs.sh index da5ffcf..7c41c2c 100755 --- a/gen_initramfs.sh +++ b/gen_initramfs.sh @@ -116,20 +116,6 @@ append_base_layout() { date -u '+%Y%m%d-%H%M%S' > ${TEMP}/initramfs-base-temp/etc/build_date echo "Genkernel $GK_V" > ${TEMP}/initramfs-base-temp/etc/build_id - # The ZFS tools want the hostid in order to find the right pool. - # Assume the initramfs we're building is for this system, so copy - # our current hostid into it. - # We also have to deal with binary+endianness here: glibc's gethostid - # expects the value to be in binary using the native endianness. But - # the coreutils hostid program doesn't show it in the right form. - local hostid - if file -L "${TEMP}/initramfs-base-temp/bin/sh" | grep -q 'MSB executable'; then - hostid="$(hostid)" - else - hostid="$(hostid | sed -E 's/(..)(..)(..)(..)/\4\3\2\1/')" - fi - printf "$(echo "${hostid}" | sed 's/\([0-9A-F]\{2\}\)/\\x\1/gI')" > ${TEMP}/initramfs-base-temp/etc/hostid - mkdir -p "${TEMP}/initramfs-base-temp/etc/mdev/helpers" install -m 644 -t "${TEMP}/initramfs-base-temp/etc" /usr/share/genkernel/mdev/mdev.conf install -m 755 -t "${TEMP}/initramfs-base-temp/etc/mdev/helpers" /usr/share/genkernel/mdev/helpers/nvme @@ -516,6 +502,18 @@ append_zfs(){ fi done + if [ -f "/etc/hostid" ] + then + local _hostid=$(hostid) + print_info 1 "$(getIndent 2)zfs: >> Embedding hostid '${_hostid}' into initramfs..." + cp -a /etc/hostid "${TEMP}/initramfs-zfs-temp/etc" 2> /dev/null \ + || gen_die "Failed to copy /etc/hostid" + + echo "${_hostid}" > "${TEMP}/.embedded_hostid" + else + print_info 2 "$(getIndent 2)zfs: /etc/hostid not found; You must use 'spl_hostid' kernel command-line parameter!" + fi + copy_binaries "${TEMP}/initramfs-zfs-temp" /sbin/{mount.zfs,zdb,zfs,zpool} cd "${TEMP}/initramfs-zfs-temp/" diff --git a/genkernel b/genkernel index c4ce4f8..25e9ca9 100755 --- a/genkernel +++ b/genkernel @@ -363,10 +363,25 @@ then isTrue "${DMRAID}" && print_warning 1 'add "dodmraid" for dmraid support' isTrue "${MDADM}" && print_warning 1 'add "domdadm" for MDRAID support' isTrue "${DMRAID}" && print_warning 1 ' or "dodmraid=<additional options>"' - isTrue "${ZFS}" && print_warning 1 'add "dozfs" for ZFS volume management support' - isTrue "${ZFS}" && print_warning 1 ' and either "root=ZFS" to use bootfs autodetection or "root=ZFS=<dataset>" to force booting from a specific dataset' - isTrue "${ZFS}" && print_warning 1 'If importing ZFS pool is slow, add dozfs=cache or dozfs=force to kernel commandline.' - isTrue "${ZFS}" && print_warning 1 '"man genkernel" explains "dozfs" in detail.' + + if isTrue "{ZFS}" + then + print_warning 1 'add "dozfs" for ZFS volume management support' + print_warning 1 ' and either "root=ZFS" to use bootfs autodetection or "root=ZFS=<dataset>" to force booting from a specific dataset' + print_warning 1 '' + if [ -f "${TEMP}/.embedded_hostid" ] + then + local _hostid=$(cat "${TEMP}/.embedded_hostid") + print_warning '1' "Hostid '${_hostid}' is embedded into initramfs." + print_warning '1' "If you will use this initramfs for a different system you MUST set 'spl_hostid=<hostid>' parameter to overwrite embedded hostid!" + else + print_warning '1' "No hostid embedded into initramfs. You MUST set 'spl_hostid=<hostid>' parameter to provide hostid for ZFS!" + fi + print_warning 1 '' + print_warning 1 'If importing ZFS pool is slow, add dozfs=cache or dozfs=force to kernel commandline.' + print_warning 1 '"man genkernel" explains "dozfs" in detail.' + fi + isTrue "${BTRFS}" && print_warning 1 'add "dobtrfs" for Btrfs device scanning support' isTrue "${ISCSI}" && print_warning 1 'add at least "iscsi_initiatorname=<initiator name> iscsi_target=<target name> and iscsi_address=<target ip>" for iscsi support'