I was curious about how to create a LiveCD, so I tried it. Having a LiveCD might make demos and such easier.
1. Install Tools
# aptitude -y install xorriso live-build syslinux squashfs-tools
2. debootstrap
Create an appropriate work directory (~/livework) and use debootstrap to create a new environment. This creates structures like bin, etc, var under ~/livework/chroot.
# mkdir ~/livework && cd ~/livework
# debootstrap --arch=amd64 sid chroot
3. chroot
Use chroot to enter the new environment created by debootstrap. Mount proc, etc., and install the kernel image and live-boot.
# chroot chroot # export HOME=/root
# export LC_ALL=C
# export PS1="(chroot) $PS1"
# mount -t proc none /proc
# mount -t sysfs none /sys
# mount -t devpts none /dev/pts
# aptitude -y install linux-image-amd64 live-boot
# passwd
# aptitude clean
# rm -rf /tmp/*
# umount /proc /sys /dev/pts
# exit
4. isolinux
Create a directory called binary and copy vmlinuz and initrd from the chroot environment. Create (compress) the filesystem from under chroot with mksquashfs. However, exclude /boot. (Can be verified with mount binary/live/filesystem.squashfs /media/hoge) It seems syslinux is used when booting from CD.
# cd ~/livework
# mkdir -p binary/live
# mkdir -p binary/isolinux
# cp chroot/boot/vmlinuz-3.13-1-amd64 binary/live/vmlinuz
# cp chroot/boot/initrd.img-3.13-1-amd64 binary/live/initrd
# mksquashfs chroot binary/live/filesystem.squashfs -comp xz -e boot
# cp /usr/lib/syslinux/isolinux.bin binary/isolinux
# cp /usr/lib/syslinux/menu.c32 binary/isolinux
Write the boot configuration as well.
# vim binary/isolinux/isolinux.cfg
ui menu.c32
prompt 0
menu tile Boot Menu on MyDebian
timeout 300
label live-amd64
menu label ^Live (amd64)
menu defalut
linux /live/vmlinuz
append initrd=/live/initrd boot=live persistence
label live-amd64-failsafe
menu label ^Live (amd64 failsafe)
menu defalut
linux /live/vmlinuz
append initrd=/live/initrd boot=live config memtest noapic noapm nodma nomce nolapic nomodeset nosmp nosplash vga=normal
endtext
5. Create ISO Image
This is the important part, but I don’t fully understand it. It seems to be working fine in qemu tests.
# cd ~/livework
# xorriso -as mkisofs -r -J -joliet-long -l -cache-inodes \
-isohybrid-mbr /usr/lib/syslinux/isohdpfx.bin -partition_offset 16 \
-A "Debian Live" -b isolinux/isolinux.bin -c \
isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
-boot-info-table -o remaster.iso binary
# qemu-system-x86_64 remaster.iso
References
Addendum
# aptitude install live-build
# lb config
# lb build
I found that you can do the same (similar) thing with this. live-build seems much richer than debootstrap and has more packages. It even includes an installer. lb build seemed to work fine, but it crashed in both qemu and virtualbox, which was a bit disappointing.
/init line 220: can't open /scripts/live
Kernel panic - not syncing: Attempted to kill init!
So I looked at the init script.
# mkdir initrd_expand; cd initrd_expand
# gzip -cd ../initrd.img | cpio -imd --quit
line 220: ./scripts/${BOOT}
Looking inside ./scripts/, there’s nothing called live. This is troublesome.