File Systems
Default File Systems
- macOS: APFS, Apple File System
- replaces HFS+
- optimized for flash and solid-state drive storage, with a primary focus on encryption
- APFS supports 64-bit inode numbers, supporting over 9 quintillion files on a single volume
- Windows 10: NTFS
- RHEL / CentOS: XFS.
- Fedora: Btrfs
- gvfs: GNOME Virtual file system. GNOME's userspace virtual filesystem.
- Debian / Ubuntu: ext4
ramfs
ramfs (RAM Filesystem) is a very basic and lightweight filesystem that stores all of its files and directories directly in your computer's RAM (Random Access Memory), instead of on a physical disk (like an HDD or SSD).
Think of it as the purest, fastest, but most volatile "virtual disk" you can create.
How It Works
- Purely in RAM: This is its defining feature. It doesn't use any other storage medium.
- Extremely Fast: Because it avoids all disk I/O, operations on a ramfs are lightning-fast. Creating, deleting, reading, and writing files happens at memory speed.
- Dynamically Sized: This is a crucial and sometimes dangerous feature. A ramfs filesystem starts with a size of zero and grows dynamically as you write files to it. It will continue to grow until it consumes all available RAM, potentially crashing your system if you're not careful. It has no built-in size limit.
- No Backing Store: Unlike other RAM-based filesystems, it doesn't use a disk as a backup or swap space. What's in RAM is all there is.
- Not "Swappable": The data stored in ramfs cannot be swapped out to disk by the kernel's memory manager. It is "pinned" in RAM.
tmpfs
/dev/shm
: an implementation of traditional shared memory concept, i.e. passing data between programs. One program will create a memory portion, which other processes (if permitted) can access. This will result into speeding up things on Linux.
tmpfs
: a temporary file storage paradigm implemented in many Unix-like operating systems, overcomes many of the drawbacks with ramfs
. It is intended to appear as a mounted file system, but data is stored in volatile memory instead of a persistent storage device.
ramfs vs. tmpfs
While ramfs is the original concept, in modern Linux systems, you will almost always use its more advanced and safer successor: tmpfs.
It's important to understand the difference, as tmpfs
is what you'll encounter 99% of the time (for example, your /dev/shm
directory is a tmpfs
mount).
Feature | ramfs (The Original) | tmpfs (The Modern Successor) |
---|---|---|
Storage Location | RAM only | RAM, but can use swap space if memory gets low. |
Size Limit | No limit. It will grow until it eats all your RAM, potentially causing a system crash. | Has a size limit. You can (and should) specify a maximum size when you mount it (e.g., mount -t tmpfs -o size=1G tmpfs /mnt/mytmp ). The default is half your physical RAM. |
Persistence | Volatile (lost on reboot/unmount) | Volatile (lost on reboot/unmount) |
Use Case | Very niche, mostly for kernel internal use or specific debugging scenarios where its "no-limit" nature is required. | The standard for all temporary, RAM-based storage. Used for /tmp , /var/run , /dev/shm , etc. |
Safety | Considered less safe due to the lack of a size limit. | Much safer because of the configurable size limit. |
When Would You Use a RAM-based Filesystem?
Despite being volatile, these filesystems are incredibly useful for specific tasks:
- High-Speed Temporary Files: When an application needs to create, read, and delete many small temporary files very quickly (e.g., during compilation, data processing, or for web server session files). Storing these in
/tmp
(which is often atmpfs
) dramatically speeds up the process. - Shared Memory: The
/dev/shm
directory is atmpfs
filesystem used for POSIX shared memory. It allows multiple processes to share data at extremely high speeds by reading and writing to a "file" that is actually just a block of RAM. - Security: Since the data is wiped on reboot, it's perfect for storing sensitive temporary information that you don't want to leave any trace of on a physical disk.
- Creating a "Scratchpad" Environment: If you need a temporary, clean environment to test something without touching your hard drive, you can mount a
tmpfs
and work inside it.
btrfs
btrfs has been "almost production ready" for many years now, but never quite got to the stage where it actually was ready. In the meantime, many of the features that btrfs provides are now available via other more mature and stable storage technologies like ext4, XFS, LVM, etc. Redhat is moving from btrfs to Stratis user level file system written in Rust.
Format Portable Disk
TL;DR: exFAT is the best cross platform option, designed to work on Windows and macOS systems.
- FAT32. Read/write on all three systems. Not journaled. File size < 4G.
- NTFS. Poor write support on Mac. Journaled.
- exFAT. Read/write on all three systems. Not journaled. No 4G limit as FAT32.
exFAT has been adopted by the SD Association as the default file system for SDXC cards larger than 32 GB.
ext4 is not accepted by Microsoft.
overlayfs
An overlay filesystem combines two filesystems - an upper filesystem and a lower filesystem. When a name exists in both filesystems, the object in the upper filesystem is visible while the object in the lower filesystem is either hidden or, in the case of directories, merged with the upper object.
The lower filesystem can be any filesystem supported by Linux and does not need to be writable. The lower filesystem can even be another overlayfs. The upper filesystem will normally be writable and if it is it must support the creation of trusted.* extended attributes, and must provide a valid d_type in readdir responses, so NFS is not suitable.
- lowerdir: Any filesystem, does not need to be on a writable filesystem.
- upperdir: The upperdir is normally on a writable filesystem.
- workdir: The workdir needs to be an empty directory on the same filesystem as upperdir. for overlayfs to store metadata