7

In RHEL 7.2, systemd starts up and determines the host's hostname. If /etc/hostname is unavailable (ie, removed), and /etc/machine-info is unavilable, and the kernel is not configured with that information (ie, sysctl's kernel.hostname), systemd assigns a "transient" hostname to the host. The question is: from where does it determine this?

The host was originally named this way. I then cloned the host (it's a VM) and wiped all references to that name. But then during the boot process, very early, it gets set that way.

If I boot into rescuemode I can see that it sets the hostname very early:

[    0.456076] systemd[1]: systemd 208 running in system mode. (+PAM +LIBWRAP +AUDIT +SELINUX +IMA +SYSVINIT +LIBCRYPTSETUP +GCRYPT +AC
L +XZ)
[    0.456664] systemd[1]: Detected virtualization 'kvm'.
[    0.456955] systemd[1]: Running in initial RAM disk.
[    0.458496] systemd[1]: Set hostname to <badhostname.example.com>.
[    0.475394] systemd[1]: Expecting device dev-mapper-vgroot\x2dlvroot.device...

At the command prompt, it's set as a "transient" hostname:

# hostnamectl status
Transient hostname: badhostname.mydomain.com
...

It might be that it's not systemd: I even get this problem when using init=/bin/bash, but systemd is running within the initrd image.

  • It's not set in grub or anything.
  • It's not set by DHCP as networking is disabled at boot.
  • It's not anywhere in the filesystem:

    # find / \( -path /sys -prune -o -path /proc -prune -o -path /run -prune \) -o -type f -exec grep -ilrF "${HOSTNAME}" {} +
    <some .git files>
    <history files of non-root user>
    

Somehow, the kernel or systemd is determining the old hostname and using it as a transient, and I'm at a complete loss as to how! . I did a find ... -exec grep with no results except /var/log/dmesg. I'm telling you, systemd has haunted my host!

EDIT 2: The only time I don't get it is if I boot into the provided rescue initramfs. Apparently, the generated initramfs holds dirty secrets!

2
  • I've narrowed it down to 3 possibilities: (1) the initrd image, (2) even when not in networked mode, it uses DHCP to get the hostname -- possibly within initrd, (3) black magic. – Otheus May 20 '16 at 22:23
  • 1
    As an aside, nice use of the word "whence." ;) – Wildcard Nov 5 '16 at 16:11
8

Thanks to Don Crissti's insights and via process of elimination, it is concluded that the culprit is the initramfs image. Somehow dracut when it builds the image decides to include a cached version of the hostname (!?!).

Rebuilding the initrd/initram fs is covered here but in short (since you, dear reader might not have access), do

dracut -f -v

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.