Initial commit of LFS notes and scripts.

This commit is contained in:
Shaun Setlock
2025-01-20 15:44:57 -05:00
commit 386dc3cec7
78 changed files with 2628 additions and 0 deletions

View 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`