Freelance Projects

Upeksha Wisidagama

Building the System Software From Scratch

Various file systems exported by the kernel are used to communicate to and from the kernel itself. These file systems are virtual in that no disk space is used for them. The content of the file systems resides in memory. Begin by creating directories onto which the file systems will be mounted.

‘Virtual Kernel FileSystems’
1
2
3
4
5
mkdir -v $LFS/{dev,proc,sys}

mount -vt devpts devpts $LFS/dev/pts
mount -vt proc proc $LFS/proc
mount -vt sysfs sysfs $LFS/sys

Dev File System

‘Virtual Kernel FileSystems’
1
2
3
4
mknod -m 600 $LFS/dev/console c 5 1
mknod -m 666 $LFS/dev/null c 1 3

mount -v --bind /dev $LFS/dev

Chroot into the System

‘Chrooting to the System’
1
2
3
4
5
6
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

-i option will clear all environment variables of the chroot environment. Then ‘HOME’, ‘TERM’, ‘PS1’ and ‘PATH’ variables are set again.

Notice that ‘/tools/bin’ comes last in the PATH. This means that a temporary tool will no longer be used once its final version is installed. This occurs when the shell does not “remember” the locations of executed binaries—for this reason, hashing is switched off by passing the ‘+h’ option to bash.

Install the System Software from Source

The following list of programs needs to be installed.

‘System Software List’
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Linux-3.8.1 API Headers
Man-pages-3.47
Glibc-2.17
Zlib-1.2.7
File-5.13
Binutils-2.23.1
GMP-5.1.1
MPFR-3.1.1
MPC-1.0.1
GCC-4.7.2
Sed-4.2.2
Bzip2-1.0.6
Pkg-config-0.28
Ncurses-5.9
Util-linux-2.22.2
Psmisc-22.20
Procps-ng-3.3.6
E2fsprogs-1.42.7
Shadow-4.1.5.1
Coreutils-8.21
Iana-Etc-2.30
M4-1.4.16
Bison-2.7
Grep-2.14
Readline-6.2
Bash-4.2
Libtool-2.4.2
GDBM-1.10
Inetutils-1.9.1
Perl-5.16.2
Autoconf-2.69
Automake-1.13.1
Diffutils-3.2
Gawk-4.0.2
Findutils-4.4.2
Flex-2.5.37
Gettext-0.18.2
Groff-1.22.2
Xz-5.0.4
GRUB-2.00
Less-451
Gzip-1.5
IPRoute2-3.8.0
Kbd-1.15.5
Kmod-12
Libpipeline-1.2.2
Make-3.82
Man-DB-2.6.3
Patch-2.7.1
Sysklogd-1.5
Sysvinit-2.88dsf
Tar-1.26
Texinfo-5.0
Udev-197
Vim-7.3

Now we have all System Software installed. Next we should compile the kernel. See Compiling a Linux Kernel From Source post.