Remastering the LFS LiveCD

From CBLFS
Jump to: navigation, search

Contents

Remastering the LFS LiveCD

While the Linux from Scratch LiveCD may be used to build a CLFS system, the source tarballs, patches, and the book for CLFS are not included on the LiveCD. These instructions will remaster the LFS LiveCD to include the CLFS packages and patches necessary to build a version 1.0.0 ix86, "pure" x86_64, or multilib x86_64 CLFS system. The original version of this hint can be found at http://www.linuxfromscratch.org/hints/downloads/files/lfscd-remastering-howto.txt.

If you do not wish to remaster the LFS LiveCD, a remastered iso that also contains the CLFS books, version 1.0.0 may be downloaded from:

http://cross-lfs.org/~arowland/cluster_project/lfslivecd-CLFS-1.0.0-Cluster.iso

Creating the Working Environment

On the LiveCD, you will find the following files:

boot/*
root.ext2

The boot directory contains the Linux kernel, the initramfs image and the bootloader. The actual root filesystem (ext2) is in the root.ext2 file.

Before remastering the LiveCD, we set up the environment. To simplify, create a $WORK environment variable:

export WORK=/mnt/lfslivecd

Mount the LFS LiveCD:

mount /media/dvd

Look at the root.ext2 file size:

ls -l /media/dvd/root.ext2

If it is approximately 1.5 GB, our kernel decompressed the CD for us. In this case, we can copy the file to our hard disk as usual:

cp /media/dvd/root.ext2 $WORK/root.ext2

If it is only 500 MB, you have to rebuild your kernel with ZISOFS support, or decompress the file manually:

mkzftree -u -F /media/dvd/root.ext2 $WORK/root.ext2

In either case, we end up with a $WORK/root.ext2 file that is 1.5 GB in size. This may not be sufficient for your remastered CD (or DVD) filesystem. If you want, you can resize the file with the resize2fs program from e2fsprogs.

Mount the filesystem image with a loop device:

mkdir -pv $WORK/root &&
mount -o loop $WORK/root.ext2 $WORK/root

It is a good idea to create and bind-mount a temporary directory, in order to preserve as many zeroed sectors as possible:

mkdir -pv $WORK/build $WORK/root/build &&
mount --bind $WORK/build $WORK/root/build

Mount other directories necessary for chrooting:

mount -t proc proc $WORK/root/proc &&
mount -t sysfs sysfs $WORK/root/sys &&
mount -t devpts devpts $WORK/root/dev/pts &&
mount -t tmpfs tmpfs $WORK/root/dev/shm

Chroot to the filesystem and change to the /build directory:

chroot $WORK/root
cd /build

Add CLFS Packages and Patches

We need to add the packages and patches to our new LiveCD. The easiest way to do this is to download the single, mega-tarball for the version of CLFS we choose to use.

mkdir /clfs-sources &&
cd /clfs-sources

Choose the CLFS version you wish to use. Note the date string for the development version may be different on the day you attempt to download.

wget http://cross-lfs.org/files/packages/clfs-packages-1.0.0.tar
wget http://cross-lfs.org/files/packages/clfs-packages-1.1.0.tar
wget http://cross-lfs.org/files/packages/clfs-packages-svn-20090205.tar

Return to our build directory.

cd /build

Rebuilding Initramfs

Rebuild the initramfs image for the LiveCD. The zipped files for initramfs can be obtained from the Linux from Scratch wiki. There is a link at the bottom of the page.

Remove the "include $(ROOT)/scripts/functions" line from the Makefile and then generate the initramfs image for your CD:

32 bit

make compile-stage2 VERSION="x86-6.3-custom"

64 bit

make compile-stage2 VERSION="x86_64-6.3-custom" \
	    LINKER=ld-linux-x86-64.so.2 64bit=true

You can replace the "x86-6.3-custom" or "x86_64-6.3-custom" with your own string. This produces the initramfs_data.cpio.gz file in the current directory. This needs to be copied to /build:

cp initramfs_data.cpio.gz ../ &&
cd ../ &&
rm -dfr initramfs

Remaster the LiveCD

Everything is complete and ready to be remastered. Exit from the chroot and clean up the mounts:

exit
umount $WORK/root/dev/shm &&
umount $WORK/root/dev/pts &&
umount $WORK/root/sys &&
umount $WORK/root/proc &&
umount $WORK/root/build &&
rmdir $WORK/root/build

Remove the bash history from the chroot or it will become part of the remastered LiveCD:

rm $WORK/root/root/.bash_history
rm $WORK/root/etc/resolv.conf

Since we created and removed some files, the sectors previously occupied by those files begin to contain non-zero data. Such sectors are useless, but they don’t compress well. Zero them out:

dd if=/dev/zero of=$WORK/root/zeroes

This command will print a message that the disk is full. This is not an error. Now remove the file that was created above:

rm $WORK/root/zeroes

Unmount the root.ext2 file:

umount $WORK/root &&
sync

The sync command is needed due to a bug in the loop driver in some kernels that leads to a filesystem with errors. Now make the directory structure for your LiveCD, copy the boot directory from the original LiveCD, and replace the initramfs with new one you just created. The underscore before cpio in the following commands is not a typo.:

mkdir -pv $WORK/iso &&
cp -r /media/dvd/boot $WORK/iso &&
cp -v $WORK/build/initramfs_data.cpio.gz $WORK/iso/boot/isolinux/iniramfs_data_cpio.gz

Recompress the root.ext2 file:

mkzftree -F $WORK/root.ext2 $WORK/iso/root.ext2

Recreate the CD image. The string after "lfslivecd-" must be the same as you used when creating the initramfs:

cd $WORK/iso

32 bit

mkisofs -z -R -l --allow-leading-dots -D -o \
../lfslivecd-x86-6.3-custom.iso -b boot/isolinux/isolinux.bin \
-c boot/boot.cat -no-emul-boot -boot-load-size 4 \
-boot-info-table -V "lfslivecd-x86-6.3-custom" ./

64 bit

mkisofs -z -R -l --allow-leading-dots -D -o \
../lfslivecd-x86_64-6.3-custom.iso -b boot/isolinux/isolinux.bin \
-c boot/boot.cat -no-emul-boot -boot-load-size 4 \
-boot-info-table -V "lfslivecd-x86_64-6.3-custom" ./

Burn The New Image

Burn the new image to a CD or DVD. To burn an iso with cdrecord you will have to find out the device id. This is used to identify your burner on the scsi bus. Yes even for ATAPI drives you will need the device id. Find it by issuing the following command:

cdrecord dev=ATAPI -scanbus

Notice the 3 numbers seperated by commas, this is the device id that should be used for cdrecord. I have the choice of 0,0,0 or 0,1,0, but yours could be different so you need to replace it with your device id. Some people will advice to use dev=/dev/hdc but this is unsupported and might not work. It might work for you, but it is wrong.

If you are using a re-writable disk, you may need to erase it. This can be done with the cdrecord command:

cdrecord dev=ATAPI:0,0,0 -blank=all

To burn the iso use the following command. Replace the 0,0,0 (device id) with the id you found above. You might also want to add driveropts=burnfree to turn on buffer underrun protection. Note that your burner will have to support buffer underrun protection for this to work.

32 bit

cdrecord dev=ATAPI:0,0,0 driveropts=burnfree $WORK/lfslivecd-x86-6.3-custom.iso

64 bit

cdrecord dev=ATAPI:0,0,0 driveropts=burnfree $WORK/lfslivecd-x86_64-6.3-custom.iso

It is recommended that you reboot your working machine using the LiveCD to ensure that it works properly.

Personal tools