Linux From Scratch
8 chapters
1. Linux From Scratch: Building Your First Minimal System
[Verse 1]
Started with a host system running strong and true
Downloaded all the sources that we're gonna need to use
Seven point four guidebook in our steady hands
Time to build from nothing with a detailed plan
[Chorus]
Linux From Scratch, we're building from the ground
Bootstrap then chroot, that's how systems are found
Toolchain first, then the base, compile it all with care
LFS methodology, freedom everywhere
Bootstrap, chroot, compile, repeat
LFS makes your system complete
[Verse 2]
Chapter five begins the temporary toolchain phase
Cross-compile the binutils in their proper place
GCC comes next with its first pass complete
Building tools to build the tools, the cycle's neat
[Chorus]
Linux From Scratch, we're building from the ground
Bootstrap then chroot, that's how systems are found
Toolchain first, then the base, compile it all with care
LFS methodology, freedom everywhere
Bootstrap, chroot, compile, repeat
LFS makes your system complete
[Verse 3]
Glibc library provides the system calls we need
Then the second GCC pass, letting progress feed
Change root into our new environment so clean
Isolated from the host, a building machine
[Bridge]
Configure, make, make install
Every package standing tall
From the kernel to the shell
Each component built so well
[Verse 4]
Chapter eight brings the final system into view
Kernel compilation with the config that you knew
Bootloader installation, GRUB or what you choose
First boot up and running, you just cannot lose
[Chorus]
Linux From Scratch, we're building from the ground
Bootstrap then chroot, that's how systems are found
Toolchain first, then the base, compile it all with care
LFS methodology, freedom everywhere
Bootstrap, chroot, compile, repeat
LFS makes your system complete
[Outro]
From source code to system
Every byte you can trust
LFS teaches you the way
From the ground up, robust
2. Cross-Compilation Fundamentals
[Verse 1]
When you build for distant machines
Your laptop is the host it seems
But target architecture waits
Across the silicon divides
ARM chips dream while x86 compiles
Different instruction sets collide
Host builds tools, target runs code
Two worlds walking separate roads
[Chorus]
Cross compile, cross compile
Host to target, mile by mile
Toolchain bridge across the gap
ARM, MIPS, or x86 map
Different endian, different word
Make your binary understood
Cross compile, cross compile
Architecture reconciled
[Verse 2]
GCC prefix tells the tale
arm-linux-gnueabihf won't fail
Triple format speaks the truth
Architecture, vendor, system proof
Sysroot holds the target libs
Headers living where code fibs
Without them linking falls apart
Cross compilation breaks your heart
[Chorus]
Cross compile, cross compile
Host to target, mile by mile
Toolchain bridge across the gap
ARM, MIPS, or x86 map
Different endian, different word
Make your binary understood
Cross compile, cross compile
Architecture reconciled
[Bridge]
Environment variables aligned
CC and CXX redefined
Configure scripts need guidance too
Host equals build but target's new
PKG_CONFIG_PATH must redirect
Or dependencies you'll neglect
[Verse 3]
Common pitfalls block your way
Header paths will lead astray
Host libraries creeping in
Make your target build rescind
Test early, test it small
Before complexity enthralls
Qemu helps you validate
Before hardware seals your fate
[Chorus]
Cross compile, cross compile
Host to target, mile by mile
Toolchain bridge across the gap
ARM, MIPS, or x86 map
Different endian, different word
Make your binary understood
Cross compile, cross compile
Architecture reconciled
[Outro]
From development to deploy
Cross compilation we employ
Host and target hand in hand
Building for the promised land
3. Kernel Configuration Deep Dive
[Verse 1]
Time to dive deep in the kernel's core
Menuconfig opens up the door
Navigate the tree with arrow keys
Select the drivers that you need with ease
Every hardware needs its perfect match
Configure options, make them catch
From processors down to USB ports
Build the system that your board supports
[Chorus]
Menu config, navigate and select
Drivers, subsystems, interconnect
Size matters when you optimize
For your target, make it shine
Y for built-in, M for module
N to skip what you don't need at all
Configure, compile, deploy with care
Kernel tailored for the hardware there
[Verse 2]
Start with architecture, set your base
Then dive into device drivers' space
Network cards and storage controllers
Graphics, sound, and input handlers
Subsystems like file systems too
Choose ext4, btrfs, what suits you
Each selection adds to final size
Balance features with resource ties
[Chorus]
Menu config, navigate and select
Drivers, subsystems, interconnect
Size matters when you optimize
For your target, make it shine
Y for built-in, M for module
N to skip what you don't need at all
Configure, compile, deploy with care
Kernel tailored for the hardware there
[Bridge]
Embedded systems need it lean
Strip away what won't be seen
Server builds can handle more
But still configure what's in store
Use help text when you're unsure
Dependencies will guide you for sure
Save your config, make it clean
The most efficient kernel you've seen
[Verse 3]
Power management, security features
Debugging tools and system teachers
Real-time patches for timing critical
Multi-core support, asymmetrical
Every option has a cost in space
Memory footprint, loading pace
Profile your target, know its needs
Then configure for successful deeds
[Chorus]
Menu config, navigate and select
Drivers, subsystems, interconnect
Size matters when you optimize
For your target, make it shine
Y for built-in, M for module
N to skip what you don't need at all
Configure, compile, deploy with care
Kernel tailored for the hardware there
[Outro]
From menuconfig to final boot
Your custom kernel's absolute
Hardware specific, optimized and tight
Full-stack engineering done right
4. Init Systems and Boot Process
[Verse 1]
When the kernel finishes loading all its code
Process number one takes control of the road
Three systems waiting to answer the call
SysV, systemd, BusyBox standing tall
Scripts and services need someone to start
Init system becomes the beating heart
[Chorus]
Boot it up, hand it off, kernel to user space
SysV scripts, systemd units, BusyBox saves space
Run levels, targets, dependencies in line
Init systems make everything align
From hardware to software, the handoff is clean
The best orchestrated startup you've ever seen
[Verse 2]
SysV init with its numbered run levels
Zero through six, each state it develops
Shell scripts in order, S for start
K for kill when systems depart
Sequential loading, one by one
Traditional method since Unix begun
[Chorus]
Boot it up, hand it off, kernel to user space
SysV scripts, systemd units, BusyBox saves space
Run levels, targets, dependencies in line
Init systems make everything align
From hardware to software, the handoff is clean
The best orchestrated startup you've ever seen
[Verse 3]
Systemd brings units and parallel might
Services and sockets starting up right
Targets replace the old run level way
Dependencies managed throughout the day
Journal logging and D-Bus control
Modern approach with a unified goal
[Bridge]
BusyBox init keeps it simple and small
Embedded systems don't need it all
Lightweight footprint, minimal code
Perfect for when you're space constrained mode
[Verse 4]
Kernel mounts root, then exec's PID one
Hardware detection is finally done
User space services begin their dance
Network and storage get their chance
From bootloader to login prompt bright
Init systems make everything right
[Chorus]
Boot it up, hand it off, kernel to user space
SysV scripts, systemd units, BusyBox saves space
Run levels, targets, dependencies in line
Init systems make everything align
From hardware to software, the handoff is clean
The best orchestrated startup you've ever seen
[Outro]
Three different paths but the goal's the same
Bringing your system up to play the game
Init one takes the kernel's final call
And brings user space services to all
5. Device Trees: Hardware Description Language
[Verse 1]
When the kernel boots up on your ARM machine
It needs to know what hardware it can see
No more hardcoded addresses in the code
Device trees show the way, the proper road
A text file describes your system's parts
Memory maps and interrupts, where everything starts
[Chorus]
Device tree source, D-T-S file
Describes the hardware with structured style
Nodes and properties, parent and child
Compatible strings make drivers bind
Device tree source, hardware's guide
Kernel discovery simplified
[Verse 2]
Start with the root node, slash is the name
Memory and chosen nodes stake their claim
CPU information, cores and cache
Clock frequencies, timing in place
Each device gets a node with address
Properties define how drivers access
[Chorus]
Device tree source, D-T-S file
Describes the hardware with structured style
Nodes and properties, parent and child
Compatible strings make drivers bind
Device tree source, hardware's guide
Kernel discovery simplified
[Bridge]
Compile with D-T-C, device tree compiler
Binary blob for bootloader supplier
U-Boot passes it to the kernel space
Platform device creation takes place
No more board files, configuration clean
Generic kernels, hardware unseen
[Verse 3]
GPIO controllers, SPI and I-two-C
UART and timers, all defined precisely
Interrupt numbers, register ranges
When hardware changes, just the tree changes
Pinmux settings, power domains too
Device tree tells the kernel what to do
[Chorus]
Device tree source, D-T-S file
Describes the hardware with structured style
Nodes and properties, parent and child
Compatible strings make drivers bind
Device tree source, hardware's guide
Kernel discovery simplified
[Outro]
From source to binary, hardware described
Driver binding automated, perfectly timed
Device tree magic, ARM's modern way
Full-stack engineers use it every day
6. Writing Your First Kernel Module
[Verse 1]
Deep beneath the applications that we see each day
Lives a kernel space so different from the user's way
No malloc here, no printf calls to help you debug
Just kernel memory and printk when your code gets stuck
[Chorus]
Init and exit, that's the way
Module load and cleanup, every day
Register your driver, claim your space
Kernel module dancing in the system's embrace
From user land to kernel land
Understanding where you stand
[Verse 2]
Start with hashtag include, bring the headers that you need
Linux slash module dot h, that's the kernel's creed
Module underscore init marks your entry function clear
Module underscore exit when it's time to disappear
[Chorus]
Init and exit, that's the way
Module load and cleanup, every day
Register your driver, claim your space
Kernel module dancing in the system's embrace
From user land to kernel land
Understanding where you stand
[Verse 3]
No floating point allowed, interrupts can steal your time
GFP underscore KERNEL when you need memory sublime
Return zero for success, negative for error state
Static functions keep it clean, don't pollute the kernel's gate
[Bridge]
Makefile magic, obj dash m
Point to kernel build and then
Make will compile your C code
Insert mod to load your node
[Chorus]
Init and exit, that's the way
Module load and cleanup, every day
Register your driver, claim your space
Kernel module dancing in the system's embrace
From user land to kernel land
Understanding where you stand
[Verse 4]
Register your device node, claim your major number slot
Character or block device, choose the type that fits your plot
File operations structure holds your read and write and more
Open, close, and ioctl knocking at your driver's door
[Outro]
Hello kernel, goodbye user space
Welcome to the driver's place
Module loaded, system knows
That's how kernel programming goes
7. Character and Block Device Drivers
[Verse 1]
In the kernel space where drivers live and breathe
Character devices stream data byte by byte
No buffering here, just raw sequential read
Open close read write, the ops we must provide
File operations structure holds our function calls
Each pointer maps to code that serves it all
[Chorus]
Char by char, block by block
Device drivers are the bridge we rock
Read and write and seek and poll
IO control takes full control
Char by char, block by block
Making hardware and software talk
[Verse 2]
Register your device with major minor pairs
Dynamic allocation or static if you dare
Character device add, then make the device node
User space can access through the file system road
Copy to user, copy from user space
Kernel boundaries we must never misplace
[Chorus]
Char by char, block by block
Device drivers are the bridge we rock
Read and write and seek and poll
IO control takes full control
Char by char, block by block
Making hardware and software talk
[Verse 3]
Block devices work in sectors not in streams
Request queues and elevator algorithms dream
Bio structures carry data through the stack
Make request function handles front and back
Buffering and caching, performance is the key
Block layer abstractions set the hardware free
[Bridge]
Interrupts and DMA, async operations flow
Bottom half processing when the top half lets it go
Memory mapped IO or port based access
Synchronization locks prevent the racing mess
[Chorus]
Char by char, block by block
Device drivers are the bridge we rock
Read and write and seek and poll
IO control takes full control
Char by char, block by block
Making hardware and software talk
[Outro]
From the application down to silicon
Device drivers make the magic run
Character streams and block arrays
Bridging worlds in countless ways
8. Interrupt Handling and Hardware Interfaces
[Verse 1]
When the hardware needs attention from the CPU
It sends a signal through the interrupt queue
The processor stops what it's currently running
To handle the event that's just begun
A handler function waits to be called
Registered early when the system's installed
The kernel keeps a table of addresses neat
Where each interrupt has its own seat
[Chorus]
Register handlers, map the memory
Hardware talking directly to me
IRQ numbers in the vector table
Make the system fast and stable
Memory mapped I-O in view
Hardware interface breaking through
[Verse 2]
Memory-mapped means hardware looks like RAM
Same address space, same reading plan
No special instructions to reach the device
Just load and store, simple and nice
The kernel module claims its hardware space
Ioremap gives it a virtual place
Physical addresses get translated clean
To virtual ones the kernel's seen
[Chorus]
Register handlers, map the memory
Hardware talking directly to me
IRQ numbers in the vector table
Make the system fast and stable
Memory mapped I-O in view
Hardware interface breaking through
[Bridge]
Request IRQ with flags and name
Free it up when you're done with the game
Shared interrupts need careful thought
Check your device or handle naught
Volatile pointers for hardware reads
The compiler knows when memory feeds
Could change at any moment's time
Without the code that's in your line
[Verse 3]
Direct hardware from kernel space means power
Control the chips in their finest hour
But with great access comes responsibility
Handle errors with capability
Disable interrupts when sections are critical
Atomic operations keep data identical
The hardware waits while you're in control
Then interrupts resume their vital role
[Chorus]
Register handlers, map the memory
Hardware talking directly to me
IRQ numbers in the vector table
Make the system fast and stable
Memory mapped I-O in view
Hardware interface breaking through
[Outro]
From silicon to software's embrace
Interrupts bridge the hardware space
Handlers registered, memory mapped tight
Full-stack systems burning bright
Back to Home