mkfs.cramfs
Create a compressed read-only filesystem (cramfs)
TLDR
Create a ROM filesystem out of a directory inside partition Y on device X
Create a ROM filesystem with a volume-name
SYNOPSIS
mkfs.cramfs [OPTIONS] DIRECTORY OUTPUT_FILE
PARAMETERS
DIRECTORY
The source directory whose contents will be packed into the Cramfs image.
OUTPUT_FILE
The path to the output Cramfs image file or device.
-h
Display help information and exit.
-b
Set the block size in bytes. The default is 4096 (4KB). Must be a power of 2.
-e
Set the edition number for the filesystem header. This is an arbitrary number.
-i
Inject a file as the root inode. This is typically used for specialized boot scenarios.
-n
Set the filesystem name displayed in the header. The maximum length is 16 characters.
-p
Pad the filesystem to a page boundary (4KB). This can improve performance on some hardware.
-s
Sort directory entries to ensure a consistent image build, which can be useful for reproducible builds.
-z
Force zlib compression (this is the default and only supported compression method for Cramfs).
DESCRIPTION
The mkfs.cramfs command is a utility used to create a Cramfs (Compressed ROM File System) image from a given directory structure. Cramfs is a simple, highly compressed, and read-only filesystem designed primarily for embedded systems and other applications where space efficiency is paramount.
It achieves its small footprint by compressing individual files using zlib and by having a very lightweight metadata structure. Unlike typical filesystems, Cramfs does not support writing, in-place updates, or advanced features like file permissions (beyond basic read/execute) or modification timestamps for individual files. Once created, the Cramfs image can be mounted as a read-only filesystem, making it suitable for firmware, initial ramdisks (initramfs/initrd), or read-only partitions on devices where data integrity and compactness are critical.
CAVEATS
Cramfs is a read-only filesystem; data cannot be written to or modified on a mounted Cramfs image. It lacks support for common filesystem features like hard links, symbolic links with absolute paths (relative paths are supported), and robust file permissions (it stores only basic read/execute bits). Timestamp information for individual files is also limited. Due to these limitations and the emergence of more advanced compressed filesystems like Squashfs, Cramfs is less commonly used for general purposes today, primarily finding niches in legacy embedded systems.
FILESYSTEM STRUCTURE
A Cramfs image consists of a header, followed by metadata and compressed file data. The header contains basic information like the filesystem size, name, and a checksum. Files are stored individually compressed using zlib, and directories are stored as simple lists of filenames and their inode numbers.
TYPICAL USE CASES
Beyond embedded devices, Cramfs was also used for bootable CDs/DVDs (like early Linux live distributions) where a read-only, compressed filesystem was beneficial for fitting the OS into a smaller space. However, for most modern live systems and embedded applications, Squashfs is now the preferred choice due to its superior features and performance.
HISTORY
Cramfs (Compressed ROM File System) was developed by Linus Torvalds and others for the Linux kernel, with initial patches appearing around 1999. Its design was driven by the need for a simple, compact, and efficient read-only filesystem suitable for embedded devices with limited memory and storage, particularly those relying on ROM or flash memory. It became a popular choice for initial ramdisks (initrd) and root filesystems in early embedded Linux distributions. While still supported, its usage has declined over time in favor of more modern and feature-rich compressed filesystems like Squashfs, which offer better compression ratios, more robust features, and active development.


