freeramdisk
Free ramdisk memory
TLDR
Free loadlin ramdisk memory
SYNOPSIS
freeramdisk [<filelist]
PARAMETERS
-
Reads file list from standard input (default behavior)
DESCRIPTION
The freeramdisk command is a utility from the klibc package designed to reclaim memory used by the initramfs (initial RAM filesystem) after the real root filesystem has been mounted. During the Linux boot process, the kernel unpacks the initramfs cpio archive into RAM to provide a temporary root environment for early boot tasks like loading modules, mounting filesystems, and assembling RAID or LVM volumes.
Once these tasks are complete and the switch to the real root is made (via switch_root or exec newroot:/sbin/init), the memory occupied by the unpacked initramfs files remains allocated unless explicitly freed. freeramdisk solves this by reading a list of filenames (one per line) from standard input—typically generated during unpacking—and invalidating the page cache pages associated with those files, returning the memory to the kernel's free pool.
This is crucial in memory-constrained environments like embedded systems, servers with limited RAM, or systems booting from slow storage where initramfs is large. Usage is automated in initramfs scripts (e.g., in Debian/Ubuntu's mkinitramfs hooks), where a prerun list is captured and fed to freeramdisk just before pivot_root. It improves boot performance and available memory for the running system without requiring a reboot.
CAVEATS
Only effective in initramfs context before root switch; files must still exist in tmpfs; does not work on non-ramdisk filesystems; potential risk of freeing active files if list is incorrect.
TYPICAL USAGE
In initramfs script:
find . | cpio -o -H newc > /newroot/initramfs.cpio (unpack)
find . > /prerunlist
... boot tasks ...
freeramdisk </prerunlist
SOURCE
Part of klibc (<a href='https://www.kernel.org/pub/linux/libs/klibc/'>kernel.org</a>); compile with klibc tools for custom initramfs.
HISTORY
Introduced in klibc around 2004-2005 as part of efforts to provide a minimal libc for initramfs environments. Gained prominence with widespread initramfs adoption in Linux 2.6 kernels (2004+). Maintained in distributions like Debian, Ubuntu, and embedded Linux; minor updates for kernel page cache changes.
SEE ALSO
mkinitramfs(8), switch_root(8), pivot_root(2), kinit(1), cpio(1)


