Creating a custom ISO image in CentOS

1) Create a directory to mount your source.

[root@localhost ~]# mkdir /tmp/bootiso

2) Loop mount the source ISO you are modifying. (Download from Red Hat / CentOS.)

[root@localhost ~]# mount -o loop /path/to/some.iso /tmp/bootiso

3) Create a working directory for your customized media.

[root@localhost ~]# mkdir /tmp/bootisoks

4) Copy the source media to the working directory.

[root@localhost ~]# cp -r /tmp/bootiso/. /tmp/bootisoks/

5) Unmount the source ISO and remove the directory.

[root@localhost ~]# umount /tmp/bootiso && rmdir /tmp/bootiso.

6) Change permissions on the working directory.

[root@localhost ~]# chmod -R u+w /tmp/bootisoks

7) Copy your Kickstart script which has been modified for the packages and %post to the working directory.

[root@localhost ~]# cp /path/to/someks.cfg /tmp/bootisoks/isolinux/ks.cfg

8) Copy any additional RPMs to the directory structure and update the metadata.

[root@localhost ~]# cp /path/to/*.rpm /tmp/bootisoks/Packages/.
[root@localhost ~]# cd /tmp/bootisoks/Packages && createrepo -dpo .. .

9) Create the new ISO file.

[root@localhost ~]# cd /tmp/bootisoks && mkisofs -o /tmp/boot.iso -b isolinux/isolinux.bin -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -R -J -v -T .

Sources:

ServerFault – How to create a custom ISO image in CentOS

Creating a customized RedHat/Fedora Boot CD

 Building a custom CentOS 6 Kickstart Disc

 

Custom ks.cfg: (cdrom:/isolinux/ks.cfg)

install
url --url http://kickstarter.home/centos/6.7/os/x86_64
lang en_US.UTF-8
keyboard us
network --noipv6 --onboot=yes --bootproto dhcp
authconfig --enableshadow --enablemd5
rootpw --iscrypted $6$BN4UlspxSvNaafBP$wEkEbnMie32ROjudhpztln9tRD1P2xE88YJLq/cqPbdTlIADLzaI8ZpLb6aEAVYzXqn7Y/M7wxiLehDUJ/.3r.
firewall --disabled
authconfig --enableshadow --passalgo=sha512
selinux --permissive
timezone --utc America/New_York
#timezone America/New_York
#bootloader --location=mbr --driveorder=vda --append="crashkernel=auto rhgb quiet"
bootloader --location=mbr --driveorder=vda --append="crashkernel=auto rhgb"

# Disk Partitioning
# Don't prompt before overwriting partition table
zerombr
clearpart --all --initlabel --drives=vda
%include /tmp/disk.ks

# END of Disk Partitioning

# Make sure we reboot into the new system when we are finished
reboot

# Package Selection
%packages --nobase --excludedocs
@core
-*firmware
-iscsi*
-fcoe*
-b43-openfwwf
kernel-firmware
-efibootmgr
wget
sudo
perl

%pre
cat > /tmp/disk.ks <<EOF
part /boot --fstype=ext4 --size=200
part pv.01 --grow --size=1
volgroup vg_$(hostname) --pesize=4096 pv.01

logvol / --fstype=ext4 --name=lv_root --vgname=vg_$(hostname) --size=4096
logvol swap --name=lv_swap --vgname=vg_$(hostname) --size=1000
logvol /var --fstype=ext4 --name=lv_var --vgname=vg_$(hostname) --grow --size=1
EOF

%post --log=/root/install-post.log
(
PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH

# PLACE YOUR POST DIRECTIVES HERE
echo "Converting DHCP scope to static IP address"

DEVICE=`route -n|grep '^0.0.0.0'|awk '{print $8}'`
IPADDR=`ifconfig $DEVICE|grep 'inet addr:'|awk '{sub(/addr:/,""); print $2}'`
NETMASK=`ifconfig $DEVICE|grep 'Mask'|awk '{sub(/Mask:/,""); print $4}'`
NETWORK=`ipcalc $IPADDR -n $NETMASK|awk -F= '{print $2}'`
GATEWAY=`route -n|grep '^0.0.0.0'|awk '{print $2}'`
HWADDR=`ifconfig $DEVICE|grep 'HWaddr'|awk '{print $5}'`

cat <<EOF >/etc/sysconfig/network
NETWORKING=yes
HOSTNAME=$HOSTNAME
GATEWAY=$GATEWAY
EOF

cat <<EOF >/etc/sysconfig/network-scripts/ifcfg-$DEVICE
DEVICE=$DEVICE
BOOTPROTO=static
IPADDR=$IPADDR
NETMASK=$NETMASK
ONBOOT=yes
HWADDR=$HWADDR
EOF

echo "Updating YUM Repositories"
cd /etc/yum.repos.d
perl -npe '/mirrorlist=.*repo=os/ && s/^/#/' -i /etc/yum.repos.d/CentOS-Base.repo
perl -npe '/mirrorlist=.*repo=updates/ && s/^/#/' -i /etc/yum.repos.d/CentOS-Base.repo
perl -npe '/^#baseurl=.*\/os\// && s/^#//' -i CentOS-Base.repo
perl -npe '/^#baseurl=.*\/updates\// && s/^#//' -i CentOS-Base.repo
perl -npe '/^baseurl/ && s/mirror.centos.org/kickstarter.home/' -i CentOS-Base.repo
yum -y update
) 2>&1 >/root/install-post-sh.log 

Custom isolinux.cfg (cdrom:/isolinux/isolinux.cfg)

default vesamenu.c32
#prompt 1
timeout 50

display boot.msg

menu background splash.jpg
menu title Welcome to CentOS 6.7!
menu color border 0 #ffffffff #00000000
menu color sel 7 #ffffffff #ff000000
menu color title 0 #ffffffff #00000000
menu color tabmsg 0 #ffffffff #00000000
menu color unsel 0 #ffffffff #00000000
menu color hotsel 0 #ff000000 #ffffffff
menu color hotkey 7 #ffffffff #ff000000
menu color scrollbar 0 #ffffffff #00000000

label linux
  menu label ^Install or upgrade an existing system
  menu default
  kernel vmlinuz
  append initrd=initrd.img ks=cdrom:/ks.cfg
label vesa
  menu label Install system with ^basic video driver
  kernel vmlinuz
  append initrd=initrd.img nomodeset
label rescue
  menu label ^Rescue installed system
  kernel vmlinuz
  append initrd=initrd.img rescue
label local
  menu label Boot from ^local drive
  localboot 0xffff
label memtest86
  menu label ^Memory test
  kernel memtest
  append -

Leave a Reply