Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 531192 - The /etc/hostid file in the initramfs has mangled byte order
Summary: The /etc/hostid file in the initramfs has mangled byte order
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Hosted Projects
Classification: Unclassified
Component: genkernel (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo Genkernel Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-11-29 23:57 UTC by Anthony Lieuallen
Modified: 2019-03-27 11:54 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Anthony Lieuallen 2014-11-29 23:57:50 UTC
This was surprising to me:


# dd if=/dev/urandom of=/dev/stdout bs=1 count=4 > /etc/hostid
# hexdump /etc/hostid
0000000 9872 1823
0000004
$ hostid
72982318
# xzcat /boot/initramfs | cpio -id
# hexdump ./etc/hostid
0000000 2318 7298
0000004


The byte order in the file in the initramfs is incorrect.  In my case, with a root ZFS, this value is loaded first at initramfs time, from this incorrect value.  Then forever on after the system is booted, "zpool status" will complain about a mismatch.

Workaround: copy the hostid file out of the initramfs into /etc/ of the booted system and the error goes away.  Probably manually copying the file _into_ the initramfs would work as well.


I believe this should not happen.  After running genkernel, the hostid file in the initramfs should match that in /etc/ exactly.  It appears that today genkernel is doing:

    printf "$(hostid | sed 's/\([0-9A-F]\{2\}\)/\\x\1/gI')" > ${TEMP}/initramfs-base-temp/etc/hostid

But this is incorrect, due to the network ordering of the bytes in that file.  Note the difference between the output of the first hexdump and hostid commands above.
Comment 1 John Einar Reitan 2014-12-09 22:46:31 UTC
I've got the exact same problem;

apoc ~ # hexdump /etc/hostid 
0000000 6302 a8c0                              
0000004

Doing the same on the output of the line from ./gen_initramfs.sh:

apoc ~ # printf "$(hostid | sed 's/\([0-9A-F]\{2\}\)/\\x\1/gI')" | hexdump
0000000 c0a8 0263                              
0000004

Adding
perl -0777e 'print scalar reverse <>'
fixes this;

printf "$(hostid | sed 's/\([0-9A-F]\{2\}\)/\\x\1/gI')" | perl -0777e 'print scalar reverse <>' | hexdump
0000000 6302 a8c0                              
0000004
Comment 2 Scott Bowe 2014-12-31 16:45:38 UTC
Same issue observed today.

Once I extracted the hostid file from the initramfs - all was happy.
Comment 3 Larry the Git Cow gentoo-dev 2019-03-27 11:54:19 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=4e46cfcd6f50560a9e8c31163663940a99875e0c

commit 4e46cfcd6f50560a9e8c31163663940a99875e0c
Author:     Thomas Deutschmann <whissi@gentoo.org>
AuthorDate: 2019-03-27 11:53:54 +0000
Commit:     Thomas Deutschmann <whissi@gentoo.org>
CommitDate: 2019-03-27 11:53:54 +0000

    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@gentoo.org>

 gen_initramfs.sh | 26 ++++++++++++--------------
 genkernel        | 23 +++++++++++++++++++----
 2 files changed, 31 insertions(+), 18 deletions(-)