Linux RAM disk, initramfs & tmpfs guide
Memory-backed filesystems provide high-speed temporary storage and handle early-boot initialization in Linux. The three main technologies are tmpfs for dynamic RAM-backed mounts, zram for compressed in-memory swap, and initramfs for unpacking kernel drivers and storage decryption at boot.
Memory filesystem overview
| Technology | Memory Management | Standard Use Cases |
|---|---|---|
tmpfs | Dynamic allocation (uses RAM/swap only for actual stored data) | /tmp, /dev/shm, /run, build directories |
zram | Compressed block device in RAM (default lzo-rle; zstd optional) | In-memory swap, fast ephemeral block storage |
initramfs | CPIO archive unpacked into rootfs at boot | Early boot kernel drivers, storage decryption (LUKS) |
Creating a high-speed tmpfs mount
tmpfs dynamically allocates memory and provides high read/write throughput:
# 1. Create mount point
sudo mkdir -p /mnt/ramdisk
# 2. Mount a 4GB tmpfs filesystem
sudo mount -t tmpfs -o size=4G,noatime,nodev,nosuid tmpfs /mnt/ramdisk
# 3. Add to /etc/fstab for persistent configuration
tmpfs /mnt/ramdisk tmpfs size=4G,noatime,nodev,nosuid 0 0For persistent mounts, add tmpfs entries to /etc/fstab using the same options; the labels and UUIDs guide covers fstab configuration in detail. tmpfs is also useful as scratch space for containers, where it provides a fast writable layer without touching disk.
Early boot: initramfs, dracut & Unified Kernel Images (UKIs)
The early boot environment provides the necessary drivers and utilities to unlock and mount the root filesystem:
- dracut / mkinitcpio / initramfs-tools: Builds the initial ramdisk (CPIO archive) containing storage drivers, network boot utilities, and cryptographic modules (TPM2/FIDO2).
- Unified Kernel Images (UKI): Combines the UEFI boot stub (
systemd-stub), the Linux kernel binary, the initramfs, and the kernel command line into a single signed EFI executable (.efi) for Secure Boot verification.
Generating a Unified Kernel Image (UKI) with dracut
# Generate a UKI executable
sudo dracut --uefi --kver $(uname -r) /boot/efi/EFI/Linux/linux-$(uname -r).efiSources & references
- tmpfs(5) — Linux manual page — documents tmpfs as a virtual memory filesystem with dynamic allocation, mount options, and default size=50% of RAM
- tmpfs — Linux Kernel Documentation — official kernel documentation explaining tmpfs internals, including swap backing and use cases for /dev/shm and /tmp
- dracut(8) — Linux manual page — documents dracut for creating initramfs images containing kernel modules and utilities needed to access the root filesystem
- UAPI.5 Unified Kernel Images — canonical specification defining UKI format as a combination of UEFI boot stub, Linux kernel, initrd, and kernel command line
- ukify(1) — Linux manual page — documents ukify tool for combining kernel, initrd, and systemd-stub into a Unified Kernel Image
Frequently asked questions
What is tmpfs in Linux?
tmpfs is a memory-backed filesystem that dynamically allocates RAM and swap only for actual stored data. It is commonly used for /tmp, /dev/shm, /run, and build directories.
How do I create a tmpfs mount?
Create a mount point, then run sudo mount -t tmpfs -o size=4G,noatime,nodev,nosuid tmpfs /mnt/ramdisk. Add an entry to /etc/fstab with the same options for persistent configuration.
What is initramfs?
initramfs is a CPIO archive unpacked into rootfs at boot. It provides early boot kernel drivers, storage decryption (LUKS), and network boot utilities needed to unlock and mount the root filesystem.
What is a Unified Kernel Image (UKI)?
A UKI combines the UEFI boot stub (systemd-stub), the Linux kernel, the initramfs, and the kernel command line into a single signed EFI executable (.efi) for Secure Boot verification.
How do I generate a UKI with dracut?
Run sudo dracut --uefi --kver $(uname -r) /boot/efi/EFI/Linux/linux-$(uname -r).efi to generate a Unified Kernel Image executable.
What compression does zram use?
zram uses lzo-rle as the kernel default compression algorithm. zstd is a common high-ratio alternative. zram provides in-memory swap and fast ephemeral block storage without disk latency.