At work we normally do all our CentOS builds using Kickstart and our own local mirrors. On top of which I built a couple of custom repositories — one for own own private software, and one for customer boxes (with software such as updated Sendmail, Clam AV, SpamAssassin, etc).
That works very well, and a (reasonably performing) box takes about 5-10 minutes from plugging a flash stick in, to pulling it out and rebooting with a fresh OS install.
But one thing we’ve needed is to build a recovery stick for use on a customer’s site. The default LiveCDs are too bogged down with extraneous crap (like X for a start) to be of any use in the field, while the recovery option on an install CD suffers the opposite problem. I needed to build something that was the best of both worlds — it had to have heaps of tools on there and it had to boot quickly. On top of which we’ve got some custom stuff that would be useful to be able to carry around such as a custom version of gawk that has a lot of modules written by my boss, Don, such as file IO functions (ala libc), cgi, and more.
So I investigated building a flash image that would meet all our worldly desires.
Accessible through CentOS is a LiveCD repo that can be used to build a LiveCD ISO image, which can in turn be written to a flash stick. You could just write the ISO image direct to CD if you like, but then you don’t get the persistent filesystem feature. In other words, you can set up “persistent” space so that any changes you make to the filesystem will be saved.
Doing it’s pretty simple. First add the LiveCD repo so yum can see it. Put this into /etc/yum.repos.d/centos-livecd.repo:
# Name: CentOS LiveCD repository [livecd] name = CentOS $releasever - LiveCD baseurl = http://www.nanotechnologies.qc.ca/propos/linux/centos-live/$basearch/live enabled=1 protect=0 gpgkey = http://www.nanotechnologies.qc.ca/propos/linux/RPM-GPG-KEY-PGuay
Then run
bash# yum install livecd-tools syslinux anaconda-runtime
OK, so now you’ve got all the tools you need on your system. The two we’ll use are livecd-creator and livecd-iso-to-disk. It’s not a complicated process, but the one thing you will put some thought into is creating your kickstart file. Here’s mine:
lang en_US.UTF-8 keyboard us timezone US/Eastern auth --useshadow --enablemd5 selinux --disabled firewall --disabled repo --name=a-base --baseurl=http://foo.nz/centos-5.4-base/i386 repo --name=a-updates --baseurl=http://foo.nz/centos-5.4-updates/i386 #repo --name=a-extras --baseurl=http://mirror.centos.org/centos/5/extras/$basearch repo --name=a-live --baseurl=http://www.nanotechnologies.qc.ca/propos/linux/centos-live/$basearch/live %packages bash kernel syslinux passwd policycoreutils chkconfig authconfig rootfiles comps-extras xkeyboard-config util-linux vim-minimal openssh-clients # extras dhclient bind-utils bzip2 bc lsof man parted pciutils traceroute dmraid dump ftp man-pages mdadm mkbootdisk mlocate mtr nc nfs-utils rsync tcpdump telnet unzip wget time which zip tar # dev stuff autoconf automake binutils gcc gcc-c++ gdb gettext libtool make pkgconfig rpm-build strace elfutils patchutils python perl gawk
This will create a LiveCD of about 180MB and will consume about 6-700MB unpacked in memory.
From there, you create the LiveCD ISO image:
bash# LANG=C livecd-creator --config=centos-livecd-minimal.ks --fslabel=CentOS-minimal
The –config parameter is the filename of the kickstart file you created above, and the –fslabel defines what your ISO image’s filename will be. For example, the one above will deposit a file in your current directory called Centos-minimal.iso.
This step take a frackin’ long time. Or at least it did on the P3 devbox I was running it on. It looks like it’s dead but it’s not. Check top if you’re paranoid. SquishFS takes forever.
After that you want to put a flash stick in a USB hole. Mine had a FAT16 partition on it, and I left it as is. That partition does have to be bootable though.
bash# livecd-iso-to-disk --overlay-size-mb 200 CentOS-minimal.iso /dev/sdb1
That overlay is the size of the “persistent overlay” which defines how much space you’ve got to write to, basically. You can modify any files on the filesystem, or install new stuff or whatever you want. The bigger your memory stick, the bigger you can make this.
After that you’re done. This guy boots up in 30 seconds and leaves me at a fully functional prompt. We can futz with md devices, dmraid devices, roll a new initrd (which my boss has had the pleasure of having to do a few times on shitty Intel Matrix WinRAID shit), dump and restore stuff, ssh to boxes on the network, configure the network manually or via dhcp, it’s got GCC, python, perl, and gawk so we can write scripts onsite, and keep them on the stick.