CustomFedoraBootableCD

You may also find this page useful: http://www.pre-emptive.net/doco/linux-boot-and-installation-disk

Introduction

This page is about making your own bootable (Fedora) Linux CDs. You may need this information if you're creating your own "live CD" or otherise making some sort of software installer that you want to provide on CD.

In my case, I've made a CD that installs a system with a pre-defined Linux image. The image is specific to a small number of hardware variants, each running exactly the same software. That means I can literally "clone" one system onto the next (and changing IP addresses etc once that's done).

If you're looking for information on how to boot Fedora CDs, or how to make and burn CDs under Linux, you're out of luck - sorry ;-)

Basic Recipe

In short, you will need:
* Some sort of linux image that will ultimately appear on the CD
* The isolinux software
* An initrd image for the kernel your CD will be using
* A stack of blank CDs - you're bound to make a few mistakes along the way!
* Lots of testing and development time! (including a machine to work with, of course)

Step 1: Make the Linux Image for the CD

This is the process of making a system that boots up, and does whatever you want your CD to do. Most of this is obviously dependent on what you're trying to do, but making the image work when it eventually gets onto the (read only!) CD takes a bit of work, which I've tried to describe here.

(sorry, still got to do this section!)

Step 2: Use isolinux

isolinux is software that you can use to make bootable CDs quite easily. It's a bit like Grub or Lilo, but it's for CDs. Curiously, you need to make a boot disk to get it. You should do this on a running system, although probably not your "CD system" because you'll probably have stripped that down and removed the necessary files.

You need to select a kernel to use. Any kernel will do, so long as you have a modules directory for it, and it's installed properly on your system (you don't need to be running it to use it though). Run mkbootdisk to get an isolinux bundle for it:

mkbootdisk --iso --device /tmp/boot.iso 2.6.11-1.14_FC3

(obviously, change "2.6.11-1.14_FC3" to whatever kernel version you want to use)

The mkbootdisk program will create an ISO file in /tmp. You need to mount this to get at the files inside it:

mount /tmp/boot.iso /mnt -o loop

You'll find nothing but an isolinux subdirectory, which you should copy into your "CD system". After that, you're done with the image, so unmount it and delete /tmp/boot.iso.

Step 3: Sort out isolinux Config and initrd Images

First, a little recap about Linux booting. Linux boots in a series of steps. The first step is to run whatever code is in the boot sector of the disk (true for CDs, harddisks, floppies etc). That bit of code tells the machine what to do next. The next stage is to run the main bootloader, which will be located somewhere on the actual disk. The boot sector really just says where to find the bootloader.

The bootloader is a program such as [[LILO]] or Grub (for harddisks) or isolinux for CDs. Most bootloaders can do all sorts of things like allow you to select systems to boot, or change boot options. However, in essence they all load a kernel. That kernel uses an Initial Ram Disk (initrd) to boot the rest of the system.

The initrd contains the bare minimum that the system needs to get the filesystems mounted (where of course it can find all the other things it needs). This usually involves getting kernel modules like the filesystem modules and perhaps USB modules loaded. Once they're in, the real disks are mounted and the system boots. Note: Everything that happens before that mount comes from the initrd image - NOT the disk!

The mkbootdisk program used in step 2 assumes you're going to use the harddisk to boot your system. Of course you're going to use a CD, so we have to make a few changes. The first is to change the boot config for isolinux. This is much like a Grub config and is called isolinux.cfg (in the isolinux directory of the "CD system"). If you look at the file, you'll obviously have to change the root location from /dev/hda1 (or whatever) to /dev/hdc. You might also want to stop isolinux displaying any welcome page or prompting for kernel options. Here's my isolinux.cfg file:

default linux
prompt 0
timeout 0
label linux
kernel vmlinuz
append initrd=initrd.img roroot=/dev/hdc

This will instruct isolinux to look to /dev/hdc for the root of the system, where it will also find the initrd image.

The initrd image is a funny one. On my FC2 system, mkbootdisk created a ext2fs format initrd file. On FC3 it seems to create a gzipped [[CPIO]] archive. I couldn't get that to work at all, so had to recreate it as an ext2fs file instead. I guess FC2 users can skip this next bit ;-)

To make the modified initrd image, we have to do the following (taken from [http://trinityhome.org/trk/old/trk04-dev-howto.htm]):

dd if=/dev/zero of=/tmp/newinitrd.img bs=1k count=2880

(to create a file that we'll put a filesystem onto in a moment)

losetup /dev/loop0 /tmp/newinitrd.img

(to get the loopback system working with our file)

mke2fs /dev/loop0

(to make a filesystem on the file)

mount /dev/loop0 /mnt

(to mount it)

cd /mnt
zcat (wherever)/isolinux/initrd.img | cpio -i
cd /
umount /mnt

(to extract the old initrd image into the new one)

gzip /tmp/newinitrd.img
cp /tmp/newinitrd.img.gz (wherever)/isolinux/initrd.img

(to compress the new file and put it in place of the old one)

Step 4: Burn Baby, Burn!

Now we have a whole system and bootloader ready, we can burn it to disk. Change directory into the root of the "CD system" and run this:

mkisofs -o ../image.iso -V 'My Linux CD' -b isolinux/isolinux.bin -c isolinux/boot.cat \
-no-emul-boot -boot-load-size 4 -boot-info-table -R -J -V -T .

Now to burn it to a CD:

cdrecord -eject -tao ../image.iso

(or else do whatever you need to in order to burn a .iso to a CD)

Step 5: Test, Rinse and Repeat

Try booting your system with the CD. If you're very lucky it'll work right away. You're more than likely going to make a few mistakes or havea few problems though, so you'll probably burn quite a few CDs that go straight into the bin.

You could have any number of problems, some of them are listed here so might give you some clues as to where the problem is:

* System "ignores" the CD and just goes ahead and boots the harddisk
Check the mkisofs command and make sure you've got isolinux in place properly.

* System start to boot the kernel, but then panics (possibly with "unable to mount root fs on unknown block(22,0)")
This is the initrd image problem - Check and make sure that your initrd.img file is a gzipped ext2fs file, not a gzipped CPIO archive.

This problem can also be due to some problem with "udev" (which dynamically makes entries in /dev) during the initrd booting phase. I think the advice is "update udev", which probably means you need to update quite a few things in your system. Sorry, I don't really know te answer ;-)

* System boots from the CD but then switches over to the harddisk
Check that you have correctly edited the isolinux.cfg file to point the kernel at the CD rather than the harddisk.

* As the system boots, it grumbles about "read only filesystem"
Hmm, tough one. It depends on what exactly the problem is, but you might like to look into ram disks, udev and the like so whatever it is doesn't have a problem.

Stuff to Try (if you've got it all working!)

If you're "CD system" is small, you could move it all into the initrd image. You'll need to be careful to modify your rc.sysinit file to include the things that previously got done in the initrd image. However, once done, your whole system will run out of the initial ram disk, so besides loading in the image, the CD won't get used. In fact, if you play your cards right, the CD won't even get mounted, so you can eject it! (which is very useful if you want to use a second disk for something).

Using the initrd image for everything is useful in other ways too. For example, it's a read-write filesystem, so you don't have to make special concessions for /tmp, /var/tmp etc. Also, since it's all in ram, it's faster than running off CD. You do have to be careful though, because of course the ram disk is using up a chunk of your available memory. In other words, make the uncompressed initrd image as small as you can, which of course defines the size of the filesystem of the ram disk.

Comments

a bit confused...

I have a clean Fedora system which is the model for my image. I have trouble to understand, which command I suppose to run on my "Running System" and which on my "CD system" (which I assume is the model)

Thanks, Oren

Submitted by Anonymous (not verified) on Tue, 2005-08-30 15:39.
no space left on device???

I followed the instructions, and this is what I am getting:
# df -k
Filesystem 1K-blocksUsed Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
73575592 155323668224548 3% /
/dev/sda1 101086 14184 8168315% /boot
/dev/shm517140 0517140 0% /dev/shm
/dev/hdd649838649838 0 100% /media/cdrom
/dev/loop02830252661 1% /mnt
root@localhost mnt# zcat /tmp/isolinux/initrd.img | cpio -i
cpio: write error: No space left on device
root@localhost mnt# df -k
Filesystem 1K-blocksUsed Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
73575592 155323668224548 3% /
/dev/sda1 101086 14184 8168315% /boot
/dev/shm517140 0517140 0% /dev/shm
/dev/hdd649838649838 0 100% /media/cdrom
/dev/loop028302830 0 100% /mnt

Thanks

Submitted by Anonymous (not verified) on Tue, 2005-08-30 15:58.
Re: a bit confused...

> I have a clean Fedora system which is the model for my image. I have trouble to understand, which command I suppose to run on my "Running System" and which on my "CD system" (which I assume is the model)
>
> Thanks, Oren

Not sure I completely understand what you mean. The idea is that you make a partition and install Linux into it. You then do what ever configuration you need in that partition so that when you boot it, it acts as if you'd booted from a CD. For that to work, you'll have to consider the root filesystem is read-only, and of course size limited. You'll end up customising /etc/rc.sysinit, the modules in the kernel, the packages you have installed etc etc.

Once you've got a system that behaves as if it were a CD, then you should be ready to make an ISO of it. To boot the ISO you'll need Isolinux and an suitable Initrd image. Of course, to be able to make an ISO of the partition, you'll need to be able to "see" it, which means you'll need to be booted off another partition, with your "CD System" mounted on it.

Submitted by coofercat on Wed, 2005-08-31 09:53.
A very interesting piece

I'm trying to get in contact with coofercat about this and I have a project I'm working on.
If you get a change please email steveatlasersol.co.uk

Submitted by Anonymous (not verified) on Tue, 2005-11-01 13:35.
Good article but i need this !!! pls help

Hi,,

Actually i amtrying to create my custom linux distro which shld include FC OS kernel , basic utilities & commands , Apache , PHP , MySQL , FTP , DNS. targeted my distro size 100MB.

Pls suggest me the steps to create my distro with the packages above.

Thanks in advance

Best Regards
ashok

Submitted by Anonymous (not verified) on Tue, 2006-01-17 15:39.
Re: Good article but i need this !!! pls help

Looks to me like you should probably start with Knoppix?

Failing that, install a minimum fedora, install all the apps you need, then remove everything you don't need. At some point, you'll have to remove the RPM facility as this actually uses quite a bit of space. After that it gets harder - you'll have to delete files manually to remove them. The chances are you'll leave a few things you don't actually need, so your end result my be a few percent larger than it needs to be.

Alternatively, it's possible to build a distro completely from scratch: install kernel, install suitable startup scripts and supporting binaries (like a shell!). Then copy over the bits of the various applications you need. It's a lot of work, but you'll only ever have *exactly* what you need, so it'll be as small as it ever can be.

Either way, 100MB is probably not enough space for all those apps (although compression may help - either using the initrd method above or on-the-fly compression like Knoppix uses).

Submitted by coofercat on Tue, 2006-01-17 16:58.
FC4 live cd issue with ext3

yo bro, you stuff quite clear, but my boot not fully successful as I met a problemsaid that can not mount ext3. I was building in on FC4, I guess the kernel defaultly expecting a health ext3 initrd but the one I have it not a loadable one. Any ideas?

Submitted by Anonymous (not verified) on Fri, 2006-01-20 10:08.
Re: FC4 live cd issue with ext3

Hey Homey, wassup? Man, you got some whack shit goin' down.

The initrd has to be loaded by the kernel with no modules loaded. In other words, ext2. The initrd can be used to load modules, so the rest of the system can be anything you like, but initrd pretty much has to be ext2 (or a CPIO archive).

Submitted by coofercat on Fri, 2006-01-20 11:10.
Booting issue

Hey bro wassup? I madea new initrd image and tried on again. I found new problem. Well, since the initrd.img I was made in a ext2fs format gz. It was indeed mounted during initial booting, but later it shot me a error said that the old initrd can not be mounted to /root, /root mount failed .....

Is that supposed to be the final look of this livecd? Thx.

Submitted by Anonymous (not verified) on Tue, 2006-01-24 04:31.
I Am Going Nowhere Fast

Hi,
I have downloaded Fedora 4. I have unzipped the iso files and written them to CD's.
However CD 1 does not autorun.(:question:)
While I do not mean to be cynical but it seems that just to Install any linux flavour takes lots of frisbee CD's and hours of research. It's no wonder that Windows (Which does autorun) is in front.
Do you have any ideas on this please?

Submitted by Anonymous (not verified) on Fri, 2006-03-17 04:34.
Re: I Am Going Nowhere Fast

Not something I'm an expert on, but...

When you say "autorun", you do mean "boot the machine" don't you? Simply sticking the CD in while Windows is running will indeed do very little. Reboot your machine, and it should start the install.

Also, when you say "burned the iso to disk", you did "burn the image", as opposed to making a CD with one file on it, didn't you? Once burned, you should find a load of files on the CD (if you look at it in Windows).

Other than that, I have no idea. If you're still stuck, I'd question your CD drive, perhaps not liking burned CDs or something...?

Submitted by coofercat on Fri, 2006-03-17 10:12.
all messed up...

hi there..ive jus d\l the live cd ver. for FC 7.I got a rar file in which were 3 folders,#1 isolinux(has files like boot.cat,intrd.img,etc..),#2 sysroot(this one's empty) and #3 squashfs.img(an image file). What do i do now and how do i make a bootable cd of these stuffs...I d\l this from Fedora's site itself.Help me...
Regards,
Shank.

Submitted by shank (not verified) on Tue, 2007-10-23 18:54.