
Here’s a step-by-step guide to help you build a minimal, fast-booting Linux system that meets your specified key requirements. This guide assumes you’re targeting an ARM SoC (like Allwinner) with Lima GPU and aiming for custom kernel and userspace.
βοΈ Step 1: Set Up the Build Environment
Install required packages on your host Linux (Ubuntu/Debian-based):
sudo apt update && sudo apt install -y \
build-essential gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf \
u-boot-tools debootstrap qemu-user-static \
libncurses-dev bc bison flex libssl-dev
𧱠Step 2: Download and Prepare Kernel Source
git clone https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
cd linux
- Checkout the latest LTS kernel version supported by Lima.
- Apply board/device-specific patches if needed.
π§ Step 3: Configure and Strip the Kernel
Start configuration:
make ARCH=arm menuconfig
Minimal Kernel Config Options:
- β
Enable DRM/KMS & Lima (
CONFIG_DRM
,CONFIG_DRM_LIMA
) - β
Enable HDMI and audio (
CONFIG_SND_SOC
,CONFIG_HDMI
) - β
Enable Input Devices: Keyboard, Mouse, Gamepad (
CONFIG_INPUT_KEYBOARD
,CONFIG_INPUT_MOUSE
,CONFIG_INPUT_JOYSTICK
) - β Filesystems: Only enable needed ones like ext4 or squashfs
- β Disable: WiFi, Bluetooth, IPv6, VPN, Debugging, ACLs, Hibernation, Virtualization, etc.
- β
Enable static binary support if needed (
CONFIG_STATIC_LINK
) - β
Disable kernel debugging (
CONFIG_DEBUG_KERNEL=n
)
Then compile:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage dtbs -j$(nproc)
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- modules
π§° Step 4: Build Minimal Root Filesystem
Use debootstrap
or buildroot
:
Option 1: debootstrap
sudo debootstrap --arch=armhf --foreign stable ./rootfs http://deb.debian.org/debian
sudo cp /usr/bin/qemu-arm-static ./rootfs/usr/bin/
sudo chroot ./rootfs /debootstrap/debootstrap --second-stage
Strip unnecessary packages:
chroot ./rootfs
apt remove --purge -y systemd network-manager wpasupplicant \
isc-dhcp* avahi-daemon openssh-server \
&& apt autoremove -y && apt clean
exit
Option 2: buildroot (recommended for static and minimal)
git clone https://github.com/buildroot/buildroot.git
cd buildroot
make menuconfig
Enable:
- Toolchain: external or internal static toolchain
- Target packages: GCC (build essentials), SDL2, minimal init
- Remove all networking and debugging services
𧱠Step 5: Static Build of SDL2 and User Binaries
Compile SDL2 statically:
./configure --enable-static --disable-shared
make && make install
Cross-compile your own app statically:
arm-linux-gnueabihf-gcc -static -o myapp myapp.c `sdl2-config --cflags --libs`
π Step 6: Optimize Boot Time
- Use
init=/sbin/init
(simple custom init or busybox). - Remove all unnecessary services.
- Use squashfs or initramfs.
- Use U-Boot for fast boot and directly launch kernel.
- Optionally use
systemd-analyze blame
(if using systemd) or bootchart to find slow areas.
πΎ Step 7: Assemble Image
Use your preferred method to combine:
zImage
dtb
- RootFS (as ext4, squashfs, or initramfs)
Example for SD card:
dd if=u-boot-sunxi-with-spl.bin of=/dev/sdX bs=1024 seek=8
Copy kernel and rootfs to partitions.
β Step 8: Test on Hardware
Boot on target device via SD card or eMMC. Confirm:
- HDMI output
- Input devices working
- Your SDL2 app launches
- Fast boot time (target < 5 seconds)
π Summary
Component | Optimized For |
---|---|
Kernel | Minimal, GPU, HDMI |
Init System | Static / BusyBox |
RootFS | Custom, stripped |
Build Method | Cross-compiled |
SDL2 & App | Statically linked |
Boot Time | Under 5 seconds |