Initial commit of LFS notes and scripts.
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
# Chapter 2
|
||||
## Section 2 Preparing Host
|
||||
Two issues encountered after running `bash version_check.sh`.
|
||||
1. Missing `texinfo`
|
||||
`dnf install texinfo -y`
|
||||
2. `yacc` is NOT `bison`
|
||||
`ln -s /usr/bin/bison /usr/bin/yacc`
|
||||
## Section 4 Partitioning
|
||||
Label disk with GPT.
|
||||
```
|
||||
fdisk /dev/sdb
|
||||
g
|
||||
w
|
||||
```
|
||||
Create partitions.
|
||||
1. Boot ("/boot") - 1M
|
||||
- Ensure the partition type is switched to "Bios boot".
|
||||
1. Swap - 2G
|
||||
- Ensure the partition type is switched to "Linux swap".
|
||||
1. Root ("/") - 10G
|
||||
1. Home ("/home") - 10G
|
||||
## Section 5 Filesystems
|
||||
Make swap on the swap partition.
|
||||
`mkswap /dev/sdb2`
|
||||
`swaplabel -L lfs_swap /dev/sdb2`
|
||||
Make ext4 on / and /home.
|
||||
`mkfs -v -t ext4 /dev/sdb3`
|
||||
`e2label /dev/sdb3 lfs_root`
|
||||
`mkfs -v -t ext4 /dev/sdb4`
|
||||
`e2label /dev/sdb4 lfs_home
|
||||
## Section 6 Setting $LFS
|
||||
I will follow the book.
|
||||
`export LFS=/mnt/lfs`
|
||||
`echo "export LFS=/mnt/lfs" >> /root/.bash_profile`
|
||||
## Mounting LFS Filesystems (via /etc/fstab)
|
||||
The book outlines temporarily mounting, and indicates consideration should be given to /etc/fstab entries.
|
||||
First, we'll make the /mnt/lfs mountpoint(s). The below will create both /mnt/lfs and /mnt/lfs/home.
|
||||
`mkdir -pv $LFS/home`
|
||||
We will append the following to the host's /etc/fstab file.
|
||||
```
|
||||
# LFS mounts
|
||||
UUID=49600a93-8e64-4ac1-b7d9-7a5ccdb2b179 /mnt/lfs ext4 defaults,nofail 0 0
|
||||
UUID=0c0505fe-b133-4257-888e-9b16f4fca86c /mnt/lfs/home ext4 defaults,nofail 0 0
|
||||
UUID=5bd12ccf-c72f-4cca-8a6a-7d40e847fc42 none swap defaults,nofail 0 0
|
||||
```
|
||||
Then load the new /etc/fstab file.
|
||||
`systemctl daemon-reload`
|
||||
And finally mount the new filesystems automatically.
|
||||
`mount -a`
|
||||
With the following output ...
|
||||
```
|
||||
# lsblk
|
||||
|
||||
sdb 8:16 0 30G 0 disk
|
||||
├─sdb1 8:17 0 511M 0 part
|
||||
├─sdb2 8:18 0 2G 0 part
|
||||
├─sdb3 8:19 0 10G 0 part /mnt/lfs
|
||||
└─sdb4 8:20 0 10G 0 part /mnt/lfs/home
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
#!/bin/bash
|
||||
# A script to list version numbers of critical development tools
|
||||
|
||||
# If you have tools installed in other directories, adjust PATH here AND
|
||||
# in ~lfs/.bashrc (section 4.4) as well.
|
||||
|
||||
LC_ALL=C
|
||||
PATH=/usr/bin:/bin
|
||||
|
||||
bail() { echo "FATAL: $1"; exit 1; }
|
||||
grep --version > /dev/null 2> /dev/null || bail "grep does not work"
|
||||
sed '' /dev/null || bail "sed does not work"
|
||||
sort /dev/null || bail "sort does not work"
|
||||
|
||||
ver_check()
|
||||
{
|
||||
if ! type -p $2 &>/dev/null
|
||||
then
|
||||
echo "ERROR: Cannot find $2 ($1)"; return 1;
|
||||
fi
|
||||
v=$($2 --version 2>&1 | grep -E -o '[0-9]+\.[0-9\.]+[a-z]*' | head -n1)
|
||||
if printf '%s\n' $3 $v | sort --version-sort --check &>/dev/null
|
||||
then
|
||||
printf "OK: %-9s %-6s >= $3\n" "$1" "$v"; return 0;
|
||||
else
|
||||
printf "ERROR: %-9s is TOO OLD ($3 or later required)\n" "$1";
|
||||
return 1;
|
||||
fi
|
||||
}
|
||||
|
||||
ver_kernel()
|
||||
{
|
||||
kver=$(uname -r | grep -E -o '^[0-9\.]+')
|
||||
if printf '%s\n' $1 $kver | sort --version-sort --check &>/dev/null
|
||||
then
|
||||
printf "OK: Linux Kernel $kver >= $1\n"; return 0;
|
||||
else
|
||||
printf "ERROR: Linux Kernel ($kver) is TOO OLD ($1 or later required)\n" "$kver";
|
||||
return 1;
|
||||
fi
|
||||
}
|
||||
|
||||
# Coreutils first because --version-sort needs Coreutils >= 7.0
|
||||
ver_check Coreutils sort 8.1 || bail "Coreutils too old, stop"
|
||||
ver_check Bash bash 3.2
|
||||
ver_check Binutils ld 2.13.1
|
||||
ver_check Bison bison 2.7
|
||||
ver_check Diffutils diff 2.8.1
|
||||
ver_check Findutils find 4.2.31
|
||||
ver_check Gawk gawk 4.0.1
|
||||
ver_check GCC gcc 5.2
|
||||
ver_check "GCC (C++)" g++ 5.2
|
||||
ver_check Grep grep 2.5.1a
|
||||
ver_check Gzip gzip 1.3.12
|
||||
ver_check M4 m4 1.4.10
|
||||
ver_check Make make 4.0
|
||||
ver_check Patch patch 2.5.4
|
||||
ver_check Perl perl 5.8.8
|
||||
ver_check Python python3 3.4
|
||||
ver_check Sed sed 4.1.5
|
||||
ver_check Tar tar 1.22
|
||||
ver_check Texinfo texi2any 5.0
|
||||
ver_check Xz xz 5.0.0
|
||||
ver_kernel 4.19
|
||||
|
||||
if mount | grep -q 'devpts on /dev/pts' && [ -e /dev/ptmx ]
|
||||
then echo "OK: Linux Kernel supports UNIX 98 PTY";
|
||||
else echo "ERROR: Linux Kernel does NOT support UNIX 98 PTY"; fi
|
||||
|
||||
alias_check() {
|
||||
if $1 --version 2>&1 | grep -qi $2
|
||||
then printf "OK: %-4s is $2\n" "$1";
|
||||
else printf "ERROR: %-4s is NOT $2\n" "$1"; fi
|
||||
}
|
||||
echo "Aliases:"
|
||||
alias_check awk GNU
|
||||
alias_check yacc Bison
|
||||
alias_check sh Bash
|
||||
|
||||
echo "Compiler check:"
|
||||
if printf "int main(){}" | g++ -x c++ -
|
||||
then echo "OK: g++ works";
|
||||
else echo "ERROR: g++ does NOT work"; fi
|
||||
rm -f a.out
|
||||
|
||||
if [ "$(nproc)" = "" ]; then
|
||||
echo "ERROR: nproc is not available or it produces empty output"
|
||||
else
|
||||
echo "OK: nproc reports $(nproc) logical cores are available"
|
||||
fi
|
||||
@@ -0,0 +1,20 @@
|
||||
# Chapter 3
|
||||
## Section 1 Intro
|
||||
## Section 2 Packages
|
||||
Make a directory for all the sources of packages/patches we're going to build.
|
||||
`mkdir -v $LFS/sources`
|
||||
Make it sticky and writable.
|
||||
`chmod -v a+wt $LFS/sources`
|
||||
Fetch the list of all packages needed.
|
||||
`wget https://www.linuxfromscratch.org/lfs/downloads/stable-systemd/wget-list`
|
||||
Pull them all down.
|
||||
`wget --input-file=wget-list --continue --directory-prefix=$LFS/sources`
|
||||
Fetch their MD5 checksums.
|
||||
`wget https://www.linuxfromscratch.org/lfs/downloads/stable-systemd/md5sums`
|
||||
Check every package for its integrity.
|
||||
```
|
||||
pushd $LFS/sources
|
||||
md5sum -c md5sums
|
||||
popd
|
||||
```
|
||||
## Section 3 Patches
|
||||
68
lfs-notes/p2_preparing_the_build/c4_final_prep/c4_notes.md
Normal file
68
lfs-notes/p2_preparing_the_build/c4_final_prep/c4_notes.md
Normal file
@@ -0,0 +1,68 @@
|
||||
# Chapter 4
|
||||
## Section 1 Intro
|
||||
## Section 2 Simple File Structure
|
||||
We start by building simple of the early pieces of the file structure.
|
||||
The following is to be performed as root. These directories are not owned by an unprivileged user.
|
||||
```
|
||||
mkdir -pv $LFS/{etc,var} $LFS/usr/{bin,lib,sbin}
|
||||
|
||||
for i in bin lib sbin; do
|
||||
ln -sv usr/$i $LFS/$i
|
||||
done
|
||||
|
||||
case $(uname -m) in
|
||||
x86_64) mkdir -pv $LFS/lib64 ;;
|
||||
esac
|
||||
```
|
||||
We will also make a special, temporary directory for the cross compiler toolchain.
|
||||
`mkdir -pv $LFS/tools`
|
||||
## Section 3 The lfs User
|
||||
As a measure of caution, let's proceed with the remaining steps as a normal user.
|
||||
We will use the name lfs since it is unlikely to be found on the host system.
|
||||
```
|
||||
groupadd lfs
|
||||
useradd -s /bin/bash -g lfs -m -k /dev/null lfs
|
||||
```
|
||||
Though not strictly required, we can set the password for the lfs user.
|
||||
`passwd lfs`
|
||||
Then, let's transfer ownership of this simple file structure to the lfs user.
|
||||
```
|
||||
chown -v lfs $LFS/{usr{,/*},lib,var,etc,bin,sbin,tools}
|
||||
case $(uname -m) in
|
||||
x86_64) chown -v lfs $LFS/lib64 ;;
|
||||
esac
|
||||
```
|
||||
Finally, let's become lfs.
|
||||
`su - lfs`
|
||||
## Section 4 Setting Up The Environment
|
||||
Create the bash profile for lfs.
|
||||
```
|
||||
cat > ~/.bash_profile << "EOF"
|
||||
exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash
|
||||
EOF
|
||||
```
|
||||
And the bashrc for lfs.
|
||||
```
|
||||
cat > ~/.bashrc << "EOF"
|
||||
set +h
|
||||
umask 022
|
||||
LFS=/mnt/lfs
|
||||
LC_ALL=POSIX
|
||||
LFS_TGT=$(uname -m)-lfs-linux-gnu
|
||||
PATH=/usr/bin
|
||||
if [ ! -L /bin ]; then PATH=/bin:$PATH; fi
|
||||
PATH=$LFS/tools/bin:$PATH
|
||||
CONFIG_SITE=$LFS/usr/share/config.site
|
||||
export LFS LC_ALL LFS_TGT PATH CONFIG_SITE
|
||||
EOF
|
||||
```
|
||||
Since this system will only be used for this project, it is safe to force builds to use all cores.
|
||||
```
|
||||
cat >> ~/.bashrc << "EOF"
|
||||
export MAKEFLAGS=-j$(nproc)
|
||||
EOF
|
||||
```
|
||||
Finally, let's load this new environment setup contained within the bash profile and rc.
|
||||
`source ~/.bash_profile`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user