# Creating a stage3 based bootable cd

## Kobboi

Can someone help me through the fundamental steps of creating a simple bootable cd?

I have a kernel and bootloader that I can put on the cd to boot. Then I assume I have to use some mechanism to find the device that represents the cd, to be able to access more than just the kernel. What method is preferred? Why? 

How do I load what is supposed to be the root filesystem? When booting a Gentoo minimal install cd, I see stuff is being copied from the cd to some tmpfs. Is this what should normally be done? Does it work on memory restricted setups (say 256MB)? Do 700MB livecds also copy a whole lot of things to a tmpfs? 

Wikipedia's take on livecds talks about cases using unionfs/aufs. Needed? Recommended?

A lot of questions, thanks for your help and insights.

----------

## pappy_mcfae

It's not absolutely necessary for you to re-invent the wheel, so to speak. If you check out the SysRescueCD site, they have instructions on how to customize your own personal CD with whatever you wish on it. I'd recommend you take a look at what they have to offer. 

Blessed be!

Pappy

----------

## Kobboi

Agreed and I will check out the site. On the other hand, I would like to learn a bit more about how things work, so if anyone wants to share some knowledge or insights, please do.

----------

## Tolstoi

You could make your own live usb stick. I think it makes sense because you can boot from it when you have problems and surf the web for solutions and so on.

----------

## Kobboi

I have too much older hardware not supporting booting from USB and I really want to do the livecd exercise.

----------

## Tolstoi

There used to be a guide on Gentoo wiki about modifying a gentoo cd but I can't guarantee for that since the wiki went down.

----------

## Kobboi

 *Tolstoi wrote:*   

> There used to be a guide on Gentoo wiki about modifying a gentoo cd but I can't guarantee for that since the wiki went down.

 

Again, I'm not really interested in modifying anything. I would like to understand the bottom-up fundamentals.

----------

## ccp

to create a stage3 bootable cd, it is really two processes, one is create a directory to store stage3 dump. the other step is to create a bookable CD, this involve use isolinux to create a iso file then burn the file to CD.

so,

```
# mkdir /path/to/stage3_dump

# untar xvf stage3-snapshot.tar -C /path/to/stage3_dump

# mkdir /path/to/stage3_dump/boot/isolinux

# cd /path/to/stage3_dump/boot/isolinux

# cp /usr/lib/syslinux/isolinux.bin /path/to/stage3_dump/boot/isolinux

# mkisofs -o -r -l /path/to/stage3-snapshot.iso \

      -b boot/isolinux/isolinux.bin 

      -c boot/isolinux/boot.cat \

      -no-emul-boot -boot-load-size 4 -boot-info-table \

      /path/to/stage3_dump

```

the initramfs 

```
#!/bin/sh

/bin/mount -n -t proc proc /proc

/bin/mount -n -t sysfs sys /sys

mdev -s

# debug /bin/sh

/bin/mount /dev/sr0 /cdrom

/bin/umount /sys

/bin/umount /proc

exec /bin/switch_root /cdrom /sbin/init

```

the isolinux.cfg

```
# Example of isolinux.cfg:

# default to boot

default 0

prompt 0

# various options are available for booting

# hd

label 0

kernel vmlinuz

append initrd=initrd init=/bin/sh
```

And your kernel need to have cdrom drive buildin and iso file system drive.

ccp

----------

## Kobboi

Ok, and thanks for continuing the discussion in a productive way, but isn't this the easy part? /cdrom becomes my root filesystem, read-only. Now some of the init-scripts will want to write things (udev will maybe want to create rules for persistent network interface in /etc, other scripts will want to do stuff in /var/), but I assume this will fail with ugly [!!]'s ?

----------

## ccp

Yes, if you switch_root /cdrom /sbin/init, if your do switch_root /cdrom /bin/sh then you just drop in to shell, you can do what ever you want from there.

ccp

----------

## bob doe

If you wish, you can check out my autobuild scripts I use to make my LiveCD: http://www.linuxfly.net/knowledge/make/index.html

----------

