Linux Kernel Dev Blog 6 - Linux From Scratch (LFS) Starting
4/6/2020
I swapped over to an Ubuntu VBox setup on my mac, below is the notes
get vm box ready and connected
$ sudo apt-get install openssh-server $ sudo service ssh start $ hostname -I $ ssh-keygen
VirtualBox > Settings > Network > Advanced > Port Foward 127.0.0.1:222 > VMHOSTNAME:22
Put key on GitHub
install stuff to compile kernel
$ sudo apt-get install -y git libncurses5-dev gcc make git exuberant-ctags libssl-dev bison flex libelf-dev bc vim zsh tmux texinfo g++ gawk
$ git clone git@github.com:jordansavant/ashes.git ~/.ashes
$ bash ~/.ashes/boot
$ sudo mv /bin/sh /bin/sh-old
$ sudo ln -s /bin/bash /bin/sh
lfs host requirements
http://www.linuxfromscratch.org/lfs/view/stable/chapter02/hostreqs.html
#!/bin/bash
# Simple script to list version numbers of critical development tools
export LC_ALL=C
bash --version | head -n1 | cut -d" " -f2-4
MYSH=$(readlink -f /bin/sh)
echo "/bin/sh -> $MYSH"
echo $MYSH | grep -q bash || echo "ERROR: /bin/sh does not point to bash"
unset MYSH
echo -n "Binutils: "; ld --version | head -n1 | cut -d" " -f3-
bison --version | head -n1
if [ -h /usr/bin/yacc ]; then
echo "/usr/bin/yacc -> `readlink -f /usr/bin/yacc`";
elif [ -x /usr/bin/yacc ]; then
echo yacc is `/usr/bin/yacc --version | head -n1`
else
echo "yacc not found"
fi
bzip2 --version 2>&1 < /dev/null | head -n1 | cut -d" " -f1,6-
echo -n "Coreutils: "; chown --version | head -n1 | cut -d")" -f2
diff --version | head -n1
find --version | head -n1
gawk --version | head -n1
if [ -h /usr/bin/awk ]; then
echo "/usr/bin/awk -> `readlink -f /usr/bin/awk`";
elif [ -x /usr/bin/awk ]; then
echo awk is `/usr/bin/awk --version | head -n1`
else
echo "awk not found"
fi
gcc --version | head -n1
g++ --version | head -n1
ldd --version | head -n1 | cut -d" " -f2- # glibc version
grep --version | head -n1
gzip --version | head -n1
cat /proc/version
m4 --version | head -n1
make --version | head -n1
patch --version | head -n1
echo Perl `perl -V:version`
python3 --version
sed --version | head -n1
tar --version | head -n1
makeinfo --version | head -n1 # texinfo version
xz --version | head -n1
echo 'int main(){}' > dummy.c && g++ -o dummy dummy.c
if [ -x dummy ]
then echo "g++ compilation OK";
else echo "g++ compilation failed"; fi
rm -f dummy.c dummy
saved to lfs_hostcheck.sh
$ bash lfs_hostcheck.sh
WORKED
lfs 2.3.1. Chapters 1–4
partitioning
New partition for lfs install AND shared swap partion with host (which does not need to be created)
Partitions must be placed on a drive such as /dev/sda
and will be named something like sda5
Build partitions with cfdisk
or fdisk
. cfdisk
appears to be ncurses menu for fdisk, gonna try to learn it with only man pages
mounts for df -h
show:
/dev/sda1 98G 6.1G 87G 7% /
lsblck
shows:
sda 8:0 0 100G 0 disk
└─sda1 8:1 0 100G 0 part /
...
Well I completely f-d the OS because I downsized the mounted /
drive to 70GB from 30GB to create the partion, this deleted a chunk of data on the primary mount :facepalm: and now its fubar
Re-installing Ubuntu...
Set VBOX disk to 70GB and will install Ubuntu there, from there I will extend the VBOX disk to 105GB and dedicate the 30GB extra as the boot partition (with a 5GB swap partition)
In the meantime let me compile a launch script for the host
host_install.sh
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
# install primary packages
sudo apt-get install -y openssh-server git curl libncurses5-dev gcc make git exuberant-ctags libssl-dev bison flex libelf-dev bc vim zsh tmux texinfo g++ gawk
sudo service ssh start
# make bash primary shell
sudo mv /bin/sh /bin/sh-old
sudo ln -s /bin/bash /bin/sh
# install git keys
if [ ! -d ~/.ssh ]; then
su doomguy -c 'mkdir ~/.ssh'
fi
cat >~/.ssh/id_rsa <<EOL
-----BEGIN RSA PRIVATE KEY-----
REDACTED
-----END RSA PRIVATE KEY-----
EOL
cat >~/.ssh/id_rsa.pub <<EOL
REDACTED
EOL
sudo chown -R doomguy:doomguy .ssh
# get hostname
hostname -I
OK back again, gonna resize drive now to 100GB then attempt to repartition the remaining space with cfdisk
This time I was able to partition the disk at 30GB and all seems ok
for the SWAP partition, seems like the ubuntu install does not have one
$ swapon -s
Filename Type Size Used Priority
/swapfile file 2097148 0 -2
Using https://linuxtechlab.com/create-swap-using-fdisk-fallocate/ I will attempt to make one (with 4GB of more VBOX HD)
created another 5GB partition with cfdisk
at /dev/sda3
Make it swap
$ sudo mkswap /dev/sda3
Setting up swapspace version 1, size = 5 GiB (5368705024 bytes)
no label, UUID=c34da079-9c3c-4715-b656-218ccced9cd7
Activate it as swap (this is temporary while OS is running)
$ sudo swapon /dev/sda3
$ swapon -s
Filename Type Size Used Priority
/swapfile file 2097148 0 -2
/dev/sda3 partition 5242876 0 -3
Make it always use swap with /etc/fstab
/dev/sda3 swap swap default 0 0
After reboot htop
confirms the 7GB (2GB swap file original + 5GB partition)
Some LSF partition recommendations (interesting reads)
- /boot – Highly recommended. Use this partition to store kernels and other booting information. To minimize potential boot problems with larger disks, make this the first physical partition on your first disk drive. A partition size of 100 megabytes is quite adequate.
- /home – Highly recommended. Share your home directory and user customization across multiple distributions or LFS builds. The size is generally fairly large and depends on available disk space.
- /usr – A separate /usr partition is generally used if providing a server for a thin client or diskless workstation. It is normally not needed for LFS. A size of five gigabytes will handle most installations.
- /opt – This directory is most useful for BLFS where multiple installations of large packages like Gnome or KDE can be installed without embedding the files in the /usr hierarchy. If used, 5 to 10 gigabytes is generally adequate.
- /tmp – A separate /tmp directory is rare, but useful if configuring a thin client. This partition, if used, will usually not need to exceed a couple of gigabytes.
- /usr/src – This partition is very useful for providing a location to store BLFS source files and share them across LFS builds. It can also be used as a location for building BLFS packages. A reasonably large partition of 30-50 gigabytes allows plenty of room.
adding file system
- ext2 is good for small partitions like boot
- ext3 upgrade of ext2 with a journal to help recover partition status in case of unclean shutdown
- ext4 newest and best with big 16TB files supported
df -hT
shows our Ubuntu install is on ext4
Make the new partition for LFS ext4 with mkfs -v -t ext4 /dev/<xxx>
$ sudo mkfs -v -t ext4 /dev/sda2
mke2fs 1.44.1 (24-Mar-2018)
fs_types for mke2fs.conf resolution: 'ext4'
warning: 256 blocks unused.
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1969920 inodes, 7864320 blocks
393215 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2155872256
240 block groups
32768 blocks per group, 32768 fragments per group
8208 inodes per group
Filesystem UUID: afb42649-d29a-4f3e-8fc8-834a5cbe4fdc
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
LFS export var
We need to setup the partition as a mount we can build our linux into
I added the following export var to my bash_profile, zshenv and root bash_profile
export LFS="/mnt/lfs"
Create the mount point
$ sudo mkdir -vp $LFS
mkdir: created directory '/mnt/lfs'
$ sudo mount -v -t ext4 /dev/sda2 $LFS
mount: /dev/sda2 mounted on /mnt/lfs.
Run the mount command without any parameters to see what options are set for the mounted LFS partition. If nosuid and/or nodev are set, the partition will need to be remounted
mount
didn't show these
Adding the mount to bootup /etc/fstab
which now looks like
UUID=4ceb7055-34a1-442a-a82a-fe88a527783e / ext4 errors=remount-ro 0 1
/swapfile none swap sw 0 0
/dev/sda3 swap swap defaults 0 0
/dev/sda2 /mnt/lfs ext4 defaults 1 1
Stopping here, tomorrow we are going to start the binary downloads and stuff