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/livecd
    • mkdir $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

  1. rpm --root ${LIVE} --initdb
  2.  
  3. for key in $(rpm -qa gpg-pubkey*) ; do
  4. TMPFILE=`mktemp -t key.XXXXXXXXXX` || exit 1
  5. rpm -qi ${key} > ${TMPFILE}
  6. rpm --root ${LIVE} --import ${TMPFILE}
  7. rm ${TMPFILE}
  8. done

Get the tools for the live cd

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
  • 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"
  • Optional: edit linux-live.sl4/cd-root/isolinux.cfg
    • Find this line timeout 300
    • and change it into timeout 30

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

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=/
  • edit build-livecd.sh
    • alter ramdisk_size=required_size
  • linux-live.sl4/config
    • alter RAM0SIZE=required_size

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.

  1. cd ${LIVE}/tmp
  2. cd live_data_*
  3. cd boot
  4. gunzip initrd.gz
  5. mkdir ird
  6. mount -o loop initrd ird
  7. cd ird
  8. mv ../../base/*.mo .
  9. cd ..
  10. umount ird
  11. gzip initrd
  12. 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:

  1. label centos4live
  2. kernel centos4live/vmlinuz
  3. 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)

Links