Building Linux System (PiLFS) from scratch on Raspberry Pi (Raspberry Pie) (II)

VII. Constructing Temporary System

1. General Compilation Guide

a. Verify that LFS environment variables are set correctly

echo $LFS

b. Assume that you have set it correctly Host system requirements And symbolic links

c. For each package:

(1) Make sure that you are using lfs users when decompressing packages

(2) Unless otherwise specified, delete the extracted directory and build directories generated during all compilation processes

 

2. Execute shell script to complete the construction of temporary system

cd $LFS/sources
chmod +x ch5-build.sh
./ch5-build.sh

  

3. Change of ownership

Later commands must be executed as root instead of lfs users. Also, confirm that the $lfs variable is also defined in the root user environment.

Currently, the $LFS/tools directory belongs to the lfs user, and the owner of the $LFS/tools directory is changed to the root user by the following command:

su - root export LFS=/mnt/lfs chown -R root:root $LFS/tools

 

VIII. Construction of LFS System

1. Preparing Virtual Kernel File System

The kernel mounts several file systems for exchanging information with user-space programs. These file systems are virtual and do not occupy real disk space.

Their contents are stored in memory.

mkdir -pv $LFS/{dev,proc,sys,run}
mknod -m 600 $LFS/dev/console c 5 1
mknod -m 666 $LFS/dev/null c 1 3
mknod -m 444 /dev/random c 1 8 mknod -m 444 /dev/urandom c 1 9 mount -v --bind /dev $LFS/dev
mount -vt devpts devpts $LFS/dev/pts -o gid=5,mode=620
mount -vt proc proc $LFS/proc
mount -vt sysfs sysfs $LFS/sys
mount -vt tmpfs tmpfs $LFS/run
if [ -h $LFS/dev/shm ]; then
  mkdir -pv $LFS/$(readlink $LFS/dev/shm)
fi

2. Enter the Chroot environment

Since then, LFS variables are no longer needed, because all subsequent work will be limited to the LFS filesystem.

chroot "$LFS" /tools/bin/env -i \
    HOME=/root                  \
    TERM="$TERM"                \
    PS1='\u:\w\$ '              \
    PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
    /tools/bin/bash --login +h

3. Create directories

# Now ready to create LFS Some directory structures in the file system. Use the following command to create a standard directory tree:
# This directory tree is based on the file system directory structure standard( FHS)

mkdir -pv /{bin,boot,etc/{opt,sysconfig},home,lib/firmware,mnt,opt}
mkdir -pv /{media/{floppy,cdrom},sbin,srv,var}
install -dv -m 0750 /root
install -dv -m 1777 /tmp /var/tmp
mkdir -pv /usr/{,local/}{bin,include,lib,sbin,src}
mkdir -pv /usr/{,local/}share/{color,dict,doc,info,locale,man}
mkdir -v  /usr/{,local/}share/{misc,terminfo,zoneinfo}
mkdir -v  /usr/libexec
mkdir -pv /usr/{,local/}share/man/man{1..8}

case $(uname -m) in
 x86_64) mkdir -v /lib64 ;;
esac

mkdir -v /var/{log,mail,spool}
ln -sv /run /var/run
ln -sv /run/lock /var/lock
mkdir -pv /var/{opt,cache,lib/{color,misc,locate},local}

4. Create the necessary files and symbolic links

ln -sv /tools/bin/{bash,cat,echo,pwd,stty} /bin
ln -sv /tools/bin/perl /usr/bin
ln -sv /tools/lib/libgcc_s.so{,.1} /usr/lib
ln -sv /tools/lib/libstdc++.so{,.6} /usr/lib
sed 's/tools/usr/' /tools/lib/libstdc++.la > /usr/lib/libstdc++.la
ln -sv bash /bin/sh
ln -sv /proc/self/mounts /etc/mtab


# root The user's actual password (here)“ x" Just placeholders) will be created later.
cat > /etc/passwd << "EOF"
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/dev/null:/bin/false
daemon:x:6:6:Daemon User:/dev/null:/bin/false
messagebus:x:18:18:D-Bus Message Daemon User:/var/run/dbus:/bin/false
nobody:x:99:99:Unprivileged User:/dev/null:/bin/false
EOF


cat > /etc/group << "EOF"
root:x:0:
bin:x:1:daemon
sys:x:2:
kmem:x:3:
tape:x:4:
tty:x:5:
daemon:x:6:
floppy:x:7:
disk:x:8:
lp:x:9:
dialout:x:10:
audio:x:11:
video:x:12:
utmp:x:13:
usb:x:14:
cdrom:x:15:
adm:x:16:
messagebus:x:18:
systemd-journal:x:23:
input:x:24:
mail:x:34:
nogroup:x:99:
users:x:999:
EOF


exec /tools/bin/bash --login +h
touch /var/log/{btmp,lastlog,faillog,wtmp}
chgrp -v utmp /var/log/lastlog
chmod -v 664  /var/log/lastlog
chmod -v 600  /var/log/btmp

5. Execute shell script to complete the construction of LFS system

cd /sources
chmod +x ch6-build.sh
./ch6-build.sh

master.tar.gz: Cross-compiled binary kernel, kernel module, bootloader, GPU (Video Core) firmware

Optional installation and upgrade according to script prompt.

6. Clean up useless content again

logout
chroot $LFS /tools/bin/env -i            \
    HOME=/root TERM=$TERM PS1='\u:\w\$ ' \
    PATH=/bin:/usr/bin:/sbin:/usr/sbin   \
    /tools/bin/bash --login
/tools/bin/find /usr/lib -type f -name \*.a \
   -exec /tools/bin/strip --strip-debug {} ';'

/tools/bin/find /lib /usr/lib -type f -name \*.so* \
   -exec /tools/bin/strip --strip-unneeded {} ';'

/tools/bin/find /{bin,sbin} /usr/{bin,sbin,libexec} -type f \
    -exec /tools/bin/strip --strip-all {} ';'

7. Cleaning up

rm -rf /tmp/*
logout chroot "$LFS" /usr/bin/env -i              \
    HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \
    PATH=/bin:/usr/bin:/sbin:/usr/sbin     \
    /bin/bash --login
rm -rf /tools rm -f /usr/lib/lib{bfd,opcodes}.a
rm -f /usr/lib/libbz2.a
rm -f /usr/lib/lib{com_err,e2p,ext2fs,ss}.a
rm -f /usr/lib/libltdl.a
rm -f /usr/lib/libfl.a
rm -f /usr/lib/libfl_pic.a
rm -f /usr/lib/libz.a

Tags: Linux shell DBus

Posted on Fri, 22 Mar 2019 06:15:53 -0700 by chiprivers