7.14. Cleaning up and Saving the Temporary System

The libtool .la files are only useful when linking with static libraries. They are unneeded, and potentially harmful, when using dynamic shared libraries, specially when using non-autotools build systems. While still in chroot, remove those files now:

find /usr/{lib,libexec} -name \*.la -delete

Remove the documentation of the temporary tools, to prevent them from ending up in the final system, and save about 35 MB:

rm -rf /usr/share/{info,man,doc}/*
[Note]

Note

All the remaining steps in this section are optional. Nevertheless, as soon as you begin installing packages in Chapter 8, the temporary tools will be overwritten. So it may be a good idea to do a backup of the temporary tools as described below. The other steps are only needed if you are really short on disk space.

The following steps are performed from outside the chroot environment. That means, you have to leave the chroot environment first before continuing. The reason for that is to:

Leave the chroot environment and unmount the kernel virtual file systems:

[Note]

Note

All of the following instructions are executed by root. Take extra care about the commands you're going to run as mistakes here can modify your host system. Be aware that the environment variable LFS is set for user lfs by default but it might not be set for root. Whenever commands are to be executed by root, make sure you have set LFS accordingly. This has been discussed in Section 2.6, “Setting The $LFS Variable”.

exit
umount $LFS/dev{/pts,}
umount $LFS/{sys,proc,run}

7.14.1. Stripping

If the LFS partition is rather small, it is good to know that unnecessary items can be removed. The executables and libraries built so far contain a little over 90 MB of unneeded debugging symbols.

Strip off debugging symbols from binaries:

strip --strip-debug $LFS/usr/lib/*
strip --strip-unneeded $LFS/usr/{,s}bin/*
strip --strip-unneeded $LFS/tools/bin/*

These commands will skip a number of files reporting that it does not recognize their file format. Most of these are scripts instead of binaries.

Take care NOT to use --strip-unneeded on the libraries. The static ones would be destroyed and the toolchain packages would need to be built all over again.

At this point, you should have at least 5 GB of free space on the chroot partition that can be used to build and install Glibc and GCC in the next phase. If you can build and install Glibc, you can build and install the rest too. You can check the free disk space with the command df -h $LFS.

7.14.2. Backup

Now that the essential tools have been created, its time to think about a backup. When every check has passed successfully in the previously built packages, your temporary tools are in a good state and might be backed up for later reuse. In case of fatal failures in the subsequent chapters, it often turns out that removing everything and starting over (more carefully) is the best option to recover. Unfortunately, all the temporary tools will be removed, too. To avoid spending extra time to redo something which has been built successfully, prepare a backup.

Make sure you have at least 600 MB free disk space (the source tarballs will be included in the backup archive) in the home directory of user root.

Create the backup archive by running the following command:

cd $LFS &&
tar -cJpf $HOME/lfs-temp-tools-10.1-rc1-systemd.tar.xz .

Replace $HOME by a directory of your choice if you do not want to have the backup stored in root's home directory.

7.14.3. Restore

In case some mistakes have been made and you need to start over, you can use this backup to restore the temporary tools and save some recovery time. Since the sources are located under $LFS, they are included in the backup archive as well, so they do not need to be downloaded again. After checking that $LFS is set properly, restore the backup by executing the following commands:

cd $LFS &&
rm -rf ./* &&
tar -xpf $HOME/lfs-temp-tools-10.1-rc1-systemd.tar.xz

Again, double check that the environment has been setup properly and continue building the rest of the system.

[Important]

Important

If you left the chroot environment either to strip off debug symbols, create a backup, or restart building using a restore, remember to mount the kernel virtual filesystems now again as described in Section 7.3, “Preparing Virtual Kernel File Systems” and re-enter the chroot environment (see Section 7.4, “Entering the Chroot Environment”) again before continuing.