world leader in high performance signal processing
Trace: » rootfs

Root Filesystems

There are many types of root file systems which a Linux kernel can mount and boot. Which is the “best” one depends on your needs and your system - do you require persistent storage? What type of flash (NAND, NOR, serial Flash, USB)? Do you have spinning media (disk, CD, DVD)? It is likely the defaults which we have picked are not the right choice for your system.

Before getting into some of the specific details about each implementation - here are some generic description of the Linux filesystem, which is necessary to understand the pros and cons of other file systems.

Since many filesystems are on slower media, Linux uses a disk caching mechanisms (the page cache and dentry cache) to speed things up. Pages of data read from backing storage device are kept around in case it's needed again, but marked as clean (freeable) in case the memory system needs the memory for something else. Similarly, data written to files is marked clean as soon as it has been written to backing store, but kept around for caching purposes until the system is low on memory. A similar mechanism (the dentry cache) greatly speeds up access to directories. On devices which are backed by persistent storage (disk, flash, etc), this means shutdowns, reboots, power cycles, etc. must be managed to make sure these caches which are marked as dirty are flushed to the backing storage device before the information is lost.

Types

ramfs

With ramfs, there is no backing storage device. Files written into ramfs allocate dentries and page cache as usual, but there's nowhere to write them to. This means the pages are never marked clean, so they can't be freed by the memory subsystem when it's looking to free memory. It also means that ramfs is not persistent, and can grow and grow until all the ram has been consumed.

Another upside is that since everything is maintained in the page cache, there is only one copy of the file in RAM at all times. This is the opposite of a classical ramdisk.

tmpfs

tmpfs was created to add size limits to ramfs to stop normal systems from consuming all the available ram.

rootfs

rootfs is a special instance of ramfs, which is always present. It is used internally in the kernel as the starting and stopping point for searches of doubly-linked list of mount points.

Most systems just mount another filesystem over it and ignore it.

initramfs

initramfs is a gzipped “cpio” format archive in the init section of the kernel (freed when as the kernel boots), which is extracted, and decompressed into rootfs when the kernel boots up.

After extracting, the kernel checks to see if rootfs contains a file “init”, and if so it executes it. If rootfs does not contain an init program after the embedded cpio archive is extracted into it, the kernel will fall through to the older code to locate and mount a root partition, then exec some variant of /sbin/init out of that.

ext2

Ext2 is either a ram based disk image, or something backed by a real drive. In either case, an ext2 image is generated for you by the genext2fs application.

The variable EXT2_BLOCKS controls the number of blocks (the size of the partition) and is typically set in your uClinux-dist/vendors/<VENDOR>/<BOARD>/Makefile.

ramdisk

In older releases, the default root filesystem was an ext2 image sitting in a statically sized ramdisk. You could use a ramdisk to prototype any block filesystem type. So while ultimately the root filesystem is sitting in RAM, the filesystem layer hides that and acts like any other block device (like a real hard drive).

The downside is that, since a ramdisk emulates a block device, you end up with double the RAM usage when reading files -- once in the ramdisk itself and once in the page cache. If you want to run a filesystem out of RAM, you should look at ramfs as it does not suffer this penalty.

jffs2

ubifs

nfs

nfs

uClinux-dist Integration

All root filesystem images for the uClinux distribution are built from the directory uClinux‑dist/romfs/. If you want to quickly add/edit files in here, you may do so, and then run make image to recreate all of the images. However, this is intended for testing only, and permanent files additions should be handled in the vendors subdirectory (see Managing uClinux Distribution Upgrades) via the $(ROMFSINST) helper program. Otherwise, files may be lost with doing make clean or similarly destructive operations.

Typical Layout

This is a typical Linux filesystem layout and what the uClinux distribution uses. You're free to add/change it as you see fit, but be aware that some applications hard coded paths (such as /lib/ and /lib/modules/).

  • /bin - (Binaries) This directory contains the executable binaries for programs that were selected in the application configuration window when compiling the kernel.
  • /dev - (Devices) On the target system this directory will contain the device files for the system. For more information see Device Files.
  • /etc - (Etc.) This directory contains various system configuration files.
  • /home - (Home) This directory provides a location for system users to store their files.
  • /lib - (Libraries) This directory is for shared libraries.
  • /mnt - (Mount) This directory contains any mounted file systems.
  • /proc - (Processes) This directory stores virtual files which contain information on system processes.
  • /tmp - (Temporary) In uClinux this directory is a link to /var/tmp.
  • /usr - (User) This directory stores various user programs.
  • /var - (Various) Unlike the other directories which exist on the device /dev/root, this directory exists on the device /dev/ram0, this makes it the only writable directory as the other directories exist on a read-only file system.