Remastering the LFS LiveCD

From CLFS-HINTS

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. If you do not wish to remaster the LFS LiveCD, a remastered iso that also contains the CLFS book, 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

The LiveCD uses the ISO9660 filesystem with Linux-specific transparent decompression extension. On that filesystem, there are 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 on the master node. To simplify, create a $WORK environment variable:

export WORK=/mnt/lfslivecd

Mount the CD:

mount /media/dvdrw

Look at the root.ext2 file size:

ls -l /media/dvdrw/root.ext2

If it is approximately 1.5 GB, the kernel uncompresses the CD for you. In this case, you can copy the file to your hard disk as usual:

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

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

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

In either case, you end up with a $WORK/root.ext2 file that is 1.5 GB in size. This may or 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 version >= 1.39. Earlier versions of e2fsprogs cannot resize filesystem images directly.

Mounting the filesystem image is achieved 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

The packages required to build CLFS version 1.0.0 are the same as the packages required to build LFS version 6.2-3. However, the versions of several of these packages is not the same. While it may be possible to use the versions already included on the LFS LiveCD this has not been tested. We need to remaster the LiveCD to add the CLFS version of the packages.

cd /lfs-sources &&
wget http://homepage.ntlworld.com/robert.debath/dev86/bin86-0.16.17.tar.gz &&
wget http://ftp.gnu.org/gnu/binutils/binutils-2.17.tar.bz2 &&
wget http://ftp.gnu.org/gnu/bison/bison-2.3.tar.bz2 &&
wget http://cross-lfs.org/files/packages/1.0.0/bootscripts-cross-lfs-1.0.tar.bz2 &&
wget ftp://alpha.gnu.org/gnu/diffutils/diffutils-2.8.7.tar.gz &&
wget http://ftp.gnu.org/gnu/gcc/gcc-4.1.1/gcc-4.1.1.tar.bz2 &&
wget http://ftp.gnu.org/gnu/glibc/glibc-2.4.tar.bz2 &&
wget http://ftp.gnu.org/gnu/groff/groff-1.19.2.tar.gz &&
wget ftp://ftp.metalab.unc.edu/pub/Linux/system/boot/lilo/lilo-22.7.1.src.tar.gz &&
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.17.13.tar.bz2 &&
wget http://cross-lfs.org/files/packages/1.0.0/linux-headers-2.6.17.13-09092006.tar.bz2 &&
wget http://ftp.gnu.org/gnu/make/make-3.81.tar.bz2 &&
wget http://primates.ximian.com/\~flucifredi/man/man-1.6d.tar.gz &&
wget http://www.kernel.org/pub/linux/docs/manpages/man-pages-2.33.tar.bz2 &&
wget ftp://alpha.gnu.org/gnu/diffutils/patch-2.5.9.tar.gz &&
wget http://cross-lfs.org/files/packages/1.0.0/shadow-4.0.16.tar.bz2 &&
wget http://prdownloads.sourceforge.net/tcl/tcl8.4.12-src.tar.gz?download &&
wget http://cross-lfs.org/files/packages/1.0.0/udev-cross-lfs-1.0-3.tar.bz2 &&
cd /build

Add CLFS Patches

The patches required to build CLFS version 1.0.0 are different from the patches required for LFS version 6.2-3. All of the CLFS patches for an X86 or x86 64 system will be added to the LiveCD. With all of the patches on the LiveCD you will be able to build a 32-bit system on an x86 or x86_64 platform, a "pure" 64-bit system on an x86_64 platform, or a multilib system on an x86_64 platform.

cd /lfs-sources &&
wget http://patches.cross-lfs.org/1.0.0/bash-3.1-fixes-8.patch &&
wget http://patches.cross-lfs.org/1.0.0/bin86-0.16.17-x86_64-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/binutils-2.17-genscripts_multilib-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/binutils-2.17-posix-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/bzip2-1.0.3-install_docs-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/bzip2-1.0.3-remove_tempfile-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/bzip2-1.0.3-bzgrep_security-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/coreutils-5.96-suppress_uptime_kill_su-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/coreutils-5.96-uname-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/expect-5.43.0-spawn-2.patch &&
wget http://patches.cross-lfs.org/1.0.0/gawk-3.1.5-segfault_fix-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/gcc-4.1.1-cross_search_paths-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/gcc-4.1.1-PR20425-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/gcc-4.1.1-posix-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/gcc-4.1.1-pure64-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/gcc-4.1.1-pure64_specs-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/gcc-4.1.1-specs-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/glibc-2.4-iconv_fix-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/iproute2-2.6.16-060323-libdir-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/glibc-2.4-libgcc_eh-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/glibc-2.4-localedef_segfault-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/grub-0.97-fixes-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/grub-0.97-use_mmap-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/gzip-1.3.5-security_fixes-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/inetutils-1.4.2-inet_addr_fix-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/inetutils-1.4.2-gcc4_fixes-3.patch &&
wget http://patches.cross-lfs.org/1.0.0/inetutils-1.4.2-no_server_man_pages-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/kbd-1.12-gcc4_fixes-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/lilo-22.7.1-cross_compile_x86_64-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/linux-2.6.17.13-tulip-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/mktemp-1.5-add_tempfile-3.patch &&
wget http://patches.cross-lfs.org/1.0.0/perl-5.8.8-Configure_multilib-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/perl-5.8.8-libc-2.patch &&
wget http://patches.cross-lfs.org/1.0.0/readline-5.1-fixes-3.patch &&
wget http://patches.cross-lfs.org/1.0.0/sysklogd-1.4.1-fixes-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/tar-1.15.1-gcc4_fix_tests-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/tar-1.15.1-security_fixes-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/tar-1.15.1-sparse_fix-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/texinfo-4.8-tempfile_fix-2.patch &&
wget http://patches.cross-lfs.org/1.0.0/udev-096-lib64-2.patch &&
wget http://patches.cross-lfs.org/1.0.0/util-linux-2.12r-cramfs-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/util-linux-2.12r-gcc4_fixes-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/util-linux-2.12r-missing_header-1.patch &&
wget http://patches.cross-lfs.org/1.0.0/vim-7.0-fixes-5.patch &&
wget http://patches.cross-lfs.org/1.0.0/zlib-1.2.3-fPIC-1.patch &&
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:

make compile-stage2 VERSION="x86-6.2-3"

You can replace the "x86-6.2-3" 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

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/cdrom/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 &&
mkisofs -z -R -l --allow-leading-dots -D -o \
../lfslivecd-x86-6.2-3.iso -b boot/isolinux/isolinux.bin \
-c boot/boot.cat -no-emul-boot -boot-load-size 4 \
-boot-info-table -V "lfslivecd-x86-6.2-3" ./

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.

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

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

Personal tools