CentOS 7 kickstart file set hostname with hostnamectl

273 Views Asked by At

I used remote HTTP server to install CentOS 7. Following is my kickstart file code for setting hostname, but it didn't work.

%post --nochroot --interpreter=/bin/bash --log=/var/log/hostname_post.log 
hostnamectl set-hostname f10web01 
%end 

%post --interpreter=/bin/bash --log=/var/log/another.log
# did something else successfully here
%end

Any clue why set hostname didn't do the work? Also, log file hostname_post.log was not generated, so seem like the first post section was not executed at all.

1

There are 1 best solutions below

0
On

Use this instead:

%post --nochroot
hostnamectl set-hostname server.example.com
hostnamectl --pretty set-hostname server.example.com
cp /etc/hostname /mnt/sysimage/etc/hostname
cp /etc/machine-info /mnt/sysimage/etc/machine-info

This is the recommended way to do this according to Red Hat.