2025-3-15 Linux From Nothing Git, Perl, Strace

everything is there Linux From Nothing

4. Git, Perl, Strace

Lets mount things up and config a new kernel.

cd LFN

sudo modprobe nbd max_part=8
sudo qemu-nbd -c /dev/nbd0 disk2.img
sudo mount /dev/nbd0p1 /mnt

cd linux

make menuconfig

General setup --->

----[*] Configure standard kernel features (expert users) --->

--------[*] Posix Clocks timers

[*] Networking support --->

----Networking options --->

--------[*] DNS Resolver support (needs the other option ↓ to be shown)

Security options --->

----[*] Enable access key retention support


Posix Clocks timers WILL ENABLE timers/NANOSLEEP and fix freeze with m4 and others:

checking for working nanosleep..

The other 2 option are for Curl

Lets compile again and mv to our LFN.

make -j8
sudo mv arch/x86/boot/bzImage /mnt/boot/
sudo cp .config /mnt/boot/
cd ..

Now we unmount everything and boot LFN

sudo umount /mnt
sudo qemu-nbd -d /dev/nbd0
qemu-system-x86_64 disk2.img -smp 8 -m 8G -enable-kvm -cpu host

Fix $PATH

$PATH is not properly set in LFN, lets fix that so our programs know where to look for bin.

#on LFN
nano /sbin/init

Init should look like:

#!/bin/bash

mount -t proc none /proc
mount -t sysfs none /sys

ip link set up eth0
ip addr add 10.0.2.15/24 dev eth0
ip route add 10.0.2.2 dev eth0
ip route add 0/0 via 10.0.2.2 dev eth0

dnsmasq -uroot

export SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
export COMPILER_PATH=/usr/libexec/gcc/x86_64-pc-linux-gnu/14.2.0:/usr/bin
export LIBRARY_PATH=/usr/lib/gcc/x86_64-pc-linux-gnu/14.2.0
export CPATH=/usr/lib/gcc/x86_64-pc-linux-gnu/14.2.0/include
export PATH=/usr/bin:/usr/sbin

exec /bin/bash

Sync and reboot to make the change take effect.

#on LFN
sync
#reboot LFN

Diffutils

https://www.gnu.org/software/diffutils/

Provides diff and cmp needed broadly across GNU software.

#on LFN
cd root
wget https://ftp.gnu.org/gnu/diffutils/diffutils-3.11.tar.xz

tar -xvf diffutils-3.11.tar.xz

mkdir diffutils-build
cd diffutils-build

../diffutils-3.11/configure --prefix=/usr
make -j8
make install

cd ..

M4

Macros M4 needed by autoconf.

#on LFN
wget https://ftp.gnu.org/gnu/m4/m4-1.4.19.tar.xz

tar -xvf m4-1.4.19.tar.xz

mkdir m4-build
cd m4-build
../m4-1.4.19/configure --prefix=/usr

make -j8
make install

cd ..

Bison

Needed by the kernel and GNU software.

#on LFN
wget https://ftp.gnu.org/gnu/bison/bison-3.8.tar.xz

tar -xvf bison-3.8.tar.xz

mkdir bison-build
cd bison-build
../bison-3.8/configure --prefix=/usr

make -j8
make install

cd ..

Bzip2

https://sourceware.org/bzip2/

We didn't have it!

#on LFN
wget https://sourceware.org/pub/bzip2/bzip2-latest.tar.gz

tar -xvf bzip2-latest.tar.gz


cd bzip2-1.0.8

make -j8
make install

cd ..

FLEX

used by the kernel and others.

#on LFN
wget https://github.com/westes/flex/releases/download/v2.6.4/flex-2.6.4.tar.gz

tar -xvf flex-2.6.4.tar.gz

mkdir flex-build
cd flex-build
../flex-2.6.4/configure --prefix=/usr

make -j8
make install

cd ..

FindUtils

https://www.gnu.org/software/findutils/

Provides find.

#on LFN
wget https://ftp.gnu.org/gnu/findutils/findutils-4.10.0.tar.xz

tar -xvf findutils-4.10.0.tar.xz

mkdir findutils-build
cd findutils-build
../findutils-4.10.0/configure --prefix=/usr

make -j8
make install

cd ..

Perl

https://www.perl.org/get.html

Needed everywhere... and Curl.

#on LFN
ln -s gcc /bin/cc

wget https://cpan.org/src/5.0/perl-5.40.1.tar.gz

tar -xvf perl-5.40.1.tar.gz

cd perl-5.40.1

./Configure -d 
#not needed with configure -D prefix=/usr
make -j8
make install

cd ..

Autoconf

Needed by Git

#on LFN
wget https://ftp.gnu.org/gnu/autoconf/autoconf-2.72.tar.xz

tar -xvf autoconf-2.72.tar.xz

mkdir autoconf-build
cd autoconf-build

../autoconf-2.72/configure --prefix=/usr

make
# DO NOT USE -J8
make install

cd ..

Texinfo

https://www.gnu.org/software/texinfo/

Needed by bc which is needed by the kernel.

#on LFN
wget https://ftp.gnu.org/gnu/texinfo/texinfo-7.2.tar.xz

tar -xvf texinfo-7.2.tar.xz

mkdir texinfo-build
cd texinfo-build

../texinfo-7.2/configure --prefix=/usr

make -j8
make install

cd ..

BC

https://www.gnu.org/software/bc/

BC is needed to compile the Linux Kernel.

#on LFN
wget https://ftp.gnu.org/gnu/bc/bc-1.08.1.tar.xz

tar -xvf bc-1.08.1.tar.xz

mkdir bc-build
cd bc-build

../bc-1.08.1/configure --prefix=/usr

make -j8
make install

cd ..

Curl (Libcurl)

https://github.com/curl/curl/

Used to download everything... and Git.

#on LFN
wget https://github.com/curl/curl/releases/download/curl-8_12_1/curl-8.12.1.tar.gz

tar -xvf curl-8.12.1.tar.gz

mkdir curl-build
cd curl-build

../curl-8.12.1/configure --with-openssl --without-libpsl --prefix=/usr

make -j8
make install

cd ..

Git

https://github.com/git/git

Git, we all know what it is by now.

#on LFN
wget https://github.com/git/git/archive/refs/tags/v2.48.1.tar.gz
tar -xvf v2.48.1.tar.gz
cd git-2.48.1

make configure
#we can ignore the error which is about perl's flock (not implemented)
./configure --prefix=/usr

make NO_GETTEXT=1 NO_TCLTK=1 install -j8

cd ..

git clone --depth 1 https://github.com/torvalds/linux
#and we see that it does not work
curl -v google.com
#not working too!

Strace

More and more we are having small issues with missing functions, to find what we need lets download Strace!

#on LFN
wget https://github.com/strace/strace/releases/download/v6.13/strace-6.13.tar.xz

tar -xvf strace-6.13.tar.xz

mkdir strace-build
cd strace-build

../strace-6.13/configure --prefix=/usr

make -j8
make install

cd ..

Debugging with Strace

So we need to know what function we are missing in order to add it to our system.

Lets run:

strace -o trace.log curl -v google.com

nano trace.log

Inside of trace.log we can see eventfd2 being called and ending in -1 enosys (Function not implemented)

So we need to implement it!

wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.13.6.tar.xz
tar -xvf linux-6.13.6.tar.xz

cd linux-6.13.6

cp /boot/.config ./

ln -s /usr/lib/libncursesw.a /usr/lib/libncurses.a

make menuconfig
#big fail
cd ..

Ncurses (no-widec)

Lets do it again but without widec

wget https://ftp.gnu.org/gnu/ncurses/ncurses-6.5.tar.gz

tar -xvzf ncurses-6.5.tar.gz

mkdir ncurses-build

cd ncurses-build
../ncurses-6.5/configure --with-shared --disable-widec --prefix=/usr

make -j8
make install
cd ..

cd linux-6.13.6

make menuconfig

General setup --->

----[*] Configure standard kernel features (expert users) --->

--------[*] Enable eventfd() system call


make -j8

mv arch/x86/boot/bzImage /boot/LFN-4

make headers

cp -r usr/include/* /usr/include/

nano /boot/grub/grub.cfg

Here is the new content:

menuentry 'LFN-4' {
        set root='(hd0,1)'
        linux /boot/LFN-4 root=/dev/sda1 rw
}
menuentry 'LFN' {
        set root='(hd0,1)'
        linux /boot/bzImage root=/dev/sda1 rw
}

Lets sync reboot and test again!

sync
#reboot
cd root

git clone --depth 1 https://github.com/torvalds/linux
#it works!

ls linux
#it works!
#lets purge root because we dont need the source anymore!
cd ..
rm -r root
mkdir root

sync

Here is the image: https://d2xw7bkejy3jlh.cloudfront.net/disk4.img.xz