Linux Boot CDs (kernel 2.4 notes)|
Making Linux Boot CDs using kernel 2.4A few years ago I wrote this article describing how to create Linux Boot CDs. I thought its about time for an update. The old article is still mostly relevant with one important change; you don't need that fangled linuxrc I wrote.
TheoryAs with the old article I am using ISOLINUX to put a boot sector on the CD. ISOLINUX will load your kernel off the CD, and then pass it the name of your initrd.gz (compressed initial root filesystem). The initrd.gz gets decompressed into /dev/ram0. Atypically its an ext2 filesystem (obviously your kernel needs ext2 support compiled into it). This gets mounted as the root of your filesystem (ie. / ). Then the kernel tries to run /linuxrc. If thats missing it will try to run /sbin/init instead.
In my prior notes I indicated that the role of the initrd is to somehow mount your real root filesystem and hand over control to it. Thats why I came up with that tiny linuxrc.c thing. However, its not strictly necessary to leave the initrd at all. In the case of a boot floppy or boot CD, your initrd runs in a ramdisk and your root filesystem will also need to run in a ramdisk, so there is no real point in leaving the initrd given that all you're doing is moving from one ramdisk to the next ramdisk.
Getting StartedTry downloading this file and extract it. You end up with a template structure for creating your own simple bootCD:
image/ the directory tree to burn to the CD isolinux/ Where isolinux.bin, your kernel and initrd goes initrd/ the directory tree for your initrd bin dev etc lib sbin usrThe 'kit' includes a 2.4.20 kernel setup for 16mb ram disks, initrd support, framebuffer support and a few other bits. To create your CD image you need to do two steps:
1. Run ./setup_16mb.sh (you need to have loopback support available) 2. Run ./make_iso.sh (to create the file iso.img which you can burn to a CD)
The kernel in this kit is already setup such that /dev/ram0 is considered to be its initial root disk. To do this for your own kernel you would need to do something like:
rdev image/isolinux/vmlinuz /dev/ram0The initrd tree in the kit contains a very small busybox setup that has been statically compiled with dietlibc. When compressed with gzip -9, the initrd.gz file should be about 450k. It was originally designed to fit on a floppy ... and still probably can (you would need a smaller kernel though). One of the key features of this small busybox is that you can insmod kernel modules with it). As well as busybox, there is fgetty (again statically compiled). You may think it odd running a system with no dynamic libraries, but the rationale is that 'the basic userland' stuff runs independent of any libraries. If you want to add a specific function to your boot disk ... and that function requires libraries then just add everything relating to that function under /usr. Any libs can be added under /usr/lib, any binaries under /usr/bin etc. For example you can mount /usr using NFS, or a loopback cramfs or whatever ... or as you'll see below, I've actually put some useful stuff into /usr within the initrd.gz
Building itSuffice to say, you put everything you want in your initrd and do something like the following (remember we are using 16mb ram disks here):
dd if=/dev/zero of=16mbfile bs=1k count=16384 losetup /dev/loop0 16mbfile mkfs -t ext2 -m 0 /dev/loop0 mount /dev/loop0 /mnt cd initrd tar cvf - . | (cd /mnt && tar xf - ) cd .. umount /mnt losetup -d /dev/loop0 gzip -9 -c 16mbfile >image/isolinux/initrd.gzIn fact, this is exactly what the setup_16mb.sh script does.
Now you need to create the iso image to burn to your CD (what make_iso.sh does):
mkisofs -o iso.img -b isolinux/isolinux.bin -c isolinux/boot.cat \ -no-emul-boot -boot-load-size 4 -boot-info-table -l -R -r imageNow take your CDRW (you didn't burn it to a CDR did you?) and try booting from it. Hopefully you'll get prompted for what screen mode you want (640x480, 800x600 or 1024x768), then the kernel will boot and you'll get prompted to login. Use 'root' for the username and 'bootcd' as your password.
A bootable Media PlayerAs an example of what you can do with a boot CD, download k2.4_mplayercd_0.03.tar.gz. Its the same as the bootcd kit shown earlier, except that /usr has been populated with mplayer and some requisite libraries. Enough libraries so that you can play divx's in framebuffer mode. It still uses a 16mb initrd, so you build it with exactly the same commands shown earlier.
Make sure you select one of the graphical modes (anything but text mode) when you first boot the CD. Once you've logged in (same user and password as before), you will probably want to insmod modules for your network card and your sound card. Admitedly, to keep the download size small, I have not included many sound card drivers or network card drivers, so it'll be a matter of luck as to whether you get these going. The insmod in busybox is not that smart so if you have a modules that depends on another module, then you wull have to manually insmod the dependencies first. Here's an example:
insmod es1371 won't work BUT the following will work insmod ac97_codec insmod es1371And say you have a RTL8139 network card, you might:
insmod 8139tooSo to setup your network card properly you might:
ifconfig eth0 10.0.0.1 netmask 255.255.255.0 broadcast 10.0.0.255 route add default gw 10.0.0.200You get the basic idea. Once you have network and sound setup you need to grab some media to play. If you have a divx on a CD, you could pop out the boot CD and insert your divx CD, mount it and then do something like:
mplayer -fs -vo fbdev /mnt/test.aviOr lets say you have some media on a nearby web server:
mplayer -fs -vo fbdev http://10.0.0.2/test.aviAlso, here's an example of using software scaling (ie. poor performance) for resizing your output picture:
mplayer -vo fbdev -sws 0 -vop scale=640:480 /mnt/test.avi
pablo , 2003-12-09 03:28:38