Build a Debain based live cd
From wiki.network-crawler.de
Contents |
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?
Tool-time
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/ LC_ALL=POSIX export LC_ALL mount -t proc /proc proc
Now you can install the packages you like on the life cd
apt-get install myfavouritepackages
e.g.
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 2.6.17.14 because it is works with unionfs):
cd /usr/src wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.17.14.tar.bz2 tar xfvj linux-2.6.17.14.tar.bz2 ln -s /usr/src/linux-2.6.17.14 linux cd linux make menuconfig wget http://downloads.sourceforge.net/squashfs/squashfs3.1-r2.tar.gz tar xfvz squashfs3.1-r2.tar.gz patch -p1 < squashfs3.1-r2/linux-2.6.17.14/squashfs3.1-patch cd squashfs3.1-r2/squashfs-tools/ make cp mksquashfs /usr/sbin
cd /usr/src/linux make menuconfig make bzImage modules modules_install
cd .. wget ftp://ftp.fsl.cs.sunysb.edu/pub/unionfs/unionfs-1.3.tar.gz tar xfvz unionfs-1.3.tar.gz cd unionfs-1.3 touch fistdev.mk echo 'TOPINC=-I/usr/src/linux/include' > fistdev.mk make -C /lib/modules/2.6.17.14/build SUBDIRS=/usr/src/unionfs-1.3 FISTDEVMK=/usr/src/unionfs-1.3/fistdev.mk modules cp unionfs.ko /lib/modules/2.6.17.14/kernel/fs/
echo "/lib/modules/2.6.17.14/kernel/fs/unionfs.ko:" >> /lib/modules/2.6.17.14/modules.dep
cd /boot mkdir isolinux cd isolinux cp /usr/src/linux/arch/i386/boot/bzImage ./vmlinuz
wget http://www.kernel.org/pub/linux/utils/boot/syslinux/syslinux-3.31.tar.bz2 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 EOF
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"
#!/bin/sh
export PATH=/bin:/sbin
mount -t proc none /proc
CMDLINE=`cat /proc/cmdline`
umount /proc
# search for CDROM and mount it
CDROM=""
for x in hda hdb hdc hdd
do
mount -t iso9660 -r /dev/${x} /cdrom > /dev/null 2>&1
if [ "$?" = "0" ]
then
CDROM="${x}"
break
fi
done
if [ "${CDROM}" == "" ]
then
exec /bin/sh
exit
fi
#/bin/bash
CDBOOT="yes"
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}
EOF
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/ld-linux.so.2 /mnt/initrd/lib/ cp /lib/libacl.so.1 /mnt/initrd/lib/ cp /lib/libattr.so.1 /mnt/initrd/lib/ cp /lib/libblkid.so.1 /mnt/initrd/lib/ cp /lib/libc.so.6 /mnt/initrd/lib/ cp /lib/libdl.so.2 /mnt/initrd/lib/ cp /lib/libncurses.so.5 /mnt/initrd/lib/ cp /lib/libpthread.so.0 /mnt/initrd/lib/ cp /lib/librt.so.1 /mnt/initrd/lib/ cp /lib/libuuid.so.1 /mnt/initrd/lib/ cp /lib/libdevmapper.so.1.02 /mnt/initrd/lib/ cp /lib/libselinux.so.1 /mnt/initrd/lib/ cp /lib/libsepol.so.1 /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/ mkdir 2.6.17.14 cd 2.6.17.14/ cp /lib/modules/2.6.17.14/modules.dep . mkdir kernel cd kernel mkdir fs cd fs cp /lib/modules/2.6.17.14/kernel/fs/unionfs.ko .
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 EOF
cd /etc/init.d rm xdebconfigurator wget http://www.minimix.ch/debian-live/files/xdebconfigurator chmod 755 xdebconfigurator
cd /usr/src rm -rf * apt-get clean apt-get autoclean umount /proc exit
cat > buildcd.sh << "EOF" #!/bin/bash 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/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o ../debian-live.iso . cd .. EOF
Notes
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;
-#ifdef CONFIG_EXPORTFS
- sb->s_export_op = &unionfs_export_ops;
-#endif
+ 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;
}
-#ifdef CONFIG_EXPORTFS
+#if defined(CONFIG_EXPORTFS) || defined(CONFIG_EXPORTFS_MODULE)
+/*
+ - 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;
-#ifdef CONFIG_EXPORTFS
+#if defined(CONFIG_EXPORTFS) || defined(CONFIG_EXPORTFS_MODULE)
extern struct export_operations unionfs_export_ops;
+#define init_export_op(sb) ({(sb)->s_export_op = &unionfs_export_ops;})
+#else
+#define init_export_op(sb) /* */
#endif
/* How long should an entry be allowed to persist */
UNDER CONSTRUCTION
