CentOS Live
From ByteWiki
Contents |
How to make a CentOS 4 Live CD
Introduction
If you don't want any custom features you can just use the official CentOS 4 Live CD, but if you want to add custom software, this procedure will show you how to build a minimal live CD and then add your own software. This procedure was written for use on a CentOS-4 box but anything with yum 2.4 should work.
You will need root access for many of these steps (for chroot and mount) but it is designed to not impact your main install. (ie. the build is contained to a single sub directory).
This procedure uses scripts modified for the CentOS live CD. From what I can tell, those scripts came from Scientific Linux. Parts of those scripts were taken from http://www.linux-live.org/. Thankyou to all the people who have put work into these scripts. These instructions don't attempt to explain how and why the scripts work, it provides a quick start for people who want quick results.
Procedure
Prepare a chroot environment
- Start with a working CentOS-4 box. You will need a working yum setup
- You will have to disable SElinux (setenforce 0)
- make a new directory to build in
LIVE=/tmp/livecdmkdir $LIVE
- make some subdirectories
-
cd $LIVE -
mkdir dev proc sys etc tmp
-
- mount some virtual filesystems, if you reboot you will have to redo this step
-
mount --bind /dev dev -
mount null -t proc proc -
mount null -t sysfs sys
-
- Copy your existing yum.conf into the new etc directory
-
cp /etc/yum.conf $LIVE/etc
-
- Yum might require an initial redhat-release file to get the ball rolling.
-
cp /etc/redhat-release $LIVE/etc
-
-
edit the copied yum.conf and set gpgcheck=0 (because your chroot does not have keys installed yet. You can change this back later)See Installing Keys below - Install the system with yum like this:
-
yum -c $LIVE/etc/yum.conf --installroot=$LIVE install yum rootfiles bind-utils gnupg vim-enhanced vixie-cron crontabs passwd which kudzu dhclient pciutils eject alsa-utils mkisofs wget - This should install around 115 packages for a total of 90 Meg or so. You could use this next command for a more complete starting point, but some people think that this installs too much
-
yum -c $LIVE/etc/yum.conf --installroot=$LIVE groupinstall base - You will have to play around until you find what you need. It does depend on what you will be doing. You can easily add things later
-
- copy resolv.conf to the chroot (so yum will work in the chroot)
-
cp /etc/resolv.conf $LIVE/etc
-
- copy your networking config file
- cp /etc/sysconfig/network etc/sysconfig
- Edit the new shell prompt so you don't get lost when you enter the chroot
-
echo 'if [ ! -d /proc/1/root ] ; then PS1="[\u@LIVE \W]\\$ " ; fi' >> $LIVE/root/.bashrc
-
- chroot into the new image
-
chroot $LIVE
-
Installing GPG Keys
This script will copy your keys from your real rpm database into the livecd database
rpm --root ${LIVE} --initdb for key in $(rpm -qa gpg-pubkey*) ; do TMPFILE=`mktemp -t key.XXXXXXXXXX` || exit 1 rpm -qi ${key} > ${TMPFILE} rpm --root ${LIVE} --import ${TMPFILE} rm ${TMPFILE} done
Get the tools for the live cd
- Download the kernel from http://mirror.centos.org/centos-4/4.3/build/livecd/RPMS/kernel-2.6.9-34.19.EL.livecd.2.i686.rpm
- Install the kernel (inside the chroot)
-
rpm -i http://mirror.centos.org/centos-4/4.3/build/livecd/RPMS/kernel-2.6.9-34.19.EL.livecd.2.i686.rpm --oldpackage
-
- Optional: uninstall the old kernel to save space.
-
rpm --erase kernel-2.6.9-34.0.1.EL
-
- download http://mirror.centos.org/centos-4/4.3/build/livecd/livecd-0.9.1.tgz
-
wget http://mirror.centos.org/centos-4/4.3/build/livecd/livecd-0.9.1.tgz -O livecd-CentOS-0.9.1.tgz
-
- extract livecd-CentOS-0.9.1.tgz into /root (the chroot root user home directory)
-
tar -zxvf livecd-CentOS-0.9.1.tgz
-
- Change into the livecd directory
-
cd livecd-0.9.1
-
Prepare the scripts
WARNING: do not run any of the scripts on your real machine! Only run them inside the chroot
- edit linux-live.sl4/config and set KERNEL=2.6.9-34.19.EL.livecd.2
-
echo 'KERNEL=2.6.9-34.19.EL.livecd.2' >> linux-live.sl4/config
-
- disable the restore-system script because you don't need it in the chroot
-
chmod a-x restore-system.sh
-
- edit the customize-livecd.sh script to fix a few things
- Find this line
depmod -a - and change it into
( . linux-live.sl4/config ; depmod -a -v $KERNEL ) - Find this line
ln -fs /boot/vmlinuz-$( uname -r ) /boot/vmlinuz - and change it into
( . linux-live.sl4/config ; ln -fs /boot/vmlinuz-$KERNEL /boot/vmlinuz ) - Fint this line
sed -i 's/id:3:initdefault:/id:5:initdefault:/' /etc/inittab - and change it into
sed -i 's/id:5:initdefault:/id:3:initdefault:/' /etc/inittab - There are lots of other things done which are not always needed. Edit as required. You can come back and tweak things later
- Find this line
- Optional: edit build-livecd.sh
- Find this line
BOOT_OTPIONS=(yes, it is spelt wrong in the file) - And add new on the next line
BOOT_OTPIONS="nopasswd kb=1 $BOOT_OTPIONS"
- Find this line
- Optional: edit linux-live.sl4/cd-root/isolinux.cfg
- Find this line
timeout 300 - and change it into
timeout 30
- Find this line
Build the cd
- run build-livecd.sh
- !! WARNING: Do not run this script on a real machine! Only run it in the chroot environment!!
-
./build-livecd.sh -sl - Expect some errors. All going well you will get to
creating compressed images...which will take some time, particularly usr.mo - You should then get to Your ISO is created in /tmp/livecd.iso
Testing
I highly recommend that you use VMWare Server to test the CD. Grab the RPM version for linux. Sure, the RPM is not well packaged but it is at least a start.
If things are not exactly how you like them, try some of these:
- Install packages using yum / rpm
- Edit customize-livecd.sh to control which init scripts will be run
- no network? did you copy /etc/sysconfig/network?
One script to build them all
- All the steps to build a live cd http://uranus.it.swin.edu.au/~jn/linux/centos4live/livecd.sh
- the patch file to make life easy http://uranus.it.swin.edu.au/~jn/linux/centos4live/customize.diff
- Extra steps to make PXE initrd http://uranus.it.swin.edu.au/~jn/linux/centos4live/livecd-pxe.sh
PXE booting your live CD
This will works more or less like the procedure from Gentoo_live
- edit linux-live.sl4/initrd/linuxrc
- find
DATA=... - change to
DATA=/
- find
- edit build-livecd.sh
- alter
ramdisk_size=required_size
- alter
- linux-live.sl4/config
- alter
RAM0SIZE=required_size
- alter
The required_size depends on how much you have in your image, I don't know what the maximum it but I have been using 128000 (128Meg) which works. You can reduce it later but you must leave about 5% free which is needed at boot time.
Build the CD like normal. This CD will not work at this stage. That is OK because we are not interested in the .iso. Once you complete the next step you can rebuild the .iso with ./make_iso.sh ../livecd.iso but that will load the contents into memory which is probably not required from CD. You might be able to remove the CD though???
Move the .mo files into the initrd.
cd ${LIVE}/tmp cd live_data_* cd boot gunzip initrd.gz mkdir ird mount -o loop initrd ird cd ird mv ../../base/*.mo . cd .. umount ird gzip initrd cd ..
If you run out of space in the initrd then you need to increase RAM0SIZE
Once you have doen this, you will have 2 files
- boot/vmlinuz (the kernel)
- boot/initrd.gz (the large initrd)
You can now PXE boot these files like this:
label centos4live kernel centos4live/vmlinuz append initrd=centos4live/initrd.gz nopasswd kb=1 max_loop=32 init=linuxrc load_ramdisk=1 prompt_ramdisk=0 ramdisk_size=''required_size'' root=/dev/ram0 rw
Remember to replace required_size with it's value from above (larger is OK, too small and you will get errors).
And thats all there is too it.
Trimming the fat
When PXE booting, the entire image needs to be transfered over the network using tftp and then loaded into memory. You want to reduce the size of your image to speed things up. Some things that can be easily trimmed:
- lib/modules/everything except 2.6.9-34.19.EL.livecd.2
- usr/share/locale
- usr/lib/locale
- usr/lib/perl5 (unless you want perl)
- usr/lib/python2.3 (needed by yum and some RH tools)
