2017-06-27 05:17 UTC

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0012828CentOS-7dracutpublic2017-04-07 06:13
Reportermwmanley 
PrioritynormalSeverityminorReproducibilityalways
StatusnewResolutionopen 
Product Version7.3.1611 
Target VersionFixed in Version 
Summary0012828: dracut/anaconda do not set system hostname from ip kickstart parameter
DescriptionWhen booting a CentOS 7.3.1611 image with the following kickstart parameters:

Feb 15 21:01:46 localhost kernel: Command line: ks=http://kickstart/pub/kickstart/conf/prd/7_template.cfg biosdevname=0 net.ifnames=0 ksdevice=eth0 load_ramdisk=1 initrd=centos/7.3/initrd.img ip=::::centos7::dhcp rd.debug BOOTIF=01-00-50-56-a2-3c-9a BOOT_IMAGE=centos/7.3/vmlinuz

the hostname ("centos7") gets somehow swallowed somewhere. When the system boots I can see the systemd does not have a name:

Feb 15 21:01:46 localhost systemd[1]: No hostname configured.
Feb 15 21:01:46 localhost systemd[1]: Set hostname to <localhost>.

I can see all these kickstart parameters come from our kickstart server and dracut is setting the host name down the line:

Feb 15 21:01:46 localhost dracut-cmdline[79]: //lib/net-lib.sh@494(ip_to_var): '[' -n centos7 ']'
Feb 15 21:01:46 localhost dracut-cmdline[79]: //lib/net-lib.sh@494(ip_to_var): hostname=centos7

Feb 15 21:01:47 localhost dracut-initqueue[541]: /lib/net-lib.sh@440(ip_to_var): unset ip srv gw mask hostname dev autoconf macaddr mtu dns1 dns2
Feb 15 21:01:47 localhost dracut-initqueue[541]: /lib/net-lib.sh@442(ip_to_var): '[' 7 -eq 0 ']'
Feb 15 21:01:47 localhost dracut-initqueue[541]: /lib/net-lib.sh@447(ip_to_var): '[' 7 -eq 1 ']'
Feb 15 21:01:47 localhost dracut-initqueue[541]: /lib/net-lib.sh@475(ip_to_var): '[' '' = dhcp -o '' = on -o '' = any -o '' = dhcp6 -o '' = auto6 ']'
Feb 15 21:01:47 localhost dracut-initqueue[541]: /lib/net-lib.sh@490(ip_to_var): '[' -n '' ']'
Feb 15 21:01:47 localhost dracut-initqueue[541]: /lib/net-lib.sh@491(ip_to_var): '[' -n '' ']'
Feb 15 21:01:47 localhost dracut-initqueue[541]: /lib/net-lib.sh@492(ip_to_var): '[' -n '' ']'
Feb 15 21:01:47 localhost dracut-initqueue[541]: /lib/net-lib.sh@493(ip_to_var): '[' -n '' ']'
Feb 15 21:01:47 localhost dracut-initqueue[541]: /lib/net-lib.sh@494(ip_to_var): '[' -n centos7 ']'
Feb 15 21:01:47 localhost dracut-initqueue[541]: /lib/net-lib.sh@494(ip_to_var): hostname=centos7
Feb 15 21:01:47 localhost dracut-initqueue[541]: /lib/net-lib.sh@495(ip_to_var): '[' -n '' ']'
Feb 15 21:01:47 localhost dracut-initqueue[541]: /lib/net-lib.sh@496(ip_to_var): '[' -n dhcp ']'
Feb 15 21:01:47 localhost dracut-initqueue[541]: /lib/net-lib.sh@496(ip_to_var): autoconf=dhcp

then later it seems to appear here:

Feb 15 21:01:50 localhost dracut-initqueue[541]: //sbin/ifup@400(): '[' centos7 ']'
Feb 15 21:01:50 localhost dracut-initqueue[541]: //sbin/ifup@400(): echo hostname=centos7

and here:

Feb 15 21:01:50 localhost dracut-initqueue[541]: //lib/net-lib.sh@121(setup_net): '[' -e /tmp/net.eth0.hostname ']'
Feb 15 21:01:50 localhost dracut-initqueue[541]: //lib/net-lib.sh@122(setup_net): '[' -e /tmp/net.eth0.override ']'
Feb 15 21:01:50 localhost dracut-initqueue[541]: //lib/net-lib.sh@122(setup_net): . /tmp/net.eth0.override
Feb 15 21:01:50 localhost dracut-initqueue[541]: ///tmp/net.eth0.override@1(source): hostname=centos7

Then NetworkManager comes along and does not have this name:

Feb 15 21:02:08 localhost.localdomain systemd-hostnamed[1373]: Changed host name to 'localhost.localdomain'
Feb 15 21:02:08 localhost NetworkManager[1345]: <info> [1487192528.6887] settings: hostname: using hostnamed
Feb 15 21:02:08 localhost NetworkManager[1345]: <info> [1487192528.6887] settings: hostname changed from (none) to ""
Feb 15 21:02:08 localhost NetworkManager[1345]: <debug> [1487192528.6887] dispatcher: (1) dispatching action 'hostname'
Feb 15 21:02:08 localhost.localdomain NetworkManager[1345]: <info> [1487192528.7492] policy: setting system hostname to 'localhost.localdomain' (no default device)

As a result, I am left with a host registering itself in DNS (we use DDNS) as "localhost."

This used to work in CentOS 7.2 before systemd took over this function. Is there some issue with dracut and systemd not speaking to each other? I checked and re-checked all the anaconda and dracut documentation and do not see any issues there.
Steps To ReproduceKickstart of this host or any other host will result in "localhost"
Additional InformationI do not specify a hostname in the kickstart configuration files. I never had to in the past.
TagsNo tags attached.
abrt_hash
URL
Attached Files
  • patch file icon ip-hostname.patch (522 bytes) 2017-03-31 08:26 -
    --- /usr/lib/dracut/modules.d/40network/ifup.sh.dist	2016-11-12 03:27:26.000000000 +0900
    +++ /usr/lib/dracut/modules.d/40network/ifup.sh	2017-03-31 15:47:19.874950930 +0900
    @@ -46,6 +46,7 @@ do_dhcp() {
         [ -n "$macaddr" ] && ip link set address $macaddr dev $netif
         [ -n "$mtu" ] && ip link set mtu $mtu dev $netif
         ip -4 addr flush dev $netif
    +    [ -n "$hostname" ] && echo $hostname > /proc/sys/kernel/hostname
     
         while [ $_COUNT -lt $_DHCPRETRY ]; do
             info "Starting dhcp for interface $netif"
    
    patch file icon ip-hostname.patch (522 bytes) 2017-03-31 08:26 +
  • patch file icon patch-anaconda-iphostname.patch (1,788 bytes) 2017-04-06 07:44 -
    From: Taketo Kabe <kabe@>
    Date: Thu, 6 Apr 2017 16:24:03 -0900
    
    patch: honour ip=::::hostname::dhcp kernel option as final hostname
    
    This patch enables hostname specified as
    "ip=::::hostname::dhcp" kernel option (dracut.cmdline(7))
    to be set as a final hostname.
    Previously the final /etc/hostname was only set from kickstart ks.cfg,
    and became always "localhost.localdomain" if not in ks.cfg.
    
    
    diff -up ./pyanaconda/network.py.dist ./pyanaconda/network.py
    --- ./pyanaconda/network.py.dist	2016-09-16 03:39:36.000000000 +0900
    +++ ./pyanaconda/network.py	2017-04-06 14:29:36.723286226 +0900
    @@ -1174,6 +1174,7 @@ def write_network_config(storage, ksdata
         # overwrite previous settings for LiveCD or liveimg installations
         overwrite = flags.livecdInstall or ksdata.method.method == "liveimg"
     
    +    log.debug("current kickstart hostname = %s", ksdata.network.hostname)
         write_hostname(rootpath, ksdata, overwrite=overwrite)
         if ksdata.network.hostname != DEFAULT_HOSTNAME:
             set_hostname(ksdata.network.hostname)
    @@ -1338,7 +1339,13 @@ def networkInitialize(ksdata):
             logIfcfgFiles(msg)
     
         if ksdata.network.hostname is None:
    -        update_hostname_data(ksdata, DEFAULT_HOSTNAME)
    +        # Should we use getHostname() here?
    +        # Depends on what we want with hostname DHCP gives us...
    +        hn = socket.gethostname()
    +        if not hn or hn in ('(none)', 'localhost', 'localhost.localdomain'):
    +            hn = DEFAULT_HOSTNAME
    +        log.debug("No hostname given in kickstart, using %s", hn)
    +        update_hostname_data(ksdata, hn)
     
     def _get_ntp_servers_from_dhcp(ksdata):
         """Check if some NTP servers were returned from DHCP and set them
    diff -up ./pyanaconda/ui/tui/spokes/network.py.dist ./pyanaconda/ui/tui/spokes/network.py
    
    patch file icon patch-anaconda-iphostname.patch (1,788 bytes) 2017-04-06 07:44 +
  • patch file icon patch-dracut-ip-hostname.patch (930 bytes) 2017-04-06 07:44 -
    From: Taketo Kabe <kabe@>
    Date: Thu, 6 Apr 2017 15:13:02 -0900
    
    patch: honour ip=::::hostname::dhcp kernel option as final hostname
    
    This patch enables hostname specified as
    "ip=::::hostname::dhcp" kernel option (dracut.cmdline(7))
    to be set as a hostname during initrd run.
    Previously the hostname was just ignored and not set.
    If /etc/hostname is also nonexistent, the hostname will survive 
    multiuser boot and NetworkManager setup.
    
    --- ./modules.d/40network/ifup.sh.dist	2016-11-12 03:27:26.000000000 +0900
    +++ ./modules.d/40network/ifup.sh	2017-03-31 15:47:19.874950930 +0900
    @@ -46,6 +46,7 @@ do_dhcp() {
         [ -n "$macaddr" ] && ip link set address $macaddr dev $netif
         [ -n "$mtu" ] && ip link set mtu $mtu dev $netif
         ip -4 addr flush dev $netif
    +    [ -n "$hostname" ] && echo $hostname > /proc/sys/kernel/hostname
     
         while [ $_COUNT -lt $_DHCPRETRY ]; do
             info "Starting dhcp for interface $netif"
    
    patch file icon patch-dracut-ip-hostname.patch (930 bytes) 2017-04-06 07:44 +

-Relationships
+Relationships

-Notes

~0028988

kabe (reporter)

This seems to be an obscure bug in dracut.

As "rd.debug" dracut debug script you collected,
the hostname is set from "ip=::::hostname::dhcp" into $hostname shell variable.

But it isn't used anywhere. Discarded.
(It seems to be used in static IP config and IPv6 DHCP though)

After this, NetworkManager detects hostname is not set and sets the
#define FALLBACK_HOSTNAME4 "localhost.localdomain" .

Test: When I dropped to rdshell via "rd.break", and
manually set the hostname via "echo host.name > /proc/sys/kernel/hostname",
the hostname was honoured and survived through NetworkManager. Good.

So the fix is to do "echo $hostname > /proc/sys/kernel/hostname"
somewhere in the dracut plugins. Proposed patch attached.

=========
This patch enables hostname specified as
"ip=::::hostname::dhcp" kernel option (dracut.cmdline(7))
to be set as a hostname during initrd run.
Previously the hostname was just ignored and not set.
If /etc/hostname is also nonexistent, the hostname will survive
multiuser boot and NetworkManager setup.
=========

Apply patch, erase /etc/hostname and rebuild the initramfs.
You are rebuilding initramfs anyway, right?


The downside of this patch is that you need a network interface
to set just the hostname.
(You can't kickstart a host without a network with a custom hostname)
But since dracut.cmdline(7) only has ip=::::hostname::dhcp
to place a hostname, this shouldn't be a problem in most cases.

~0028990

kabe (reporter)

I think I made a bit misassumption;
you are using an Installation isolinux/initrd.img, not a
normal initramfs for disk boot?
Then you have to rebuild the dracut package and re-lorax the boot image,
which isn't trivial...

~0029038

kabe (reporter)

Just patching dracut wasn't enough.
Anaconda only reads hostname from kickstart file, and if is not set,
always hardcoded "localhost.localdomain" as the final hostname.

Fix:

Patch and rebuid anaconda, and replace anaconda-core package:
https://bugs.centos.org/file_download.php?file_id=19591&type=bug

Patch and rebuild dracut, and replace dracut-network package:
https://bugs.centos.org/file_download.php?file_id=19592&type=bug


After these fixes and rebuilding installation DVD ISO by lorax,
I succeeded in installing PXE-booted machine with hostname set
by passing kernel options:

    ip=::::host.name::dhcp inst.repo=nfs:vers=4:<nfsserver>:/export/centos inst.ks=nfs:vers=4:<nfsserver>:/export/centos/ks/ks.cfg

hostname survived through anaconda and
was set into /etc/hostname in the final installation.

Since NOT setting a "network --hostname=..." in kickstart seems not a standard deployment,
I don't think that this will ever be considered a bug.
(How do you set individual hostname in PXE/kickstart setup? From every boot: prompt?)
+Notes

-Issue History
Date Modified Username Field Change
2017-02-15 21:35 mwmanley New Issue
2017-03-31 08:26 kabe File Added: ip-hostname.patch
2017-03-31 08:26 kabe Note Added: 0028988
2017-03-31 09:33 kabe Note Added: 0028990
2017-04-06 07:44 kabe File Added: patch-anaconda-iphostname.patch
2017-04-06 07:44 kabe File Added: patch-dracut-ip-hostname.patch
2017-04-07 06:13 kabe Note Added: 0029038
+Issue History