Build a Minimal Linux System with SDL2, HDMI, and Input Support (Fast Boot)

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

ComponentOptimized For
KernelMinimal, GPU, HDMI
Init SystemStatic / BusyBox
RootFSCustom, stripped
Build MethodCross-compiled
SDL2 & AppStatically linked
Boot TimeUnder 5 seconds

About Anant 446 Articles
Senior technical writer