Captain's Universe Home
Captain's Universe Home
Cosmic Ray Muon DetectorTeleGarden Pages
Time on MarsBryophyllum Plants
Jupiter Radio AstronomyAncient Pages
Salzburg Tourist GuideEarth Magnetometer
  H O M E     AJAX & MORE     LINUX & MORE     RTAI     XENOMAI     ADEOS IPIPE      
    JAVA & BROWSERS     *NIX     ELECTRONICS     REVIEWS     ARTEMIA     FAIRY SHRIMP      


Linux Boot CD HOWTO - Scripts to create a boot CD from your existing Linux system

Most boot CD tutorials on the web provide templates with existing directory structures, provide their own libraries and binaries. These scripts create a boot CD from your existing Linux system, i.e. uses the binaries and libraries available.


This howto uses isolinux to boot the cd, not like other boot CD's, which use "El Torito". Booting a CD via "El Torito" uses a disk image similar like a floppy image, which will take care of loading and configuring the system and the rest of the CD.
Booting a CD with isolinux is pretty straight forward. Isolinux will load the kernel and the initial ram disk (initrd) - the ramdisk (with linuxrc) will take care of mounting the CDROM and doing further initialization.

The scripts:
  • check.sh will check if all needed binaries and libraries are available on your base system. If something critical is missing, i.e. a library, replace the name of the library with the new name (most likely only the version number will have changed). Don't forget to update the symlink name aswell (if it has changed at all).
  • make.sh will create the directory structure, copy binaries, libraries and configuration files.
  • iso.sh will create the initial ramdisk (initrd), the root filesystem (rootfs) and the ISO CDROM image itself.

BOOT CD CREATION:

This system was developed on Debian Sarge.
  • Download lbcd-0.1.tar.gz (30.3kB) and unpack it
  • Compile your kernel (see below for notes), install it and boot it (if you don't want to install it, just make sure that the kernel "vmlinuz" (=bzImage in i.e. arch/i386/boot) is in the lbcd-0.1 directory and the modules are copied to image/modules/<kernel-version> in make.sh
  • Run check.sh. If there are no CRITICAL messages, chances are good that the ISOimage will boot.
  • Then run make.sh. If there are messages that some /dev/ "files" (i.e. /dev/kbd) can't be copied, DON'T PANIC. Chance are still good that the CD-ROM will boot.
  • Now run "iso.sh". This will create the actual ISO image "bootcd.iso". Burn this image to a CDROM or CD-RW and off the fun goes. Since the schript make.sh simply copies /etc/shadow, just log in with your current machines root password when you boot the CD.
The last part in "make.sh" (cp /home/rtai/adeos1/test2.o root/data) is optional. This is a pre-compiled ADEOS kernel test module. If you don't have an ADEOS patched kernel just remove this line.


NOTES:
The latest verion of isollinux is available at kernel.org. Extract the RPM file with
# rpm2cpio syslinux-3.09-1.i386.rpm > syslinux
# cpio -d -i < syslinux
You find isolinux.bin in [current-directory]/usr/lib/syslinux/isolinux.bin

If you want to add binaries, check their library dependencies with "ldd" and copy those to root/lib. i.e.
# ldd /bin/ls
        librt.so.1 => /lib/librt.so.1 (0x40028000)
        libacl.so.1 => /lib/libacl.so.1 (0x4003a000)
        libc.so.6 => /lib/libc.so.6 (0x40041000)
        libpthread.so.0 => /lib/libpthread.so.0 (0x40175000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
        libattr.so.1 => /lib/libattr.so.1 (0x401c6000)

Most likely you need to compile your own kernel to use these scripts. Some stuff is usually compiled as module in normal distribution kernels, which needs to be compiled into the kernel - otherwise the CD does not boot. These options are for kernel 2.4.x:

♦ Support for Unix domain sockets: (CONFIG_UNIX=y) (otherwise: can't locate module net-pf-1)
Networking options  --->
	<*> Unix domain sockets
♦ RAM disk and initrd support:
Block devices  --->
	<*> RAM disk support
	[...]
	[*]   Initial RAM disk (initrd) support
♦ IDE and CDROM support:
ATA/IDE/MFM/RLL support  ---> [*] ATA/IDE/MFM/RLL support
                              IDE, ATA and ATAPI Block devices  --->
                                       <*> Enhanced IDE/MFM/RLL disk/cdrom/tape/floppy support 
                                       <*>   Include IDE/ATA-2 DISK support
                                       [...]
                                       <*>   Include IDE/ATAPI CDROM support
♦ ext3 and ISO9660 filesystem support:
File systems  --->
	<*> Ext3 journalling file system support 
	[...]
	<*> ISO 9660 CDROM file system support
	[*]   Microsoft Joliet CDROM extensions
	[*]   Transparent decompression extension


Troubleshooting:
If you see something like this
kmod: failed to exec /sbin/modprobe -s -k iso9660, errno = 2
[FAIL]
cramfs: wrong magic
Kernel panic: VFS: Unable to mount root fs on 01:01
you did not compile in some needed stuff into the kernel, in this case iso9660 file system support.
Another possibility to avoid this sort of error is to add the missing kernel modules, modprobe (+libraries) to the initial ramdisk (initrd). But since I used this boot CD for some ADEOS real time testing (i.e. data logging), I had to compile my own kernel anyway, so making the system more flexible for generic kernels is left to you as exercise.

check.sh (checks for needed files)
#!/bin/sh

# LINUX BOOT CD BUILD SCRIPTS (C) 2005 www.captain.at
# This script checks if all needed binaries and libraries are available
# WARNINGs are non-critical, CRITICALs are, well, critical, which mean that
#   the boot CD might not work as expected

# check for non-critical programs
for prg in "basename" "cat" "chgrp" "chmod" "chown" "chroot" "chvt" \
"clear" "cmp" "cp" "cut" "date" "dd" "df" "dirname" "dmesg" "du" \
"env" "false" "fbset" "find" "free" "freeramdisk" "grep" "gunzip" "gzip" \
"head" "ifconfig" "kill" "killall" "ln" "ls" "mkdir" "mknod" "more" \
"mv" "ps" "pwd" "reboot" "rm" "rmdir" "shutdown" "sleep" "stty" \
"sync" "syslogd" "tail" "tar" "tee" "test" "touch" "tr" "true" \
"tty" "uname" "uptime" "yes" "zcat"
do
let "I=0"
for dir in "bin" "sbin" "usr/bin" "usr/sbin"
do
if [ -e /$dir/$prg ]; then
let "I=1"
fi
done
if [ $I -eq 0 ]; then
echo "WARNING: $prg not found"
fi 
done

# check for critical programs (needed to boot properly)
for prg in "echo" "mount" "umount" "sh" "bash" "sulogin"
do
let "I=0"
for dir in "bin" "sbin" "usr/bin" "usr/sbin"
do
if [ -e /$dir/$prg ]; then
let "I=1"
fi
done
if [ $I -eq 0 ]; then
echo "CRITICAL: $prg not found"
fi 
done

# check for /sbin/init (needed to boot properly)
if [ ! -e /sbin/init ]; then
echo "CRITICAL: /sbin/init not found"
fi

for prg in "insmod" "lsmod" "rmmod" "modprobe"
do
if [ ! -e /sbin/$prg ]; then
echo "CRITICAL: /sbin/$prg not found"
fi
done

# check for essential /etc files
if [ ! -e /etc/passwd ]; then
echo "CRITICAL: /etc/passwd not found"
fi
if [ ! -e /etc/shadow ]; then
echo "CRITICAL: /etc/shadow not found"
fi
if [ ! -e /etc/services ]; then
echo "CRITICAL: /etc/services not found"
fi
if [ ! -e /etc/nsswitch.conf ]; then
echo "CRITICAL: /etc/nsswitch.conf not found"
fi

if [ ! -e /etc/terminfo/l/linux ]; then
echo "CRITICAL: /etc/terminfo/l/linux not found"
fi

# check for essential libraries
libarray=(ld-2.3.2.so libc-2.3.2.so libcrypt-2.3.2.so libdl-2.3.2.so \
libm-2.3.2.so libncurses.so.5.4 librt-2.3.2.so libacl.so.1.1.0 \
libpthread-0.10.so libattr.so.1.1.0)

for I in $(seq 0 $((${#libarray[@]} - 1)))
do
if [ ! -e /lib/${libarray[$I]} ]; then
echo "CRITICAL: /lib/${libarray[$I]} not found"
fi
done

if [ ! -e /usr/lib/libtermcap.so ]; then
echo "CRITICAL: /usr/lib/libtermcap.so not found"
fi
if [ ! -e /lib/libproc.so.3.2.1 ]; then
echo "CRITICAL: /lib/libproc.so.3.2.1 not found"
fi

make.sh
#!/bin/sh

# LINUX BOOT CD BUILD SCRIPTS (C) 2005 www.captain.at
# This script creates all needed directories and copies files for
# the initial ramdisk (initrd), the cd-image and the root filesystem.

rm -R -f image
rm -R -f initrd
rm -R -f root

################
# BUILD INITRD #
################

for dir in "initrd" "initrd/bin" "initrd/cdrom" "initrd/dev" \
"initrd/dev/pts" "initrd/etc" "initrd/proc" "initrd/ram"
do
mkdir $dir
done

# create devices
cd initrd/dev
for dev in "/dev/agpgart" "/dev/console" "/dev/fb*" "/dev/fd0" \
"/dev/hda" "/dev/hdb" "/dev/hdc" "/dev/hdd" "/dev/kbd" "/dev/md0" \
"/dev/mem" "/dev/null" "/dev/psaux" "/dev/ptmx" "/dev/pts" "/dev/ptyp0" \
"/dev/ram0" "/dev/ram1" "/dev/ram2" "/dev/ram3" "/dev/tty0" "/dev/tty1" \
"/dev/ttyp0" "/dev/ttyS*" "/dev/zero"
do
cp -ap $dev .
done
cd ../../

ln -s /proc/mounts initrd/etc/mtab
cp resources/linuxrc initrd
cp resources/linuxrc.c initrd

############################
# BUILD CD-IMAGE DIRECTORY #
############################

for dir in "image" "image/config" "image/isolinux" "image/modules" "image/usr"
do
mkdir $dir
done

cp resources/isolinux.bin image/isolinux
cp resources/isolinux.cfg image/isolinux

# copy kernel and modules
KERNELVERSION=`uname -r`
##cp "/boot/vmlinuz-$KERNELVERSION" image/isolinux/vmlinuz
cp vmlinuz image/isolinux/vmlinuz
# set kernel root device (otherwise it boots from i.e. /dev/hda1)
rdev image/isolinux/vmlinuz /dev/ram1
# copy kernel modules (will be in /cdrom/modules when cdrom is mounted)
cp -R "/lib/modules/$KERNELVERSION" image/modules

#################
# BUILD ROOT-FS #
#################

mkdir root
mkdir root/bin

# copy tools - this is a basic selection (there might be some libraries missing)
cd root/bin
for prg in "basename" "bash" "cat" "chgrp" "chmod" "chown" "chroot" "chvt" \
"clear" "cmp" "cp" "cut" "date" "dd" "df" "dirname" "dmesg" "du" "echo" \
"env" "false" "fbset" "find" "free" "freeramdisk" "grep" "gunzip" "gzip" \
"head" "ifconfig" "kill" "killall" "ln" "ls" "mkdir" "mknod" "more" "mount" \
"mv" "ps" "pwd" "reboot" "rm" "rmdir" "sh" "shutdown" "sleep" "stty" \
"sulogin" "sync" "syslogd" "tail" "tar" "tee" "test" "touch" "tr" "true" \
"tty" "umount" "uname" "uptime" "yes" "zcat"
do
for dir in "bin" "sbin" "usr/bin" "usr/sbin"
do
if [ -e /$dir/$prg ]; then
cp /$dir/$prg .
fi
done
done
cd ../../

mkdir root/sbin
# copy unix init
cp /sbin/init root/sbin
# copy kernel tools
for prg in "insmod" "lsmod" "rmmod" "modprobe"
do
cp /sbin/$prg* root/sbin
done

mkdir root/cdrom
mkdir root/dev
mkdir root/dev/pts

#create devices
cd root/dev
for dev in "/dev/agpgart" "/dev/console" "/dev/fb*" "/dev/fd0" "/dev/hd*" \
"/dev/kbd" "/dev/md0" "/dev/mem" "/dev/null" "/dev/psaux" "/dev/ptmx" \
"/dev/ptyp*" "/dev/pts" "/dev/ptyp0" "/dev/ram0" "/dev/ram1" "/dev/ram2" \
"/dev/ram3" "/dev/tty*" "/dev/ttyp*" "/dev/ttyS*" "/dev/zero"
do
cp -ap $dev .
done
cd ../../

mkdir root/etc
# copy fstab
cp resources/fstab root/etc
# copy inittab
cp resources/inittab root/etc

# config file for ldconfig
# ld.so.conf lists paths to additional library directories i.e. /usr/X11R6/lib
echo "" > root/etc/ld.so.conf

# create mounttab
ln -s /proc/mounts root/etc/mtab

# login of root user via sulogin -> we need passwd, shadow etc...
cp /etc/passwd root/etc
cp /etc/shadow root/etc
cp /etc/services root/etc
cp /etc/nsswitch.conf root/etc

# copy shell profile (executed after sulogin)
cp resources/profile root/etc

# copy terminfo data
mkdir root/etc/terminfo
mkdir root/etc/terminfo/l
cp /etc/terminfo/l/linux root/etc/terminfo/l

# rc.S for system init
mkdir root/etc/rc.d
cp resources/rc.S root/etc/rc.d
chmod +x root/etc/rc.d/rc.S

mkdir root/initrd

# copy libraries
mkdir root/lib
cd root/lib

# if you add a library, you need to add a symlink aswell
# if the library you want to add does no require a symlink, just copy
#    it below
libarray=(ld-2.3.2.so libc-2.3.2.so libcrypt-2.3.2.so libdl-2.3.2.so \
libm-2.3.2.so libncurses.so.5.4 librt-2.3.2.so libacl.so.1.1.0 \
libpthread-0.10.so libattr.so.1.1.0)

symlinkarray=(ld-linux.so.2 libc.so.6 libcrypt.so.1 libdl.so.2 \
libm.so.6 libncurses.so.5 librt.so.1 libacl.so.1 \
libpthread.so.0 libattr.so.1)

for I in $(seq 0 $((${#libarray[@]} - 1)))
do
cp /lib/${libarray[$I]} .
ln -s ${libarray[$I]} ${symlinkarray[$I]}
done

# copy libraries without symlinking
cp /usr/lib/libtermcap.so .
cp /lib/libproc.so.3.2.1 .
# make a symlink for the kernel modules - those are stored on the CD,
#   so we save ramdisk space
ln -s /cdrom/modules modules
cd ../../

# create various directories
for dir in "root/mnt" "root/proc" "root/tmp" "root/var" "root/var/adm" \
"root/var/lock" "root/var/run"
do
mkdir $dir
done

ln -s root/tmp root/var/tmp
ln -s /cdrom/usr root/usr

# additonal stuff
mkdir root/data
cp /home/rtai/adeos1/test2.o root/data
iso.sh
#!/bin/sh

# LINUX BOOT CD BUILD SCRIPTS (C) 2005 www.captain.at
# This script creates and gzips the initial ramdisk, root filesystem
# the the ISO image itself

# define some stuff
IMAGENAME=bootcd.iso
LOOPDIR=/mnt/loop
LOOPDEV=/dev/loop1
ROOTFS=image/rootfs
INITRD=image/isolinux/initrd
IMAGEDIR=image
INITRDDIR=initrd
ROOTDIR=root

# make sure we have loopback device support form the kernel
modprobe loop
# check if LOOPDIR exists and is a directory
# if not, create the LOOPDIR directory
[ ! -d $LOOPDIR ] && mkdir -p $LOOPDIR

#####################
# build the INIT RD #
#####################

# create a file with zeros of 4096 1k blocks
dd if=/dev/zero of=$INITRD bs=1k count=4096

# loopback that file to the loop-device
losetup $LOOPDEV $INITRD

# now make a filesystem in the file
mkfs -t ext3 -m 0 $LOOPDEV

# the file now behaves like a i.e. harddisk, so we can mount it
mount $LOOPDEV $LOOPDIR

# pack all files in INITRDDIR and unpack in LOOPDIR
cd $INITRDDIR
tar cf - . | (cd $LOOPDIR ; tar xf - )
cd ..

# unmount file, release loop-device and gzip it
umount $LOOPDIR
losetup -d $LOOPDEV
echo "GZIPPING INITRD..."
gzip -f $INITRD
echo "****** INITIAL RAMDISK (INITRD) READY ******"

#############################
# build the ROOT filesystem #
#############################
# for comments, see above
dd if=/dev/zero of=$ROOTFS bs=1k count=16384
losetup $LOOPDEV $ROOTFS
mkfs -t ext3 -m 0 $LOOPDEV
mount $LOOPDEV $LOOPDIR
cd $ROOTDIR
tar cf - . | (cd $LOOPDIR ; tar xf - )
cd ..
umount $LOOPDIR
losetup -d $LOOPDEV
echo "GZIPPING ROOTFS..."
gzip -f $ROOTFS
echo "****** ROOT FS READY ******"

#######################
# build the ISO image #
#######################
# create the iso image with isolinux as loader.
# The catalogue file will be written into boot.cat.
mkisofs -o $IMAGENAME -b isolinux/isolinux.bin -c isolinux/boot.cat \
 -no-emul-boot -boot-load-size 4 -boot-info-table -l -R -r $IMAGEDIR
echo "****** ISO IMAGE READY ******"
Last-Modified: Sat, 04 Feb 2006 16:03:08 GMT

Google
 
Web www.captain.at
go to top
© 1996-2010 . All rights reserved.
No reproduction, distribution, publishing or transmission of the copyrighted materials at this site is permitted. Policy
go to top