How to Build a Linux RootFS for Embedded Devices – Step‑by‑Step Guide
This article walks through the theory of Linux file systems, compares flash‑specific filesystems, outlines the essential rootfs directories, details required tools like a cross‑compiler and TFTP/NFS servers, and provides a complete step‑by‑step procedure—including BusyBox compilation, rootfs population, init scripts, and ramdisk creation—to produce a bootable root filesystem for an embedded board.
1. File System Overview
In theory, an embedded device that can run the kernel without user processes does not need a file system, but Linux treats devices as files, so a directory structure (the file system) is required to expose kernel interfaces and provide user control.
The root file system is the first filesystem mounted by the kernel and must contain all directories and files needed for boot, such as /init, /etc/fstab, and essential binaries.
Linux supports many filesystems (ext2, ext3, vfat, ntfs, iso9660, jffs, yaffs, romfs, nfs, etc.) and abstracts them through the Virtual File System (VFS) layer.
2. Flash‑Based Filesystems
Cramfs : read‑only, fast, reliable, but cannot be expanded.
Jffs2 : journalling flash FS, read/write, supports compression, but performance degrades when near full due to garbage collection.
Yaffs/Yaffs2 : designed for NAND flash, faster than Jffs2, smaller memory footprint, supports both small‑page (512 B) and large‑page (2 KB) NAND.
NFS : network file system useful during development to mount a rootfs from a host.
3. RootFS Composition
bin – essential executables
opt – optional packages
boot – bootloader files
proc – virtual process info
dev – device nodes
root – root user home
etc – configuration files
sbin – system binaries
home – user homes
tmp – temporary files
lib – shared libraries
usr – user applications
mnt – mount points
var – logs and variable data
4. Default Prerequisites
Cross‑compilation toolchain (e.g., arm-none-linux-gnueabi-gcc) must be installed, typically under /home/peng/toolchain/gcc-4.6.4.
TFTP server configuration (directory /tftpboot) for transferring kernel images.
NFS server configuration via /etc/exports to export /source/rootfs to the target board.
5. RootFS Creation Steps
Download BusyBox source (e.g., busybox-1.22.1.tar.bz2) from http://busybox.net/downloads/.
Extract the archive: $ tar xvf busybox-1.22.1.tar.bz2 Enter the source directory: $ cd busybox-1.22.1 Configure BusyBox to build a static binary and set the cross‑compiler prefix arm-none-linux-gnueabi- using make menuconfig (enable Build BusyBox as a static binary).
Compile: $ make Install into _install directory:
$ make install6. Populate the RootFS
Create required top‑level directories: $ mkdir dev etc mnt proc var tmp sys root Copy libraries from the toolchain into _install/lib and strip symbols:
$ chmod +w lib
$ rm lib/*.a
$ arm-none-linux-gnueabi-strip lib/*Ensure total library size < 8 MiB (use du -mh lib/).
Add essential system files: /etc/inittab (example content shown in the article). /etc/fstab mounting proc, tmpfs, and dev. /etc/profile setting environment variables and prompt.
Create device node /dev/console with mknod dev/console c 5 1.
Make rcS script executable and place it under /etc/init.d to mount filesystems and start mdev.
7. Testing
Replace the old /source/rootfs with the newly built one, set appropriate U‑Boot environment variables (e.g., bootcmd, bootargs), and reboot the board to verify NFS mounting and functionality.
8. Create a Ramdisk
Create an 8 MiB empty file: $ dd if=/dev/zero of=ramdisk bs=1k count=8192 Format it as ext2: $ mkfs.ext2 -F ramdisk Mount it at /mnt/initrd and copy the tested rootfs contents into it.
Unmount, compress with gzip, and convert to a U‑Boot image:
$ gzip --best -c ramdisk > ramdisk.gz
$ mkimage -n "ramdisk" -A arm -O linux -T ramdisk -C gzip -d ramdisk.gz ramdisk.img
$ cp ramdisk.img /tftpboot9. Kernel Support for Ramdisk
Enable the following kernel options via make menuconfig:
* Second extended fs support * RAM block device support (default 16 disks, 8192 kB size – change to 8 MiB) * Initial RAM filesystem (initramfs/initrd) supportRecompile the kernel and copy the image to /tftpboot.
10. U‑Boot Boot Commands
Set the boot command to load the kernel, device tree, and ramdisk, then boot:
# setenv bootcmd tftp 41000000 uImage; tftp 42000000 exynos4412-fs4412.dtb; tftp 43000000 ramdisk.img; bootm 41000000 43000000 42000000
# saveenvFinally, reboot the board and verify that it boots from the newly created rootfs and ramdisk.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
