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:
ks=cdrom:/ks.cfg

mkisofs -T -o /build/custom/centos62custom.iso -b /build/iso/isolinux/isolinux.bin -c /build/iso/isolinux/boot.cat -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'
v=verbose
p=pretty

Make the .repo file so you can use the repository
#cat > /etc/yum.repos.d/local.repo << EOF
>[local]
>name=local repo for centos6.2
>baseurl=file:///var/www/html/yum/centos/6.2
>gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
>gpgcheck=1
>enabled=1
>EOF

#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 10.1.1.0 netmask 255.255.255.0 {
range 10.1.1.50 10.1.1.75;
next-server 10.1.1.150;  #This is your kickstart server IP
filename="pxelinux.0";

#chkconfig dhcpd on ; service dhcpd start
#iptables -I INPUT -p tcp -m multiport --ports 67,68 -s 10.1.1.0/24 -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 10.1.1.0/24 -j ACCEPT
#service iptables save
#chkconfig xinetd on ; service xinetd start


Make the pxe menu
#cat > /tftpboot/pxelinux.cfg/default << EOF
>DEFAULT vesamenu.c32
>TIMEOUT 60
>PROMPT 0
>LABEL centos cluster
>  MENU LABEL centos cluster
>    KERNEL vmlinuz
>    APPEND ks=http://10.1.1.150/kick/ks.cfg initrd=initrd.img
>EOF

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.

#version=DEVEL
install
url --url http://10.1.1.150/install   #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
zerombr
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

%packages
@base
@client-mgmt-tools
@console-internet
@core
@debugging
@basic-desktop
@desktop-platform
@directory-client
@general-desktop
@hardware-monitoring
@java-platform
@large-systems
@network-file-system-client
@performance
@perl-runtime
@server-platform
@server-policy
@x11
yum-plugin-downloadonly
mtools
pax
oddjob
sgpio
genisoimage
wodim
certmonger
pam_krb5
krb5-workstation
perl-DBD-SQLite
%end

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 www.example.com:80
ServerName kick.lab.local:80

#iptables -I INPUT -p tcp --dport 80 -s 10.1.1.0/24 -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.