# 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 ```shell #!/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: ```text /dev/sda1 98G 6.1G 87G 7% / ``` `lsblck` shows: ```text 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` ```shell #!/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 <~/.ssh/id_rsa.pub <` ```shell $ 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