# [howto] Gentoo Linux Livecd [last update 01/22/2007]

## Lepaca Kliffoth

UPDATE 1, 12/11/2005: Dropped Grub in favor of ISOLINUX.

UPDATE 2, 12/16/2005: Added section "10. HD PARTITIONS AUTODETECTION".

UPDATE 3, 12/21/2005: Changed several things.

 - The linuxrc script has changed. Check it out, now it umounts the initrd claiming 10 MB of RAM back.

 - Section 6. has been upgraded with some "graphics" (  :Laughing:  ). I've made some changes to make it a little easier to understand.

 - Fixed a "bug". Somehow I confused /var/lib/portage with /usr/lib/portage o_O Fixed. The build environment has changed and so have the prepare_env and release_env scripts.

 - Slightly changed the X autoconfiguration section, check it out.

UPDATE 4, 01/06/2006: Migrated to UNIONFS!

- You can find the old guide at the address http://lepacakliffoth.interfree.it/howto.txt

UPDATE 5, 01/21/2006: Minor update

- Fixed some typos and other inconsistencies. Big thanks to Aszrael and anyNiXwilldo and everyone else who pointed them out!

- In particular Section 2. has undergone an important change. Now you have to change the checkroot service. Check it out.

UPDATE 6, 06/07/2006: Improvement

- At the end of page 4 you'll find an improved version of the HD autodetect script, pending integration in the guide.

UPDATE 7, 12/20/2006: Some changes

- Section 10 has changed.

- Merged some corrections users suggested a long time ago.

UPDATE 8, 01/22/2007: One change

- Thanks to STrRedWolf there's now an additional, easier way to make the initrd (Section 5).

----------

## Lepaca Kliffoth

Gentoo Linux Livecd HOWTO - the Lepaca way

ACKNOWLEDGEMENTS

This guide was heavily based on the "Gentoo Linux LiveCD for Dummies!" guide by veezi. This guide has changed considerably during its first month of life but it started as a simple upgrade/update on the one by veezi and still shares many things with it.

INTRODUCTION / DISCLAIMER

First of all, I have no idea what you can or cannot do with Catalyst so it could be that this is just a complicated way of re-inventing the wheel. The one and only thing I can assure you is that it works.

This is a relatively simple method most experienced Gentoo users will be able to follow without too many problems. Here is a rough list of what you should be confident with before attempting to follow this guide, some is common knowledge and some you may not be confident with:

- Please don't attempt this if you still need the gentoo handbook to install a Gentoo base system. I won't replicate the relevant handbook parts here and you'll probably fsck lots of things up anyway because of your lack of experience.

- You must have mastered portage, i.e. you should know how to emerge things properly and configure gentoo-related things.

- This guide doesn't deal with software that isn't stricly related to running Linux from a CD. You have to configure programs by yourself.

- Read the mount man page, you should at least know about the --bind.

- One of the most difficult things in the guide is understanding how a Linux system boots, from grub/isolinux to init. I'll try to give as much info as I can but I'm not sure it'll be enough. It's important to understand the linuxrc script as it's very easy to make mistakes when writing one. You should be fine with the code I provide but some previous knowledge will make things way easier.

Keep in mind that even if I provide a few scripts -- very simple ones as they're not meant to be powerful -- and some bash code fragment, they won't add up to a big complete installation script that you can run once to get a working iso. Always make sure you know exactly what you're doing unless I tell you "you will understand this later" and remember that the ctrl-c,ctrl-v combo can't really replace your brain :p

I tried to be as informative as I could; this is not a quick howto, it's meant to be a complete guide. The best way to follow this guide is to read a whole section without doing anything, then go back to the beginning and actually do what you're told to do as you go through the section a second time. Let me know if you feel this guide lacks detail in some or all of its parts.

0. THE HOST OS

The host operating system doesn't have to be Gentoo, e.g. I only built Gentoo livecds until now but the host system has always been SourceMage. Before you start reading the guide and building the livecd make sure the host OS you use meets the following requirements.

- You need mksquashfs, mkisofs and mkfs.ext2 to create filesystems

- You need support in the kernel for ext2. Squashfs support isn't required but would probably come in handy for debugging purposes. To this day I never had any need of it although I built more than 20 livecds.

- You need an app to burn the iso you will produce. Since you may find yourself working from the command line without any X running you may want to use good old cdrecord/growisofs without any gui. Of course you need mkisofs to create the iso

- You need root access

That's all.

1. FIRST STEPS

(a.k.a emerge system)

This guide assumes you're always logged as root. Throughout the guide we'll also use features that imply you're going to run a 2.6 kernel on your livecd; if you want to run 2.4 you'll have to figure out what you have to change by yourself.

We need to install a Gentoo base system either inside a directory or in its own partition. It doesn't make a difference which approach you use but using a simple directory will be quicker and easier. On the other hand if you use a partition you can test the livecd without even creating an iso.

Create a directory that you will use exclusively for the building of the livecd. Set an environment variable to that path, like this:

```
export LIVEDIR="~/livecd"
```

or something like that. In the few scripts I provide and in the guide itself the variable LIVEDIR will be used extensively. In this guide and those scripts ${LIVEDIR} means "the content of the variable LIVEDIR", in this case ~/livecd.

Under ${LIVEDIR} create a directory called "source". If you have chosen to install Gentoo in its own partition you must now format it and mount it under ${LIVEDIR}/source.

If you have a working Gentoo inside that partition, you're ready to go on; read the rest of this section just in case you have to make some changes (e.g. fstab and isolinux) and then go on with the guide. Make sure your installation isn't too big for the media you want to use; you can't tell how much space it will take on the cd until you've compressed it (more on that much later) but as a reference I can tell you my 1.1 GB gentoo installation produces a 316 MB iso. This guide will go on assuming you're building from scratch.

Inside ${LIVEDIR}/source/ unpack a stage3 tarball, chroot into it and rebuild the Gentoo base system with your own optimizations.

*WARNING* From now on we're chrooted inside the Gentoo base system. Keep in mind that /var really is ${LIVEDIR}/source/var on your HD.

When you build the base system follow this guidelines:

- Don't install the kernel. Emerge the sources but leave them alone. Do not emerge Grub, emerge the "syslinux" package instead. Don't configure fstab.

- I suggest you follow Bob P's stage 1/3 method as it's probably the best one, however the objective here is just to get a working base system (barring the kernel and fstab); you can choose whatever method you want, just make sure you're getting the equivalent of "emerge system". You can add the most basic things like hotplug and a logger but forget about kde/gnome/fluxbox and even X. We will install them much later.

- USE flags should be kept to a minimum. What we want here is just a platform to build any kind of system we may want to use. Space IS an issue so follow the "less is more" philosophy.

- CFLAGS should be tuned for "the less space taken the better", i.e. -Os. It's the one optimization that makes most sense for a system that has to live in a very limited space; at any rate, if you want to use something different suit yourself - I don't even know how much space you actually save.

Once you're done, don't forget to activate whatever services you need. By the way, go for the parallel startup of services (RC_PARALLEL_STARTUP in /etc/conf.d/rc), it makes a huge difference when booting from a livecd.

Here is your /etc/fstab:

```
 unionfs              /               unionfs        defaults             0 0 

 none                    /proc           proc            defaults                0 0 

 none                    /dev/shm        tmpfs           defaults                0 0 

 none                    /dev/pts        devpts          defaults                0 0 
```

Whatever the system you built, this is what you must use. Add whatever you want but leave these lines unchanged. If you don't understand this particular configuration don't worry, by the end of this guide everything will be clear. Read it again after you've read the section of this guide that explains the initrd and the linuxrc script.

Our bootloader will be ISOLINUX since Grub doesn't work properly on many laptops.

First create a directory under /boot called "isolinux". Copy inside that directory the file /usr/lib/syslinux/isolinux.bin and create an empty isolinux.cfg:

```
mkdir /boot/isolinux

cp /usr/lib/syslinux/isolinux.bin /boot/isolinux/

touch /boot/isolinux/isolinux.cfg
```

Here is your isolinux.cfg:

```
timeout 1

default linux

label linux

 kernel vmlinuz

 append initrd=initrd init=/linuxrc root=/dev/ram0
```

As you can see our kernel will be named "vmlinuz". The "append" command does exactly what you think it does, which is appending whatever follows it to the kernel command line. The first parameter specifies the initrd to load in memory, the second states that the kernel must start an executable called "/linuxrc" instead of the default /sbin/init and the last tells the kernel to mount as root /dev/ram0, which will point to the initrd loaded in memory. We'll talk extensively about initrd and linuxrc scripts later on so for the moment hold your horses.

Don't exit the chroot yet; we need to make some tuning and install a generic kernel.

You have completed the first, most boring part of the guide.

2. TUNING THE DIRECTORY TREE (AND OTHER IMPORTANT THINGS)

(a.k.a. fix Gentoo so it will run from the cd)

If for any reason you dropped out of the system we're building, chroot back into it.

The directory /var contains two huge directories that we won't put inside the finished livecd; they are "cache" and "db". These are portage-related and completely useless as you won't emerge anything from a running read-only livecd, so let's move them together with other portage components that will be left out of our disk:

```
cd /var

mv cache db /usr/lib/portage/

ln -s /usr/lib/portage/cache cache

ln -s /usr/lib/portage/db db
```

That's it for /var. As you will see later, /usr/lib/portage will be left out of our livecd, freeing some precious space.

One other thing we must do is to modify the checkroot service. If we don't it'll try to remount the root filesystem readonly, causing problems with unionfs and making the bootup fail.

Change the file so that it contains only the following:

/etc/init.d/checkroot:

```
#!/sbin/runscript 

 # Copyright 1999-2005 Gentoo Foundation 

 # Distributed under the terms of the GNU General Public License v2 

 

 depend() { 

         before * 

 } 

 

 start() { 

         return 0 

 } 

 

 

 # vim:ts=4
```

Nothing less, nothing more than this.

We're finished adjusting things.

Don't exit from the chroot yet.

3. KERNEL CONFIGURATION

(a.k.a.: beyond genkernel)

Writing a generic kernel configuration is far from trivial. We're lucky enough since genkernel does it for us when we need a generic kernel for a regular Gentoo installation, but that tool is not perfectly suited for the custom livecd we want to build; kernels generated with it rely on the functionality of genkernel's initrd, which contains a complex script we don't want to modify as it would make things way too complex.

My advice is to start with a simple kernel that runs on the hardware you own; you can go back inside our "build environment" (next section) later and spend some more time on kernel configuration once most of the difficult things have been dealt with.

If you feel like doing it right now but you still don't have the knowledge needed to do it, here's what I did the first time I built a livecd: I simply ran genkernel and stopped it while it was compiling. At that point genkernel had already placed a fine .config in /usr/src/linux. All I needed to do was to run "make menuconfig" and switch from "M" to "Y" anything I thought would be needed before mounting /, like IDE and SCSI drivers. Easy and fast, but I got a huge kernel with support for lots of hardware almost nobody owns.

Make sure you choose "Y" for ext2, squashfs and iso9660 filesystem support; you also need initrd support and you should make the default initrd size more than 9 megabytes.

Since we're going to use union, you'll have to include union support too. To keep things simple, please avoid doing emerge unionfs as it will only build a module. We want unionfs INSIDE the kernel. To get union inside the filesystem menu in menuconfig, download the appropriate version of unionfs for your kernel from the table on http://www.filesystems.org/project-unionfs.html and then untar the tarball, cd into the directory it created, and run patch-kernel.sh /usr/src/linux to patch your current kernel. Next time you run menuconfig, unionfs will be under File systems --> Miscellaneous filesystems --> Union fs support.

[thanks to peaceful for the correction]

Once you're done configuring, compile the kernel and install its modules; name the kernel bzImage "vmlinuz", copying it in /boot/isolinux/. If you want you can use a better name, like "kernel-2.6.12-gentoo-r2", but make sure you change isolinux.cfg accordingly.

You can now exit from the chroot. We won't be going back into our Gentoo installation for a while.

4. PREPARATION OF THE BUILD ENVIRONMENT

(a.k.a.: make "mkdir" sound cool)

The following list of directories describes the "environment" in which our livecd will be built:

```
source

backup

boot

usr-lib-portage

usr-include

usr-portage

usr-share-doc

usr-share-info

usr-share-gtk-doc

usr-share-man

usr-src

usr-X11R6-man
```

All of this dirs must be created under ${LIVEDIR}, except of course the directory "source" we have just filled with Gentoo c00ln3ss. Create all of them now.

So, how does it work? The directory usr-include will hold the contents of /usr/include, usr-portage the contents of /usr/portage and so on. This are some of the many dirs containing totally useless things that portage installed, like headers or documentation. We do need headers when we emerge something and docs to read up things we forgot, so instead of deleting them we're moving them out of the installation, keeping them nearby. In the end they'll be left out of the cd since we'll include only what's under the ${LIVEDIR}/source directory.

Before you actually move the files, take note of the following:

Note that we're moving /boot out of the system even though it'll obviously be required. That's ok, when we get to the point of building the livecd you'll see that it will be included on the disc after all, just not in the same way as the rest of the system. Indeed ${LIVEDIR}/source/* will be compressed inside a single file while we want the kernel to be present on the CD outside that file, so that it can be accessed by isolinux.

Here's the list of mv commands. The directories belonging to Xorg and gtk are included here as an example:

```
cd ${LIVEDIR}

mv              source/boot/*  boot

mv       source/usr/include/*  usr-include

mv       source/usr/portage/*  usr-portage

mv   source/usr/lib/portage/*  usr-lib-portage

mv     source/usr/share/doc/*  usr-share-doc

mv    source/usr/share/info/*  usr-share-info

mv     source/usr/share/man/*  usr-share-man

mv     source/usr/X11R6/man/*  usr-X11R6-man

mv           source/usr/src/*  usr-src

mv source/usr/share/gtk-doc/*  usr-share-gtk-doc

#WARNING it's NOT /source/usr/share/gtk/doc
```

In the same way you can move anything that you think isn't needed out of the base system, e.g. most of gcc. If you mess up you can always go back by moving things back under their original directory. At the moment, however, you should stick to this list; it won't save a huge space but it's good enough for our first prototype. After you've made your first iso you'll be able to go beyond this guide easily.

Now that we have cleaned our base system from uncool things we can't emerge anything anymore. To get back the ability to add software and read man pages we need to bind the directories under ${LIVEDIR} back to their original place under ${LIVEDIR}/source. Here's the script to do it, just to save some of your time. It also mounts proc and binds dev and sys so you can chroot into it immediately after you run it:

prepare_env:

```
#!/bin/bash

cd ${LIVEDIR}

mount -t proc                   none  source/proc

mount -o bind                   /sys  source/sys

mount -o bind                   /dev  source/dev

mount -o bind               usr-src/  source/usr/src

mount -o bind           usr-portage/  source/usr/portage

mount -o bind       usr-lib-portage/  source/usr/lib/portage

mount -o bind           usr-include/  source/usr/include

mount -o bind        usr-share-info/  source/usr/share/info

mount -o bind         usr-share-man/  source/usr/share/man

mount -o bind         usr-share-doc/  source/usr/share/doc

mount -o bind     usr-share-gtk-doc/  source/usr/share/gtk-doc

mount -o bind         usr-X11R6-man/  source/usr/X11R6/man 
```

Here is the script to umount everything so you don't have to waste time writing it:

release_env:

```
#!/bin/bash

cd ${LIVEDIR}

umount source/proc

umount source/sys

umount source/dev

umount source/usr/src

umount source/usr/portage

umount source/usr/lib/portage

umount source/usr/include

umount source/usr/share/info

umount source/usr/share/man

umount source/usr/share/doc

umount source/usr/share/gtk-doc

umount source/usr/X11R6/man
```

Now we're all set. We can "switch on and off" the directories needed to compile packages; while they're "switched on" we can chroot inside ${LIVEDIR}/source and emerge anything. If you want to backup your system before making some dangerous changes, just run prepare_env, umount sys dev and proc by hand and finally tar source/*.

For the advanced users: if you're wondering why I didn't just build an exclude list so I could pass it to mksquashfs, there's a simple reason. If you move something out of the base system and you're not sure if it really is unneeded, you can just mount proc, sys and dev and chroot inside the system to see if things still work. That's a lot of time saved since the alternative is to spend 20 minutes running the build script and burning the cd.

5. INITRD CREATION

(a.k.a.: head starts to spin)

An initrd is the image of a partition, usually formatted in ext2 (it must be little), containing some basic tools like mount and our linuxrc script. What we're going to do right now is to create an initrd that contains everything linuxrc needs.

Here is a simple list of things that happen when Linux boots up. It's not complete or exaustive, just good enough for what we have to do. Refer to the isolinux configuration I gave you in the first section as you read the list.

1- The kernel and initrd are loaded in the RAM

2- The kernel takes over and goes through a hardware recognition routine, activating all the drivers you compiled inside it. Anything compiled as module isn't usable yet.

3- The kernel mounts the root partition specified by the "root" parameter specified in isolinux's configuration. In our case root equals /dev/ram0, which is the device bound to the initrd that has been loaded. That means the kernel mounts the initrd as the root partition.

4- The kernel calls init. Since we passed the parameter init=/linuxrc, instead of /sbin/init the kernel executes /linuxrc. That's a script we'll write later (next section)

5- The linuxrc script takes over. What it can or cannot do depends on what we put inside the initrd (this section deals with just that). Kernel modules are still off-limits with the initrd we'll create. At the end the script will call the real /sbin/init

6- /sbin/init takes over. Gentoo boots normally going through all the services you activated.

Keep all this in mind and this section and the next will make a lot more sense. 

We're going to create an initrd and then write a linuxrc script, effectively completing the livecd "framework". Once we've gone through this we can finally backup everything and start building whatever system we want, be it it a MythTV box or a diagnostics system.

First of all, create an empty file, 8 MB should be enough:

```
dd if=/dev/zero of=${LIVEDIR}/boot/isolinux/initrd bs=1M count=8
```

Bind the file to a loop device and format it ext2:

```
losetup /dev/loop0 ${LIVEDIR}/boot/isolinux/initrd

mkfs.ext2 /dev/loop0
```

Now we have an 8 MB "partition file" bound to /dev/loop0 and we can mount/umount it and copy files in it at will.

Start by mounting it anywhere, laying out the basic directory structure of a root partion and touching some files:

```
mount /dev/loop0 /mnt/initrd

cd /mnt/initrd

mkdir etc dev lib bin proc new cdrom static dynamic union

touch linuxrc 

chmod +x linuxrc 

touch etc/mtab 

touch etc/fstab
```

Now we need to copy inside the initrd all the executables we will need. Here is a list:

```
/bin/sh 

/bin/cat 

/bin/mount 

/bin/umount 

/bin/mkdir 

/bin/chroot 

/bin/tar 

/sbin/pivot_root
```

All those files go under /mnt/initrd/bin. pivot_root goes there too. Copy them now.

Next we have to copy inside the initrd all the libraries needed by those executables we just copied. To find out which libraries you need, use the comamnd "ldd". Like this:

```
#> ldd /bin/sh

linux-gate.so.1 =>  (0xffffe000)

libreadline.so.5 => /lib/libreadline.so.5 (0xb7f72000)

libhistory.so.5 => /lib/libhistory.so.5 (0xb7f6b000)

libncurses.so.5 => /lib/libncurses.so.5 (0xb7f33000)

libdl.so.2 => /lib/libdl.so.2 (0xb7f2f000)

libc.so.6 => /lib/libc.so.6 (0xb7e42000)

/lib/ld-linux.so.2 (0xb7fad000)
```

Run ldd once for each executable and copy all the libraries listed by it under /mnt/initrd/lib. Ignore linux-gate.so.1. 

We need to populate /dev with devices so we have access to the hardware. Since we're not going to use udev in the initrd, we have to create the following devices by hand:

```
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
```

Console, null and tty are the bare minimun you can have. Then we have the hd*, which will let us mount the cdrom, while loop0 will be needed to mount the compressed (squashfs) root image. 

If your cd-rom drive is not an IDE or if you plan on adding support for non-IDE drives you'll need to create other devices and modify slightly the linuxrc script; however this guide will now proceed assuming you, like most people, own and use and IDE drive.

Don't umount the initrd yet.

Alternatively:

 *STrRedWolf wrote:*   

> 
> 
> Using Busybox in the initrd
> 
> Gentoo always builds a copy of Busybox, which is a small integrated subset of utilities.  It currently lives in /bin/busybox.  Instead of all those major utilities when building the initrd:
> ...

 

6. THE LINUXRC SCRIPT

(a.k.a.: back to sh)

The linuxrc script is very volatile and can explode in your face without any warning so pay extra attention.

The starting point is a situation in which we have unrestricted access to the whole PC and we can manipulate whatever is attached to it, provided we have put the necessary devices under /dev inside the initrd; the objective is to create an environment where our linux installation can run. Whatever modifications we have made to the system, like squashing it, must be "canceled"; we need to make them transparent to Gentoo so it finds everything it needs and can boot normally without any hacking of the base system. The tool we'll use to do all this is the linuxrc script.

First of all, here's a list of things you have inside the cd:

- livecd.squashfs: this file contains the whole root, minus what we moved out of it. It's compressed and we can mount it with mount -o loop.

- /boot: here we have things we're not going to care about (kernel, initrd, isolinux) because by the time the linuxrc script is executed they all have long since finished doing their job.

Mainly we need to do three things, which will break down to several commands:

1- Since right after booting we don't know where the livecd is, even if that's where the kernel was loaded from, we need to probe all the IDE devices we can access through /dev/hd*.

2- Once we have found and mounted our livecd, we need to provide the "root partition"; we will simply mount -o loop livecd.squashfs. We also need to solve the problem of having rw access to the system, which will involve creating a ramdisk and merging the ramdisk and the squashed root image using unionfs. The union between the two filesystems will be mounted under /union.

3- We have to use pivot_root. The objective here is to change / from the initrd's root to /union; at that point we can simply call init to finally go all the way to the console/Gnome/KDE.

I'll now list and comment each code fragment. Don't copy/paste yet, you'll find the whole script in one piece at the end of this section. If you're impatient or very knowledgeable, you can skip the next part, get the script and move on.

We start like in any script, declaring who's going to interpret it. In this case, sh. Then since we have placed all our executables in /bin we set PATH to that directory:

```
#!/bin/sh

export PATH=/bin
```

Next we should get the kernel parameters since some of them may be important for init. When we call init we'll pass them on. To get them we have to mount /proc, they'll be inside /proc/cmdline:

```
mount -t proc none /proc 

CMDLINE=`cat /proc/cmdline` 

umount /proc
```

Then we need to find the livecd; this fragment should be almost self-explanatory: we loop trying to mount hda, hdb, hdc and hdd until we find the right one. When the loop ends either we have found the cd or something has gone terribly wrong. In the second case we're stuck and we must stop.

```
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
```

So, have we found it or not?

```
if [ "${CDROM}" == "" ] 

then 

  echo "FATAL --- LIVECD NOT FOUND"

  exec /bin/sh 

  exit 

fi 

echo "LiveCD found in /dev/$CDROM"
```

Ok we're done gathering data. From now on everything we do will create, step by step, a sane environment we will be able to boot Gentoo inside of.

First of all, we have to mount livecd.squashfs, which contains our compressed root image. The target is /static.

```
mount -t squashfs -o loop /cdrom/livecd.squashfs /static
```

Now we have to mount a ramdisk under /dynamic so we can later merge static and dynamic in /union.

The command to create a ramdisk is:

```
mount -t tmpfs -o size=<size> none /target/directory
```

This will mount a ramdisk of the specified size under the specified target directory. The ramdisk will occupy 0 bytes until we start filling it and will grow and grow until it reaches the specified size; it won't grow bigger than that.

Here's what will go inside the linuxrc script:

```
mount -t tmpfs -o size=300 none  /dynamic
```

If you think 300 is too big as a limit feel free to reduce it (or increase it).

Finally we have to merge /static and /dynamic. The command to create a union is:

```
mount -t unionfs -o dirs=/dir1=ro,dir2=rw,dir3=ro,dir4=rw unionfs /union
```

Basically we're saying that we want to merge those 4 directories, dir1 and dir3 are read only while dir2 and dir4 are writable. The files in each directory will appear all under /union as if they were all inside the same directory. If there are files that have the same exact name, the file belonging to the directory that appears first -- more on the left -- in the mount command gets the priority. The same mechanism is used to decide where files are written; in this particular example everything will be written in dir2/ until there's no space left, then dir4 will be used.

Our case is particularly simple; we have a read-only directory, /static, which holds all of the files. The other directory, /dynamic, is writable and enpty. This means we don't have to worry about priorities at all, we'll just merge the two dirs and be done with it. This is what we'll put inside the linuxrc script:

```
mount -t unionfs  -o dirs=/dynamic=rw:/static=ro  unionfs  /union
```

Simple, isn't it?

To make things easier to understand here is an image I've made that describes where everything is mounted at this point in the linuxrc execution:

```
Before pivot_root:

/ (ext2 initrd)

|

|----- cdrom/ (iso9660) --->---|

|                              |

|                  livecd.squashfs via loop

|                              |

|----- static/ (squashfs) <----|

|            |

|            |----------->----------\

|                                  union-|

|----- dynamic/ (tmpfs) ------->----/    |

|                                        |

|                                        |

|                                        |

|----- union/ (unionfs) <----------------|

```

I hope it's as clear as it seems to me. As you can see our "root partition", the one containing the system we want to boot, is mounted under union/. We want it to be mounted as / and to do that we have to use the pivot_root magic, like this:

```
cd /union

pivot_root . initrd
```

The pivot_root command can be a little tricky to understand. After we have run it, /new will be our /; the old /, which is the initrd, will be mounted uder /initrd which is inside the compressed root (livecd.squashfs). Got it? Check the man page and look at this other image:

```
After pivot_root:

/ (unionfs, was "/union") <------------------|

|                                            |

|----- initrd/ (ext2 initrd, was "/")        |

          |                                  |

          |----- dynamic/ (tmpfs)-->---\     |

          |                           union--|

          |            |------->-------/

          |            |

          |----- static/ (squashfs) <--|

          |                            |

          |----- cdrom/ (iso9660) -----|
```

Now we have modified the environment to the point that running /sbin/init is enough to boot Gentoo. However we're not going to do it yet, and here is why:

As you can see, the initrd is still mounted under /initrd. That means 10 megabytes of RAM are still taken by things we don't need anymore. Indeed, any executable we run from now on will be run from our compressed root image, not from the initrd; the initrd itself is now completely useless.

The problem is, we can't just go on and umount /initrd. We would get a "/initrd is busy"-like error message. There are 2 things keeping us from umounting the initrd:

1) The most obvious one: our cdrom, dynamic and static are still mounted under /initrd.

2) The "sh" that's executing our linuxrc script is the one we ran from the initrd! So even if we get rid of the cdrom we still can't umount initrd until /initrd/bin/sh has died.

To claim those 10 megabytes back we're going to use some more magic:

 - Check out the mount manpage. There's a "move" option. Using that we can move those mountpoints somewhere else.

 - Instead of trying to umount the initrd from the the linuxrc script, which is being executed by /initrd/bin/sh, we're going to spawn a new sh -- this time it will be the sh executable that resides inside the compressed root image -- telling it in advance what it has to do: umount the initrd and run /sbin/init. By the time the new sh is actually executed the old sh from the initrd will be dead and umounting the initrd won't be a problem anymore.

Here is a last image. We have just moved cdrom, static and dynamic from /initrd to /mnt:

```
After "mount -o move":

/ (unionfs) <---------------------------|

|                                       |

|----- initrd/ (initrd)                 |

|                                       |

|----- mnt/dynamic/ (tmpfs) -->--\      |

|                               union --|

|                |------->-------/

|                |

|----- mnt/static/ (squashfs) <-----|

|                                   |

|----- mnt/cdrom/ (iso9660)---------|

```

Now the initrd is free so later we'll be able to umount it. Here is the code fragment:

```
mount -o move /initrd/dynamic /mnt/dynamic

mount -o move /initrd/static /mnt/static

mount -o move /initrd/cdrom /mnt/cdrom
```

One last thing we have to do about mount points is updating /etc/mtab with the contents of /proc/mounts:

```
mount -t proc none /proc

cat /proc/mounts > /etc/mtab

umount /proc
```

And finally we spawn a new sh which will spawn /sbin/init and let /initrd/bin/sh terminate its execution, freeing initrd completely and making it umountable.

```
exec chroot . /bin/sh <<- EOF >dev/console 2>&1 

umount /initrd

echo "Starting init!"

exec /sbin/init ${CMDLINE} 

EOF
```

Here's the linuxrc script in its entirety:

```
#!/bin/sh

export PATH=/bin

for x in hdc hdd

do

   mount -t iso9660 /dev/${x} /cdrom

   if [ "$?" == "0" ]

   then

      CDROM=${x}

      break

   fi

done

if [ "${CDROM}" == "" ]

then

   echo "FATAL --- LIVECD NOT FOUND"

   exec /bin/sh

   exit

fi

echo "LiveCD found in /dev/${CDROM}"

mount -t squashfs -o loop /cdrom/livecd.squashfs  /static 

mount -t tmpfs -o size=300 none  /dynamic 

mount -t unionfs  -o dirs=/dynamic=rw:/static=ro  unionfs  /union 

cd /union

pivot_root . initrd

mount -o move  /initrd/dynamic  /mnt/dynamic

mount -o move   /initrd/static  /mnt/static

mount -o move    /initrd/cdrom  /mnt/cdrom

mount -t proc none /proc

cat /proc/mounts > /etc/mtab

umount /proc

exec chroot . /bin/sh <<- EOF >dev/console

umount /initrd

echo "Starting init!"

exec /sbin/init

EOF
```

Save the script and umount the initrd. Under ${LIVEDIR}/source create the directories we're going to use with the linuxrc script: /initrd and /mnt/cdrom, /mnt/static, /mnt/dynamic.

Run release_env.

7. BACKUP

(a.k.a.: run for cover)

It's time to do some tarring. We have a fine base system we can use to build anything we have in mind, to make sure we can get back to this point anytime let's store it somewhere safe.

First create a "backup" directory under ${LIVEDIR}, then tar the entire content of ${LIVEDIR}/source under ${LIVEDIR}/backup/basesys-backup.tbz2. This means running prepare_env, umounting by hand sys, dev and proc and then running the tar command. Maybe it would be best to create a gz archive rather than bz2 since it's way faster and you lose only a little space.

8. EMERGE NEEDED APPS - KEEPING IT SLIM

(a.k.a.: everybody knows, but just in case...)

Run prepare_env if needed, chroot into ${LIVEDIR}/source and set the USE flags according to the kind of Gentoo installation you have in mind. Here are some tips about building a slim base system, most are common knowledge.

- Don't use ccache! Its huge cache goes under /root, if you want to use it at least remember to move it out of the system.

- Make sure what you have in mind isn't too broad. We're not replacing Kanotix, what we want is a fast system that is useful in some very specific cases. E.g. if you want a MythTV/Freevo box make sure you don't add anything else. If you want a diagnostics/disaster recovery system then avoid building X. And so on.

- Thanks to KDE having been divided in its single components, you can have a very light KDE installation. Emerge kdebase-startkde and build up from there making sure you don't pull inside the system unneeded crap.

- Avoid redundancy. If you're a KDE user just use Konqueror and leave Firefox out. As great as FF is, you don't need it for 99% of the sites out there, Konq can replace it perfectly. The same is true for most DE-related things.

- Rather then using OOo or KOffice, go for Abiword and Gnumeric. They're fast, light and can replace MS apps perfectly for most users.

- Rather than going directly for MythTV, give Freevo a chance. You'll find several HOWTOs around the net helping you set it up and it makes for a great mplayer/xine interface while occupying much less space than MythTV.

- CONSIDER USING KDRIVE! Soon we'll be able to cut down on xorg's size thanks to the modular xorg, until then kdrive is very very tiny (guess what the Damn Small Linux guys are using  :Wink: ). It may not be suited for what you have in mind, so check carefully what it can and what it cannot do (e.g. scrolling down pages in Konqueror is very slow under Kdrive).

Once your box is done torturing your HD, do whatever amount of configuring you need to do. If you built X don't configure it yet (more on that later). Your DE will have to wait, too, since you can't run it until X has been configured. Don't leave the chroot yet.

9. X AUTOCONFIGURATION

(a.k.a.: plug & pray)

To make the livecd truly able to run on anything, we need to put in place some kind of X autoconfiguration service that kicks in right before the login manager (or wm or whatever you use) and lays out a working xorg.conf. The package x11-misc/mkxf86config does it; pay special attention to its dependency sys-apps/hwsetup, you may want to read documentation about it as it's useful for more than creating a xorg.conf. If you're a good scripter you may build some interesting things with it. Let's move on.

```
emerge mkxf86config -av
```

Once we have emerged the needed packages we can go on activating the service and making some changes.

First of all, add the mkxf86config service to the default runlevel.

The executable is /usr/sbin/mkxf86config.sh, open it with your text editor and take a look. As you can see the program assumes that hwsetup has been already run once; hwsetup works by probing every device you can imagine -- I think it uses /proc or /sys, actually -- and reporting what it actually finds. Its output is saved in a number of text files under /etc/sysconfig/.

Exit the editor and run "hwsetup". It'll take  a little while. Once you get the console back, look inside /etc/sysconfig and check the text files it created, especially xserver. Those are the files mkxf86config will work with. Now delete them all, they are good only for the machine you've just run hwsetup on.

Imagine the livecd is booting. The mkxf86config script starts... and errors out: it didn't find hwsetup's output files under /etc/sysconfig. That means the first thing we have to do is to run hwsetup right before it's needed; instead of writing a service just for that little program we're going to hack /etc/init.d/mkxf86config. Modify the start function:

```
start() {

    ebegin "Creating X Configuration"

    /usr/sbin/hwsetup

    /usr/sbin/mkxf86config.sh

        eend $?

}

```

Easy enough. Now mkxf86config works so add the related service to the default runlevel.

It's important to know that mkxf86config uses /etc/X11/xorg.conf.in as a template to generate a working xorg.conf; if the script doesn't work for you, try forcing some settings hacking the xorg.conf.in. You'll have to use a trial-and-error approach, but in the end you should get it to work quite easily, although it'll be time-consuming. An extended treaty on the quirks of mkxf86config is beyond the scope of this guide.

If you need more than just a working X, e.g. you want KDE/Gnome, you can't move on yet; you'll want to configure KDE/Gnome going through the inital configuration, theming it and finally setting your preferences. To do that, start by dropping out of the DE you're inside right now. Once you're back to the console with no X running, just chroot inside ${LIVEDIR}/source and run hwsetup && mkxf86config.sh by hand. Don't try to start the service, it won't work. Once mkxf86config.sh is done just run the login manager/wm/whatever and configure to your heart's content. Remeber to delete /etc/sysconfig/* and /etc/X11/xorg.conf once you're done.

If you have installed X you're probably going for a regular Gentoo system with a DE like KDE or Gnome; if that's the case and you care about giving the normal unprivileged user access to the partitions on his hard disks read the next section. Otherwise you can exit from the chroot and run release_env. We're ready to build the livecd!

10. HD PARTITIONS AUTODETECTION

(a.k.a. update fstab)

Here's a horrible script (that works) to update fstab at boot time so that the normal user has the ability to mount hard-disk partitions.

Create the directoy ${LIVEDIR}/source/mnt/temp. Then create a script under /sbin and make it executable only by root. Here's the content of the script (most of you can script better than me, if you make a better version let me know and I'll put it here):

hd_autodetect:

```
#!/bin/bash 

 

 #Get a list of partitions 

 fdisk -l | grep /dev | awk '{print $1}'| sort | uniq | grep /dev > /tmp/disklist 

 

 #Get a list of swap partitions 

 fdisk -l | grep swap | awk '{print $1}' > /tmp/swaplist 

 

 #Get a list of NTFS partitions 

 fdisk -l | grep NTFS | awk '{print $1}' > /tmp/ntfslist 

 

 #Use a ludicrously complicated way to subtract swaplist and 

 #  ntfslist from disklist because my coding skills suck

 cat /tmp/swaplist /tmp/ntfslist >> /tmp/disklist 

 cat /tmp/disklist | sort | uniq -c | grep \ 1\ | awk '{print $2}' > /tmp/finaldisklist 

 

 #Go through every partition that isn't swap or NTFS and if 

 #  the kernel can mount it then add a line for it in fstab 

 for i in `cat /tmp/finaldisklist` 

 do 

    mount $i /mnt/temp 

    if [ $? -eq 0 ] 

    then 

       DISK=`echo $i | cut -c 6-` 

       echo "/dev/$DISK /media/$DISK auto users 0 1" >> /etc/fstab 

       mkdir /media/$DISK -p 

       umount /mnt/temp 

    fi 

 done 

 

 #Same thing but for NTFS partitions. The line added 

 #  to fstab is different because the NTFS module, like 

 #  NTFS itself, sucks 

 for i in `cat /tmp/ntfslist` 

 do 

    mount $i /mnt/temp 

    if [ $? -eq 0 ] 

    then 

       DISK=`echo $i | cut -c 6-` 

       echo "/dev/$DISK /media/$DISK auto users,umask=000,ro 0 0" >> /etc/fstab 

       mkdir /media/$DISK -p 

       umount /mnt/temp 

    fi 

 done 

 

 #Activate the swap partitions for added pwnage 

 for i in `cat /tmp/swaplist` 

 do 

    swapon $i 

 done
```

Removable media should be handled by KDE/Gnome just fine and doesn't need an fstab entry.

Call the script from local (add "/sbin/hd_autodetect" in /etc/conf.d/local.start) so that it runs before Gnome or KDE have a chance to bring up the desktop and you'll get all those nice HD partition icons. If you don't want to stop the booting process for the time needed to mount and umount all the partitions you can add "&" after "/sbin/hd_autodetect".

Exit from the chroot and run release_env, we're going to write the build scripts and create our first iso!

11. LIVECD BUILD SCRIPTS

(a.k.a.: your life just got 20 mins shorter)

It's now time to waste hours building isos. The build process will take ~15 mins plus another ~5 to burn the image; that's too short to have dinner and too long to avoid boredom. In other words, it sucks.

Here's a rough list of the things we have to do to build an image:

1- Clean out any temporary files created during our test runs.

2- Copy the ${LIVEDIR}/boot directory in a temporary dir called ${LIVEDIR}/cdroot

3- Create a squashfs image of the ${LIVEDIR}/source directory and put it under ${LIVEDIR}/cdroot

4- Build an iso that contains ${LIVEDIR}/cdroot/* and is bootable

And here is the script that does it, self-explanatory I believe:

build:

```
#!/bin/bash 

mkdir cdroot

cp -a boot cdroot/

cd source

rm -rf var/tmp/* 

rm -rf var/run/* 

mkdir var/run/dbus

rm -rf var/lock/* 

cd ..

rm -rf source/tmp/* 

rm -f source/etc/mtab 

touch source/etc/mtab 

echo squashing

mksquashfs source/ cdroot/livecd.squashfs

echo building iso

mkisofs -R -b boot/isolinux/isolinux.bin -no-emul-boot -boot-load-size \

4 -boot-info-table -c boot/isolinux/boot.cat -iso-level 3 -o livecd.iso cdroot/
```

The last command may seem a little cryptic; basically it installs isolinux inside the iso in such a way that a cd burned from that iso will be bootable. Don't waste time trying to decipher it, I lifted it right off of isolinux's site myself. You can start worrying about it if the cd doesn't boot at all  :Wink: .

The rest is quite clear: the output image is called livecd.iso, which will appear right under ${LIVEDIR}/, built from the contents of ${LIVEDIR}/cdroot/.

NOTE: remember to delete the cdroot directory every time you want to make a full build of the livecd running the "build" script. And backup your isos!

After you have built the squashfs image once, you won't have to rebuild it every single time you make a little change.The squashfs image contains only the read-only part of the system. If you modify things under /boot, e.g. you make a correction to the linuxrc script inside the initrd, you don't need to recreate the whole squashfs image, just rebuild the iso:

build_iso:

```
#!/bin/bash

mkisofs -R -b boot/isolinux/isolinux.bin -no-emul-boot -boot-load-size \

4 -boot-info-table -c boot/isolinux/boot.cat -iso-level 3 -o livecd.iso cdroot/
```

If you have followed the guide properly you should now be able to build your first iso. Do it now!

12. TRY IT OUT!

(a.k.a.: burn baby, burn!)

Once you have the livecd.iso just burn it on some rewritable media. Slap the cd inside a machine, reboot and look out for any kind of error message. Here is what might go wrong:

- First of all, even if we're using isolinux we can't be sure the cd will boot on all of the machines on the Earth. The isolinux homepage states clearly that there are a lot of buggy BIOSes around the globe and if you're unlucky enough to own one please go read on the isolinux homepage what alternatives you can use.

- Once isolinux takes over, it'll load the kernel and initrd. If it doesn't find them check isolinux.cfg for typ0s.

- Once the kernel and initrd have been loaded, the kernel will start the hardware recognition routine. Once it's finished, the kernel will try to mount the initrd; if you get an error now, it means you compiled ext2 as a module. Compile it IN. The linuxrc script will then be executed instead of init; a lot of things could go wrong here.

- If the linuxrc script doesn't find the cdrom drive, you probably put the wrong devices inside the initrd under /dev. Check them out. If it cannot mount the cd or cannot mount the squashfs/unionfs image please check the kernel's configuration. You probably compiled as modules some filesystems that are needed, namely iso9660, squashfs and unionfs. Fix your kernel.

If the script gets to the point when it runs init and you see Gentoo starting, you've made it!

Any error you get after init starts will be probably caused by bad Gentoo configuration.

If everything's OK, good job! You have completed the basics. Now you must refine the system configuration until it's perfect. Good luck!

13. ADDING MORE ROOT IMAGES

(a.k.a.: two-seats flying saucer)

[HELD UP]

14. RUN FROM RAM MODE

(a.k.a.: process killed: out of memory)

[HELD UP]

15. FAQ && QUIRKS && BUGS

(a.k.a.: ...but does it run Linux?)

Q. Can I turn my current Gentoo system in a Livecd?

A. Sure, but it isn't covered in the guide yet. You'll have to either mount the root partition from another Linux system or copy /usr, /var, /lib etc etc in ${LIVEDIR}/source. Either way, when you have the whole system isolated inside a directory you can follow the guide. Start from the beginning and go through the FIRST STEPS section figuring out what kind of modifications you have to make to the system (fstab, install isolinux etc etc). The remaining sections should be followed normally.

Q. How much can I fit inside a CD/DVD?

A. That's quite difficult to say because in your system there are a lot of things like text files that will be compressed so much they'll almost diappear but also a lot of other things like jpg images that are already compressed and won't shrink any more. In an effort to give you an idea of how much compression you can expect, I can tell you that my ~1.1 GB source produces a ~306 MB iso.

Known quirks

1) Initrd umounting

I'm not sure but it seems that since the switch to unionfs I can't umount the initrd. I have to debug this properly, anything you find out let me know.

2) Rebooting doesn't work

I'm trying to figure out why unionfs prevents the system from rebooting properly, I'll probably have to hack some init script. As always, anything you find out...

temporary solution:

Change halt.sh:

```
grep "^/dev/" /proc/mounts | grep -v cdrom | grep -v static \ 

       | cut -d " " -f 1 | sort | uniq > /tmp/mounted

for i in `cat /tmp/mounted` 

 do 

         mount -o remount,ro $i 

         umount $i 

 done 

 

 sync && sync && sync 

 

 sleep 3 

 

 if [[ -f /etc/killpower ]] ; then 

         UPS_CTL=/sbin/upsdrvctl 

         UPS_POWERDOWN="${UPS_CTL} shutdown" 

 elif [[ -f /etc/apcupsd/powerfail ]] ; then 

         UPS_CTL=/etc/apcupsd/apccontrol 

         UPS_POWERDOWN="${UPS_CTL} killpower" 

 fi 

 

 if [[ -x ${UPS_CTL} ]] ; then 

         ewarn "Signalling ups driver(s) to kill the load!" 

         ${UPS_POWERDOWN} 

         ewarn "Halt system and wait for the UPS to kill our power" 

         /sbin/halt -id 

         while [ 1 ]; do sleep 60; done 

 fi 

 

 halt -i -f -d -h -p 
```

Change reboot.sh:

```
grep "^/dev/" /proc/mounts | grep -v cdrom | grep -v static \ 

       | cut -d " " -f 1 | sort | uniq > /tmp/mounted 

 for i in `cat /tmp/mounted` 

 do 

         mount -o remount,ro $i 

         umount $i 

 done 

 

 sync && sync && sync 

 

 sleep 3 

 

 /sbin/reboot -idpk 

 

 # hmm, if the above failed, that's kind of odd ... 

 # so let's force a reboot 

 /sbin/reboot -f 
```

Make sure the modified versions are the first in your PATH and modify inittab so they get called. Also modify kde/gdm configuration accordingly if you use them.

[thanks to schneekater for his help on this]

16. SPECIAL THANKS

To the Gentoo community for its continued support during my first year of Gentoo Forums membership.

To Yuki Kajiura. Without your soundtracks keeping me sane this guide wouldn't exist.

To my cat. Without your frantic jumping on and off my keyboard the scripts in this guide wouldn't exist.

This guide has been written with Kate under KDE 3.5 running over a SourceMage installation.

----------

## dbasetrinity

Nice looking How to, I think i shall give it a try

----------

## linuxchimp

have you considered using unionfs for writing to the filesystem?

----------

## Gotterdammerung

really nice indeed.

----------

## MixMax

If this would use unionfs this would be perfect howto. There is a small howto in the last livecd topic (somewhere in the early pages) how to get livecd with unionfs (recoment it).

----------

## Lepaca Kliffoth

Sorry guys for some reason I stopped being notified of your replies. If you want me to add unionfs support please explain the advantages of it. Then if I think it's interesting I'll test and add it. Sorry but  don't have the time to check things myself so give me a hand ^^

edit: actually, I did have some time today and managed to look into the unionfs thing. I'm going to add it to the guide during the weekend; actually, it'll replace the current symlink mess and you won't have to sweat so much to make things writable. Just give me some time to determine the best directory layout and test stuff.

----------

## Lepaca Kliffoth

I have switched one of my livecds to unionfs. Great stuff. However there's one outstanding bug in that particular liveced, as soon as I either fix it or make sure it doesn't have anything to do with union I'll update the guide. Anyone who's following the guide right now (probably nobody, heh) be warned that it will change considerably, so if you want to go on with the current one save it somewhere on your disk! You have time until tomorrow evening (GMT+1). Any section dealing with the linuxrc script, the initrd and/or the build environment will change. The section about tuning the directory layout will be completely rewritten. The livecd build scripts will change too since they're tied to the build environment.

----------

## thedangerouscrew

i have been trying to make a slax like livecd and the only thing that is keeping me

 from getting it to work is that unionfs craps out when i boot my cd.

i get "unable to handle kernel null pointer"

i have done some research on this and haven't found much help. needless to say i haven't

 gotten this resolved. 

forums i visited:

http://slax.linux-live.org/forum/

http://www.knoppix.net/forum/

i wish you luck and i will post any helpfull info i find

----------

## thedangerouscrew

ok i fixed my problem.  what i did to fix my problem is that i

downgraded to unionfs-1.0.11.

this should helps if you were getting the same error i was

----------

## Lepaca Kliffoth

My problem is that QT claims it can't write in some temp file under /usr/tons/of/subdirs and KDE doesn't start. I have to figure out what the hell is happening, which is exactly what I'm starting to do right now. I had stability problems (oopses) with union but instead of downgrading I upgraded to 1.1.1 and now I get no oops.

When I'll update the guide one of the improvements will be that we'll be able to umount the initrd and claim 10 MB back. The upgrade will happen in 10-12 hours from now. Shortly after I'll clean out the "run from ram" section and by the end of the week you'll get a proper howto for that too.

----------

## Gotterdammerung

I have a system if KDE, Qt, OpenOffice, etc installed, and I plan to create a stage4.tgz-like backup file, or a LiveCD. In case it will become a LiveCD, what it is the maximum size it may reach in order to still fit a CD?

Thanks!

----------

## Lepaca Kliffoth

 *Tleilaxu wrote:*   

> I have a system if KDE, Qt, OpenOffice, etc installed, and I plan to create a stage4.tgz-like backup file, or a LiveCD. In case it will become a LiveCD, what it is the maximum size it may reach in order to still fit a CD?
> 
> Thanks!

 

This is a strange question. 700 MB?  :Razz:  If you mean how much you can compress the system using squashfs you can't tell until you've compressed it and have seen the size of the image; for reference I can tell you the source for the livecd I test things on is 1.1 GB and it produces a 310 MB iso.

----------

OK newsflash: KDE doesn't work with uonionfs and kernel 2.6, no matter what. I'm putting on hold the switch to unionfs until this problem has been solved. If you're curious about why it doesn't work, all I can tell you is that DCOP doesn't work at all. I have no idea about the _real_ why.

For those of you who still want to switch to unionfs, expect an addition to the guide by tomorrow (sorry but it's not top-priority anymore as there's no way to tell how many bugs could arise from using union at this point).

----------

## Gotterdammerung

 *Lepaca Kliffoth wrote:*   

>  *Tleilaxu wrote:*   I have a system if KDE, Qt, OpenOffice, etc installed, and I plan to create a stage4.tgz-like backup file, or a LiveCD. In case it will become a LiveCD, what it is the maximum size it may reach in order to still fit a CD?
> 
> Thanks! 
> 
> This is a strange question. 700 MB?  If you mean how much you can compress the system using squashfs you can't tell until you've compressed it and have seen the size of the image; for reference I can tell you the source for the livecd I test things on is 1.1 GB and it produces a 310 MB iso.

 

That will do. Thanks!

----------

## thedangerouscrew

i've had that problem before on a hd install a couple of times and it been a permission

problem. i can boot my live cd into kde but i'm running as root. i don"t know if it works

for a user account

note: in order for unionfs to work on a live cd you have to disable mounting rootfs

as ro during bootup

http://www.unionfs.org/

----------

## cheater1034

Looks pretty nice  :Wink:  but I prefer using genkernel's initramfs (easier and more compatible)

Perhaps add a step 'Adding a motd'

which is just adding words to /etc/motd

e.g.

```
# cat /etc/motd

Welcome to the super livecd

Type 'gdm' to get started!

visit http://website.com for more information!
```

Also, what I do is...

# emerge livecd-kconfigs

(Fetch the all-over compatible gentoo livecd configurations)

# cp /usr/share/livecd-kconfigs-2005.1/x86/2.6.12-smp /usr/src/linux/.config

(for my amd64 it is, .../livecd-kconfigs-2005.1/amd64/2.6.12-smp)

Then I edit it as necessary, i add reiser4 personally (after patching gentoo-sources) but you could do things like ALSA, etc

# cd /usr/src/linux; make menuconfig

Then, after setting up gensplash I build it with...

# genkernel all --gensplash=livecd-2005.1 --no-clean

Then edit isolinux.cfg for splash...

# nano /isolinux/isolinux.cfg

LABEL ...

APPEND ... vga=791 splash=silent,theme:livecd-2005.1 quiet CONSOLE=/dev/tty1 ...

Then you have your initramfs-genkernel-gentoo-r* and kernel-genkernel-gentoo-r* in /boot and are ready to go.

I think it is easier, and it is the most compatible thing you are going to get  :Smile: 

----------

## Lepaca Kliffoth

 *thedangerouscrew wrote:*   

> i've had that problem before on a hd install a couple of times and it been a permission
> 
> problem. i can boot my live cd into kde but i'm running as root. i don"t know if it works
> 
> for a user account
> ...

 

Every single KDE component crashes. On the unionfs mailing list people are saying that KDE doesn't work on 2.6+union. What can I do?  :Sad: 

 *cheater1034 wrote:*   

> Looks pretty nice  but I prefer using genkernel's initramfs (easier and more compatible)

 

If you mean the kernel config is the most compatible we can get, sure. I don't see how the initramfs is more compatible, though, since in my initrd I only mount and umount things. Maybe you mean it's got more features? I can assure you that the initrd I've explained (which is pretty much the same as veezi's) has worked flawlessly on many pcs.

 *cheater1034 wrote:*   

> Perhaps add a step 'Adding a motd'
> 
> which is just adding words to /etc/motd
> 
> e.g.
> ...

 

Next time I update I'll put this in the guide  :Wink: 

 *cheater1034 wrote:*   

> [code]Also, what I do is...
> 
> # emerge livecd-kconfigs
> 
> (Fetch the all-over compatible gentoo livecd configurations)
> ...

 

I'll test this and put it in the kernel configuration section of the guide.

edit: oh and I'm still working on the unionfs addition for those who want to use it. Sorry but everything always takes longer than I think

----------

## cheater1034

 *Lepaca Kliffoth wrote:*   

>  *thedangerouscrew wrote:*   i've had that problem before on a hd install a couple of times and it been a permission
> 
> problem. i can boot my live cd into kde but i'm running as root. i don"t know if it works
> 
> for a user account
> ...

 

I was just considering the initrd, it is used on the Gentoo LiveCD's (which boot on EVERYTHING) so just considering, it might be a bit easier

----------

## Lepaca Kliffoth

 *cheater1034 wrote:*   

> I was just considering the initrd, it is used on the Gentoo LiveCD's (which boot on EVERYTHING) so just considering, it might be a bit easier

 

No problem, just making sure what you were saying. The linuxrc inside the initramfs is quite complex and diving into it would have taken too long. The one I propose is quicker to understand and easier to mantain and add things to. As for booting, if isolinux loads the kernel properly you're done (it's that simple). There's nothing in the initrd making booting any easier. The only big problem is creating a truly generic kernel, but now that you have told me about the gentoo configuration being available in portage (I didn't know) I can add that to the kernel config section and hopefully consider the gap closed.

----------

## thedangerouscrew

my live cd

kernel: 2.6.12.2 (compiled by me)

unionfs v1.0.11 (any version higher than this, is too buggy)

and kde

it works on my live cd but i'm using slackware

you might want to take a look at this site http://slax.org

live cd with kernel 2.6.13 kde and unionfs

the sight also has a forum

----------

## Lepaca Kliffoth

 *thedangerouscrew wrote:*   

> my live cd
> 
> kernel: 2.6.12.2 (compiled by me)
> 
> unionfs v1.0.11 (any version higher than this, is too buggy)
> ...

 

Which version of KDE are you talking about? I tested 3.5.0 and it doesn't work on any unionfs version.

----------

## thedangerouscrew

i'm running  kde v3.4.2

are you using portage or are you compiling by hand?

i would compile by hand and avoid gentoo's manipulation of the source.

especialy with unionfs.

----------

## Lepaca Kliffoth

I'm using portage of course. Compilation by hand is WAY beyond the scope of this guide. Remember that this is not a support request to make KDE run on unionfs. This is a guide explaining how to make a livecd and I'm not going to include unionfs if it doesn't work by default. As soon as the problem is fixed (whatever it is, probably socket madness since it's DCOP crashing and making everything else crash too) and KDE, which is what many ppl use, can work over union I'll modify the guide. Anyway, I'm going to make an addition to the guide explaining how to use Union as soon as I have some time -- I had to work hard this last few days -- what's being held up is only its integration inside the guide.

----------

## thedangerouscrew

noted

----------

## victordavion83

I have a few questions before I go out trying to make my own LiveCD. First thing is that I would like to make one that will work for everyone in my house and naturally the priority would be that it works on my computer first than everyone elses afterwards. 

One of the things I want it to be is a XFCE4 setup with some basic programs (web browser, office programs, IM, etc.) and wireless support when I boot. I know how I can do this on my computer (emerge rtl8180) but I know my uncle's computer would need ndiswrapper for his to work. Is there a way I can make a dynamic script to load his wireless card on start?

I also would like to include the gentoo installer if possible on the LiveCD as it's updated and becomes more official. I know the way I installed Gentoo on this computer was through the LiveDVD RR4 and he seems to have setup the installer to allow a direct copy of what is on the DVD onto your hard drive as well as build your own install. I would want to have both of those options available to me (so maybe later it could be used by anybody).

Another thing is the question of burning it onto a CD or a DVD. Will having a DVD speed up the processing at all and if so how would I go about making an image for the DVD?

For my last question I would like to ask if it's possible for me to graphically login to the setup I have created to change the layout of the programs I've installed and if so how would I go about doing it? My goal being to make the layout as close as possible to what my family would expect it to look like.

I don't mind if you don't feel like writing out a whole thing and rather link me to stuff already written to find the answers but I would love to do this for my family so they would always be able to use their systems after I'm done making this thing. Then maybe later I could come back and top the icing by asking the question of allowing on the same disk an option to load the AMD64 or the 32bit version.

I appreciate the time you have put into making this guide. I'm trying to follow it now but will wait for the replies before I get myself in way too deep. =)

EDIT: Clarified a graphical login

----------

## Lepaca Kliffoth

 *victordavion83 wrote:*   

> One of the things I want it to be is a XFCE4 setup with some basic programs (web browser, office programs, IM, etc.) and wireless support when I boot. I know how I can do this on my computer (emerge rtl8180) but I know my uncle's computer would need ndiswrapper for his to work. Is there a way I can make a dynamic script to load his wireless card on start?

 

[warning: I don't own anything wireless] I think you could just have support for both cards and blindly try to start both; otherwise emerge hwsetup and run it. Look in /etc/sysconfig/ and see if there's something in those text files you can use in a script. Most probably you'll find that hwsetup has detected and written the wireless card name. edit: for more info on hwconfig and what it does read the "X AUTOCONFIGURATION section"

 *victordavion83 wrote:*   

> I also would like to include the gentoo installer if possible on the LiveCD as it's updated and becomes more official. I know the way I installed Gentoo on this computer was through the LiveDVD RR4 and he seems to have setup the installer to allow a direct copy of what is on the DVD onto your hard drive as well as build your own install. I would want to have both of those options available to me (so maybe later it could be used by anybody).

 

I'm afraid I can't help you here. I know nothing about the Gentoo installer  :Sad:  To install my livecd on a hard disk I simply copy everything in a partition, add what I took out of the base system (most of portage and all the headers), fix fstab, chroot inside it, emerge grub and install it int he MBR. This is all I can tell you.

 *victordavion83 wrote:*   

> Another thing is the question of burning it onto a CD or a DVD. Will having a DVD speed up the processing at all and if so how would I go about making an image for the DVD?

 

The iso you produce with this guide is ok for both cds and dvds. You should use a DVD only if you need the extra space because it could be slower than a CD (I'm not sure because I use only RW media and RW DVDs are slower than RW CDs but it could be the opposite for normal media).

 *victordavion83 wrote:*   

> For my last question I would like to ask if it's possible for me to graphically login to the setup I have created to change the layout of the programs I've installed and if so how would I go about doing it? My goal being to make the layout as close as possible to what my family would expect it to look like.

 

This is covered inside the guide. Just follow it. First you set up X autoconfiguration, than if you want it some primitive form of HD autodetection; then you run mkxf86config and finally you start X. You're still inside a chroot here, no iso building/running required. If you can get X to start -- the autoconfiguration always worked for me but I guess problems can always arise -- you can configure your DE/WM. Let me underline the fact that all of this has been painless in my experience.

 *victordavion83 wrote:*   

> I don't mind if you don't feel like writing out a whole thing and rather link me to stuff already written to find the answers but I would love to do this for my family so they would always be able to use their systems after I'm done making this thing. Then maybe later I could come back and top the icing by asking the question of allowing on the same disk an option to load the AMD64 or the 32bit version.

 

You can put more than a single system on a CD although that will probably force you to go for a DVD because of all the space you need. There's a section for it in the guide but it's only a stub and largely untested. Dont try it until you're experienced in making livecds or until I make it as user-friendly as the resto of the guide.

The next section that will recieve an update is the run-from-ram section, the "add more root images" section will come after that one. Basically you can have as many kernels and root images you want on a CD/DVD, unless you run out of space ^^ If you can use the same bootloader for 32- and 64-bit systems you're going to be able to make it.

 *victordavion83 wrote:*   

> I appreciate the time you have put into making this guide. I'm trying to follow it now but will wait for the replies before I get myself in way too deep. =)
> 
> EDIT: Clarified a graphical login

 

Ask away. I was starting to think nobody was going to bother with my poor guide  :Very Happy:  I'm in serious need of some feedback.

----------

## victordavion83

Thank you for your quick reply! I'm going to start creating a LiveCD tonight and see if I can get it working. I think that will be about 3 days on my Thinkpad T21. I guess I have a bunch of thinking to do. =)

----------

## Lepaca Kliffoth

Good luck and if you're unsure about something ask.

----------

## Ma3oxuct

I've started following this guide yesterday. I am stuck on step5.

I do the following:

```
dd if=/dev/zero of=${LIVEDIR}/source/boot/isolinux/initrd bs=1M count=8

8+0 records in

8+0 records out

8388608 bytes (8.4 MB) copied, 0.030809 seconds, 272 MB/s

losetup /dev/loop0 ${LIVEDIR}/source/boot/isolinux/initrd

mkfs.ext2 /dev/loop0

mke2fs 1.38 (30-Jun-2005)

Filesystem label=

OS type: Linux

Block size=1024 (log=0)

Fragment size=1024 (log=0)

2048 inodes, 8192 blocks

409 blocks (4.99%) reserved for the super user

First data block=1

1 block group

8192 blocks per group, 8192 fragments per group

2048 inodes per group

Writing inode tables: done

Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 36 mounts or

180 days, whichever comes first.  Use tune2fs -c or -i to override.

mount /dev/loop0 /mnt/temp

cd /mnt/temp

```

When I run mkdir etc dev lib bin proc new cdrom it just hangs. If I run ls, I get:

```
ls

ls: reading directory .: Input/output error
```

I have tried with multiple loop devices such as /dev/loop1, /dev/loop2, etc. (I used different mount points of course). Even creating a kernel module for ROM filesystem support, but still no go. Any command that writes something to where the /dev/loop is mounted just hangs (won't respond to ctrl+c).

Thanks for your help. I am loving this guide  :Smile: . 

Edit: In another loop (/dev/loop3 mounted on /mnt/temp3), I get the Input Output error that ls got for any thing I do, read or write.

----------

## Lepaca Kliffoth

 *Ma3oxuct wrote:*   

> ...

 

Everything you said points to some kind of problem with the ext2 code in the kernel of the host OS. Can you try again while running a vanilla kernel? Maybe 2.6.14 rather than the newly released .15. I don't think the loopback device is at fault here since it does let you access the file; seems like your problems start when you mount the ext2 partition file. Does the host OS have anything ext2? Boot partition or something like that?

----------

## Ma3oxuct

 *Lepaca Kliffoth wrote:*   

>  *Ma3oxuct wrote:*   ... 
> 
> Everything you said points to some kind of problem with the ext2 code in the kernel of the host OS. Can you try again while running a vanilla kernel? Maybe 2.6.14 rather than the newly released .15. I don't think the loopback device is at fault here since it does let you access the file; seems like your problems start when you mount the ext2 partition file. Does the host OS have anything ext2? Boot partition or something like that?

 

Host OS has nothing ext2. ext2 is compiled as a modules in the kernel.

I will compile it into the kernel and reboot...

EDIT: Yes, that was the issue and what I just did fixed it. Odd.

----------

## Lepaca Kliffoth

Odd indeed o_O

----------

## Lepaca Kliffoth

Good news! Seems like the problems I had with KDE over union were somehow my fault. I'd like to apologize to thedangerouscrew since I obviously didn't listen to him well enough. Guide conversion underway.

Migration completed. If you're in the middle of following the guide, the old one is at http://lepacakliffoth.interfree.it/howto.txt

----------

## anyNiXwilldo

I am in the midst of creating my first live cd by following this excellent tutorial. However, I am presently confused regarding 3 separate issues, which are as follows:

1. The guide states isolinux.cfg should contain the following line, "kernel vmlinux." The first line of commentary following this, states, " As you can see our kernel will be named "vmlinuz"." My question is, what is the name of the kernel which should be placed in isolinux.cfg, "vmlinux" or "vmlinuz?"

2. Regarding the script "prepare_env," which was copied and pasted. When I run this script, I receive the following message:

mount: special device var/ does not exist

I believe the line responsible for this error exists in the prepare_env script as follows:

mount -o bind                   var/  source/var

Of course, there is no var/ directory under the livecd directory, since section "#4 PREPARATION OF THE BUILD ENVIRONMENT" does not require we "mkdir var", unless I have missed something. By viewing the old instructions for this method of live cd creation, I noticed the older version of the prepare_env script did in fact require "mkdir var" under ${LIVEDIR}. So what do I need to do here? Do I make a var directory under ${LIVEDIR}, or do I remove the "mount -o bind var/  source/var" from the script?

3. Regarding the script "release_env," when I run this script, I receive the following message:

umount: source/boot: not mounted

This error message makes perfect sense, given that the prepare_env script does not appear to mount source/boot. I noticed the older version of the prepare_env script did in fact mount boot, since it contained the following line:

mount -o bind                  boot/  source/boot

So what do I do here? Do I add the line to mount boot to the script?

Any help is appreciated.

----------

## Aszrael

Very nice HowTo

overall my CD is booting, but...

just before starting init I get:

umount: /initrd: device is busy

during boot I get "Root filesystem could not be mounted read/write"

Give password for maintenance"

after Control-D it just boots fine

may this be because of:

 *thedangerouscrew wrote:*   

> 
> 
> note: in order for unionfs to work on a live cd you have to disable mounting rootfs
> 
> as ro during bootup

 

Where can I do this? I removed checkfs and checkroot from runlevels, but the problem remains.

Please adjust your HowTo:

we need insmod.static inside initrd/bin to make your linuxrc work

but do we need this line anyway since we are supposed to patch our kernel with unionfs???

 *Lepaca Kliffoth wrote:*   

> 
> 
> ```
> 
> insmod.static /lib/unionfs.ko
> ...

 

@anyNiXwilldo:

1. it seems to be a typo - "vmlinuz" is your friend (but you can choose any name you like, just make sure isolinux.cfg is referring to the correct name)

2. there should be ${LIVEDIR}/source/var, or you'll get into trouble with some application (eg logger,X,...)

so I leave it inside ${LIVEDIR}/source/ and removed the lines from both scripts since your build-script also wants to clean it a bit

```
cd source

rm -rf var/tmp/*

rm -rf var/run/*

mkdir var/run/dbus

rm -rf var/lock/* 
```

3. just add "mount -o bind boot/ source/boot" to your prepare_env  :Smile: 

this way you keep ${LIVEDIR}/boot up to date since the build-script takes it from there:

```
...

cp -a boot cdroot/

...

mkisofs -R -b boot/isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table -c boot/isolinux/boot.cat -iso-level 3 -o livecd.iso cdroot/
```

I think this HowTo was never intended to be followed verbatim - it's work in progress  :Smile: 

EDIT:

the system refuses to shutdown  :Sad: 

-----

using gentoo-sources-2.6.14-r5 with unionfs-1.1.1

-----

----------

## Stolle

Yes, very nice howto, many thanks to Lepaca Kliffoth!

I have exactly the same problems as Aszrael, so these must be systematic errors.

Cu,

  Stolle

----------

## Aszrael

untill I fix my issues I switched to this method: http://gentoo-wiki.com/HOWTO_build_a_LiveCD_from_scratch

After minor problems it worked nice. But I really want unionfs  :Smile: 

----------

## linuxchimp

 *Quote:*   

> untill I fix my issues I switched to this method: http://gentoo-wiki.com/HOWTO_build_a_LiveCD_from_scratch
> 
> After minor problems it worked nice. But I really want unionfs 

 

I beleive that if you search addendums to that article on the wiki you will find an entry about unionfs...I beleive its solved by emerging unionfs and then 

```
genkernel all --unionfs
```

 but that is just from memory...

hey here is the link if you are interested...

http://gentoo-wiki.com/Talk:HOWTO_build_a_LiveCD_from_scratch

----------

## Stolle

@Aszrael

I tried using genkernel, but with isolinux not grub like in the howto.

I build kernel and initrd with genkernel, booting the system with grub from hdd is no problem. 

But when booting from CD, the linuxrc is not able to find a bootable media:

```
Attempting to mount CD:- /dev/hdc

...

!! Could not find CD to boot ...

```

isolinux.cfg:

```
append cdroot acpi=force initrd=initrd root=/dev/ram0 init=/linuxrc looptype=squashfs loop=/livecd.squashfs dokeymap vga=791 splash=silent,theme:default CONSOLE=/dev/tty1 quiet udev no-devfs
```

I also tried to mount the initramfs created by genkernel with:

```
gzip -cd initrd > unzipped

mount -o loop -t ext2 unzipped /mnt/cdrom
```

But I get:

```
mount: wrong fs type, bad option, bad superblock on /dev/loop0
```

Did you have similiar problems?

Cu,

  Stolle

----------

## Aszrael

@ linuxchimp:

thank you - I'll give it a try

@Stolle:

 *Stolle wrote:*   

> Attempting to mount CD:- /dev/hdc
> 
> ...
> 
> !! Could not find CD to boot ... 

 

just  guessing: did you check your kernel-config?

be sure it has 

```
CD-ROM/DVD Filesystems  --->

   <*> ISO 9660 CDROM file system support

ATA/ATAPI/MFM/RLL support  --->

   <*>     Include IDE/ATAPI CDROM support

[*]     PCI IDE chipset support

 <*> your chipset
```

I took the generic-config from /usr/share/genkernel/$archName and built it with 

```
all --menuconfig --no-bootsplash --no-initrdmodules
```

If you have SATA-HDD and IDE/ATAPI-CDROM in your system, compile your SATA-chipset as module and use --no-initrdmodules!!!

it gave me quite a headache to figure this.

here is my grub.conf:

```
title=LiveCD

   root (cd)

   kernel (cd)/boot/kernel-genkernel-x86-2.6.14-gentoo-r5 root=/dev/ram0 init=/linuxrc looptype=squashfs loop=/livecd.squashfs vga=791 udev cdroot

   initrd (cd)/boot/initramfs-genkernel-x86-2.6.14-gentoo-r5
```

 *Stolle wrote:*   

> I also tried to mount the initramfs created by genkernel with:
> 
> ```
> gzip -cd initrd > unzipped
> 
> ...

 

have a look here:

https://forums.gentoo.org/viewtopic-p-2749207-highlight-.html#2749207

and

https://forums.gentoo.org/viewtopic-t-388539-highlight-.html

----------

## Lepaca Kliffoth

I'm not receiving notifications. Sorry, I'm not ingoring you. I'm reading your posts right now.

----------

## Lepaca Kliffoth

 *anyNiXwilldo wrote:*   

> 1. The guide states isolinux.cfg should contain the following line, "kernel vmlinux." The first line of commentary following this, states, " As you can see our kernel will be named "vmlinuz"." My question is, what is the name of the kernel which should be placed in isolinux.cfg, "vmlinux" or "vmlinuz?"

 

That's an inconsistency I'm fixing right now. For the sake of choosing a name, let's say "vmlinuz" but you can name it whatever you want as long as the kernel file has the same name you write in isolinux.cfg.

 *anyNiXwilldo wrote:*   

> 2. Regarding the script "prepare_env," which was copied and pasted. When I run this script, I receive the following message:
> 
> mount: special device var/ does not exist
> 
> I believe the line responsible for this error exists in the prepare_env script as follows:
> ...

 

Before going the unionfs way var was outside the source directory. So this is another inconsistency I'll fix right now. The right thing to do is leaving the var directory inside ${LIVEDIR}/source and removing the line from prepare_env.

 *anyNiXwilldo wrote:*   

> 3. Regarding the script "release_env," when I run this script, I receive the following message:
> 
> umount: source/boot: not mounted
> 
> This error message makes perfect sense, given that the prepare_env script does not appear to mount source/boot. I noticed the older version of the prepare_env script did in fact mount boot, since it contained the following line:
> ...

 

The boot directory and its contents must be outside the source directory, directly under ${LIVEDIR}/. The solution is creating ${LIVEDIR}/boot, moving the contents of ${LIVEDIR}/source/boot in ${LIVEDIR}/boot and adding a line to prepare_env that binds ${LIVEDIR}/boot to ${LIVEDIR}/source/boot.

Sorry but I'm depending on everyone to find out this kind of inconsistencies.

----------

## Lepaca Kliffoth

 *Aszrael wrote:*   

> Very nice HowTo
> 
> overall my CD is booting, but...
> 
> just before starting init I get:
> ...

 

Please check section 15, known quirks. I'm working on it.

 *Aszrael wrote:*   

> 
> 
> during boot I get "Root filesystem could not be mounted read/write"
> 
> Give password for maintenance"
> ...

 

I'm figuring out the best way to solve this. In order not to mess up the services dependancies I suggest you edit checkroot so that it just returns 0. I'll add it to the guide immediately.

checkroot:

```
#!/sbin/runscript

# Copyright 1999-2005 Gentoo Foundation

# Distributed under the terms of the GNU General Public License v2

depend() {

        before *

}

start() {

        return 0

}

# vim:ts=4
```

 *Aszrael wrote:*   

> Please adjust your HowTo:
> 
> we need insmod.static inside initrd/bin to make your linuxrc work
> 
> but do we need this line anyway since we are supposed to patch our kernel with unionfs???
> ...

 

No, that's another inconsistency. It's a leftover from the linuxrc I coded at work. You don't need it and it's bad to do things that way, it's much better to compile unionfs inside the kernel. Just remove the line fromt he linuxrc script.

 *Aszrael wrote:*   

> EDIT:
> 
> the system refuses to shutdown 
> 
> -----
> ...

 

Again, please check section 15, known quirks problems etc. There are some things I still have to figure out.

----------

## thedangerouscrew

i just popped back in to see how things were progressing and i see that you got unionfs working.

SWEET!  :Very Happy: 

I can't wait until your howto is complete, seems like it will be a pretty cool disk.

----------

## Lepaca Kliffoth

I think you can consider it "complete" as far as you want to make a simple livecd. There are those two bugs I'll fix tomorrow (hopefully). The run from ram mode is pretty simple, I just have to figure out the best way to implement it; either copy the squashed image in a ramdisk and mount it from there or untar a "module" containing only a few apps in a ramdisk and bind it. To run from USB just format the USB key fat32 and install syslinux as the bootloader. If you're experienced enough you can figure it out yourself easily. There's no telling how long it will take to add those sections, since they have to be reasonably "user-friendly", but I think not very long. It's that in this days I'm getting pwned by beer and exams  :Sad: 

----------

## Xgates

I'm trying to make a iso bootable, what I did was mount the 'install-x86-universal-2005.1' and copied the contents out with 'cp -a' into this directory /install then I removed all the stages, just to put in a stage4 to reinstall Gentoo if  needed.

Now with everything original from the 'install-x86-universal-2005.1' in it except the stages, the inside the directory, like this one I made:

gentoo install # ls

README.txt  README_Stage4.txt  distfiles  docs  isolinux  livecd  livecd.iso  livecd.squashfs  snapshot  stages

Can I just run this command for mkisofs from the terminal, inside the /install directory and it will make a bootable iso?

mkisofs -R -b isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table -c isolinux/boot.cat -iso-level 3 -o livecd.iso /home/xgates/install/

THANKS

----------

## Lepaca Kliffoth

Well, yes  :Very Happy:  Run it and try it with qemu, if it doesn't work let me know the exact error message and I'll help you.

----------

## x-cnc

Does anyone have good disk-space-saving ideas for a livecd system?  It seems that everyone leaves these directories out of the image (usually squashfs) file:

/boot

/etc/make.profile

/etc/portage

/tmp

/usr/portage

/usr/src

/usr/share/doc

/var/cache

/var/db

/var/lock

/var/log

/var/run

/var/tmp

Secondly, one thing that takes up an awful lot of room on the disk is java.  The blackdown directories in /opt take up 55M and 92M.  Is there an alternative to blackdown that takes up less disk space?

----------

## Lepaca Kliffoth

Have you read the guide? If not, the section you want to read is the build environment section.

----------

## thedangerouscrew

one space saving idea is to ditch kde (but not realistic).  I use the kde split ebuilds and save 

a fair amount of space.

emerge kde-meta and anything else you want from the kde-base group

this is how i do it emerge kde-meta && emerge kdeutils-meta && emerge kdegraphics-meta && emerge kdemultimedia-meta then i unmerge the packages i don't want and to keep the packages i don't want from getting remerged when i update my world i do a emerge unmerge kdeutils-meta && emerge unmerge kdegraphics-meta && emerge unmerge kdemultimedia-meta.

I'm sure people will laugh at me but, i never fail a dependancy.

i hope this helps you

p.s. i also noticed that the kde docs aren't in your list wich could take a fair amount of space

----------

## x-cnc

 *thedangerouscrew wrote:*   

> one space saving idea is to ditch kde (but not realistic).

 

I already did...just kidding, I used Gnome for my desktop environment.  Gnome plus OpenOffice and all kinds of other packages on my livecd squashed down to just over the cd size limit at about 720MB, believe it or not.  If possible, I'd rather not go through the entire filesystem finding things to delete.  I think I am going to look into trying KDE like you described.  Thanks.

----------

## thedangerouscrew

might be to late but there is a light version of gnome in portage.

I can't tell you much about it though. I'm not a gnome fan

----------

## Aszrael

 *thedangerouscrew wrote:*   

> might be to late but there is a light version of gnome in portage.
> 
> 

 

That's what I use myself. Just emerge gnome-light and then emerge gnome -p to check for apps missing (and that's quite a list)

My CD is 633MB and a full replacement for Knoppix&Co featuring lot of apps I was missing on them (mainly to recover crashed/infected WinBoxes)

To be honest: I think I overdid it, but I wanted to find out how much I could fit onto a disc

Gentoo is about choice so I choose everything   :Twisted Evil: 

----------

## victorhooi

heya,

A truly great howto  :Very Happy: , just a few small questions before I take the dive.

1. Tips for saving space

What sort of things can you do to cut down on size? What stuff is safe to remove? If you're not planning to compile anything, is there anything additional you could remove? (libraries, extraneous compiler fluff etc.)

Also, if you are planning to compile stuff booting from the CD (actually a fairly useful thing - Knoppix has this), what would I need to add? (e.g., basic devel libraries like Ncurses, zlib, libpng etc.)

2. Boot Options for Different WMs

Is it possible to start different window manager's via boot options? (Like Knoppix's "desktop=fluxbox|gnome|icewm|kde|lg3d|larswm" cheatcode, link)

3. Using Knoppix autoconfig/hwsetup

Any thoughts of using the autoconfig/hwesetup scripts from Knoppix/Kanotix? Or the wireless-card setup, or X setup scripts?

4.InitNG

Would there be any advantages to using InitNG? Any special caveats or notes to applying it to this LivecCD? Just a random idea...  :Wink: 

Thanks,

Victor

----------

## Lepaca Kliffoth

 *victorhooi wrote:*   

> 1. Tips for saving space
> 
> What sort of things can you do to cut down on size? What stuff is safe to remove? If you're not planning to compile anything, is there anything additional you could remove? (libraries, extraneous compiler fluff etc.)

 

If the directories I tell you to remove are not enough (build environment section) you'll have to figure out what you can and cannot remove by yourself - I just don't have the time. Sorry.

 *victorhooi wrote:*   

> Also, if you are planning to compile stuff booting from the CD (actually a fairly useful thing - Knoppix has this), what would I need to add? (e.g., basic devel libraries like Ncurses, zlib, libpng etc.)

 

Just leave headers and things like that where they are instead of moving them out of the "source" directory. If you want portage too you'll need a lot of additional space.

 *victorhooi wrote:*   

> 2. Boot Options for Different WMs
> 
> Is it possible to start different window manager's via boot options? (Like Knoppix's "desktop=fluxbox|gnome|icewm|kde|lg3d|larswm" cheatcode, link)

 

This is up to you. You could add something to the linuxrc script that reads the commandline and modifies config files as needed.

 *victorhooi wrote:*   

> 3. Using Knoppix autoconfig/hwsetup
> 
> Any thoughts of using the autoconfig/hwesetup scripts from Knoppix/Kanotix? Or the wireless-card setup, or X setup scripts?

 

X Autoconfiguration section  :Razz: 

 *victorhooi wrote:*   

> 4.InitNG
> 
> Would there be any advantages to using InitNG? Any special caveats or notes to applying it to this LivecCD? Just a random idea... 

 

There is nothing stopping you from using InitNG or whatever init you want, just remember you have to modify one of the boot scripts (checkroot) so that Gentoo won't try to remount / readonly at boot. If it tries to do so, it dies.

----------

## thedangerouscrew

I must be missing something here

when I boot my livecd i get "no init found".

i went threw your howto a dozen times and I didn't find anything i did wrong.

so i tried switching the line in isolinux.cfg from linuxrc to /bin/sh and i still get the same error.

when it boots it says it loaded the initrd.

not sure what i did wrong, everything seems straight foward. any ideas would be great help.

btw I'm building a 64bit livecd

----------

## Lepaca Kliffoth

Can you please check again if you included in the kernel built-in support for ext2?

You should also check if in the kernel configuration you set the default initrd size big enough.

----------

## thedangerouscrew

set the image size to 10mb could that be too big?

----------

## Lepaca Kliffoth

Well it must be bigger than the actual initrd file size. If it still says init not found either you didn't make the linuxrc script executable or you didn't put it inside the initrd at all. It could help if you wrote down and posted the actual error message.

----------

## thedangerouscrew

I scrapped my cd, but the error message pretty much says "no init found use the init= option"

I plan on taking another stab at it.

I wrote this script to create the initrd:

------------------------------------------------------------------------------------------------------------

#!/bin/sh

export LIVEDIR="/home/gentoo/livecd-project/livecd"

echo "creating initrd"

dd if=/dev/zero of=${LIVEDIR}/source/boot/isolinux/initrd bs=1M count=8

losetup /dev/loop0 ${LIVEDIR}/source/boot/isolinux/initrd 

mkfs.ext2 /dev/loop0

mount /dev/loop0 initrd

echo "building base"

cd initrd

mkdir etc dev lib bin proc new cdrom static dynamic union sbin

touch linuxrc 

chmod +x linuxrc 

touch etc/mtab 

touch etc/fstab

cd ${LIVEDIR}

cp -v source/bin/sh initrd/bin/

cp -v source/bin/cat initrd/bin/

cp -v source/bin/mount initrd/bin/

cp -v source/bin/umount initrd/bin/

cp -v source/bin/mkdir initrd/bin/

cp -v source/bin/chroot initrd/bin/ 

cp -v source/bin/tar initrd/bin/ 

cp -v source/sbin/pivot_root initrd/sbin/

echo "building libraries"

cp -v source/lib/libdl.so.2 initrd/lib/

cp -v source/lib/libc.so.6 initrd/lib/

cp -v source/lib64/ld-linux-x86-64.so.2 initrd/lib/

cp -v source/lib/libblkid.so.1 initrd/lib/

cp -v source/lib/libuuid.so.1 initrd/lib/

cp -v source/lib/libpthread.so.0 initrd/lib/

echo "creating devices"

mknod initrd/dev/console c 5 1 

mknod initrd/dev/null c 1 3 

mknod initrd/dev/hda b 3 0 

mknod initrd/dev/hdb b 3 64 

mknod initrd/dev/hdc b 22 0 

mknod initrd/dev/hdd b 22 64 

mknod initrd/dev/tty c 4 0 

mknod initrd/dev/loop0 b 7 0

-----------------------------------------------------------------------------------------------------------------------

I was su to root when I built my cd

do you see anything wrong with it?

the more I think about it I wonder if I forgot to write my /etc/fstab

----------

## Lepaca Kliffoth

At that stage the fstab isn't used at all. Unless you didn't forget to "fill" the linuxrc script there's nothing wrong that I can find in your script. I trust you passed the init=/linuxrc option? You seem experienced enough to not make this mistakes. I don't know what could be wrong  :Sad:  Here's a checklist:

- support for ext2 in the kernel (initrd is formatted in ext2)

- default initrd size set big enough in the kernel config

- options "initrd=initrd init=/linuxrc root=/dev/ram0" added to the kernel commandline

- linuxrc must be executable

That's all as far as I know. Meet those 4 requirements and the initrd should work, then everything's up to the linuxrc script.

----------

## thedangerouscrew

ok i tried making a few livecds and i still get the same error. I have gathered some more information.

things i know:

initrd gets loaded

initrd gets mounted

and dies sometime after that with a kernel panic and the generic no init found error

my guess is that unionfs is not ready for x86_64 yet

i'm going to put some echo coments in the linuxrc script so i can closer figure out where it dies probaly at unionfs

and the init it can't find is probally /sbin/init.

----------

## Lepaca Kliffoth

I'm afraid you're alone on that  :Sad:  I'd really like to help and I hate not being able to.

----------

## thedangerouscrew

just an update

I was wrong it's my initrd.  I don't know what i'm doing wrong but I'm making bad initrds.

i tried the dummies version and i still get the same error.  If I do a "genkernel initrd"

i can successfully make a live cd without unionfs. i noticed that genkernels initrd is a zipped file

where the ones i make are not. Is the initrd we make here supposed to turn out as a zipped file?

will isolinux and grub only handle zipped initrd?

i do know that my kernel is ok.

any input would be greatly appreciated

thanks

----------

## Lepaca Kliffoth

Genkernel generates an initramfs. That's not the same as an initrd, it's some kind of archive, I think a gzipped cpio archive. I don't know how to make them.

----------

## westboy21

Ok, your guide has been wonderful explained up to a certain point.  You mention in the guide that you must move /boot into $LIVECD outside of $LIVECD/source.  Ok that's cool, but then you say to create the initrd file inside of $LIVECD/source/boot/isolinux/ ... I'm sure this is just a technicality.

My problem at this point, is that I'm getting a kernel panic.

```

RAMDISK: ext2 filesystem found at block 0

RAMDISK: Loading 8192KiB [1 disk] into ram disk... done.

VFS: Mounted root (ext2 filesystem) readonly.

Freeing unused kernel memory: 292k freed

Failed to execute /linuxrc.  Attempting defaults...

Kernel panic - not syncing: No init found. Try passing init= option to kernel.

```

I followed the instructions to the T for creating the initrd file.  This isn't the first time I've made a livecd before.  I have the linuxrc file inside of the root of the initrd disk.  It is executable.

Thanks

----------

## westboy21

Well, I found the source of my frustrations.  It seems I'd copied over binaries into the ramdisk from my x86_64 installation.  Ooops.  Guess I better pay attention next time.

Thanks for again for the guide.

----------

## Lepaca Kliffoth

 *westboy21 wrote:*   

> Ok, your guide has been wonderful explained up to a certain point.  You mention in the guide that you must move /boot into $LIVECD outside of $LIVECD/source.  Ok that's cool, but then you say to create the initrd file inside of $LIVECD/source/boot/isolinux/ ... I'm sure this is just a technicality.

 

Thanks for pointing it out, it's a leftover from some previous version of the guide. Correcting it now.

I'm glad you could solve that problem yourself, I just read it but I wouldn't have known the solution as I have no x86_64 systems.

----------

## thedangerouscrew

I figured out my problem with my initrd.  when making an initrd for a x86_64 live cd

you need to make a symlink lib64 that points to lib. It took me a while to figure this out and 

I feel stupid for not figuring it out sooner.    :Embarassed: 

----------

## Lepaca Kliffoth

Thanks thedangerouscrew, I'll put a notice about it somewhere in the guide next time I update (hopefully tomorrow).

----------

## bud1979

Hello everyone,

First off thanks for a great guide.  I have a bootable CD but have a question I was hoping to get some clarification on.

1.  If i umount the /dev directory before i build the cd, I am unable to fully boot the disk.  It complains about /dev not having all needed devices.  If i add all the devices from my /dev directory to it I can then boot the cd.  Any reason for that?  

Please let me know if i need to post more information.

I am using qemu to boot the iso, if that matters.

Thanks

----------

## Lepaca Kliffoth

 *bud1979 wrote:*   

> Hello everyone,
> 
> First off thanks for a great guide.  I have a bootable CD but have a question I was hoping to get some clarification on.
> 
> 1.  If i umount the /dev directory before i build the cd, I am unable to fully boot the disk.  It complains about /dev not having all needed devices.  If i add all the devices from my /dev directory to it I can then boot the cd.  Any reason for that?  
> ...

 

If you installed udev properly you only need to devices under /dev: null and console. If you need more there's a problem with your installation. In any case, please try booting from a real CD (use rewritable media!!).

----------

## bud1979

Ok,

Tried two different ways now.  Once with nothing in /dev when cd was made and again with null and console only.  Either one does not allow a working boot and comes up with the error of:

Your system seems to be missing critical device files in /dev!

Although you may be running udev or devfs, the root partition is missing

these required files.

One thing I did notice when booting without the files in /dev is that Normally it says Starting Init!--- but without the files in /dev it starts our on hardware detection after about a min or so of hanging on "Found livecd".  I installed the new udev 0.86.  Is there configuration that I need to do on it as the documentation does not say anthing about it.

Thanks again for the help.

----------

## Lepaca Kliffoth

As far as I know there's no need of any particular udev config to make the boot process work. If you still have problems booting the cd then just fill dev with devices by mounting sys and running udevstart from inside the chroot. It won't create any problem since they will be overwritten at runtime but just to be sure try running the livecd on as many pcs as you can. I don't have anything more to say on this matter, maybe someone else who knows more?

----------

## DVSoftware

hello, i have just burned my first successful livecd ISO (errm... made a mistake with linuxrc not executable)

it works correctly, but... (why always have to be "but"?)

1. ehci-hcd and  ohci-hcd are not modprobed on boot causing usb devices being not detected

2. my sound don't work (i'm sure i did compiled kernel module but i'll check, i'm writing this from livecd)

3. my screen resolution is wrong (i get 1280x1024 instead of widescreen 1680x1050 - it's not autodetected by knoppix's app - so is there anything i can do about it? ubuntu detects it for example)

other than that it's working fine

i'm planing to create simple hard disk installation script that will copy entire dvd to hard disk, adding portage and needed stuff

----------

## Lepaca Kliffoth

 *DVSoftware wrote:*   

> hello, i have just burned my first successful livecd ISO (errm... made a mistake with linuxrc not executable)
> 
> it works correctly, but... (why always have to be "but"?)
> 
> 1. ehci-hcd and  ohci-hcd are not modprobed on boot causing usb devices being not detected
> ...

 

1. Have you added coldplug to the default runlevel?

2. I'm searching for a solution myself. The easiest and ugly way is to compile every sound card driver inside the kernel instead of making them modules. For the hardest read on.

3. mkxf86config turned out not to be what I thought. What you really need is the package app-misc/livecd-tools; emerge it and add the service "autoconfig" to the default runlevel, it should take care of sound too.

I have to put this things in the guide and I don't have time  :Sad: 

----------

## DVSoftware

thanks i'll try it tomorrow  :Smile: 

----------

## DVSoftware

well app-misc/livecd-tools uses mkxf86config, too  :Sad: 

EDIT:

I have found a solution. I downloaded kanotix's ddcxinfo which correctly recognizes my resolution  :Smile: 

now let's see what we got  :Smile: 

----------

## Lepaca Kliffoth

 *DVSoftware wrote:*   

> I downloaded kanotix's ddcxinfo which correctly recognizes my resolution 

 

Can you elaborate on that? Is it "pluggable" in gentoo's autoconfig service?

----------

## DVSoftware

 *Lepaca Kliffoth wrote:*   

>  *DVSoftware wrote:*   I downloaded kanotix's ddcxinfo which correctly recognizes my resolution  
> 
> Can you elaborate on that? Is it "pluggable" in gentoo's autoconfig service?

 

yes, it's basically the same thing just expanded to support more modes  :Smile: 

btw, can i find you somewhere on IRC, i got few questions, but i don't want to flood the forums  :Smile: 

EDIT: i have added you to ICQ

----------

## jkomar

 *DVSoftware wrote:*   

> yes, it's basically the same thing just expanded to support more modes 

 

Did you add this into the autoconfig service, or are you somehow running it on its own? This is something that interests me as well.

Thanks,

Jason

----------

## rjw8703

Can we make live dvd's using this guide?

----------

## Lepaca Kliffoth

 *rjw8703 wrote:*   

> Can we make live dvd's using this guide?

 

There's no difference, you just have more space and a bigger iso to fill it  :Very Happy: 

----------

## benedikt

My linuxrc doesn't work.

To figure out why, i replaced init=/linuxrc by init=/bin/sh in order to be able to debug. 

I traced the script /linuxrc and detected that mounting the squashfs.file doesn't work.

Thats the error-message:

Squashfs 2.2 (released 2005/07/03) (C) 2002-2005 Phillip Lougher

SQUASHFS error: Major/Minor mismatch, filesystem is (3:0), I support (1 : x) or (2 : <= 1)

SQUASHFS error: Major/Minor mismatch, filesystem is (3:0), I support (1 : x) or (2 : <= 1)

I tried to build the squashfs image by 

mksquashfs source/ cdroot/livecd.squashfs  -2.0

but mksquashfs only says "not supported" 

I installed squashfs-tools 2.2_p2.

What can I do?

----------

## Lepaca Kliffoth

If there's a problem between the kernel version of the squashfs module and the version of the squashfs tools the simplest way would be to update both the kernel of the livecd and the squashfstools package of the host system to the last version.

----------

## benedikt

that's it. I patched the kernel with squashfs3.0 and everything works fine  :Smile: 

----------

## fRIOUX

This is a really cool guide!  I really enjoyed using it and I like how I can use the image stuff as a continuing project type thing.

Just for people's information I figure I will tell them my setup.

I have naim, gaim, vim, gvim, mp3blaster, amarok, screen, firefox, fvwm, openoffice-bin, and qt-4.1 installed on my cd with other various tiny things that help it boot.  The main reason I made this was so that I could demonstrate my project (a Qt base OSD library)

in Software Systems without bringing a computer to class or installing libs on the computer in the classroom.  I tested my CD in the labs and it works GREAT (not on my personal comp, but that's ok for now.)  I am crossing my fingers hoping it will work on the comp in the classroom.

Also, my cd's filesystem is 960 megs and the CD is 350~ megs.  I have all the tools I use with most of the useflags I use in my normal system, so I am very happy with this.

Lepaca, would you mind if I copied this guide to the gentoo-wiki?  I had a few ideas for the guide and I figured that if it is on the Wiki people could contribute to it more.  Just a thought.

Thanks again!

----------

## Lepaca Kliffoth

That's good to hear!

 *fRIOUX wrote:*   

> Lepaca, would you mind if I copied this guide to the gentoo-wiki?  I had a few ideas for the guide and I figured that if it is on the Wiki people could contribute to it more.  Just a thought.
> 
> Thanks again!

 

As long as I'm given credit for it and it's clear that it was originally based on veezi's guide, that's fine. Just mention veezi's name and mine. I like the idea of a guide here updated by me and another updated freely by everyone, maybe some of the problems I'm still figuring out how to solve will get more exposure and will be solved by someone smarter; indeed I'm a little disappointed that in all this time only a couple of guys actually tried to help.

----------

## fRIOUX

 *Quote:*   

> I like the idea of a guide here updated by me and another updated freely by everyone, maybe some of the problems I'm still figuring out how to solve will get more exposure and will be solved by someone smarter; indeed I'm a little disappointed that in all this time only a couple of guys actually tried to help.

 

I hear you man; when I looked at this and saw that it was originally posted a while ago and that it's only five pages and even those pages are relatively low content, I was really surprised.  Hopefully a wiki will get more traffic.

----------

## APLowman

Reguarding the kernel part of the guide, why don't you use:

genkernel kernel --menuconfig

or if you don't want modules:

genkernel bzImage --menuconfig

Just thought it would save all the run and cancel stuff.

EDIT: I did more searching on genkernel and I think you can save alot of steps by doing this (genkernel>=3.2.0):

--unionfs-dev is used instead of --unionfs becuase it is under development, when this is finalized you will want to use --unionfs

genkernel kernel --menuconfig --unionfs-dev

This will compile a kernel with unionfs support built in, which would mean you could get rid of the kernel patching. Mix this with the kernel compile from this wiki and you get this:

cd /usr/src/linux

make allmodconfig

genkernel kernel --unionfs-dev --no-clean --menuconfig

Then just change pretty much every CD block device from a module to being compiled in the kernel and you should be able to boot on most anything.

EDIT 2: The --unionfs-dev option seems not to work   :Sad: 

EDIT 3: This made me mad enough to fix it, so get my workaround here. Now you can use genkernel --unionfs-dev if you are using a 2.6 kernel (THIS IS NOW FIXED GET GENKERNEL 3.3.11d)Last edited by APLowman on Sun Apr 16, 2006 10:42 pm; edited 1 time in total

----------

## Lepaca Kliffoth

 *APLowman wrote:*   

> Reguarding the kernel part of the guide, why don't you use:
> 
> genkernel kernel --menuconfig
> 
> or if you don't want modules:
> ...

 

I'll test it soon but kernel configuration is the last one of my worries. The genkernel thing was just an idea for n00bs, the only good way of doing things is patching and configuring by hand. The guide isn't for n00bs anyway. Thanks for your work, I'll try and test as soon as I can and include your contribution in the guide.

----------

## APLowman

 *Lepaca Kliffoth wrote:*   

> I'll test it soon but kernel configuration is the last one of my worries. The genkernel thing was just an idea for n00bs, the only good way of doing things is patching and configuring by hand. The guide isn't for n00bs anyway. Thanks for your work, I'll try and test as soon as I can and include your contribution in the guide.

 

Thanks, although I dissagree on the patching bit; while genkernel is nicer for noobs it really isn't that diffrent from bulding the kernel yourself. Personally I feel while it is nice to be able to do things the hard way, it isn't necessary or even benificial to do it from scratch all the time. There is really alot of irrational stigma associated with saving time/effort by doing things the easy way around here, but I feel you should only do things the hard way if:

1. You feel like it

2. You can get a reasonable benifit

EDIT: They patched genkernel get 3.3.11d and you don't need my fix

----------

## Lepaca Kliffoth

 *APLowman wrote:*   

> Thanks, although I dissagree on the patching bit; while genkernel is nicer for noobs it really isn't that diffrent from bulding the kernel yourself. Personally I feel while it is nice to be able to do things the hard way, it isn't necessary or even benificial to do it from scratch all the time. There is really alot of irrational stigma associated with saving time/effort by doing things the easy way around here, but I feel you should only do things the hard way if:
> 
> 1. You feel like it
> 
> 2. You can get a reasonable benifit
> ...

 

Don't worry, your input IS appreciated like anyone else's, the bit about doing by hand was only my opinion, don't give it too much weight. Now, if I could just find enough time to update the damn guide...

----------

## Strowi

hi,

i just started building a new LiveCD for our CIP-Pool (currently using a pretty messed up Knoppix). After having some trouble getting unionfs-1.1.4-r2 into the latest 2.6-kernel, i found out, that i had to use the patched sources like this:

```

ebuild /usr/portage/sys-fs/unionfs-1.1.4-r2.ebuild unpack

ebuild /usr/portage/sys-fs/unionfs-1.1.4-r2.ebuild setup

cd /var/tmp/portage/unionfs-1.1.4-r2/work/unionfs-1.1.4/

./patch-kernel.sh /usr/src/linux/

```

then it compiled fine, if i just used the 1.1.4-source it always skipped out of kernel-compilation.

it still gives warning about unsupported kernel-version, but that you can either ignore (since it is only a warning) or set the parameter in fistdev.mk.

Hope that helps  a little...

----------

## Lepaca Kliffoth

I'm having trouble rewriting halt.sh and reboot.sh to get the damn thing to reboot and halt, has anyone solved that problem?

----------

## paluszak

First, I'd like to say, that your howto is great, I needed some rescue/media player livecds and I couldn't find anything suitable, everything I was able to find was either haplessly bloated or lacked some useful apps.

One thing that could be useful is swap autodetection, imagine a situation when you boot on some old box and run out of memory, but there's a swap partition on hd, eagerly waiting to be taken advantage of. There's a nice howto with a script here: http://gentoo-wiki.com/TIP_automount_swap.

J.

----------

## Lepaca Kliffoth

Thanks, it will be added to the guide as well.

Guys I'm holding this off until I figure out why it doesn't reboot. As soon as I can make it, there will be a major update to the guide, including everything pointed until now plus several things I figured out along the way.

----------

## schneekater

Thanks for the great guide!

I have one question that may not fit exactly into this discussion, but I hope it's close enough; even though it is a more generic issue, it became pertinent when creating a live CD using your method: The CD that I created is very small, a recue type thing, and even though it fits comfortably on a 200M CD, I am always looking for ways of making it smaller; todays target: the /dev/ files.

I was thinking of having as many of the device nodes created by udev during system boot, deleting everything that is not absolutely crucial from /dev/ before I burn the CD. And here comes the question (two questions, really, now that I think of it):

Do you think that this makes sense at all? I mean, udev would have to create the devices on the RAM disk, thus using up memory, whereas they should only take up some space on the CD if I leave them in place when creating the ISO file.

If it makes sense to have devices created by udev, are the any that I have to leave in place because they are needed to get to a point where udev can take over? If it doesn't make sense, is there a good way to determine which nodes are expendable, anyway? I am only running in text mode and really don't need all those video related devices, for example. 

Thanks again :)

 --j

----------

## Lepaca Kliffoth

 *schneekater wrote:*   

> Thanks for the great guide!
> 
> I have one question that may not fit exactly into this discussion, but I hope it's close enough; even though it is a more generic issue, it became pertinent when creating a live CD using your method: The CD that I created is very small, a recue type thing, and even though it fits comfortably on a 200M CD, I am always looking for ways of making it smaller; todays target: the /dev/ files.
> 
> I was thinking of having as many of the device nodes created by udev during system boot, deleting everything that is not absolutely crucial from /dev/ before I burn the CD. And here comes the question (two questions, really, now that I think of it):
> ...

 

Ok first of all you're not going to save much space that way so don't expect a big difference.

Second, having udev create the devices IS the right thing to do. That way they'll be created for the system the livecd is running on; you don't have devs lying around for things that don't exist and at any give time there are either the two needed devices or those generated by udev, not some /dev/hda3 from another PC that has 3 partitions on the first harddisk. Now I don't think there are differences in functionality and I don't think having devs from another system will create any problem, but havng udev generate them all is obviously the cleanest solution.

That said, the only devices you need to boot gentoo are /dev/null and /dev/console. None others, as far as I know. So delete anything you have in the livecd source under /dev except those two. If you have any kind of trouble please post it here regardless of wether you're able to fix it or not since it's valuable feedback.

Good luck  :Wink: 

----------

## Lepaca Kliffoth

I'm posting right now a better version of the hdsetup script (which would be the thing that autodetects partitions and adds an fstab entry for them at boot) pending integration in the guide.

```
#!/bin/bash

#Get a list of partitions

fdisk -l | grep /dev | awk '{print $1}'| sort | uniq | grep /dev > /tmp/disklist

#Get a list of swap partitions

fdisk -l | grep swap | awk '{print $1}' > /tmp/swaplist

#Get a list of NTFS partitions

fdisk -l | grep NTFS | awk '{print $1}' > /tmp/ntfslist

#Use a ludicrously complicated way to subtract swaplist and 

#  ntfslist from disklist

cat /tmp/swaplist /tmp/ntfslist >> /tmp/disklist

cat /tmp/disklist | sort | uniq -c | grep \ 1\ | awk '{print $2}' > /tmp/finaldisklist

#Go through every partition that isn't swap or NTFS and if 

#  the kernel can mount it then add a line for it in fstab

for i in `cat /tmp/finaldisklist`

do

   mount $i /mnt/temp

   if [ $? -eq 0 ]

   then

      DISK=`echo $i | cut -c 6-`

      echo "/dev/$DISK /media/$DISK auto users 0 1" >> /etc/fstab

      mkdir /media/$DISK -p

      umount /mnt/temp

   fi

done

#Same thing but for NTFS partitions. The line added 

#  to fstab is different because the NTFS module, like 

#  NTFS itself, sucks

for i in `cat /tmp/ntfslist`

do

   mount $i /mnt/temp

   if [ $? -eq 0 ]

   then

      DISK=`echo $i | cut -c 6-`

      echo "/dev/$DISK /media/$DISK auto users,umask=000,ro 0 0" >> /etc/fstab

      mkdir /media/$DISK -p

      umount /mnt/temp

   fi

done

#Activate the swap partitions for added pwnage

for i in `cat /tmp/swaplist`

do

   swapon $i

done
```

----------

## gieltje

[quote="fRIOUX"] *Quote:*   

> Post it to the gentoo-wiki.

 

It allready is there, be it in a different way see http://gentoo-wiki.com/HOWTO_build_a_LiveCD_from_scratch.

Mine was a fork of veezi's a long time ago and has it's pro's and cons against this method.

But I could always use some help if you wish to help out a bit.

----------

## Lepaca Kliffoth

The method you use in that guide is a one-shot way of making a livecd. I think it should be more like a continuing process, so that you can update the livecd source on the hard disk and re-burn it on rewritable media. Also, you keep too many useless things on the disk, like manuals and headers. Other than that, that's a very fine job   :Smile: 

----------

## gieltje

 *Lepaca Kliffoth wrote:*   

> The method you use in that guide is a one-shot way of making a livecd. I think it should be more like a continuing process, so that you can update the livecd source on the hard disk and re-burn it on rewritable media. Also, you keep too many useless things on the disk, like manuals and headers. Other than that, that's a very fine job  

 

Correct me if I am wrong but I am as far away from a one shot livecd as possible. If you would take a look on the work script somewhere one the bottom of the page you would see that it is a normal gentoo installation that you chroot into.

That I keep alot of manuals and stuff is my own decission, there are many ways to make it the way you want since it has a easy build script and is a normal gentoo installation.

----------

## Lepaca Kliffoth

 *gieltje wrote:*   

>  *Lepaca Kliffoth wrote:*   The method you use in that guide is a one-shot way of making a livecd. I think it should be more like a continuing process, so that you can update the livecd source on the hard disk and re-burn it on rewritable media. Also, you keep too many useless things on the disk, like manuals and headers. Other than that, that's a very fine job   
> 
> Correct me if I am wrong but I am as far away from a one shot livecd as possible. If you would take a look on the work script somewhere one the bottom of the page you would see that it is a normal gentoo installation that you chroot into.
> 
> That I keep alot of manuals and stuff is my own decission, there are many ways to make it the way you want since it has a easy build script and is a normal gentoo installation.

 

! Sorry I saw you delete kernel sources and portage and thought it was meant as a one-time-only method. Don't get angry  :Wink: 

----------

## gieltje

 *Lepaca Kliffoth wrote:*   

>  *gieltje wrote:*    *Lepaca Kliffoth wrote:*   The method you use in that guide is a one-shot way of making a livecd. I think it should be more like a continuing process, so that you can update the livecd source on the hard disk and re-burn it on rewritable media. Also, you keep too many useless things on the disk, like manuals and headers. Other than that, that's a very fine job   
> 
> Correct me if I am wrong but I am as far away from a one shot livecd as possible. If you would take a look on the work script somewhere one the bottom of the page you would see that it is a normal gentoo installation that you chroot into.
> 
> That I keep alot of manuals and stuff is my own decission, there are many ways to make it the way you want since it has a easy build script and is a normal gentoo installation. 
> ...

 

I am sorry if you got my intentions wrong, indeed I delete portage and a part of the sources (you can actualy compile and use a kernel module from my livecd). But the source of the installation is left intact.

But I feel our guides (except currently unionfs vs squashfs and genkernel vs manual kernel) have a lot in common, so I thought we maybe should try and work out the gentoo-wiki out together creating a better manual.

----------

## Lepaca Kliffoth

Sorry, I'm trying to find the time I need for the next version, maybe after that one I'll see what I can do.

----------

## schneekater

 *Lepaca Kliffoth wrote:*   

> 
> 
> That said, the only devices you need to boot gentoo are /dev/null and /dev/console. None others, as far as I know. So delete anything you have in the livecd source under /dev except those two. If you have any kind of trouble please post it here regardless of wether you're able to fix it or not since it's valuable feedback.
> 
> Good luck ;)

 

Thanks! It did take me a while to try it out; not quite sure of the results yet: When I do an 'ls -l /dev', I still see everything but /dev/kitchensink there, but it did indeed seem to reduce the size of the ISO by a bit - and it still works  :D

I also have a new question: Recently, when I am trying to upgrade my Gentoo installation, I get a message like this:

```
[blocks B     ] sys-apps/pam-login (is blocking sys-apps/shadow-4.0.15-r2)

[blocks B     ] >=sys-apps/shadow-4.0.14-r2 (is blocking sys-apps/pam-login-4.0.14)

[ebuild     U ] sys-apps/shadow-4.0.15-r2 [4.0.14-r1] USE="-nls -nousuid -pam -skey" 0 kB

```

One could probably fix that by just picking the right versions of both packages, but it made me wonder: Being that I use automatic login through mingetty, is there a way that I could get rid of either of them or at least replace them with something even lighter?

Emerge threatens doom and gloom if I remove sys-apps/shadow and removing sys-apps/pam-login (while happening without any warnings) does seem to break the automatic login.

So, are there any alternatives to the two of them that would be suited for use with the live CD?

Thanks  :)

----------

## Lepaca Kliffoth

I don't know much about it, I use autologin through kdm. Maybe you should go to the mingetty site (or whatever) and read how it works and what it needs to function. If you manage to make things work write up how you did it so I can put it in the guide  :Wink: 

Oh if you still see tons of things under /dev it's because of course udev re-creates the devices. On the actual disk there should be only null and console, I think.

----------

## schneekater

 *Lepaca Kliffoth wrote:*   

> I don't know much about it, I use autologin through kdm. Maybe you should go to the mingetty site (or whatever) and read how it works and what it needs to function. If you manage to make things work write up how you did it so I can put it in the guide ;)

 

Well the upshot of the lowdown is that for automatic login with mingetty to work, you need a /bin/login that honors the '-f' flag. Seems simple enough, but the login that comes in the shadow package only seems to do so if you compile it with PAM support.

So I removed pam-login and re-emerged shadow with PAM support and everything works now - though I still wonder whether there is a way to get rid of PAM altogether...

----------

## schneekater

I'm trying to switch the boot process from using the initrd that I created using your guide to an initramfs image that I made following the instructions at http://smitty1e.livejournal.com/27916.html#cutid. Basically, I replaced the binaries with busybox and used your linuxrc in lieu of Christopher's init script. Yes, I know that this approach is a bit naive - but I can already report partial success  :D 

The issue that I am still having is this: If I use your linuxrc script verbatim, pivot_root is causing all sorts of interesting issues. For the time being, I am starting a shell from the init script, walking through the contents of your linuxrc manually. Up until i reach the pivot_root line, everything sems to work fine, then:  *Quote:*   

> # pivot_root . initrd
> 
> pivot_root: pivot_root: No such file or directory
> 
> # mkdir initrd
> ...

 

So, no matter what I do, pivot_root doesn't pivot. Am I missing something here?

Things are different if I replace the pivot_root line with

```
switch_root /union /sbin/init
```

The system boots and runs fine; the only issue there is that I get ugly messages during shutdown: First, I get many error messages saying that /static could not be found and then, later, another bunch of errors about file systems that couldn't be found, including unionfs, followed by a prompt to enter the admin password or press Ctrl-D to continue. (I can't quote the exact error messages right now, because all I have is a cruddy version of qemu that segfaults before I get to that point; I can post them later if they'd be of any interest). The system finally shuts down regardless, but those messages are vaguely disquieting.

Lepaca, you mentioned that after adding unionfs, your livecd wouldn't rerstart properly. Were your problems in any way similar to what I am seeing when using switch_root? If so, are there any new insights that you'd be willing to share?

----------

## Lepaca Kliffoth

First, I don't know what's the matter with pivot_root and can't really help you there.

About the restarting problem, it's a bug that I hoped someone would be able to fix. I solved it with an ugly workaround; I simply made a dumb script that:

1 - sync && sync && sync just for safety

2 - wait 3 or 4 seconds for added safety ^^

3 - umount any filesystem that has nothing to do with the livecd, like harddisk partitions and usb drives

4 - call halt and reboot nuke-style since everything that is still mounted is either a ramdisk or the livecd itself.

That's how I solved it. I know, it sucks, but I really can't figure out why when I reboot/halt normally everything goes to hell. I was hoping in someone's contribution but as you can see this guide didn't attract enough interest  :Sad:  The next update will simply add what has actually been contributed but it won't solve the problem of rebooting. I'll post the dumb script as soon as I can.

----------

## schneekater

 *Lepaca Kliffoth wrote:*   

> [...]
> 
> That's how I solved it. I know, it sucks, but I really can't figure out why when I reboot/halt normally everything goes to hell. I was hoping in someone's contribution but as you can see this guide didn't attract enough interest :( The next update will simply add what has actually been contributed but it won't solve the problem of rebooting. I'll post the dumb script as soon as I can.

 It has been a bit quiet in here lately, hasn't it? Which is a shame, since this guide is the best one I have seen this far. 

I would be quite interested in seeing your shutdown script; the errors during system halt don't seem to be critical, since I typically don't have anything mounted that could get corrupted, but it would still be nice to be extra sure.

Thanks :)

----------

## Lepaca Kliffoth

Finally had the time to fish the script out of the livecd:

halt.sh:

```

grep /dev/hd /proc/mounts | awk '{print $1}' > /tmp/mounted

for i in `cat /tmp/mounted`

do

        mount -o remount,ro $i

        umount $i

done

sync && sync && sync

sleep 3

if [[ -f /etc/killpower ]] ; then

        UPS_CTL=/sbin/upsdrvctl

        UPS_POWERDOWN="${UPS_CTL} shutdown"

elif [[ -f /etc/apcupsd/powerfail ]] ; then

        UPS_CTL=/etc/apcupsd/apccontrol

        UPS_POWERDOWN="${UPS_CTL} killpower"

fi

if [[ -x ${UPS_CTL} ]] ; then

        ewarn "Signalling ups driver(s) to kill the load!"

        ${UPS_POWERDOWN}

        ewarn "Halt system and wait for the UPS to kill our power"

        /sbin/halt -id

        while [ 1 ]; do sleep 60; done

fi

halt -i -f -d -h -p

```

You can easily expand it to get any kind of device you want but it's exceedingly ugly and I don't have any idea how successful it is.

reboot.sh is the same:

```

grep /dev/hd /proc/mounts | awk '{print $1}' > /tmp/mounted

for i in `cat /tmp/mounted`

do

        mount -o remount,ro $i

        umount $i

done

sync && sync && sync

sleep 3

/sbin/reboot -idpk

# hmm, if the above failed, that's kind of odd ...

# so let's force a reboot

/sbin/reboot -f

```

After this, you have to make sure they get called directly. It all stinks awfully.

edit: to be perfectly clear, I did some testing and it umounts everything cleanly, what I still don't know is if there are cases when everything for some strange reason goes to hell.

----------

## daybyter

Is there anyone with mkxf86config problems lately? 

In my latest livecd versions xdm starts _before_ mkxf86config, which doesn't work (obviously). xdm restart works and gets X going. 

I wonder, if there should be a 'before xdm' in mkxf86config?

----------

## Lepaca Kliffoth

Try using app-misc/livecd-tools, the service is called autoconf.

----------

## daybyter

 *Lepaca Kliffoth wrote:*   

> Try using app-misc/livecd-tools, the service is called autoconf.

 

Yeah, I already added it. Seems like it uses mkxf86config. 

I use an older portage tree (and I don't want to update that often to avoid problems with newer packages), so I have to add a ~x86 to get a newer livecd-tools version with the 'before xdm' bugfix.

Thanks for your help.

----------

## schneekater

 *Lepaca Kliffoth wrote:*   

> Finally had the time to fish the script out of the livecd:
> 
> halt.sh:
> 
> ```
> ...

 

I managed to make this substantially uglier:

```

grep "^/dev/" /proc/mounts | grep -v cdrom | grep -v static \

      | cut -d " " -f 1 | sort | uniq > /tmp/mounted

...

```

This unmounts any (pseudo-) device I may have mounted; I use /dev/sd* and /dev/mapper/* a lot and figured that this should catch most cases without trying to unmount the CD or the static part of the root union itself.

I made sure that your script is the first halt in the $PATH and edited inittab to use it for ctrl-alt-del. The shutdown process is just so much prettier now - and much faster, too  :) 

 Thanks!

----------

## Lepaca Kliffoth

 *schneekater wrote:*   

> 
> 
> I managed to make this substantially uglier:
> 
> 

 

 :Laughing:  Computer science is great, isn't it?   :Laughing:   :Laughing: 

 *schneekater wrote:*   

> 
> 
> This unmounts any (pseudo-) device I may have mounted
> 
> ...
> ...

 

This will go into the guide, whenever I manage to update it - which will happen Real Soon Now(TM) it seems  :Sad: . Thanks!

----------

## mbar

Sorry for crossposting  :Smile:  The following is taken from Talk page, I have the same problem:

 *Quote:*   

>  Problems with Symbolic Links
> 
> After "Copying read-write image ...", when, I think, the linuxrc script starts to run, it starts giving me a LOT of errors in the form : "ln: creating symbolic link `/var/lib/init.d/softscripts.new/clock` to `/etc/init.d/clock`: No such file or directory". The same goes to all the files in init.d, such as hostname, domainname, net.lo etc... Does anyone have a clue as to what is the problem? I tried to switch to init=/bin/sh instead of the linuxrc and it still boots like this. I followed the instructions on the site exactly as it is written and I fail to see where the problem is. can anyone please help?
> 
>     * [mapelo] I have the same problem, and all files and directories in tmpfs (etc,var,...) are NOT write access, only read access. 

 

Is there any way to solve it?

www.technoportal.pl/photo/live.jpg

----------

## mbar

ok, I solved it by adding livecd-tools to my livecd source

----------

## Lepaca Kliffoth

I'm in NYC so I can't really give anyone any support at all. I'll be back Sep 2.

----------

## ahaau

I followed the guide, and have a working liveusb now.

remaining problem:

unionfs/rebooting, I don't quite understand how to use the reboot.sh script.

----------

## rickvernam

Well, I am thoroughly frustrated now.

I've been working this for a week now, and can not get past this problem.

```
RAMDISK: ext2 filesystem found at block 0

RAMDISK: Loading 7168KiB [1 disk] into ram disk... done.

VFS: Mounted root (ext2 filesystem).

Freeing unused kernel memory: 108k freed

Failed to execute /bin/sh.  Attempting defaults...

Kernel panic - not syncing: No init found.  Try passing init= option to kernel.
```

it also fails for /linuxrc, as you can imagine.

so, here are the things that I can think of off the top of my head.

kernel config

```
CONFIG_BLK_DEV_LOOP=y

CONFIG_BLK_DEV_RAM=y

CONFIG_BLK_DEV_RAM_COUNT=1

CONFIG_BLK_DEV_RAM_SIZE=8192

CONFIG_BLK_DEV_INITRD=y
```

initrd is small enough to fit in there...

```
mutt boot # ls -s initrd

7175 initrd
```

I'm using grub instead of ISOLINUX (just b/c grub is already setup - shouldn't affect this problem though, right?)

menu.lst

```
 root (cd)

 kernel (cd)/boot/vmlinuz video=vesafb-tng:mtrr,ywrap,1024x768@60 root=/dev/ram0 rw init=/bin/sh cdroot

 initrd (cd)/boot/initrd
```

the host machine is an athlon xp.  the livecd environment is 486 with cflags from the gentoo safe cflags page

```
CFLAGS="-Os -march=i486 -pipe -fomit-frame-pointer"

CHOST="i486-pc-linux-gnu"
```

The kernel is also build for 486.

if I mount the initrd, like so for example

```
mount -o loop initrd ./tmp
```

you can see that the required stuff is there (I know my initrd fs is a little different than in this how to...but that shouldn't affect the problem that I'm having, right?)

```
mutt tmp # ls -r *

linuxrc

proc:

new:

lost+found:

lib:

libuuid.so.1  librt.so.1  libreadline.so.5  libpthread.so.0  libncurses.so.5  libhistory.so.5  libdl.so.2  libc.so.6  libblkid.so.1

etc:

mtab  fstab

dev:

tty  null  loop0  hdd  hdc  hdb  hda  console

bin:

umount  tar  sh  pivot_root  mount  mkdir  chroot  cat
```

and I can run sh, too

```
mutt tmp # bin/sh

sh-3.1#
```

I thought that perhaps I could try to chroot into the initrd fs mounted in tmp...

```
mutt tmp # chroot . /bin/sh

chroot: cannot run command `/bin/sh': No such file or directory

mutt tmp # stat bin/sh

  File: `bin/sh'

  Size: 523248          Blocks: 1028       IO Block: 4096   regular file

Device: 701h/1793d      Inode: 25          Links: 1

Access: (0755/-rwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)

Access: 2006-09-14 12:42:24.000000000 -0500

Modify: 2006-09-14 12:22:48.000000000 -0500

Change: 2006-09-14 12:22:48.000000000 -0500
```

I am testing this all in qemu.  The machine is about 20 miles away, so I'm using VNC to access the qemu vm...

```
qemu -kernel-kqemu -cdrom ./aecd.iso -m 64 -localtime -usbdevice tablet -vnc 9 -boot d
```

Same result if I run qemu with -no-kqemu instead of -kernel-kqemu.

So, I'm out of ideas.  anybody else have some?

----------

## rickvernam

 *rickvernam wrote:*   

> Well, I am thoroughly frustrated now.
> 
> I've been working this for a week now, and can not get past this problem.
> 
> ```
> ...

 

Apparently, I'm not out of ideas...

but first, a bit of background.

I had, as instructions said, copied /bin/sh /bin/cat ...etc to the initrd fs.

Also, I did ldd /bin/sh, copied the resulting stuff from lib... and the same for everything in bin.

The idea was to copy ALL of bin and ALL of lib into the initrd.  While I had to omit some of the clearly unneeded things from bin, it all fit in a 7MB initrd.

And most importantly, it works!!

So, clearly the problem was that I was not careful enough when copying the lib stuff specified by ldd.

What a waste of a perfectly good week.  sheesh.

----------

## peaceful

First:  Great guide!  This is my third LiveCD attempt.  First was a failed attempt at the Catalyst method.  Second was the 'from scratch' method on gentoo-wiki, which booted, but only used squashfs and I needed to write some data...and then I found this guide.

I've just got a couple of minor suggestions:

 *Quote:*   

> To get union among the other filesystems you see in menuconfig, download the source and run the patch-kernel.sh therein.  Next time you run menuconfig, unionfs will be there.

 

It's unclear which unionfs sources should be fetched from where.  First I tried fetching the sources for the latest stable unionfs through portage, but there are no stable versions in portage.  Next, I googled around and found http://www.filesystems.org/project-unionfs.html

Since there seems to be specific versions of unionfs for specific versions of the kernel, I would assume that you could update the instructions to read something like:

 *Quote:*   

> To get union among the other filesystems you see in menuconfig, download the appropriate version of unionfs for your kernel from the table on http://www.filesystems.org/project-unionfs.html and then untar the tarball, cd into the directory it created, and run patch-kernel.sh /usr/src/linux to patch your current kernel.  Next time you run menuconfig, unionfs will be under File systems --> Miscellaneous filesystems --> Union fs support.

 

The only other issue I ran into so far (I'm just starting step 4) was on step 1:

 *Quote:*   

> I suggest you follow Bob P's stage 1/3 method...

 

There's no reference to who Bob P is, or where or what his method is, or even why we ought to follow it.

I'm excited to get through the rest of the guide.  Thanks for all your work!

----------

## ahaau

[quote="gieltje"] *fRIOUX wrote:*   

>  *Quote:*   Post it to the gentoo-wiki. 
> 
> It allready is there, be it in a different way see http://gentoo-wiki.com/HOWTO_build_a_LiveCD_from_scratch.
> 
> Mine was a fork of veezi's a long time ago and has it's pro's and cons against this method.
> ...

 

http://gentoo-wiki.com/HOWTO_build_a_LiveCD_from_scratch in gentoo-wiki is not detailed enough, and doesn't work for me (unionfs, initrd),

It helps a lot to put this howto in gentoo-wiki.

I modified the linuxrc in initrd to boot my liveusb, and I found it's very easy to do initrd with instructions outlined here,

```

#!/bin/sh

export PATH=/bin

export CDROM=""

while [ "${CDROM}" == "" ]

do

 for x in sda1 sdb1 sdc1 sdd1

 do

  echo "Trying liveusb at ${x}..."

  sleep 10

  mount -t jfs -oro /dev/${x} /cdrom

  if [ "$?" == "0" ]

  then

    if [ -e /cdrom/livecd ]

    then

     CDROM=${x}

     break

    fi

    umount /dev/${x}

  fi

 done

 if [ "${CDROM}" != "" ]

 then

         break

 fi

done

echo "LiveCD found in /dev/${CDROM}"

mount -t squashfs -o loop /cdrom/livecd.squashfs  /static

mount -t tmpfs none  /dynamic

mount -t unionfs -o dirs=/dynamic=rw:/static=ro  unionfs  /union

cd /union

pivot_root . initrd

mount --move  /initrd/dynamic  /mnt/dynamic

mount --move   /initrd/static  /mnt/static

mount --move    /initrd/cdrom  /mnt/cdrom

mount -t proc none /proc

cat /proc/mounts > /etc/mtab

umount /proc

exec chroot . /bin/sh <<- EOF >dev/console

umount /initrd

echo "Starting init!"

exec /sbin/init

EOF

```

----------

## Lepaca Kliffoth

Ok why the hell did I stop getting notifications??? Geez

Sorry guys I just found out there's a bunch of posts waiting for my attention. I will read them tomorrow.

I also wanted to let you guys know that I'm working on both this project and another unrelated one and I'm splitting time evenly between the two. While it's a long time since the last significant update, there will be a next version of this guide and it's going to be better than the current one. I know I promised an update more than once and didn't deliver anything so feel free to send me spam and hatemail  :Very Happy: 

----------

## Lepaca Kliffoth

 *peaceful wrote:*   

> 
> 
>  *Quote:*   To get union among the other filesystems you see in menuconfig, download the source and run the patch-kernel.sh therein.  Next time you run menuconfig, unionfs will be there. 
> 
> It's unclear which unionfs sources should be fetched from where.  First I tried fetching the sources for the latest stable unionfs through portage, but there are no stable versions in portage.  Next, I googled around and found http://www.filesystems.org/project-unionfs.html
> ...

 

Will update  :Wink: 

 *peaceful wrote:*   

> 
> 
> The only other issue I ran into so far (I'm just starting step 4) was on step 1:
> 
>  *Quote:*   I suggest you follow Bob P's stage 1/3 method... 
> ...

 

Bob P's "one over three" installation method is the less likely to give you trouble. It's relatively old now so I don't know if anything has popped up recently but it's mostly guaranteed to produce a perfect base system. I'll try to dig up the link.

----------

## JasonB87

Alrighty I was wondering if anybody has setup a livecd with sound?

----------

## paluszak

 *JasonB87 wrote:*   

> Alrighty I was wondering if anybody has setup a livecd with sound?

 

I haven't, but I'll try today, I don't think setting up ALSA would be an issue.

J.

----------

## JasonB87

Awesome I've been meaning to try myself but i've been working on a script that will detect the video card and load AIGLX if possible. It build the xorg.conf from scratch.

----------

## Lepaca Kliffoth

 *JasonB87 wrote:*   

> Alrighty I was wondering if anybody has setup a livecd with sound?

 

Just compile as modules all the soundcard drivers that are safe, the ALSA ones I mean. Debian's "discover" or similiar software (autoconf, or you can make a custom script) will take care of loading the right ones. As far as I know no configuration is needed but I don't know about those fancy 99999 channels soundcards  :Wink: 

The next version of the guide will still take some time. I still have to experiment with a lot of things. I hope the current version is good enough atm, you guys keep letting me know about your experience with it.

----------

## JasonB87

The guide works great. I have a livecd with gnome and i wrote a crappy little script to detect the video card and set the system up to work with either AIGLX or nVidia's direct rendering stuff lol so I have beryl 1.3 installed and working. But yea the guide was the start to all of that lol. Thank you

----------

## Lepaca Kliffoth

 *JasonB87 wrote:*   

> The guide works great. I have a livecd with gnome and i wrote a crappy little script to detect the video card and set the system up to work with either AIGLX or nVidia's direct rendering stuff lol so I have beryl 1.3 installed and working. But yea the guide was the start to all of that lol. Thank you

 

You're welcome  :Wink:  Thanks for the feedback, it motivates me a lot.

----------

## STrRedWolf

Whew!  I think this will be a better LiveCD than all those other guides.

A few hints and tips:

Using Busybox in the initrd: Gentoo always builds a copy of Busybox, which is a small integrated subset of utilities.  It currently lives in /bin/busybox.  Instead of all those major utilities when building the initrd:

Copy Busybox over into the initrd's /bin, 

make a /sbin for the initrd

chroot /mnt/initrd /bin/busybox sh

In the chroot: 'busybox --install'

This will install all the symlinks for all the utilties we need for the initrd, and then some.

Exit the chroot.

----------

## Lepaca Kliffoth

 *STrRedWolf wrote:*   

> ...

 

You're in the guide.

----------

## STrRedWolf

 *Lepaca Kliffoth wrote:*   

>  *STrRedWolf wrote:*   ... 
> 
> You're in the guide.

 

Thanks, but I've got some corrections:  "chroot . /bin/busybox sh" gets you into the shell.  Then a "busybox --install -s" will install the symlinks (otherwize they'll be hard).

There's also docs on doing a cpio/gz archive in the vanilla-sources package.  I'll extract them out for the guide.

----------

## Lepaca Kliffoth

Corrected and thanks ^^

----------

## STrRedWolf

I couldn't get cpio/gz working, but I did get the regular version working!

So, some more updates for you:

 These must be compiled into the kernel: ext2fs, iso9660fs, squashfs, unionfs, ramdisk block device, initrd support, loopback block device.  I didn't see them be mentioned, so maybe making them explicitly mentioned may help others.

In /linuxrc, if you decide to go with the Busybox configuration, make sure PATH is set to /bin:/sbin or symlink /sbin to /bin in the initrd.

More as I smack headlong into them.

----------

## Calandra

Hi to all!

I built a livecd using gentoo-catalyst tool, so i hope not to be OT here  :Smile: 

I have got a problem during the boot of my livecd:

During the boot of the latest one, at the

```
Copying read-write image contents to tmpfs
```

step, I have got a lot of error like this:

```
no space left on device
```

I did this test:

I used 2 different machine both with 512 mb of ram

1- Centrino: all was fine;

2- Sempron: error about missing space on device, during the copying image contents to tmpfs;

The livecd is built using 

subarch: i686

profile: default-linux/x86/2006.1

and genkernel 3.4.5-r1

Thanks for your help

Luca

----------

## Lepaca Kliffoth

 *Calandra wrote:*   

> Hi to all!
> 
> I built a livecd using gentoo-catalyst tool, so i hope not to be OT here 

 

Apri un thread sotto Other Things Gentoo oppure cerca un thread su Catalyst, questo thread non c'entra nulla :p

----------

## Lepaca Kliffoth

 *STrRedWolf wrote:*   

> I couldn't get cpio/gz working, but I did get the regular version working!
> 
> So, some more updates for you:
> 
>  These must be compiled into the kernel: ext2fs, iso9660fs, squashfs, unionfs, ramdisk block device, initrd support, loopback block device.  I didn't see them be mentioned, so maybe making them explicitly mentioned may help others.

 

That's covered in the kernel configuration section.

 *Quote:*   

> Make sure you choose "Y" for ext2, squashfs and iso9660 filesystem support; you also need initrd support and you should make the default initrd size more than 9 megabytes. 
> 
>  <etc, etc, there's more>

 

 *STrRedWolf wrote:*   

> In /linuxrc, if you decide to go with the Busybox configuration, make sure PATH is set to /bin:/sbin or symlink /sbin to /bin in the initrd.
> 
> More as I smack headlong into them.

 

Touching the linuxrc script may lead to premature death. I changed your addition so that it tells to symlink bin to sbin, check it.

----------

## pjf02536

TIPS:

for 2.6.18 kernels (probably others too) using busybox in initrd

loop devices

make sure you have a /dev/loop/x directory

```
      cd /dev/

      mkdir loop

      cd loop

      for i in 0 1 2 3 4 5 6 7; do mknod loop$i b 7 $i; done 
```

or you can't mount squashfs ....

linuxrc tweaks

use 

#!/bin/busybox sh (as symlinks aren't happy till we have a shell)

(note there are fewer library requirements 3 as i recall)

change "mount --move"   to  "mount -o move ..."

Build Tip:

make a $LIVEDIR/initrd  directory and work from there

when you are happy run this script to make your init. be sure to make a /mnt/initrd directory.

build-init script

```

#!/bin/bash

export LIVEDIR=`pwd`

echo "making initrd from directory"

echo "  ... removing old initrd "

# Remove loop

    losetup -d /dev/loop0

    rm boot/isolinux/initrd

echo "Making a new init ..."

    dd if=/dev/zero of=${LIVEDIR}/boot/isolinux/initrd bs=1M count=8

echo " Setting up new init"

# make sure loop is usable

    modprobe loop

    losetup /dev/loop0 ${LIVEDIR}/boot/isolinux/initrd

    mkfs.ext2 /dev/loop0

echo"Mount it to work on it:"

    mount /dev/loop0 /mnt/initrd

    cp -av initrd /mnt/

echo "To remove init mount:"

    umount /mnt/initrd

```

ok here is the modified linuxrc script, I added a few echos so we can follow it on boot

```

#!/bin/busybox sh

export PATH=/bin

for x in hda hdb hdc hdd

do

   mount -t iso9660 /dev/${x} /cdrom

   if [ "$?" == "0" ]

   then

      CDROM=${x}

      break

   fi

done

if [ "${CDROM}" == "" ]

then

   echo "FATAL --- LIVECD NOT FOUND"

   exec /bin/busybox sh

   exit

fi

echo "LiveCD found in /dev/${CDROM}"

echo " Setting loop for Squashed FS"

losetup /dev/loop0 /cdrom/livecd.squashfs

mount -t squashfs -o loop /cdrom/livecd.squashfs  /static

echo " Mounting dynamic fs"

mount -t tmpfs -o size=300 none  /dynamic

echo " Creating a perfect union"

mount -t unionfs  -o dirs=/dynamic=rw:/static=ro  unionfs  /union

cd /union

echo " and making the union the ROOT FS"

pivot_root . initrd

echo " Moving mountpoints around , dynamic static and CD"

mount -o move  /initrd/dynamic  /mnt/dynamic

mount -o move   /initrd/static  /mnt/static

mount -o move    /initrd/cdrom  /mnt/cdrom

echo " Mounting a proc to make an mtab"

mount -t proc none /proc

cat /proc/mounts > /etc/mtab

umount /proc

echo "FINALLY starting a new session"

exec chroot . '/bin/bash' <<- EOF > dev/console 2>&1

umount /initrd

echo "Starting init!"

exec /sbin/init

EOF

```

----------

## ahaau

instead of search within a list, say, hd[a-d]?

the logic device name depends on the booting box/kernel.

----------

## JeliJami

hwsetup segfaults:

```
# hwsetup

Trying method 1......using /sys/bus/pci...OK

Decided to use Linux-sysfs

Segmentation fault

# ls -l /etc/sysconfig/

total 0

```

This leaves me with an empty Driver for the video card (via), hence "no screens found"

----------

## modified_bessel

I would like to use aufs instead of unionfs in your method; however, aufs loads in as a kernel module, and is not compiled into the kernel.  Do you see major problems with this?  Thanks.

----------

## mistik1

I noticed that some guys in this thread wanted to be able to use and initramfs vs initrd and since I am working with initramfs only I wrote a little script to help me to work on my initramfs.

I save this as mkinitramfs.sh

```

#!/bin/bash

if [[ "${DEBUG}" ]]; then

   set -x

fi

DIRBASE=INITRAMFS

tempdir=${ITEMP:-$PWD}

WORKDIR=${tempdir}/${DIRBASE}

# utility functions

usage() {

   echo "Usage: ${0##*/} [-e initramfs]|[-m initramfs]"

   echo -e "\t-e </full/path/to/initramfs-image> "

   echo -e "\t-m </full/path/to/destination/image>"

   echo -e "\t-e for extract and -m for make image"

}

if [[ $# -lt 1 ]]; then

   echo "Nothing to do exiting......."

   exit

fi

while getopts "e:m:" args; do

   case $args in

      e)

      # Extract initramfs

         IMAGE=${OPTARG}

         [[ -d ${WORKDIR} ]] && rm -rf ${WORKDIR}

         mkdir -p ${WORKDIR}

         pushd ${WORKDIR} >/dev/null

         zcat ${IMAGE}|cpio -i -d -H newc --no-absolute-filenames

         popd >/dev/null

         break

      ;;

      m)

      # Make initramfs

         DESTIMAGE=${OPTARG}

         if [[ -d ${WORKDIR}/lib ]]; then

            pushd ${WORKDIR} >/dev/null

            find . | cpio -o -H newc | gzip > ${DESTIMAGE}

            popd >/dev/null

         else

            echo "${WORKDIR} does not appear to be valid"

            echo "Doing Nothing"

            exit 1

         fi

         break

      ;;

      \?)

         usage

         exit 1 ;;

      *)

         echo "Invalid Argument"

         usage

         exit 1 ;;

   esac

done

```

If you use genkernel to create your initramfs you can extract it by just running the script like this.

```
mkiniramfs.sh -e /path/to/initramfs
```

If you have not set and ITEMP variable it will extract the initramfs to ${PWD}/INITRAMFS

You can then 

```
# cd INITRAMFS 

#Do all your mods then

cd ../ 

mkinitramfs -m /path/to/new/initramfs
```

Thats about it you would now have a new initramfs in /path/to/new/

Hope this helps someone out there.

----------

## JDGBOLT

I initially started off with the linuxrc file that was in the post, and found it wasn't doing exactly what I wanted to, so I took the script as a base and completely rewrote it to be more modular, I wanted a initrd that I could easily just drop files into, which I created in the images folder on my livecd, and made the script check for the presence of the images directory so that it won't mistake another cdrom for its own. Also had to work around some of the stupidness of the beyond sources that I am currently using for my kernel. You may notice that it looks somewhat like genkernel, I worked with hacking away at genkernel a while ago to get an initrd that would boot my encrypted/lvm filesystems, and kind of liked the modular way of doing things, found it easier to read in a sense and be able to tell what is going wrong. There is plenty of output from this initrd, mostly because I wanted to tell what it was doing in case I made a mistake with typing it up. Also you will notice that I don't unmount the initrd here, whenever I tried it it would say it was busy, so decided to forego it, since it is not really hurting anything. Here are the two scripts: 

/linuxrc

```

#!/bin/ash

export PATH=/bin:/sbin >/dev/null 2>&1

echo "Remounting initrd read-write..."

mount -o remount,rw / >/dev/null 2>&1

echo "Loading modular scripts..."

. /etc/initrd.scripts

echo "Executing startMdev..."

startMdev

echo "Executing findCDRom..."

findCDRom

echo "Executing findImages..."

findImages

echo "Executing mountImages..."

mountImages

echo "Executing mountTmpfs..."

mountTmpfs

echo "Executing mountUnion"

mountUnion

echo "Executing makeUnionMount"

makeUnionMount

echo "Executing pivotRoot"

pivotRoot

echo "Executing mountUnionMount"

mountUnionMount

echo "Chrooting..."

exec chroot . /bin/sh <<- EOF >dev/console

echo "Starting init!"

exec /sbin/init

EOF

```

And here is the /etc/initrd.scripts , yes, the name taken directly from genkernel, used part of it as a base:

```

#!/bin/ash

runShell() {

        /bin/ash

}

startMdev() {

        echo "Populating device nodes with mdev busybox udev replacement..."

        mount /sys

        mount /proc

        mdev -s

        umount /sys

        umount /proc

}

findCDRom() {

        echo "Finding CD-ROM device..."

        for x in $(ls /dev/hd*)

        do

                mount -t iso9660 ${x} /cdrom > /dev/null 2>&1

                if [ "$?" == 0 ]

                then

                        if [ -d /cdrom/images ]

                        then

                                CDROM=${x}

                                break

                        else

                                umount /cdrom

                        fi

                fi

        done

        if [ "${CDROM}" == "" ]

        then

                for x in $(ls /dev/sr*)

                do

                        mount -t iso9660 ${x} /cdrom >/dev/null 2>&1

                        if [ "$?" == "0" ]

                        then

                                if [ -d /cdrom/images ]

                                then

                                        CDROM=${x}

                                        break

                                else

                                        umount /cdrom

                                fi

                        fi

                done

        fi

        if [ "$CDROM}" == "" ]

        then

                echo "Cannot find LiveCD, running shell..."

                runShell()

                exit

        fi

        echo "LiveCD found at ${CDROM}..."

}

findImages() {

        echo "Finding read-only squashfs disk images..."

        for x in $(cd /cdrom/images && ls)

        do

                echo "Found disk image ${x}..."

        done

}

mountImages() {

        echo "Mounting read-only squashfs disk images..."

        loopCount=0

        for x in $(cd /cdrom/images && ls)

        do

                echo "Mounting disk image ${x}..."

                losetup /dev/loop${loopCount} /cdrom/images/${x}

                mkdir /mnt/${x}

                mount -t squashfs /dev/loop${loopCount} /mnt/${x}

                loopCount=$(($loopCount + 1))

        done

}

mountTmpfs() {

        echo "Mounting read-write ramdisk..."

        mkdir /ramdisk

        mount -t tmpfs ramdisk /ramdisk

}

mountUnion() {

        echo "Creating argument list for mounting the unionfs..."

        UNIONARGS="dirs=/ramdisk=rw"

        for x in $(cd /mnt && ls)

        do

                UNIONARGS="$UNIONARGS:/mnt/${x}=ro"

        done

        echo "Unionfs arguments is ${UNIONARGS}"

        mount -t unionfs -o ${UNIONARGS} unionfs /union

        echo "Unionfs mounted at /union with arguments ${UNIONARGS}..."

}

makeUnionMount() {

        echo "Creating mountpoints for squashfs branches in unionfs root"

        cd /union

        for x in $(cd /mnt && ls)

        do

                echo "Making mountpoint var/.${x}"

                mkdir var/.${x}

        done

        mkdir mnt/livecd

        mkdir var/.ramdisk

        mkdir var/.initrd

}

pivotRoot() {

        echo "Chrooting into UnionFS Environment..."

        cd /union

        pivot_root . var/.initrd

}

mountUnionMount() {

        echo "Moving squashfs branches into union..."

        for x in $(cd /var/.initrd/mnt && ls)

        do

                echo "Changing branch /var/.initrd/mnt/${x} to /var/.${x}"

                mount -o move /var/.initrd/mnt/${x} /var/.${x}

        done

        echo "Moving ramdisk branch into union..."

        mount -o move /var/.initrd/ramdisk /var/.ramdisk

        echo "Moving livecd branch into union..."

        mount -o move /var/.initrd/cdrom /mnt/livecd

        echo "Creating mtab with updated mountpoints..."

        mount -t proc none /proc

        cat /proc/mounts > /dev/mtab

        umount /proc

}

```

There might be mistakes in it or doing things the hard way, but, well, this is like the third shell script that I have ever wrote, so cut me some slack. There are a number of enhancements to it, such as using mdev in order to get the device nodes so I don't have to do them all manually, multiple squashfs support, so I can just add files to the cd by putting them into separate squashfs images. I am doing this because I am building this livecd for a project, and there is a piece of it that is subject to change, but I don't want to be generating the main squashfs every time there is a change. I will be switching this over to using aufs, and with this, it is just a simple change of a couple lines. When it boots up, it moves the mounted squashfs directories into /var/.squashfs-name, and I just set it up so I have a 01-root 02..., so I can easily tell it what order to lay everything out. I may at a later point in time modify it to be able to have a disk image that it can look for in the root of another hard drive to be able to keep the changes to it. Let me know if any of you find it particularly useful.

JDGBOLT

----------

## JDGBOLT

It is possible to fix the rebooting issue by emerging livecd-tools, and editing the /sbin/livecd-functions.sh file, there is I think near the end a RC_UNMOUNT variable that it sets, I added /var/.* to the end of the argument and now the system goes down peacefully. Since in /etc/init.d/halt.sh it sources the livecd.functions file and looks for that RC_UNMOUNT variable, which tells it what not to try to unmount. A slightly more clean way of handling it than hacking away at the halt.sh file.

JDGBOLT

----------

