6.22. Making the Temporary System Bootable

6.22.1. 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.

6.22.2. Creating the GRUB Configuration File

Generate $LFS/boot/grub/grub.cfg:

mkdir -pv $LFS/boot/grub
cat > $LFS/boot/grub/grub.cfg << "EOF"
# Begin /boot/grub/grub.cfg
set default=0
set timeout=5

menuentry "LFS Temporary System" {
        linux   /vmlinuz 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.

[Note]

Note

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.

6.22.3. Copy the Temporary System to the Target Machine

[Note]

Note

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 2.40.2).
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 Section 7.13, “Cleaning up and Saving the Temporary System” 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.