Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CentOS 5 Kickstart Post-Scripting

Status
Not open for further replies.

ObiTrice

Programmer
Jul 9, 2007
3
US
I want to design a kickstart file that creates an unattended installation (I've passed that part). After it installs, I want it to automatically read the device's MAC address and change the hostname to match the MAC address with the separators removed. (For example if the MAC address is 01-02-03-04-05-06, the prompt after login should read root@010203040506)

I know this is entered in the "%post" section of the kickstart file, and I know I'm supposed to use the "cut" and "sed" commands, but I have no idea what I'm doing or how to do it.

Can someone give me the script so I can copy/paste it into my kickstart file?
 
Something like this?

Code:
OLDHOSTNAME=fred
NEWHOSTNAME=$(ifconfig eth0 | awk '/HWaddr/ { gsub(":","",$NF); print $NF }')
sed -i "s/$OLDHOSTNAME/$NEWHOSTNAME/g" /etc/sysconfig/network /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/hosts /etc/printcap # ... and anywhere else you can think of

You may have to change the paths of the files to update if the root filesystem is mounted somewhere else during the kickstart %post stage; I can't remember how that works...

Annihilannic.
 
I keep getting a "permission denied" error every time I try to access "/etc/sysconfig/network", even though I'm logged in as "root".

And why do I need OLDHOSTNAME included? I keep getting "No such file or directory" with that.
 
I think that's because of my last statement. I'm guessing that in the %post phase of kickstart that the /etc/sysconfig/network you are accessing is on the boot/install image, and the "real" root filesystem is mounted under another location. I can't remember what location CentOS/RHEL uses for that, but let's say it's under /a, then you need to change all of those paths, e.g.:

Code:
 ... /a/etc/sysconfig/network /a/etc/sysconfig/network-scripts/ifcfg-eth0 /a/etc/hosts ...

You need to know what the old host name in those files was so that the sed search and replace function can replace it with the hostname of the system you are building. The best way to check is to build a system without this %post script and have a look in those files to see what "default" hostname it is given.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top