commit:     f3299dffb18d26fe500bc59a59a8bc591b2dcf78
Author:     Jason Miller <aidenn0 <AT> geocities <DOT> com>
AuthorDate: Wed Jun 22 23:12:10 2016 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Thu Jun 23 19:05:06 2016 +0000
URL:        https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=f3299dff

gen_initramfs: fix little-endian problem with hostid

 gen_initramfs.sh | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/gen_initramfs.sh b/gen_initramfs.sh
index f113373..1fd5d2a 100755
--- a/gen_initramfs.sh
+++ b/gen_initramfs.sh
@@ -110,7 +110,19 @@ 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
 
-       printf "$(hostid | sed 's/\([0-9A-F]\{2\}\)/\\x\1/gI')" > 
${TEMP}/initramfs-base-temp/etc/hostid
+       # 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

Reply via email to