Saturday, June 15, 2013

Create custom CentOS ISO

Sometimes the need arises to make your own customized bootable DVD for server installations.  This process is actually really easy.

Take DVD1 of whatever distribution your using (RHEL/CentOS). In this example I am using CentOS 6.2 64 bit.

mount -o loop CentOS-6.2-x86_64-bin-DVD1.iso /mnt/1

mkdir -p /build/iso /build/custom

cp -arv /mnt/1/.* /builder/iso

Create your custom kickstart file (ks.cfg) and put it in /builder/iso/isolinux

vim /build/iso/isolinux/isolinux.cfg
add the following line to the append line:

mkisofs -T -o /build/custom/centos62custom.iso -b /build/iso/isolinux/isolinux.bin -c /build/iso/isolinux/ -no-emul-boot -boot-load-size 4 \
-boot-info-table -R -m /build/iso/TRANS.TBL .

The (.) at the end is important, otherwise the command will fail.

Test it out!

Sunday, March 31, 2013

Kickstart - centOS-6.2

This is a "how-to" on creating a kickstart server.  The local YUM repo isn't necessary but if you don't have internet access or if you're using RHEL without a subscription it's nice to have one available.

This should be enough to get you going. You can do as much (or as little) as you'd like with Kickstart. 

Local YUM repository (if you have direct internet access you don't have to do this):
Required Packages: createrepo deltarpm python-deltarpm
#cd /media/Packages ; rpm -ivh deltarpm.vers.rpm python-deltarpm.vers.rpm creatrepo.vers.rpm
#mkdir -p /var/www/html/yum/centos/6.2

Copy the Packages directory from the installation media into the newly created directory:
#cp -arv /media/Packages/* /var/www/html/yum/centos/6.2
#cp /media/repodata/3a27232698a261aa4022fd270797a3006aa8b8a346cbd6a31fae1466c724d098-c6-x86_64-comps.xml /var/www/html/yum/centos/6.2/

#createrepo -g  /var/www/html/yum/centos/6.2/3a27232698a261aa4022fd270797a3006aa8b8a346cbd6a31fae1466c724d098-c6-x86_64-comps.xml -vp /var/www/html/yum/centos/6.2

createrepo Switches:
g=group file - so you can use ' yum grouplist'

Make the .repo file so you can use the repository
#cat > /etc/yum.repos.d/local.repo << EOF
>name=local repo for centos6.2

#yum repolist

Install DHCP server
Required packages: dhcp
#yum -y install dhcp
#vim /etc/dhcp/dhcpd.conf

####Global Settings #####
ddns-update-style interim;
allow booting;
allow bootp;
default-lease-time 84600;
max-lease-time 84600;

subnet netmask {
next-server;  #This is your kickstart server IP

#chkconfig dhcpd on ; service dhcpd start
#iptables -I INPUT -p tcp -m multiport --ports 67,68 -s -j ACCEPT
#service iptables save

Setup TFTP and PXE
Required Packages: tftp-server syslinux 
#yum -y install tftp-server syslinux
NOTE: The default location for tftpboot is '/var/lib/tftpboot' but I always change it:
#mkdir -p /tftpboot/pxelinux.cfg
#mkdir -p /kickstart/conf.d /kickstart/media/centos/6.2

Copy the install media from the disc to the install directory:
#cp -arv /media/* /kickstart/media/centos/6.2/

Populate the /tftpboot directory with the files it needs:
#cp /usr/share/syslinux/{pxelinux.0,vesamenu.c32} /tftpboot
#cp /kickstart/media/centos/6.2/isolinux/{initrd.img,vmlinuz} /tftpboot

Set file contexts for SELinux
#semanage fcontext -a -t cobbler_var_lib_t "/tftpboot(/.*)?" 
#restorecon -FRvv /tftpboot

Edit the TFTP conf file:
#vim /etc/xinetd.d/tftp
service tftp
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /tftpboot
        disable                 = no
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4

#iptables -I INPUT -p udp --dport 69 -s -j ACCEPT
#service iptables save
#chkconfig xinetd on ; service xinetd start

Make the pxe menu
#cat > /tftpboot/pxelinux.cfg/default << EOF
>DEFAULT vesamenu.c32
>LABEL centos cluster
>  MENU LABEL centos cluster
>    KERNEL vmlinuz
>    APPEND ks= initrd=initrd.img

Create the kickstart file
Optional Packages: system-config-kickstart
NOTE: You can either edit the anaconda-ks.cfg in /root or use system-config-kickstart. Save the file in /kickstart/conf.d

#cp /root/anacond-ks.cfg /kickstart/conf.d/ks.cfg

# Kickstart file automatically generated by anaconda.

url --url   #path to install media for web install
text    #text-only installation
firstboot --disable   #disables firstboot setup
lang en_US.UTF-8
keyboard us
network --onboot yes --device eth0 --bootproto dhcp
rootpw  --iscrypted your encrypted password
reboot   #Reboots machine when install is finished
firewall --service=ssh
authconfig --enableshadow --passalgo=sha512
selinux --enforcing
timezone --utc America/Chicago
bootloader --location=mbr --driveorder=sda --append=" rhgb crashkernel=auto 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
#I like to use LVM's for flexibility#
part /boot --fstype=ext4 --size=200
part swap --size=500
part pv.03 --grow --size=200
volgroup vgsrv --pesize=4096 pv.03
logvol / --fstype=ext4 --name=vol_root --vgname=vgsrv --size=10240

#repo --name="CentOS"  --baseurl=cdrom:sr0 --cost=100


Setup the web directory for web installations:
I use symbolic links back to the required directories:
#cd /var/www/html
Media: #ln -Ts /kickstart/media/centos/6.2 install
Conf File: #ln -Ts /kickstart/conf.d/ kick

#vim /etc/httpd/conf/httpd.conf
Change the following:
ServerName kick.lab.local:80

#iptables -I INPUT -p tcp --dport 80 -s -j ACCEPT
#service iptables save
#chkconfig httpd on ; service httpd start

You should now be able to provision a centOS machine now.  Let me know if something's not working.