Custom CentOS Live CD

December 12, 2012
centos livecd tutorial

This is a tutorial on creating a custom CentOS live CD. A custom live CD can be useful for many different purposes. I will just cover my specific use case in the post below, but you should be able to follow along and customize where you see fit. If you follow this post as is, you will end up with a CentOS 6.2 live ISO which is configured with a static IP and a ramdisk being presented over NFS at startup.

Download and extract

The first step is to download the CentOS Live CD ISO.

mkdir /iso
cd /iso
wget <url for centos live ISO>

Mount the CentOS ISO and copy the contents to a temporary location.

mount CentOS-6.2-x86_64-LiveCD.iso mnt -o loop
mkdir CentOS-6.2-x86_64-LiveCD
cp -arp mnt/* CentOS-6.2-x86_64-LiveCD/
umount mnt

Make customizations

Create a new isolinux.cfg file in the current directory. This menu will be displayed when booting the custom CentOS Live CD.

##########
UI vesamenu.c32
MENU TITLE Custom CentOS
TIMEOUT 50

DEFAULT centos
LABEL centos
KERNEL vmlinuz0
APPEND initrd=initrd0.img root=live:CDLABEL=CentOS-6.2-x86_64-LiveCD rootfstype=auto ro liveimg 3 quiet nodiskmount nolvmmount  rhgb vga=791 rd.luks=0 rd.md=0 rd.dm=0 selinux=0
##########

Overwrite isolinux.cfg file in temporary location.

cp isolinux.cfg CentOS-6.2-x86_64-LiveCD/isolinux/

Mount squashfs and copy off all contents to temporary location.

mount CentOS-6.2-x86_64-LiveCD/LiveOS/squashfs.img mnt -o loop -t squashfs
mkdir squashfs
cp -a mnt/* squashfs
umount mnt

Mount the ext3fs filesystem from the extracted squashfs.

mkdir ext3fs
mount squashfs/LiveOS/ext3fs.img ext3fs -o loop

Edit file ext3fs/etc/rc.local to change boot settings for the custom ISO to your liking. In this case I am configuring networking, creating a ramdisk, and presenting it over NFS.

touch /var/lock/subsys/local
/sbin/ifconfig eth0 192.168.100.100 netmask 255.255.255.0 up
/bin/mkdir /ramdisk
/bin/mount -o size=10G -t tmpfs tmpfs /ramdisk
/bin/echo '/ramdisk *(rw,sync,insecure,fsid=1,all_squash,sync,no_wdelay)'>/etc/exports
/sbin/service nfs restart

Chroot into mounted ext3fs filesystem and make any required modifications. In this case, I am updating root password, disabling firewall, and enabling sshd.

chroot /iso/ext3fs/
passwd root <password>
chkconfig NetworkManager off
chkconfig iptables off
chkconfig ip6tables off
chkconfig sshd on
exit

Generate a new ISO

Regenerate squashfs with updates and create a new ISO (Custom-CentOS.iso).

rm /iso/CentOS-6.2-x86_64-LiveCD/LiveOS/squashfs.img
mksquashfs /iso/squashfs /iso/CentOS-6.2-x86_64-LiveCD/LiveOS/squashfs.img
mkisofs -o Custom-CentOS.iso \
              -J -r -hide-rr-moved -hide-joliet-trans-tbl -V CentOS-6.2-x86_64-LiveCD \
              -b isolinux/isolinux.bin -c isolinux/boot.cat \
              -no-emul-boot -boot-load-size 4 -boot-info-table \
              /iso/CentOS-6.2-x86_64-LiveCD