Build a Debain based live cd

Jump to: navigation, search

This HOWTO aim at building a selfmade live cd

In which case is this a good idea

If remastering of live cds isn't freaky enough, than why not building your own live cd?


Since we start with the debain base system we need the debain netinstall iso:

download debian-testing-i386-netinst.iso

Later we will use sqashfs and unionfs. To install the Debain base system there are many possibilities. The easiest way to perform it with our needs is to install it within a qemu i386 emulated system or whatever the live cd is aimed to run later ;). Okay, install Qemu and prepare an image:

qemu-img create debian-live.img 1G

1 GByte should be quite enough for a first try. Then start the installation system with:

qemu -hda debian-live.img -cdrom debian-testing-i386-netinst.iso -boot d -m 256

Select your Hostname, format the whole disk, install grub as your boot manager at the MBR. At the packet selection choose nothing, you can select your favourite packages later.

install xen-tools e.g.:

smart install xen-tools

Then lomount your fresh Debain Etch with:

mkdir source
lomount -t ext3 -diskimage debian-live.img -partition 1 source/

After that it is useful to copy or pack the Debain base installation:

tar cfvj blind-base-system.tar.bz2 source/

From this point on there are two possibiliteis to go on a safe and easy way and a fast one ;) The easy way is to boot with qemu and perform the next steps or to chroot in th source directory.

I'll explain the fast one of course:

chroot source/
export LC_ALL
mount -t proc /proc proc

Now you can install the packages you like on the life cd

apt-get install myfavouritepackages


apt-get install zlib1g-dev x-window-system fluxbox xdebconfigurator \
bzip2 discover libncurses-dev cdrecord mkisofs \
qemu rox-filer mozilla-firefox mozilla-firefox-locale-de-de \
read-edid mdetect xdebconfigurator hwinfo xresprobe alsa-base

Then install and configure your kernel (kernel is the because it is works with unionfs):

cd /usr/src
tar xfvj linux-
ln -s /usr/src/linux- linux
cd linux
make menuconfig
tar xfvz squashfs3.1-r2.tar.gz
patch -p1 < squashfs3.1-r2/linux-
cd squashfs3.1-r2/squashfs-tools/
cp mksquashfs /usr/sbin
cd /usr/src/linux
make menuconfig
make bzImage modules modules_install
cd ..
tar xfvz unionfs-1.3.tar.gz
cd unionfs-1.3
echo 'TOPINC=-I/usr/src/linux/include' >
make -C /lib/modules/ SUBDIRS=/usr/src/unionfs-1.3 FISTDEVMK=/usr/src/unionfs-1.3/ modules
cp unionfs.ko /lib/modules/
echo "/lib/modules/" >> /lib/modules/
cd /boot
mkdir isolinux
cd isolinux
cp /usr/src/linux/arch/i386/boot/bzImage ./vmlinuz
tar xfvj syslinux-3.31.tar.bz2
cp syslinux-3.31/isolinux.bin .
rm -rf syslinux-3.31
rm syslinux-3.31.tar.bz2
echo "Welcome to BLIND Beyers LINux Distribution" > greetings.txt
cat > isolinux.cfg << "EOF"
default 1
prompt 1
timeout 300
display greetings.txt
label 1
kernel vmlinuz
append ramdisk_size=16384 initrd=initrd init=/linuxrc root=/dev/ram0 rw
Building the RAM disk
touch /boot/isolinux/initrd
dd if=/dev/zero of=/boot/isolinux/initrd bs=1024k count=16
mke2fs /boot/isolinux/initrd
cd /mnt
mkdir initrd
mount -o loop /boot/isolinux/initrd /mnt/initrd
cd /mnt/initrd
mkdir etc dev lib bin proc new cdrom
touch etc/mtab
touch etc/fstab
cat > linuxrc << "EOF"
export PATH=/bin:/sbin
mount -t proc none /proc
CMDLINE=`cat /proc/cmdline`
umount /proc
# search for CDROM and mount it
for x in hda hdb hdc hdd
 mount -t iso9660 -r /dev/${x} /cdrom > /dev/null 2>&1
 if [ "$?" = "0" ]
if [ "${CDROM}" == "" ]
  exec /bin/sh
export CDBOOT
# mount root and create rw directories 
modprobe unionfs
mount -t squashfs -o loop /cdrom/files/source.img /new > /dev/null 2>&1
mount -t tmpfs -o size=64m none /new/ramdisk > /dev/null 2>&1
mount -t unionfs -o dirs=/new/ramdisk=rw:/new=ro none /new > /dev/null 2>&1
# start original Debian init script
cd /new
pivot_root . BLIND
exec /usr/sbin/chroot . /bin/sh <<- EOF >dev/console 2>&1
exec /sbin/init ${CMDLINE}
chmod +x linuxrc
cp /bin/cat /mnt/initrd/bin/
cp /usr/sbin/chroot /mnt/initrd/bin/
cp /sbin/init /mnt/initrd/bin/
cp /bin/ls /mnt/initrd/bin/
cp /bin/mkdir /mnt/initrd/bin
cp /sbin/modprobe /mnt/initrd/bin
cp /bin/mount /mnt/initrd/bin
cp /sbin/pivot_root /mnt/initrd/bin
cp /bin/sh /mnt/initrd/bin
cp /bin/tar /mnt/initrd/bin
cp /bin/umount /mnt/initrd/bin
cp /lib/ /mnt/initrd/lib/
cp /lib/ /mnt/initrd/lib/
cp /lib/ /mnt/initrd/lib/
cp /lib/ /mnt/initrd/lib/
cp /lib/ /mnt/initrd/lib/
cp /lib/ /mnt/initrd/lib/
cp /lib/ /mnt/initrd/lib/
cp /lib/ /mnt/initrd/lib/
cp /lib/ /mnt/initrd/lib/
cp /lib/ /mnt/initrd/lib/
cp /lib/ /mnt/initrd/lib/
cp /lib/ /mnt/initrd/lib/
cp /lib/ /mnt/initrd/lib/
mknod /mnt/initrd/dev/console c 5 1
mknod /mnt/initrd/dev/null c 1 3
mknod /mnt/initrd/dev/hda b 3 0
mknod /mnt/initrd/dev/hdb b 3 64
mknod /mnt/initrd/dev/hdc b 22 0
mknod /mnt/initrd/dev/hdd b 22 64
mknod /mnt/initrd/dev/tty c 4 0
mknod /mnt/initrd/dev/loop0 b 7 0
cd /mnt/initrd/lib
mkdir modules
cd modules/
cp /lib/modules/ .
mkdir kernel
cd kernel
mkdir fs
cd fs
cp /lib/modules/ .
Unmount it:
cd /mnt
umount initrd/
cd /
mkdir BLIND ramdisk
mv /etc/fstab /etc/fstab_hdinst
cd /etc
cat > fstab << "EOF"
proc            /proc           proc    defaults        0       0
/dev/hda1       /               ext3    defaults,errors=remount-ro 0       1
/dev/hda5       none            swap    sw              0       0
/dev/hdc        /media/cdrom0   iso9660 ro,user,noauto  0       0
cd /etc/init.d
rm xdebconfigurator
chmod 755 xdebconfigurator
cd /usr/src
rm -rf *
apt-get clean
apt-get autoclean
umount /proc
cat > << "EOF"
rm -rf target
rm debian-live.iso
mkdir target
cp -a source/boot target/
mkdir target/files
rm -rf source/var/tmp/*
rm -rf source/var/run/*
rm -rf source/var/lock/*
rm -rf source/tmp/*
rm -f source/etc/mtab
touch source/etc/mtab
mksquashfs source/ target/files/source.img
cd target
mkisofs -R -b boot/isolinux/isolinux.bin -c boot/isolinux/ -no-emul-boot -boot-load-size 4 -boot-info-table -o ../debian-live.iso .
cd ..


If you want to export unionfs file system parts apply this patch:

Index: main.c
RCS file: /home/cvs/unionfs/unionfs/main.c,v
retrieving revision 1.171
diff -u -p -r1.171 main.c
--- main.c      25 Jun 2006 23:57:43 -0000      1.171
+++ main.c      12 Aug 2006 09:58:19 -0000
@@ -634,9 +634,7 @@ static int unionfs_read_super(struct super_block *sb, void *raw_data,
                              int silent)
        sb->s_maxbytes = maxbytes;
        sb->s_op = &unionfs_sops;
-       sb->s_export_op = &unionfs_export_ops;
+       init_export_op(sb);
         * we can't use d_alloc_root if we want to use
Index: super.c
RCS file: /home/cvs/unionfs/unionfs/super.c,v
retrieving revision 1.96
diff -u -p -r1.96 super.c
--- super.c     25 Jun 2006 23:57:43 -0000      1.96
+++ super.c     12 Aug 2006 09:58:19 -0000
@@ -488,7 +488,12 @@ static int unionfs_show_options(struct s
        return ret;
+  - move this part to new file export.c
+  - remove '#if defined(...) || defined(..._MODULE)' from export.c
+  - add 'unionfs-$(CONFIG_EXPORTFS) += export.o' to Makefile
  * export operations.
  * unionfs cannot handle disconnected dentry, since it has no hidden dentries.
Index: unionfs.h
RCS file: /home/cvs/unionfs/unionfs/unionfs.h,v
retrieving revision 1.205
diff -u -p -r1.205 unionfs.h
--- unionfs.h   25 Jun 2006 23:57:44 -0000      1.205
+++ unionfs.h   12 Aug 2006 09:58:20 -0000
@@ -76,8 +76,11 @@ extern struct inode_operations unionfs_d
 extern struct inode_operations unionfs_symlink_iops;
 extern struct super_operations unionfs_sops;
 extern struct dentry_operations unionfs_dops;
 extern struct export_operations unionfs_export_ops;
+#define init_export_op(sb)     ({(sb)->s_export_op = &unionfs_export_ops;})
+#define init_export_op(sb)     /* */
 /* How long should an entry be allowed to persist */