Bug 76102

Summary: hostnamectl set-hostname destroys /etc/machine-info
Product: systemd Reporter: Brian "Redbeard" Harrington <brian.harrington>
Component: generalAssignee: systemd-bugs
Status: RESOLVED NOTABUG QA Contact: systemd-bugs
Severity: minor    
Priority: medium    
Version: unspecified   
Hardware: Other   
OS: Linux (All)   
Whiteboard:
i915 platform: i915 features:

Description Brian "Redbeard" Harrington 2014-03-13 08:09:25 UTC
While doing some work in trying ensure hostnames get set correctly on CoreOS I found that running hostnamectl set-hostname would destroy the file /etc/machine-info.

In this case the hostname "host-10-0-0-7" is the hostname assigned via DHCP.  The file /etc/machine-info was created by hand and the system was subsequently rebooted.


[bharrington@leviathan-alticon-net coreos]$ ssh 192.168.1.202
Warning: Permanently added '192.168.1.202' (RSA) to the list of known hosts.
Last login: Thu Mar 13 00:55:57 UTC 2014 from 192.168.1.63 on pts/1
   ______                ____  _____
  / ____/___  ________  / __ \/ ___/
 / /   / __ \/ ___/ _ \/ / / /\__ \
/ /___/ /_/ / /  /  __/ /_/ /___/ /
\____/\____/_/   \___/\____//____/
core@host-10-0-0-7 ~ $ 
core@host-10-0-0-7 ~ $ 
core@host-10-0-0-7 ~ $ 
core@host-10-0-0-7 ~ $ cat /etc/machine-info 
PRETTY_HOSTNAME=coreos-2.coreos.lab
core@host-10-0-0-7 ~ $ sudo hostnamectl set-hostname coreos-1.coreos.lab
core@host-10-0-0-7 ~ $ cat /etc/machine-info 
cat: /etc/machine-info: No such file or directory
core@host-10-0-0-7 ~ $ hostname
coreos-1.coreos.lab
core@host-10-0-0-7 ~ $ cat /etc/hostname 
coreos-1.coreos.lab
Comment 1 Lennart Poettering 2014-03-13 19:08:18 UTC
"systemctl set-hostname" sets all three hostnames by default. If you want to set only the pretty, or only the transient, or only the static one use switches like --pretty, --transient, --static. You can even combine them...

"systemctl set-hostname" will set all three names, then detect that there's no point in keeping the pretty name in place if it is char-for-char identical with the static one, and simply removes the file since there's nothing else in there. 

So, this is intended operation. And explained in the man page...

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.