Last updated: 2026-08-18

Linux RAM disk, initramfs & tmpfs guide

Category: Memory FilesystemsTechnologies: tmpfs, zram, dracut, UKI, systemd-boot

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

TechnologyMemory ManagementStandard Use Cases
tmpfsDynamic allocation (uses RAM/swap only for actual stored data)/tmp, /dev/shm, /run, build directories
zramCompressed block device in RAM (default lzo-rle; zstd optional)In-memory swap, fast ephemeral block storage
initramfsCPIO archive unpacked into rootfs at bootEarly 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   0

For 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:

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).efi

Sources & references

  1. tmpfs(5) — Linux manual page — documents tmpfs as a virtual memory filesystem with dynamic allocation, mount options, and default size=50% of RAM
  2. tmpfs — Linux Kernel Documentation — official kernel documentation explaining tmpfs internals, including swap backing and use cases for /dev/shm and /tmp
  3. dracut(8) — Linux manual page — documents dracut for creating initramfs images containing kernel modules and utilities needed to access the root filesystem
  4. UAPI.5 Unified Kernel Images — canonical specification defining UKI format as a combination of UEFI boot stub, Linux kernel, initrd, and kernel command line
  5. 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.