As we want to put a whole system on little space, we will squash some directories to have some more free space on the cd or dvd.
Before squashing, we have some work to do
Issue the following:
cd $LFSMOUNT
As the system won't be writable, we have to provide a directory that will be mounted on tmpfs and will, therefore, be writable to ensure a successful boot.
mkdir -v ro rw dev
Make sure you have support for loopback device in your kernel:
ls -l /dev | grep loop
You should see a few /dev/loopX, where X is a number from 0 to 7. If this is not the case, and the loopback is supported as a kernel module, try to modprobe the module and retry again:
modprobe loop ls -l /dev | grep loop
Create some essential files in the dev directory
mknod -m 600 dev/console c 5 1 mknod -m 666 dev/null c 1 3 cp -av /dev/loop[0-7] dev/ mknod dev/ram0 b 1 0
Copy the /etc directory
cp -av /etc .
Modify some files in it
echo "" > etc/mtab cat > etc/fstab << "EOF" # Begin /etc/fstab # file system mount-point type options dump fsck # order proc /proc proc defaults 0 0 sysfs /sys sysfs defaults 0 0 devpts /dev/pts devpts gid=4,mode=620 0 0 tmpfs /run tmpfs defaults 0 0 usbfs /proc/bus/usb usbfs devgid=14,devmode=0660 0 0 # End /etc/fstab EOF
While booting, we will have to copy some directories in shared memory, and mount a root filesystem on it. This has to be done in the first bootscript.
issue the following to create a new bootscript:
cd etc/rc.d/init.d cat > mountrootfs << "EOF" #!/bin/sh # Set up variables dir_rw=/rw dir_ro=/ro # Source functions source /etc/rc.d/init.d/functions case "$1" in start) # Mount temporary files on $dir_rw echo "Mounting tmpfs on $dir_rw..." mount -t tmpfs tmpfs $dir_rw evaluate_retval sleep 1 # Create essential dirs in dir_rw mkdir $dir_rw/{dev,etc,home,media,mnt} mkdir $dir_rw/{opt,root,srv,tmp,usr,var} # If you have some other dirs in $LFSMOUNT/ like sources # Add them to that list, eg: mkdir -v $dir_rw/sources mount -n -t squashfs root.sqsh ro -o loop mount -n -t aufs -o dirs=$dir_rw/etc=rw:$dir_ro/etc=ro aufs etc mount -n -t aufs -o dirs=$dir_rw/usr=rw:$dir_ro/usr=ro aufs usr mount -n -t aufs -o dirs=$dir_rw/tmp=rw:$dir_ro/tmp=ro aufs tmp mount -n -t aufs -o dirs=$dir_rw/var=rw:$dir_ro/var=ro aufs var mount -n -t aufs -o dirs=$dir_rw/dev=rw:$dir_ro/dev=ro aufs dev mount -n -t aufs -o dirs=$dir_rw/home=rw:$dir_ro/home=ro aufs home mount -n -t aufs -o dirs=$dir_rw/media=rw:$dir_ro/media=ro aufs media mount -n -t aufs -o dirs=$dir_rw/mnt=rw:$dir_ro/mnt=ro aufs mnt mount -n -t aufs -o dirs=$dir_rw/opt=rw:$dir_ro/opt=ro aufs opt mount -n -t aufs -o dirs=$dir_rw/root=rw:$dir_ro/root=ro aufs root mount -n -t aufs -o dirs=$dir_rw/srv=rw:$dir_ro/srv=ro aufs srv chmod 1777 /tmp ;; *) echo "Usage: $0 {start}" exit 1 ;; esac EOF chmod 0754 mountrootfs
Inspect the contents of etc/rc.d/rcS.d
ls -l ../rcS.d
You should see a list beginning with S00mountvirtfs, S02consolelog, ...
Now, issue:
cd ../rcS.d mv -v S00mountvirtfs S01mountvirtfs ln -sv ../init.d/mountrootfs S00mountrootfs
The live system can not be checked with fsck so remove these bootscripts
rm S30checkfs rm S40mountfs rm S45cleanfs
As we are just copying our system, we will need the var directory while booting. We have to remove pid and sockets file from it.
cd $LFSMOUNT cp -av /var . cd var rm log/*.log for FILE in `find . -type f -name '*pid'` do rm $FILE done for FILE in `find . -type s` do rm $FILE done rm -rf tmp/* cd $LFSMOUNT
Create tmp, root and other directories, then squash all. When squashing, you might not want to add some file or directory. Add files to the -e option of mksquashfs if you wish.
mkdir -pv home media mnt opt proc root run srv sys tmp usr ro/{dev,etc,home,media,mnt,opt,root,srv,tmp,usr,var} mksquashfs dev etc /home /media mnt /opt /root /srv tmp /usr var root.sqsh -keep-as-directory -info rm -r var/*
Copy dirs that won't be squashed:
cp -av /bin /boot /lib /sbin .
Copy our previous created initrd.gz to /boot of the media.
cp <PATH-TO-INITRD>/initrd.gz $LFSMOUNT/boot