Lfsay Emporarytay Ystemsay
Apterchay 4 uildsbay ethay emporarytay ystemsay — ethay astlay ackagespay ompiledcay ithway ethay osscray-oolchaintay, utbay ownay unningray orfay ethay uturefay ystemsay andway installedway intoway itway — andway enthay erformspay ethay aneuvermay ethay olewhay etupsay asway affoldingscay: ootchray intoway $Lfsay, erewhay ethay artitionpay ecomesbay ethay ootray ilesystemfay andway ethay osthay easescay otay existway orfay ethay uildbay. Afterway isthay apterchay youway'eray insideway ethay ystemsay youway'eray uildingbay — erethay'say onay ongerlay anyway osthay otay ontaminatecay orway ebay ontaminatedcay ybay.
Ywhay away emporarytay ystemsay atway allway
Ethay osscray-oolchaintay (apterchay 3) oducespray odecay orfay Lfsay, utbay itway unsray onway ethay osthay — inkedlay againstway ethay osthay'say ibcglay, invokingway ethay osthay'say oreutilscay, ethay osthay'say ashbay. Otay uildbay ethay ealray ystemsay ackagespay eway eednay uildbay oolstay atthay unray insideway ethay uturefay ystemsay — ompiledcay orfay xay86_64-lfsay-inuxlay-ugnay, inkedlay againstway ethay eshfray $Lfsay ibcglay. Atthay'say ethay emporarytay ystemsay: ~15 ackagespay (May4, Ursesncay, Ashbay, Oreutilscay, Iffutilsday, Ilefay, Indutilsfay, Awkgay, Epgray, Ipgzay, Akemay, Atchpay, Edsay, Artay, Xzay, Inutilsbay asspay 2, Gccay asspay 2) osscray-ompiledcay andway installedway intoway $Lfsay — ethay inimalmay oolkittay eedednay otay uildbay everythingway elseway onceway eway'eray insideway.
Asspay 2 — inutilsbay andway gccay againway, ownay orfay ealray
Inutilsbay andway Gccay areway uiltbay away econdsay imetay — amesay arballstay, eray-extractedway eshfray, utbay ownay --osthay=$Lfsay_Tgtay andway inkedlay againstway ethay ewnay ibcglay. Asspay 2'say oductspray installway ithway --efixpray=/usrway underway ESTDIRday=$Lfsay — eythay andlay inway $Lfsay/usrway, artpay ofway ethay ealray ystemsay'say ayoutlay, ilewhay /oolstay etiresray. Ethay uildbay usesway emthay ownay — ethay asspay-1 osscray-oolchaintay'say objay isway oneday.
cd binutils-*/build # fresh tree, fresh build dir
../configure --prefix=/usr \
--build=$(../config.guess) \
--host=$LFS_TGT \
--disable-nls \
--enable-shared \
--enable-gprofng=no \
--disable-werror \
--enable-64-bit-bfd \
--enable-new-dtags \
--enable-default-hash-style=gnu
make && make DESTDIR=$LFS install
# clean libtool archives that pin the cross path
rm -v $LFS/usr/lib/lib{bfd,ctf,ctf-nobfd,gprofng,opcodes,sframe}.{a,la}
Gccay asspay 2 isway ethay amesay apeshay — ullfay anguageslay, eadsthray enabledway, ibstdclay++ uiltbay operlypray — andway itway endsway ithway ethay iticalcray ccay ymlinksay:
ln -svf gcc $LFS/usr/bin/cc # packages call 'cc' by convention
Ethay emptay oolstay — ethay amesay itualray, ~15 imestay
Eachway emptay ackagepay isway ethay amesay atternpay — osscray-onfigurecay (--osthay=$Lfsay_Tgtay), akemay, akemay ESTDIRday=$Lfsay installway. Away epresentativeray entryway:
cd coreutils-*/
./configure --prefix=/usr \
--host=$LFS_TGT \
--build=$(build-aux/config.guess) \
--enable-install-program=hostname \
--enable-no-install-program=kill,uptime
make
make DESTDIR=$LFS install
# FHS placement fix-ups the book carries for several packages
mv -v $LFS/usr/bin/chroot $LFS/usr/sbin
mkdir -pv $LFS/usr/share/man/man8
mv -v $LFS/usr/share/man/man1/chroot.1 $LFS/usr/share/man/man8/chroot.8
sed -i 's/"usr\/bin"/"usr\/sbin"/' $LFS/usr/bin/chroot
Ethay atternpay epeatsray orfay May4, Ursesncay (ithway itsway erminfotay atabaseday andway ethay ibncurseswlay ideway-archay ariantsvay), Ashbay, Iffutilsday, Ilefay, Indutilsfay, Awkgay, Epgray, Ipgzay, Akemay, Atchpay, Edsay, Artay, Xzay — eachway ithway itsway ownway andfulhay ofway onfigurecay agsflay andway Fhsay ixfay-upsway. Ethay ookbay'say apterchay 6 isway away ecklistchay; ethay illskay eingbay aughttay isway ethay itualray itselfway — ybay ackagepay entay youway ancay earlynay itewray ethay onfigurecay inelay yourselfway.
Ethay ootchray — ethay ivotpay
Ithway ethay emporarytay ystemsay installedway, $Lfsay ownay ontainscay away elfsay-ufficientsay Inuxlay userspaceway: itsway ownway ashbay, itsway ownway oreutilscay, itsway ownway akemay, itsway ownway gccay. Enterway itway:
# as ROOT — back to root for the pivot
chroot "$LFS" /usr/bin/env -i \
HOME=/root TERM="$TERM" \
PS1='(lfs chroot) \u:\w\$ ' \
PATH=/usr/bin:/usr/sbin \
MAKEFLAGS="-j$(nproc)" \
TESTSUITEFLAGS="-j$(nproc)" \
/usr/bin/bash --login
Everythingway atthay ollowsfay unsray insideway. Ethay omptpray eadsray (lfsay ootchray) — ethay ilesystemfay ootray isway ethay artitionpay. $Lfsay onay ongerlay existsway asway away athpay; itway'say ownay /. Ethay /oolstay ymlinksay icktray ayspay offway erehay: inariesbay ompiledcay otay ooklay inway /oolstay/... indfay exactlyway ethay irectoryday eythay ereway uiltbay orfay.
Utbay irstfay — ethay irtualvay ilesystemsfay
Away ootedchray userspaceway eedsnay ethay ernelkay'say irtualvay ilesystemsfay orway othingnay orksway — /ocpray, /yssay, /evday areway ernelkay interfacesway, otnay ealray irectoriesday. Eforebay ootingchray (orway ethay ookbay'say equivalentway orderingway), eythay ustmay ebay indbay-ountedmay intoway $Lfsay omfray ethay osthay:
# as root — populate the device tree
mkdir -pv $LFS/{dev,proc,sys,run}
mount -v --bind /dev $LFS/dev
mount -v --bind /dev/pts $LFS/dev/pts
mount -vt proc proc $LFS/proc
mount -vt sysfs sysfs $LFS/sys
mount -vt tmpfs tmpfs $LFS/run
# shm + pts for modern packages
if [ -h $LFS/dev/shm ]; then mkdir -pv $LFS/$(readlink $LFS/dev/shm);
else mount -t tmpfs -o nosuid,nodev tmpfs $LFS/dev/shm; fi
Isthay isway ethay epstay eoplepay ipskay andway enthay onderway ywhay onfigurecay ancay'tay etectday ethay ystemsay. Insideway ethay ootchray erethay isway onay /evday/ullnay unlessway youway oundbay itway — estsuitestay, ellsshay, everythingway eedsnay itway. Ethay ountsmay areway indbay ountsmay — ethay osthay'say ernelkay interfacesway owingshay oughthray intoway ethay ootchray — osay ethay emptay ystemsay ancay interrogateway ethay ealray ardwarehay itway'say uildingbay orfay.
Ethay asspay-2 onfigurecay ammargray — ethay eepday eadray
# binutils pass 2 — built for the new system, installed INTO it:
../configure --prefix=/usr \
--build=$(../config.guess) \
--host=$LFS_TGT \
--disable-nls \
--enable-shared \
--enable-gprofng=no \
--disable-werror \
--enable-64-bit-bfd \
--enable-new-dtags \
--enable-default-hash-style=gnu
make && make DESTDIR=$LFS install
rm -v $LFS/usr/lib/lib{bfd,ctf,ctf-nobfd,gprofng,opcodes,sframe}.{a,la}
--osthay=$Lfsay_Tgtay isway ethay angechay — asspay 2 unsray onway ethay ewnay ystemsay; --enableway-aredshay eturnsray (ownay erethay'say away ibclay); --enableway-64-itbay-bfday ivesgay ethay ullfay 64-itbay objectway ormatfay. Ethay .away/.alay emovalray earsclay ethay aticstay+ibtoollay archivesway — ethay ewnay ystemsay usesway aredshay ibslay.
gccay asspay 2 — ethay amesay apeshay: --osthay=$Lfsay_Tgtay, ESTDIRday=$Lfsay, allway anguageslay enabledway, eadsthray onway, ibstdclay++ ealray — usplay lnay -svfay gccay $Lfsay/usrway/inbay/ccay, ethay ccay onventioncay everyway ackagepay expectsway.
Ownershipway andoverhay
Eforebay ootingchray ethay ookbay angeschay ownershipway ofway ethay entireway $Lfsay eetray omfray lfsay otay ootray — insideway ethay ootchray, ootray isway ethay uilderbay:
chown --from lfs -R root:root $LFS/{usr,lib,var,etc,bin,sbin,tools}
case $(uname -m) in
x86_64) chown --from lfs -R root:root $LFS/lib64 ;;
esac
Ethay lfsay userway'say objay endsway erehay; ethay estray uildsbay asway ootchray-ootray. (Andway aterlay, ethay inishedfay ystemsay'say ilesfay etgay ormalizednay otay eirthay ealray ownersway.)
Ethay emptay oolstay — ethay ullfay osterray andway ywhay eachway
Ethay ~15 ackagespay atthay onstitutecay ethay emptay ystemsay, andway eirthay obsjay:
| Ackagepay | Ethay objay insideway ethay ootchray |
|---|---|
| May4 | Acromay ocessorpray — autoconfway'say engineway |
| Ursesncay | Erminaltay ibrarylay + erminfotay atabaseday |
| Ashbay | Ethay ellshay everythingway'say ittenwray orfay |
| Oreutilscay | lsay/cpay/mvay/ortsay/etcway — ethay ocabularyvay |
| Iffutilsday | iffday — atchpay'say artnerpay |
| Ilefay | agicmay-ytebay identificationway |
| Indutilsfay | indfay/argsxay |
| Awkgay | Ethay awkway anguagelay |
| Epgray | Atternpay atchingmay |
| Ipgzay | Ompressioncay — everyway arballtay |
| Akemay | Ethay uildbay iverdray |
| Atchpay | Appliesway ethay ookbay'say iffsday |
| Edsay | Eamstray editingway |
| Artay | Unpackingway everythingway |
| Xzay | Ethay odernmay ompressorcay |
| Inutilsbay asspay 2 | Ethay ealray inkerlay/assemblerway |
| Gccay asspay 2 | Ethay ealray ompilercay + ibstdclay++ |
Eachway isway ethay amesay osscray-onfigurecay anceday — --osthay=$Lfsay_Tgtay, akemay, ESTDIRday=$Lfsay installway — andway everalsay arrycay Fhsay ixfay-upsway (inariesbay ovedmay etweenbay /usrway/inbay//usrway/insbay//inbay orfay ayoutlay ompliancecay). Ybay ethay enthtay youway ancay earlynay itewray ethay onfigurecay inelay yourselfway — atthay'say ethay ointpay.
Ethay ootchray environmentway — ethay eepday eadray
chroot "$LFS" /usr/bin/env -i \
HOME=/root TERM="$TERM" \
PS1='(lfs chroot) \u:\w\$ ' \
PATH=/usr/bin:/usr/sbin \
MAKEFLAGS="-j$(nproc)" \
TESTSUITEFLAGS="-j$(nproc)" \
/usr/bin/bash --login
Everyway iecepay earnsway itsway eepkay: envway -iway ipesway ethay osthay'say environmentway — onay eakedlay ariablesvay insideway; OMEhay=/ootray etssay ethay ootchray'say omehay; Psay1 arksmay ethay omptpray (lfsay ootchray) osay youway owknay erewhay youway areway; ATHpay esetsray otay ethay ewnay ystemsay'say athspay (onay /oolstay — ethay emptay oolstay areway usedway implicitlyway); --oginlay ivesgay away ullfay oginlay ellshay. Ethay ESTSUITEFLAGStay arallelizespay ethay ackagepay eststay.
Ethay eray-entryway itualray — eavinglay andway omingcay ackbay
Youway'llay exitway ethay ootchray (ebootray, eepslay, ixfay ethay osthay) andway ustmay eray-enterway — ethay itualray:
# after any reboot — re-mount + re-bind + re-chroot
mount /dev/sda3 $LFS
mount --bind /dev $LFS/dev && mount --bind /dev/pts $LFS/dev/pts
mount -t proc proc $LFS/proc && mount -t sysfs sys $LFS/sys
mount -t tmpfs tmpfs $LFS/run
[ -h $LFS/dev/shm ] && mkdir -pv $LFS/$(readlink $LFS/dev/shm)
chroot "$LFS" /usr/bin/env -i HOME=/root TERM="$TERM" \
PS1='(lfs chroot) \u:\w\$ ' PATH=/usr/bin:/usr/sbin \
/usr/bin/bash --login
Itewray itway asway enterway-lfsay.shay — youway'llay unray itway anymay imestay. Ethay uildbay ansspay ebootsray; ethay ootchray oorday orksway othbay irectionsday.
Ethay irectoryday eletonskay
Insideway ethay ootchray, ethay Fhsay eletonskay isway aidlay eforebay ackagespay:
mkdir -pv /{boot,home,mnt,opt,srv}
mkdir -pv /etc/{opt,sysconfig}
mkdir -pv /lib/firmware
mkdir -pv /media/{floppy,cdrom}
mkdir -pv /usr/{,local/}{include,src}
mkdir -pv /usr/lib/locale
mkdir -pv /usr/local/{bin,lib,sbin}
mkdir -pv /usr/{,local/}share/{color,dict,doc,info,locale,man}
mkdir -pv /usr/{,local/}share/{misc,terminfo,zoneinfo}
mkdir -pv /usr/{,local/}share/man/man{1..8}
mkdir -pv /var/{cache,local,log,mail,opt,spool}
mkdir -pv /var/lib/{color,misc,locate}
ln -sfv /run /var/run && ln -sfv /run/lock /var/lock
install -dv -m 0750 /root
install -dv -m 1777 /tmp /var/tmp
Enthay ethay essentialway irstfay ilesfay — /etcway/ostshay, /etcway/asswdpay andway /etcway/oupgray (ethay emporarytay ersionsvay), usplay ethay oglay ilesfay ogramspray expectway:
echo "127.0.0.1 localhost $(hostname)" > /etc/hosts
cat > /etc/passwd << "EOF"
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/dev/null:/usr/bin/false
daemon:x:6:6:Daemon User:/dev/null:/usr/bin/false
messagebus:x:18:18:D-Bus Message Daemon User:/run/dbus:/usr/bin/false
uuidd:x:80:80:UUID Generation Daemon User:/dev/null:/usr/bin/false
nobody:x:65534:65534:Unprivileged User:/dev/null:/usr/bin/false
EOF
# /etc/group: root, bin, daemon, sys, kmem, tape, tty, daemon again...
# SYSTEMD EDITION: the systemd book's passwd/group add NINE entries —
# systemd-journal-gateway :73, -journal-remote :74, -journal-upload :75,
# systemd-network :76, -resolve :77, -timesync :78, -coredump :79,
# systemd-oom :81 (uuidd stays :80), plus group systemd-journal :23.
# Write them now or networkd/resolved/timesyncd fail at first boot.
**Why the nine extra users are load-bearing**: LFS builds systemd with `-D sysusers=false` — there is no runtime user-creation service, so every `User=` in the shipped unit files must resolve against this static passwd. This failure was observed live on ALB Linux: a SysVinit-edition passwd survived into a systemd build, and `systemd-networkd`, `systemd-resolved`, `systemd-timesyncd` all failed at first boot ("Failed to start Network Configuration / Name Resolution / Time Synchronization") with a `systemd-networkd-persistent-storage` dependency cascade. The unit files were fine — the *users* didn't exist. Restoring the book's systemd-edition files plus `pwconv`/`grpconv` fixed all three at once.
touch /var/log/{btmp,lastlog,faillog,wtmp}
chgrp -v utmp /var/log/lastlog
chmod -v 664 /var/log/lastlog
chmod -v 600 /var/log/btmp
Erewhay isthay apterchay oesgay ongwray
| Ymptomsay | Ausecay |
|---|---|
Insideway ootchray: onay uchsay ilefay orfay asicbay oolstay | Irtualvay ilesystemsfay otnay indbay-ountedmay — /evday emptyway |
onfigurecay ancay'tay etectday ethay ystemsay | /ocpray, /yssay otnay ountedmay insideway |
| Estsuitestay allway ailfay | /evday/ullnay, /evday/ptsay issingmay |
| Ilesfay ownedway ybay obodynay/eirdway UIDsway | Ownershipway andoverhay ippedskay |
ccay: ommandcay otnay oundfay insideway | Ethay ccay→gccay ymlinksay ippedskay inway gccay asspay 2 |
| ootchray omplainscay "ailedfay otay unray ommandcay" | /usrway/inbay/envway athpay ongwray inway ethay ootchray ommandcay, orway ashbay otnay installedway |
| Osthay inariesbay eakinglay inway | ATHpay otnay esetray inway ethay envway -iway ootchray inelay |
Away iptscray'say <(...)/ocesspray ubstitutionsay yieldsway othingnay | /evday/fday oesnday'tay existway ithoutway /ocpray ountedmay — easuredmay: away onfigcay-editway ooplay oggedlay "isabledday 138 optionsway" ilewhay ouchingtay erozay. Ixfay: ountmay /ocpray irstfay, orway lnay -say /ocpray/elfsay/fday /evday/fday, orway ewriteray ethay iptscray emptay-ilefay-asedbay |
artay -tfay xay.artay.xzay | eadhay -1 andomlyray illskay ethay iptscray | eadhay exitsway earlyway → IGPIPEsay → etsay -oway ipefailpay urnstay itway atalfay. Ufferbay ethay istinglay (apfilemay/eadarrayray) orway edsay -nay '1pay' intoway away ariablevay |
Exercisesway
- Explainway ywhay
/evdayustmay ebay away indbay ountmay atherray anthayirmkday. - Omfray insideway ethay ootchray, ovepray youway'eray isolatedway: omparecay
atcay /etcway/ostnamehay,lsay /omehay,dfayagainstway ethay osthay'say. - Indfay eethray ackagespay inway ethay emptay etsay ithway Fhsay ixfay-upsway; explainway oneway.
- Exitway ethay ootchray, eray-enterway itway — itewray ethay ullfay ountmay+ootchray iptscray omfray emorymay.
- Eakbray
ATHpayinsideway ootchray andway observeway ichwhay "ommandscay" illstay orkway (uiltinsbay vsay inariesbay).
Imelinetay
| Epstay | Esultray |
|---|---|
| inutilsbay/gccay asspay 2 | Ethay ealray oolchaintay, Lfsay-inkedlay |
| ~15 emptay ackagespay | Oreutilscay, ashbay, akemay… installedway otay $Lfsay |
| Irtualvay Fsay indsbay | /evday /ocpray /yssay /unray isiblevay insideway |
| Ownershipway andoverhay | lfsay → ootray |
| ootchray | $Lfsay ecomesbay / — youway'eray insideway |
| Eletonskay | Fhsay irsday, asswdpay/oupgray, oglay ilesfay |
| extnay | Lfsay IIIway — ethay ealray ystemsay ackagespay |
Eferencesray
- inuxfromscratchlay.orgway — apterschay 6–7: osscray-ompilingcay emporarytay oolstay; enteringway ootchray
- Ostedhay irrormay: /istday/ooksbay/ — ethay officialway Lfsay ookbay irroredmay onway isthay itesay (vay10.0–13.1, YsVsay + ystemdsay editionsway; Ccay Ybay-Ncay-Asay 2.0 / ITmay, ostedhay erbatimvay ithway attributionway)
ootchray(2),ountmay --indbay— ethay ernelkay echanismsmay- Ilesystemfay Ierarchyhay Andardstay — ethay eletonskay eingbay aidlay