Operating System - Linux
1752660 Members
5959 Online
108788 Solutions
New Discussion

Re: Kickstart %post problem

 
Ray Bell
Regular Advisor

Kickstart %post problem

I'm install RHEL5 from a kickstart script that seems to works but aftre the %post section nothing else works. Not sure what is wrong and need some hlep: Here's a copy of the script:

# Kickstart file automatically generated by anaconda.

install
cdrom
key --skip
lang en_US.UTF-8
keyboard us
xconfig --startxonboot
network --device eth0 --bootproto static --ip xxx.xxx.xxx.xx --netmask xxx.xxx.xxx.x --gateway xxx.xx.xxx.xx --nameserver xxx.xx.xx.xx,xxx.xx.x.xx --hostname tech1ap1.national.aaa.com
network --device eth1 --onboot no --bootproto dhcp --hostname xxx.xxx.xxx.com
rootpw --iscrypted $xxxxxxxxxxxxxxxxxx
firewall --disabled
authconfig --enableshadow --enablemd5
selinux --disabled
timezone --utc America/New_York
bootloader --location=mbr --driveorder=cciss/c0d0,cciss/c0d1 --append="rhgb quiet"
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
clearpart --all --initlabel
part /boot --fstype ext3 --size=100 --ondisk=cciss/c0d0
part pv.4 --size=139870 --grow --ondisk=cciss/c0d0
volgroup vg00 --pesize=32768 pv.4
logvol /tmp --fstype ext3 --name=lvol3 --vgname=vg00 --size=1000
logvol / --fstype ext3 --name=lvol1 --vgname=vg00 --size=10000
logvol /home --fstype ext3 --name=lvol2 --vgname=vg00 --size=10000
logvol /usr --fstype ext3 --name=lvol5 --vgname=vg00 --size=15000
logvol /opt --fstype ext3 --name=lvol4 --vgname=vg00 --size=5000
logvol /usr/local --fstype ext3 --name=lvol6 --vgname=vg00 --size=4000
logvol swap --fstype swap --name=swap --vgname=vg00 --size=10000
logvol /var --fstype ext3 --name=lvol7 --vgname=vg00 --size=6000
part pv.200000 --size=71000 --grow --ondisk=cciss/c0d1
volgroup vg01 --pesize=32768 pv.200000
logvol /system_backups --fstype ext3 --name=lvol20 --vgname=vg01 --size=49000


%packages
@admin-tools
@editors
@system-tools
@development-tools
@gnome-software-development
@text-internet
@x-software-development
@legacy-network-server
@gnome-desktop
@core
@base
@network-server
@legacy-software-development
@java
@java-development
@legacy-software-support
@base-x
@graphics
@web-server
@printing
@kde-software-development
@kde-desktop
@mail-server
@server-cfg
@development-libs
@news-server
@graphical-internet
system-config-kickstart
emacs
vim-X11
arpwatch
adjtimex
rdesktop
watchdog
wireshark-gnome
tsclient
x3270
am-utils
audit
amanda-client
sysstat
dejagnu
imake
expect
xorg-x11-xbitmaps
mesa-libGLU-devel
xorg-x11-server-sdk
gconf-editor
hal-gnome
aide
kexec-tools
nfs4-acl-tools
x86info
device-mapper-multipath
cpufreq-utils
amanda-server
vnc-server
krb5-server
gtk+
qt4
compat-openldap
compat-slang
xorg-x11-utils
xorg-x11-server-Xnest
xorg-x11-server-Xvfb
libsane-hpaio
tomcat5-webapps
tomcat5
kdeadmin
perl-libxml-perl
perl-XML-SAX
perl-LDAP
perl-Convert-ASN1
perl-DateManip
perl-XML-Twig
perl-XML-Grove
perl-XML-Dumper
perl-Crypt-SSLeay
perl-Mozilla-LDAP
perl-TimeDate
perl-XML-NamespaceSupport
kdewebdev
mutt
-rwho
-rusers
-sysreport
-bluez-utils
-tux
-dovecot
compat-libstdc++-33

%post --nochroot
SudoersFile="/etc/sudoers"
SSHFile="/etc/ssh/sshd_config"
SysAuthFile="/etc/pam.d/system-auth"
HostsFile="/etc/hosts"
AliasesFile="/etc/aliases"
SendmailCf="/etc/mail/sendmail.cf"
YumFile="/etc/yum/yum-updatesd.conf"
RCLocalFile="/etc/rc.local"
NTPConfFile="/etc/ntp.conf"
SysctlFile="/etc/sysctl.conf"
Profile="/etc/profile"
TextFile="/mnt/sysimage/root/ks-install.txt

echo "Kickstart `date`" >$TextFile
echo 'echo "0" > /proc/sys/kernel/core_uses_pid' >> $RCLocalFile
sed -i -e 's/^ulimit -S -c 0.+/ulimit -c 5000000/g' $Profile


echo “Adding groups and users..."
/usr/sbin/groupadd -g 500 sudoers
/usr/sbin/useradd -p 'xxxxxxxxxx' -g users -s /bin/ksh -G wheel,sudoers -d /home/john -m -u 7000 john
/usr/sbin/useradd -p 'xxxxxxxxx.' -g users -s /bin/ksh -G wheel,sudoers -d /home/doe -m -u 7001 doe
/usr/sbin/useradd -p 'xxxxx' -g users -s /bin/ksh -d /home/ham -m -u 9033 ham
/usr/sbin/useradd -p 'xxxxx' -g users -s /bin/ksh -d /home/sam -m -u 9003 sam
echo "Adding some productivity enhancements for root..."
echo "export HISTSIZE=10000" >> /root/.bash_profile
echo "alias grep='grep --color'" >> /root/.bash_profile

echo "Updating sudoers..."
sed -i -r -e 's/^rh/\# rh/g' $SudoersFile
echo '
%wheel ALL=(ALL) ALL
%sudoers ALL=(ALL) ALL
tomcat2 ALL=(ALL) NOPASSWD:/usr/sbin/lsof' >> $SudoersFile

echo "Updating sshd config..."
sed -i -r -e 's/^\#PermitEmptyPasswords no/PermitEmptyPasswords no/g' -e 's/^GSSAPIAuthentication yes/GSSAPIAuthentication no/g' -e 's/^\#KerberosAuthentication no/KerberosAuthentication no/g' $SSHFile

echo "Updating system auth for account lockout policy..."
sed -i -r -e 's/auth.+required.+pam_env.so/auth required pam_env.so\
auth required pam_tally.so onerr=fail deny=5 even_deny_root_account\
account required pam_tally.so/g' $SysAuthFile

echo "Updating sendmail configuration (setting relay)..."
sed -i -r -e 's/^DS/DSclbsrv.national.aaa.com/g' $SendmailCf

echo "Setting kernel params..."
echo 'fs.file-max = 8192' >> $SysctlFile

echo "Updating hosts file..."
echo '
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6

xxx.xx.xx.xxx abc.dcf.com abc
xxx.xx.xx.xxx ghi.jkl.com ghi

' > $HostsFile

echo "Setting up ntp for the local time server..."
sed -i -r -e 's/^server.+rhel.+/\#server/g' $NTPConfFile
echo 'server 143.61.249.68' >> $NTPConfFile
/sbin/chkconfig --levels 345 ntpd on

echo "Changing ownership of /home/cat "
chown -R root:root /cat
chmod -R 775 /home/cat


1 REPLY 1
Matti_Kurkela
Honored Contributor

Re: Kickstart %post problem

You're using "%post --nochroot".

When you use the --nochroot option, your post-installation script is executed in the installer environment. For example, when you add lines to "/etc/rc.local", they won't be added to the /etc/rc.local of the freshly-installed OS - they will be added to the /etc/rc.local of the _installer environment_ which is located on a RAM-based filesystem and will go away once the system is rebooted.

If you need to use "--nochroot" option, your script must be aware that the entire new OS is located at /mnt/sysimage - i.e. use /mnt/sysimage/etc instead of /etc, and so on.

The use of tools like chkconfig will be much more complicated with the --nochroot option. Instead of

/sbin/chkconfig --levels 345 ntpd on

you must do:

chroot /mnt/sysimage /sbin/chkconfig --levels 345 ntpd on

Otherwise the chkconfig tool will modify the /etc/rc*.d directories of the installation environment, which may fail because the installation environment does not have all the things the real system has. Even if chkconfig is successful, your changes will be lost as the system is rebooted.

As far as I can see, your installation script does not actually require the --nochroot option and seems to be mostly designed to work without it.

So, I recommend that you make two changes:
1.) change the TextFile variable to:

TextFile="/root/ks-install.txt"

2.) change "%post --nochroot" to a simple "%post".

For more information, please see:
https://www.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/5.4/html/Installation_Guide/s1-kickstart2-postinstallconfig.html

MK
MK