Index: chapter01/how.xml
===================================================================
--- chapter01/how.xml (revision 7c05ea2a4fb165a36f150b34c55938cdb98e8d95)
+++ chapter01/how.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
@@ -9,9 +9,9 @@
-
How to Build an LFS System
+ How to Cross Build an LFS System
The LFS system will be built by using an already installed
- Linux distribution (such as Debian, OpenMandriva, Fedora, or openSUSE). This
- existing Linux system (the host) will be used as a starting point to
+ UNIX-like system (such as Debian Linux or Mac OS X). This
+ existing UNIX-like system (the host) will be used as a starting point to
provide necessary programs, including a compiler, linker, and shell,
to build the new system. Select the development
option
@@ -54,7 +54,10 @@
cross-compile basic utilities using the just built cross-toolchain.
- then enters a
- "chroot" environment and uses the previously built tools to build
- the additional tools needed to build and test the final system.
+ then boots the
+ minimal Linux environment on the target machine and uses the previously
+ built tools to build the additional tools needed to build and test the
+ final system. Note that in the book the minimal Linux environment may be
+ referred as chroot environment
only to keep the consistency
+ with the original LFS book.
This effort to isolate the new system from the host distribution may
@@ -63,8 +66,5 @@
In , The
- full LFS system is built. Another advantage provided by the chroot
- environment is that it allows you to continue using the host system
- while LFS is being built. While waiting for package compilations to
- complete, you can continue using your computer as normal.
+ full LFS system is built.
To finish the installation, the basic system configuration is set up in
Index: chapter02/aboutlfs.xml
===================================================================
--- chapter02/aboutlfs.xml (revision 7c05ea2a4fb165a36f150b34c55938cdb98e8d95)
+++ chapter02/aboutlfs.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
@@ -16,8 +16,6 @@
directory where you will be building your LFS system - we will use
/mnt/lfs as an example, but the
- directory choice is up to you. If you are building LFS on a separate
- partition, this directory will be the mount point for the partition.
- Choose a directory location and set the variable with the
- following command:
+ directory choice is up to you. Choose a directory location and set the
+ variable with the following command:
export LFS=/mnt/lfs
@@ -28,4 +26,11 @@
/mnt/lfs
(or whatever the variable was set to) when it
processes the command line.
+
+ Create the directory:
+
+mkdir -pv $LFS
+
+ If you don't have much space in the partition holding the directory,
+ you can mount another partition on it.
Index: chapter02/chapter02.xml
===================================================================
--- chapter02/chapter02.xml (revision 7c05ea2a4fb165a36f150b34c55938cdb98e8d95)
+++ chapter02/chapter02.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
@@ -15,8 +15,5 @@
-
-
-
Index: chapter02/hostreqs.xml
===================================================================
--- chapter02/hostreqs.xml (revision 7c05ea2a4fb165a36f150b34c55938cdb98e8d95)
+++ chapter02/hostreqs.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
@@ -36,4 +36,9 @@
+
+ Bc-1.07.0
+
+
+
Bison-2.7 (/usr/bin/yacc
should be a link to bison or small script that executes bison)
@@ -71,25 +76,4 @@
Gzip-1.3.12
-
-
-
- Linux Kernel-&min-kernel;
-
- The reason for the kernel version requirement is that we specify
- that version when building glibc in
- and
- ,
- at the recommendation of the developers. It is also required by
- udev.
-
- If the host kernel is earlier than &min-kernel; you will need to replace
- the kernel with a more up to date version. There are two ways
- you can go about this. First, see if your Linux vendor provides a &min-kernel;
- or later kernel package. If so, you may wish to install it. If your
- vendor doesn't offer an acceptable kernel package, or you would prefer not to
- install it, you can compile a kernel yourself. Instructions for
- compiling the kernel and configuring the boot loader (assuming the host
- uses GRUB) are located in .
-
@@ -161,4 +145,5 @@
unset MYSH
+bc --version | head -n1
echo -n "Binutils: "; ld --version | head -n1 | cut -d" " -f3-
bison --version | head -n1
Index: chapter02/stages.xml
===================================================================
--- chapter02/stages.xml (revision 7c05ea2a4fb165a36f150b34c55938cdb98e8d95)
+++ chapter02/stages.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
@@ -65,29 +65,19 @@
- The /mnt/lfs partition must be mounted.
+ You must boot the temporary system on the target machine.
- A few operations, from Changing Ownership
to
- Entering the Chroot Environment
must be done as the
- root user, with the LFS
- environment variable set for the
- rootuser.
+ A few operations, from
+ Preparing Virtual Kernel File Systems
to
+ Setting up Environment
must be done.
- When entering chroot, the LFS environment variable must be set
- for root. The LFS
- variable is not used afterwards.
+ The operations in must be done
+ before starting or continuing from
+ .
-
- The virtual file systems must be mounted. This can be done
- before or after entering chroot by changing to a host virtual terminal
- and, as root, running the
- commands in
- and
- .
-
Index: chapter04/aboutsbus.xml
===================================================================
--- chapter04/aboutsbus.xml (revision 7c05ea2a4fb165a36f150b34c55938cdb98e8d95)
+++ chapter04/aboutsbus.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
@@ -38,4 +38,12 @@
+ In the cross edition, the SBUs are kept same as the original LFS
+ book. They should only be considered as a reference. It obviously does
+ not make sense to predict the building time in Chapter 7 or 8 with
+ 1 SBU
measured in Chapter 5, as the target machine and
+ the machine running the host distro may be completely different.
+
+
+
For many modern systems with multiple processors (or cores) the
compilation time for a package can be reduced by performing a "parallel
Index: chapter04/addinguser.xml
===================================================================
--- chapter04/addinguser.xml (revision 7c05ea2a4fb165a36f150b34c55938cdb98e8d95)
+++ chapter04/addinguser.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
@@ -81,8 +81,5 @@
lfs the directory owner:
-chown -v lfs $LFS/{usr{,/*},lib,var,etc,bin,sbin,tools}
-case $(uname -m) in
- x86_64) chown -v lfs $LFS/lib64 ;;
-esac
+chown -v lfs $LFS/{usr{,/*},lib*,boot,var,etc,bin,sbin,tools}
If a separate working directory was created as suggested, give
Index: chapter04/creatingminlayout.xml
===================================================================
--- chapter04/creatingminlayout.xml (revision 7c05ea2a4fb165a36f150b34c55938cdb98e8d95)
+++ chapter04/creatingminlayout.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
@@ -21,13 +21,16 @@
root:
-mkdir -pv $LFS/{etc,var} $LFS/usr/{bin,lib,sbin}
+mkdir -pv $LFS/{boot,etc,var} $LFS/usr/{bin,lib,sbin}
for i in bin lib sbin; do
ln -sv usr/$i $LFS/$i
-done
+done
-case $(uname -m) in
- x86_64) mkdir -pv $LFS/lib64 ;;
-esac
+ Some targets (for example, x86_64) needs
+ /lib64 directory. If you are
+ building for one of those targets, create it as
+ root:
+
+mkdir -pv $LFS/lib64
Programs in will be compiled
Index: chapter04/settingenviron.xml
===================================================================
--- chapter04/settingenviron.xml (revision 7c05ea2a4fb165a36f150b34c55938cdb98e8d95)
+++ chapter04/settingenviron.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
@@ -43,5 +43,5 @@
LFS=/mnt/lfs
LC_ALL=POSIX
-LFS_TGT=$(uname -m)-lfs-linux-gnu
+LFS_TGT=x86_64-lfs-linux-gnu
PATH=/usr/bin
if [ ! -L /bin ]; then PATH=/bin:$PATH; fi
@@ -104,10 +104,13 @@
- LFS_TGT=(uname -m)-lfs-linux-gnu
+ LFS_TGT=x86_64-lfs-linux-gnu
The LFS_TGT variable sets a non-default, but compatible machine
description for use when building our cross compiler and linker and when cross
compiling our temporary toolchain. More information is contained in
- .
+ .
+ If you are not building for 64-bit x86, replace
+ x86_64 with some value suitable for your target
+ machine, for example i686 for 32-bit x86.
Index: chapter05/gcc-pass1.xml
===================================================================
--- chapter05/gcc-pass1.xml (revision 7c05ea2a4fb165a36f150b34c55938cdb98e8d95)
+++ chapter05/gcc-pass1.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
@@ -63,13 +63,11 @@
mv -v mpc-&mpc-version; mpc
- On x86_64 hosts, set the default directory name for
- 64-bit libraries to lib
:
-
-case $(uname -m) in
- x86_64)
- sed -e '/m64=/s/lib64/lib/' \
- -i.orig gcc/config/i386/t-linux64
- ;;
-esac
+ For x86_64 target, set the default directory name for
+ 64-bit libraries to lib
. The command is unnecessary,
+ but harmless for 32-bit x86. If you are building for another target,
+ you may need to adjust the command for your target.
+
+sed -e '/m64=/s/lib64/lib/' \
+ -i.orig gcc/config/i386/t-linux64
The GCC documentation recommends building GCC
Index: chapter05/glibc.xml
===================================================================
--- chapter05/glibc.xml (revision 7c05ea2a4fb165a36f150b34c55938cdb98e8d95)
+++ chapter05/glibc.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
@@ -46,11 +46,13 @@
First, create a symbolic link for LSB compliance. Additionally,
for x86_64, create a compatibility symbolic link required for proper
- operation of the dynamic library loader:
-
-case $(uname -m) in
- i?86) ln -sfv ld-linux.so.2 $LFS/lib/ld-lsb.so.3
+ operation of the dynamic library loader. It's needed to adjust the
+ command if you are building LFS for a target other than 32-bit or
+ 64-bit x86.
+
+case $LFS_TGT in
+ i?86*) ln -sfv ld-linux.so.2 $LFS/lib/ld-lsb.so.3
;;
- x86_64) ln -sfv ../lib/ld-linux-x86-64.so.2 $LFS/lib64
- ln -sfv ../lib/ld-linux-x86-64.so.2 $LFS/lib64/ld-lsb-x86-64.so.3
+ x86_64*) ln -sfv ../lib/ld-linux-x86-64.so.2 $LFS/lib64
+ ln -sfv ../lib/ld-linux-x86-64.so.2 $LFS/lib64/ld-lsb-x86-64.so.3
;;
esac
@@ -90,5 +92,5 @@
--host=$LFS_TGT \
--build=$(../scripts/config.guess) \
- --enable-kernel=&min-kernel; \
+ --enable-kernel=&linux-major-version;.&linux-minor-version; \
--with-headers=$LFS/usr/include \
libc_cv_slibdir=/usr/lib
@@ -107,9 +109,11 @@
- --enable-kernel=&min-kernel;
-
- This tells Glibc to compile the library with support
- for &min-kernel; and later Linux kernels. Workarounds for older
- kernels are not enabled.
+ --enable-kernel=&linux-major-version;.&linux-minor-version;
+
+ This option tells the build system that this glibc may
+ be used with kernels as old as
+ &linux-major-version;.&linux-minor-version;. This means generating
+ workarounds in case a system call introduced in a later version
+ cannot be used.
Index: chapter05/linux-headers.xml
===================================================================
--- chapter05/linux-headers.xml (revision 7c05ea2a4fb165a36f150b34c55938cdb98e8d95)
+++ chapter05/linux-headers.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
@@ -57,7 +57,8 @@
be available. The headers are first placed in
./usr, then copied to the needed
- location.
-
-make headers
+ location. Replace x86 with a value suitable
+ for your target machine if it's not a 32-bit or 64-bit x86:
+
+make headers ARCH=x86
find usr/include -name '.*' -delete
rm usr/include/Makefile
Index: chapter06/chapter06.xml
===================================================================
--- chapter06/chapter06.xml (revision 7c05ea2a4fb165a36f150b34c55938cdb98e8d95)
+++ chapter06/chapter06.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
@@ -32,3 +32,8 @@
+
+
+
+
+
Index: chapter06/gcc-pass2.xml
===================================================================
--- chapter06/gcc-pass2.xml (revision 7c05ea2a4fb165a36f150b34c55938cdb98e8d95)
+++ chapter06/gcc-pass2.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
@@ -55,12 +55,11 @@
mv -v mpc-&mpc-version; mpc
- If building on x86_64, change the default directory name for 64-bit
- libraries to lib
:
+ For x86_64 target, set the default directory name for
+ 64-bit libraries to lib
. The command is unnecessary,
+ but harmless for 32-bit x86. If you are building for another target,
+ you may need to adjust the command for your target.
-case $(uname -m) in
- x86_64)
- sed -e '/m64=/s/lib64/lib/' -i.orig gcc/config/i386/t-linux64
- ;;
-esac
+sed -e '/m64=/s/lib64/lib/' \
+ -i.orig gcc/config/i386/t-linux64
Index: chapter06/grub-cfg.xml
===================================================================
--- chapter06/grub-cfg.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
+++ chapter06/grub-cfg.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
@@ -0,0 +1,215 @@
+
+
+ %general-entities;
+]>
+
+
+
+
+
+ grub
+ &grub-version;
+ &grub-url;
+
+
+ Making the Temporary System Bootable
+
+
+ Introduction
+
+ In a normal LFS building procedure, we will chroot into the
+ temporary system and continue to build additional temporary tools.
+ But, as we've explained, in the Cross Edition we need to make the
+ temporary system bootable and boot it on the target system.
+
+
+
+ Creating the GRUB Configuration File
+
+ Generate $LFS/boot/grub/grub.cfg:
+
+ cat > $LFS/boot/grub/grub.cfg << "EOF"
+# Begin /boot/grub/grub.cfg
+set default=0
+set timeout=5
+
+menuentry "LFS Temporary System" {
+ linux /vmlinux root=/dev/sda3 rw init=/bin/bash
+ boot
+}
+EOF
+
+
+ The meaning of the linux command options:
+
+
+ root=/dev/sda3
+
+ We will use the third parition as the partition for the
+ root filesystem of the LFS system.
+
+
+
+
+ rw
+
+ Tell the kernel to mount the root filesystem read-write.
+ In normal distros there is ro instead, so
+ the kernel will mount the root filesystem read-only. Then
+ the init process can check the filesystem
+ integrity and remount it read-write. For the temporary system
+ it's not needed.
+
+
+
+
+ init=/bin/bash
+
+ By default the kernel runs /sbin/init
+ as the first process. It's provided by SysVinit or Systemd
+ package, which is not installed yet. We explicitly tell the
+ kernel to run /bin/bash instead to start a
+ shell, so we can run further commands interactively.
+
+
+
+
+ (optional) console=ttyS0,115200
+
+ Use the serial port at /dev/ttyS0 as
+ the output console device. It's very useful if the virtual
+ console is not avaliable (for example, the target system may lack
+ graphic output, or the framebuffer console may be too slow).
+ And, by connecting the host system and the target system with a
+ NULL modem or USB serial converter, it will be able to copy the
+ commands from the book and paste it into a terminal emulator
+ (for example,
+ GNU Screen)
+ on the host, to execute them on the target system.
+ 115200 specifies the baudrate, the default
+ (9600) is too slow for large amount of console output building
+ LFS.
+
+
+
+
+ From GRUB's perspective, the
+ kernel files are relative to the partition used. We will use a
+ a separate /boot partition, so /boot is not needed in the above
+ linux line.
+
+
+
+
+
+ Copy the Temporary System to the Target Machine
+
+
+ The commands in the subsection must be performed on the host
+ system while logged in as user
+ root
+ and no longer as user lfs.
+ Also, double check that $LFS is set in root's environment.
+
+
+ Now it's the time to copy the
+ $LFS hierarchy over to your
+ target machine. You'll need a moveable
device for this.
+ Using a normal USB stick is likely a bad choice: the USB sticks are
+ generally not optimized for reading or writing many small files
+ (which will happen building packages from source). Especially, if a
+ ext filesystem is used, the performance can be very bad. You may use
+ a USB to SATA adapter and a HDD or SSD (then you can directly connect
+ it onto the SATA port of the target system, or continuing to use the
+ adapter on a USB port of the target system), or a USB stick with an I/O
+ controller for SSD (these USB sticks are significantly more expansive
+ than a normal one).
+
+ Create a GUID partition table on the device, and then create
+ three partitions on it. The first will be used as the BIOS boot
+ partition, 1 MB is sufficient enough. But if you want to use EFI to
+ boot your LFS system later, assign 100 MB for it so it will be possible
+ to convert it into an EFI system partition. The second partition will
+ be used as the boot partition, 500 MB is sufficient enough. The third
+ will be the root partition, it should be at least 20 GB.
+
+ Create filesystems for the partitions:
+
+mkfs.ext4 /dev/sdx2
+mkfs.ext4 /dev/sdx3
+
+
+ It's not needed to create a filesystem for the BIOS boot partition.
+ But, its type should be set to BIOS boot
in
+ the partition table using fdisk:
+
+
+fdisk /dev/sdx
+
+Welcome to fdisk (util-linux &util-linux-version;).
+Changes will remain in memory only, until you decide to write them.
+Be careful before using the write command.
+
+
+Command (m for help): t
+Partition number (1-9, default 9): 1
+Partition type or alias (type L to list all): BIOS boot
+Changed type of partition 'Linux' to 'BIOS boot'.
+
+Command (m for help): w
+The partition table has been altered.
+Calling ioctl() to re-read partition table.
+Syncing disks.
+
+ In it's optional to make a
+ backup for the temporary system. If you'd like to do so, prepare
+ another parition (1 GB should be enough) and make an
+ ext4 filesystem to hold
+ the backup:
+
+mkfs.ext4 /dev/sdx4
+
+ sdx should be replaced with the name
+ of the device node corresponding to your moveable device. Then mount
+ the filesystems:
+
+mkdir -pv /mnt/lfs-target
+mount -v -t ext4 /dev/sdx3 /mnt/lfs-target
+mkdir -pv /mnt/lfs-target/boot
+mount -v -t ext4 /dev/sdx2 /mnt/lfs-target/boot
+
+ Copy the temporary system onto the device, and change the
+ ownership of the copy to user
+ root:
+
+cp -av $LFS/* /mnt/lfs-target
+chown -R root:root /mnt/lfs-target
+
+ Install the bootloader onto the device:
+
+$LFS/tools/sbin/lfs-grub-install \
+ --target=i386-pc \
+ --boot-directory=/mnt/lfs-target/boot \
+ /dev/sdx
+
+ Create the mountpoint for
+ devtmpfs, so the kernel
+ will mount it automatically:
+
+install -v -dm755 /mnt/lfs-target/dev
+
+ Now, unmount the device:
+
+umount -Rv /mnt/lfs-target
+
+ Now unplug the device and connect it onto the target system,
+ and boot the target system with this device as the boot device.
+ Read the manual from the vendor of the target system to know how to
+ select the boot device.
+
+
+
+
Index: chapter06/grub.xml
===================================================================
--- chapter06/grub.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
+++ chapter06/grub.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
@@ -0,0 +1,106 @@
+
+
+ %general-entities;
+]>
+
+
+
+
+
+ grub
+ &grub-version;
+ &grub-url;
+
+
+ GRUB-&grub-version;
+
+
+ GRUB
+ tools
+
+
+
+
+
+
+
+
+ &buildtime;
+ &diskspace;
+
+
+ &grub-tmp-sbu;
+ &grub-tmp-du;
+
+
+
+
+
+
+ Installation of GRUB
+
+ Prepare GRUB for compilation:
+
+./configure --prefix=$LFS/tools \
+ --build=$(build-aux/config.guess) \
+ --host=$(build-aux/config.guess) \
+ --target=$LFS_TGT \
+ --program-prefix=lfs- \
+ --disable-werror
+
+
+ The meaning of the new configure options:
+
+
+ --build=..., --host=..., and --target=$LFS_TGT
+
+ This allows the build to generate GRUB utilities running on
+ the host system, but generating the bootloader files for $LFS_TGT.
+ Then we can use the bootloader files to boot the temporary system
+ on the target machine.
+
+
+
+
+ --program-prefix=lfs-
+
+ This ensures that the installed programs have
+ lfs- prepended to their names, to better
+ distinguish them from the GRUB installation of the host
+ distro.
+
+
+
+
+ --disable-werror
+
+ This allows the build to complete with warnings introduced
+ by more recent Flex versions.
+
+
+
+
+
+ Compile the package:
+
+make
+
+ Install the package:
+
+make install
+
+
+
+
+
+
+ Details on this package are located in
+
+
+
+
+
Index: chapter06/kernel.xml
===================================================================
--- chapter06/kernel.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
+++ chapter06/kernel.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
@@ -0,0 +1,212 @@
+
+
+ %general-entities;
+]>
+
+
+
+
+
+ kernel
+ &linux-version;
+ &linux-url;
+
+
+ Linux-&linux-version;
+
+
+ Linux
+ tools
+
+
+
+
+
+ The Linux package contains the Linux kernel.
+
+
+ &buildtime;
+ &diskspace;
+
+
+ &linux-tmp-sbu;
+ &linux-tmp-du;
+
+
+
+
+
+
+ Installation of the kernel
+
+ Building the kernel involves a few steps—configuration,
+ compilation, and installation. Read the README file
+ in the kernel source tree for alternative methods to the way this book
+ configures the kernel.
+
+ Prepare for compilation by running the following command:
+
+make mrproper
+
+ This ensures that the kernel tree is absolutely clean. The
+ kernel team recommends that this command be issued prior to each
+ kernel compilation. Do not rely on the source tree being clean after
+ un-tarring.
+
+ There are several ways to configure the kernel options. Usually,
+ This is done through a menu-driven interface, for example:
+
+make ARCH=x86 CROSS_COMPILE=$LFS_TGT- menuconfig
+
+
+ The meaning of make environment variables:
+
+
+ ARCH=x86
+
+ Configure the kernel for running on the target machine.
+ Replace x86 with a value suitable
+ for your target machine if it's not a 32-bit or 64-bit x86.
+
+
+
+
+ CROSS_COMPILE=$LFS_TGT-
+
+ Build the kernel with Binutils and GCC built in
+ .
+
+
+
+
+ menuconfig
+
+ This launches an ncurses menu-driven interface. For other
+ (graphical) interfaces, type make help.
+
+
+
+
+ (optional) LANG=<host_LANG_value> LC_ALL=
+
+ This establishes the locale setting to the one used on the
+ host. This may be needed for a proper menuconfig ncurses interface
+ line drawing on a UTF-8 linux text console.
+
+ If used, be sure to replace
+ <host_LANG_value> by the value of
+ the $LANG variable from your host. You can
+ alternatively use instead the host's value of $LC_ALL
+ or $LC_CTYPE.
+
+
+
+
+
+
+
+ A good starting place for setting up the kernel configuration is to
+ run make ARCH=x86 CROSS_COMPILE=$LFS_TGT- defconfig. This will set the base
+ configuration to a good state that takes your target system architecture
+ into account.
+
+
+
+ Read for more information
+ about kernel configuration. You should enable or disable some kernel
+ configuration options now:
+
+
+ Kernel configuration options and explanation:
+
+
+ Set CONFIG_MODULES=n
+
+ Modular kernel needs modprobe tool from
+ Kmod to load modules, which is not
+ installed in the temporary system.
+
+
+
+
+ Set CONFIG_EXTRA_FIRMWARE="a.bin b.bin"
+
+ Build firmware blobs into the kernel. Some drivers may
+ require the firmwares to be in-kernel if the driver is not built
+ as module.
+
+
+ The kernel binaries with third-party blobs are not
+ distributable. If you distribute such a kernel binary to
+ others, you may violate GPL. It's recommended to remove the
+ temporary kernel image after you've successfully boot your LFS
+ system with the new kernel image, which will be installed in
+ .
+
+
+
+
+
+
+ Set CONFIG_EXTRA_FIRMWARE_DIR="$LFS/lib/firmware"
+
+ The building system will search
+ /lib/firmware for firmware
+ blobs in CONFIG_EXTRA_FIRMWARE. Note that
+ you'll need to install the needed firmwares into
+ $LFS/lib/firmware first,
+ and manually replace $LFS with the value in
+ configuration. The firmwares in
+ $LFS/lib/filename will be
+ copied to the target machine along with the system, so kernel and
+ kernel modules which will be built in
+ can load them without
+ CONFIG_EXTRA_FIRMWARE.
+
+
+
+
+ Set CONFIG_EXT2=y,
+ CONFIG_EXT4=y,
+ and CONFIG_VFAT_FS=y
+
+ They are needed to access the filesystems we'll make for the
+ target system.
+
+
+
+
+ Set CONFIG_MODULE_SIG=n,
+ CONFIG_SECURITY=n,
+ and CONFIG_STACK_VALIDATION=n
+
+ They are unneeded for the temporary kernel, and they need
+ additional dependencies which may be unavailable on the host
+ distro. You can enable them building the kernel for the final LFS
+ system in Chapter 10 if you need these features.
+
+
+
+
+ Compile the kernel image:
+
+make ARCH=x86 CROSS_COMPILE=$LFS_TGT-
+
+ Install the kernel image into the
+ $LFS/boot directory:
+
+ install -vm644 vmlinux $LFS/boot/vmlinux
+
+
+
+
+
+
+ Details on this package are located in
+
+
+
+
+
Index: chapter06/util-linux.xml
===================================================================
--- chapter06/util-linux.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
+++ chapter06/util-linux.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
@@ -0,0 +1,83 @@
+
+
+ %general-entities;
+]>
+
+
+
+
+
+ util-linux
+ &util-linux-version;
+ &util-linux-url;
+
+
+ Programs from Util-linux-&util-linux-version;
+
+
+ programs from util-linux
+ tools
+
+
+
+
+
+ agetty, mount, and
+ setsid are utilities in
+ Util-Linux. We need them to
+ set up the environment once we boot the temporary system.
+
+
+ &buildtime;
+ &diskspace;
+
+
+ &mount-setsid-sbu;
+ &mount-setsid-du;
+
+
+
+
+
+
+ Installation of agetty, setsid and mount
+
+ Prepare Util-linux for compilation:
+
+./configure --build=$(config/config.guess) --host=$LFS_TGT --disable-shared
+
+
+ The meaning of the configure option:
+
+
+ --disable-shared
+
+ We do not need to install any of the shared libraries at
+ this time, therefore there is no need to build them.
+
+
+
+
+
+ We only need three tools from the package now, build them:
+
+make agetty mount setsid
+
+ Install the tools:
+
+install -vm755 agetty $LFS/usr/sbin
+install -vm755 mount setsid $LFS/usr/bin
+
+
+
+
+
+
+ Details on this package are located in
+
+
+
+
+
Index: chapter07/chapter07.xml
===================================================================
--- chapter07/chapter07.xml (revision 7c05ea2a4fb165a36f150b34c55938cdb98e8d95)
+++ chapter07/chapter07.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
@@ -10,8 +10,8 @@
- Entering Chroot and Building Additional Temporary Tools
+ Booting the Target System and Building Additional Temporary Tools
-
+
@@ -24,4 +24,5 @@
+
+mkdir -pv /mnt/lfs-{target,backup}
+mount -v -t ext4 /dev/sdx3 /mnt/lfs-target
+mount -v -t ext4 /dev/sdx4 /mnt/lfs-backup
+
+
The following commands are extremely dangerous. If
you run rm -rf ./* as the root user and you
- do not change to the $LFS directory or the LFS
- environment variable is not set for the root user, it will destroy
- your entire host system. YOU ARE WARNED.
+ do not change to the lfs-target directory,
+ it will destroy your entire host system.
+ YOU ARE WARNED.
-cd $LFS
+cd /mnt/lfs-target
rm -rf ./*
-tar -xpf $HOME/lfs-temp-tools-&version;.tar.xz
+tar -xpf /mnt/lfs-backup/lfs-temp-tools-&version;.tar.xz
- Again, double check that the environment has been setup properly
- and continue building the rest of the system.
+ Again, unmount the two partitions, reconnect the device to the target
+ machine, boot it and continue building the rest of system:
+
+umount /mnt/lfs-{target,backup}
- If you left the chroot environment to create a backup or restart
- building using a restore, remember to check that the virtual
- filesystems are still mounted (findmnt | grep
- $LFS). If they are not mounted, remount them now as
- described in and re-enter the chroot
+ If you reboot your target machine and restart
+ building using a restore, remount the virtual filesystems now as
+ described in and re-enter the build
environment (see ) before continuing.
Index: chapter07/introduction.xml
===================================================================
--- chapter07/introduction.xml (revision 7c05ea2a4fb165a36f150b34c55938cdb98e8d95)
+++ chapter07/introduction.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
@@ -11,22 +11,31 @@
Introduction
+
+ Please make sure the temporary system is already booted on the
+ target machine. All commands in this chapter and the following chapters
+ should be executed on the target machine instead of the host distro,
+ unless the book explicitly says a command is for the host. Running a
+ command for the temporary system on the host can completely destroy the
+ host distro.
+
+
This chapter shows how to build the last missing bits of the temporary
system: the tools needed by the build machinery of various packages. Now
- that all circular dependencies have been resolved, a chroot
- environment, completely isolated from the host operating system (except for
- the running kernel), can be used for the build.
+ that all circular dependencies have been resolved and the temporary system
+ is already bootable, we can boot it on the target machine and it would be
+ completely isolated from the host operating system. Then we can continue
+ to build on the target machine.
- For proper operation of the isolated environment, some communication
+ For proper operation of the temporary system, some communication
with the running kernel must be established. This is done through the
so-called Virtual Kernel File Systems, which must be
- mounted when entering the chroot environment. You may want to check
- that they are mounted by issuing findmnt.
+ mounted as soon as possible after boot. You may want to check
+ that they are mounted by issuing mount.
- Until , the commands must be
- run as root, with the
- LFS variable set. After entering chroot, all commands
- are run as root, fortunately without access to the OS of the computer
- you built LFS on. Be careful anyway, as it is easy to destroy the whole
- LFS system with badly formed commands.
+ All commands in this and following chapters are run as root on the
+ target system, fortunately without access to the host system.
+ Be careful anyway, as if the storage devices of your target system already
+ contain some important data, it's possible to destroy them with badly
+ formed commands.
Index: chapter07/iproute2.xml
===================================================================
--- chapter07/iproute2.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
+++ chapter07/iproute2.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
@@ -0,0 +1,93 @@
+
+
+ %general-entities;
+]>
+
+
+
+
+
+ iproute2
+ &iproute2-version;
+ &iproute2-url;
+
+
+ Setting Up Loopback Network Interface with IPRoute-&iproute2-version;
+
+
+ IPRoute2
+ tools
+
+
+
+
+
+ The IPRoute2 package contains programs for basic and advanced IPV4-based
+ networking. Now we need ip from it to bring up
+ loopback network interface, which is expected by the testsuites of
+ various packages.
+
+
+ &buildtime;
+ &diskspace;
+
+
+ &iproute2-tmp-sbu;
+ &iproute2-tmp-du;
+
+
+
+
+
+
+ Use IPRoute2 to Set Up Loopback Network Interface
+
+ IPRoute2 package has several dependencies not installed yet, but
+ we only need ip utility from the package now.
+ Disable the build of other utilities:
+
+sed '/SUBDIRS/s/=.*/=lib ip/' -i Makefile
+
+ Compile the package:
+
+PKG_CONFIG=false make
+
+
+ The meaning of the environment variable:
+
+
+ PKG_CONFIG=false
+
+ The building system attempts to find dependencies with
+ pkg-config, which is not installed yet.
+ We can override it since ip utility does not
+ need these dependencies.
+
+
+
+
+ It's not needed to install the ip utility now.
+ Just bring up the loopback interface:
+
+ip/ip link set lo up
+
+ Verify the result:
+
+ip/ip addr
+
+ The command above should show 127.0.0.1/8
+ as the IPv4 address of lo, and
+ ::1/128 as the IPv6 address.
+
+
+
+
+
+
+ Details on this package are located in
+
+
+
+
Index: chapter07/kernfs.xml
===================================================================
--- chapter07/kernfs.xml (revision 7c05ea2a4fb165a36f150b34c55938cdb98e8d95)
+++ chapter07/kernfs.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
@@ -23,56 +23,20 @@
mounted:
-mkdir -pv $LFS/{dev,proc,sys,run}
-
-
- Creating Initial Device Nodes
-
- When the kernel boots the system, it requires the presence of a few
- device nodes, in particular the console and null devices. The device nodes must be
- created on the hard disk so that they are available before the kernel
- populates /dev), and
- additionally when Linux is started with
- init=/bin/bash. Create the devices by running the
- following commands:
-
-mknod -m 600 $LFS/dev/console c 5 1
-mknod -m 666 $LFS/dev/null c 1 3
-
-
-
-
- Mounting and Populating /dev
-
- The recommended method of populating the /dev directory with devices is to mount a
- virtual filesystem (such as tmpfs) on the /dev directory, and allow the devices to be
- created dynamically on that virtual filesystem as they are detected or
- accessed. Device creation is generally done during the boot process
- by Udev. Since this new system does not yet have Udev and has not yet
- been booted, it is necessary to mount and populate /dev manually. This is accomplished by bind
- mounting the host system's /dev
- directory. A bind mount is a special type of mount that allows you to
- create a mirror of a directory or mount point to some other location. Use
- the following command to achieve this:
-
-mount -v --bind /dev $LFS/dev
-
-
+mkdir -pv /{proc,sys,run}
Mounting Virtual Kernel File Systems
- Now mount the remaining virtual kernel filesystems:
+ The kernel has already mounted
+ devtmpfs.
+ Mount the remaining virtual kernel filesystems:
-mount -v --bind /dev/pts $LFS/dev/pts
-mount -vt proc proc $LFS/proc
-mount -vt sysfs sysfs $LFS/sys
-mount -vt tmpfs tmpfs $LFS/run
-
- In some host systems, /dev/shm is a
- symbolic link to /run/shm.
- The /run tmpfs was mounted above so in this case only a
- directory needs to be created.
-if [ -h $LFS/dev/shm ]; then
- mkdir -pv $LFS/$(readlink $LFS/dev/shm)
-fi
+
+
+
+ Adjusting devtmpfs
+
+ Now proc filesystem
+ is mounted, we can replace the device nodes for standard I/O streams
+ with symlinks to pseudo files in
+ /proc/self/fd (which are symlinks
+ to the files connected to the standard I/O streams for the current
+ process). This is necessary for I/O redirection in the building system
+ of some packages to function properly:
+
+ln -sfv /proc/self/fd/0 /dev/stdin
+ln -sfv /proc/self/fd/1 /dev/stdout
+ln -sfv /proc/self/fd/2 /dev/stderr
Index: chapter08/coreutils.xml
===================================================================
--- chapter08/coreutils.xml (revision 7c05ea2a4fb165a36f150b34c55938cdb98e8d95)
+++ chapter08/coreutils.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
@@ -116,4 +116,8 @@
make NON_ROOT_USERNAME=tester check-root
+
+
+ One test named chroot-credentials.sh is
+ known to fail, but it will pass after booting the LFS system.
We're going to run the remainder of the tests as the
Index: chapter08/gcc.xml
===================================================================
--- chapter08/gcc.xml (revision 7c05ea2a4fb165a36f150b34c55938cdb98e8d95)
+++ chapter08/gcc.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
@@ -50,13 +50,11 @@
-i libsanitizer/sanitizer_common/sanitizer_posix_libcdep.cpp
- If building on x86_64, change the default directory name for 64-bit
- libraries to lib
:
-
-case $(uname -m) in
- x86_64)
- sed -e '/m64=/s/lib64/lib/' \
- -i.orig gcc/config/i386/t-linux64
- ;;
-esac
+ For x86_64 target, set the default directory name for
+ 64-bit libraries to lib
. The command is unnecessary,
+ but harmless for 32-bit x86. If you are building for another target,
+ you may need to adjust the command for your target.
+
+sed -e '/m64=/s/lib64/lib/' \
+ -i.orig gcc/config/i386/t-linux64
The GCC documentation recommends building GCC in a dedicated build directory:
Index: chapter08/glibc.xml
===================================================================
--- chapter08/glibc.xml (revision 7c05ea2a4fb165a36f150b34c55938cdb98e8d95)
+++ chapter08/glibc.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
@@ -73,5 +73,5 @@
../configure --prefix=/usr \
--disable-werror \
- --enable-kernel=&min-kernel; \
+ --enable-kernel=&linux-major-version;.&linux-minor-version; \
--enable-stack-protector=strong \
--with-headers=/usr/include \
@@ -90,8 +90,9 @@
- --enable-kernel=&min-kernel;
+ --enable-kernel=&linux-major-version;.&linux-minor-version;
This option tells the build system that this glibc may
- be used with kernels as old as &min-kernel;. This means generating
+ be used with kernels as old as
+ &linux-major-version;.&linux-minor-version;. This means generating
workarounds in case a system call introduced in a later version
cannot be used.
Index: chapter11/reboot.xml
===================================================================
--- chapter11/reboot.xml (revision 7c05ea2a4fb165a36f150b34c55938cdb98e8d95)
+++ chapter11/reboot.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
@@ -82,35 +82,17 @@
Now that we have said that, let's move on to booting our shiny new LFS
- installation for the first time! First exit from the chroot environment:
+ installation for the first time!
-logout
-
-
- Then unmount the virtual file systems:
-
-umount -v $LFS/dev/pts
-umount -v $LFS/dev
-umount -v $LFS/run
-umount -v $LFS/proc
-umount -v $LFS/sys
-
- If multiple partitions were created, unmount the other
- partitions before unmounting the main one, like this:
-
-umount -v $LFS/usr
-umount -v $LFS/home
-umount -v $LFS
-
- Unmount the LFS file system itself:
-
-umount -v $LFS
+sync
Now, reboot the system with:
-shutdown -r now
+reboot -ff
+
+ -ff option allows to reboot the system
+ without support from the init process.
Assuming the GRUB boot loader was set up as outlined earlier, the menu
Index: git-version.sh
===================================================================
--- git-version.sh (revision 7c05ea2a4fb165a36f150b34c55938cdb98e8d95)
+++ git-version.sh (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
@@ -50,6 +50,6 @@
sha="$(git describe --abbrev=1)"
rev=$(echo "$sha" | sed 's/-g[^-]*$//')
-version="$rev"
-versiond="$rev-systemd"
+version="cross-$rev"
+versiond="cross-$rev-systemd"
if [ "$(git diff HEAD | wc -l)" != "0" ]; then
Index: packages.ent
===================================================================
--- packages.ent (revision 7c05ea2a4fb165a36f150b34c55938cdb98e8d95)
+++ packages.ent (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
@@ -310,4 +310,6 @@
+
+
@@ -353,4 +355,6 @@
+
+
@@ -440,4 +444,6 @@
+
+
@@ -720,4 +726,6 @@
+
+
Index: prologue/architecture.xml
===================================================================
--- prologue/architecture.xml (revision 7c05ea2a4fb165a36f150b34c55938cdb98e8d95)
+++ prologue/architecture.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
@@ -13,11 +13,6 @@
The primary target architectures of LFS are the AMD/Intel x86 (32-bit)
and x86_64 (64-bit) CPUs. On the other hand, the instructions in this book are
-also known to work, with some modifications, with the Power PC and ARM CPUs. To
-build a system that utilizes one of these CPUs, the main prerequisite, in
-addition to those on the next page, is an existing Linux system such as an
-earlier LFS installation, Ubuntu, Red Hat/Fedora, SuSE, or other distribution
-that targets the architecture that you have. Also note that a 32-bit
-distribution can be installed and used as a host system on a 64-bit AMD/Intel
-computer.
+also known to work, with some modifications, with the Power PC and ARM
+CPUs.
For building LFS, the gain of building on a 64-bit system
Index: prologue/cross.xml
===================================================================
--- prologue/cross.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
+++ prologue/cross.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
@@ -0,0 +1,65 @@
+
+
+ %general-entities;
+]>
+
+
+
+
+ About the Cross Edition
+
+ While LFS has provided an approach to build a Linux system entirely
+ from source code, it builds the LFS system in a
+ chroot environment. The chroot environment is almost
+ seperate from the host distribution, but it still relies on the hardware
+ and Linux kernel from the host system.
+
+ The Cross Edition contains modification to the LFS book, allowing
+ to boot the temporary system instead of chroot. So it's possible to
+ bootstrap a Linux system for a target where no Linux distribution exists.
+ And, the kernel ABI may frequently change at the early stage porting Linux
+ to a new hardware. The modification in this edition completely removes
+ the dependency on the kernel from the host distribution, allowing to
+ rebuild the entire system with a new kernel ABI.
+
+ If you already have a Linux distribution running on the hardware
+ where you need a Linux From Scratch system, with the kernel ABI you want,
+ and it's compatible with the Host System Requirements specified by the
+ LFS book, it's likely you should read the original LFS book instead of
+ this edition.
+
+ This edition contains instructions to bootstrap a Linux system for
+ x86 (32-bit or 64-bit). It may looks irrational because it's easy to
+ find a host distribution for x86, but this edition can be a start point
+ where you can further modify the instruction for other hardware.
+
+
+ History of Cross LFS
+
+ A project named Cross Linux From Scratch
+ was forked from LFS in 2006, by Joe Ciccone, Jim Gifford, and
+ Ryan Oliver. It has been inactive since 2017. Its history can still
+ be explored at .
+
+ In 2020, Pierre Labastie modified the LFS book to cross-compile
+ the temporary packages before entering the chroot environment. The main
+ purpose of this approach was to fix multiple issues found by Iterative
+ Comparision Analysis. With Pierre's work, the only change needed by
+ this edition is basically to reboot instead of chroot
.
+ However, some additional steps is needed to make the system bootable
+ at the end of Chapter 6, and setting up an environment suitable for
+ building and test packages at the start of Chapter 7. Then this Cross
+ Edition is created to demonstrate these steps.
+
+ Unlike the legacy CLFS project, in the Cross Edition we don't
+ build any package containing an init process for the
+ temporary system to boot on the target machine. The temporary system
+ is booted with a shell running as PID 1, and some necessary jobs of a
+ normal init process are manually done with commands.
+ This minimizes the difference from the main LFS book, and also helpful
+ to learn the initialization steps booting a Linux system.
+
+
+
Index: prologue/preface.xml
===================================================================
--- prologue/preface.xml (revision 7c05ea2a4fb165a36f150b34c55938cdb98e8d95)
+++ prologue/preface.xml (revision 727617d28f014fcf6c34ad35bad4bca3abe6164f)
@@ -16,4 +16,5 @@
+