{"canonical_url":"https://engineer.company/glossary/file-system/","content_markdown":"# file system\n\n## What it is\n\nA file system is the part of a computer that turns a disk, which on its own\nstores only numbered blocks of bytes, into named files arranged in directories.\nIt is also written as one word, filesystem, which is the spelling the Linux\nkernel documentation mostly uses. POSIX, the standard that Unix-like systems\nfollow, defines it in its 2024 edition as “A collection of files and certain of\ntheir attributes.” The same definition adds that file serial numbers belong to a\nnamespace supplied by the file system, the numbers that identify each file\nuniquely within the file system that holds it.\n\nThe rest follows from a few more of the standard's definitions. A file is an\nobject that can be written to, read from or both, with attributes such as its\naccess permissions and its type: a regular file, a directory, a symbolic link, a\nFIFO, a socket, or a character or block special file. A directory is a file made\nof directory entries, no two of which in one directory share a name. A directory\nentry, which POSIX also calls a hard link, ties a filename to a file, and\nseveral entries can name the same file. The name of a file and the file itself\nare therefore kept apart. On Linux the record of the file itself is the inode,\nwhich the GNU df manual describes as holding the file's owner, permissions,\ntimestamps and location on the file system, while the names live in the\ndirectories that point to it.\n\nA Unix-like system shows all of its file systems as a single tree of names. The\nfirst provides the root directory, and every other one is attached at a\ndirectory of the tree, its mount point, after which the paths below that\ndirectory belong to the attached file system. Inside the Linux kernel, the\nVirtual File System sits between programs and the many file systems the kernel\nsupports. The kernel documentation describes it, also known as the Virtual\nFilesystem Switch, as the layer that gives programs their filesystem interface\nand lets different implementations exist side by side. A program calls\n`open(2)`, `stat(2)`, `read(2)` or `write(2)`, and the VFS resolves the path and\nhands the work to whichever file system holds the file: ext4 on a disk\npartition, say, or a pseudo file system whose inodes live only in memory. The\ntypes the running kernel has registered are listed in `/proc/filesystems`.\n\n## Why it matters\n\nAlmost everything a server keeps past its next reboot is kept in a file system:\nthe data files of its databases, its logs, uploaded documents, its\nconfiguration. Whether those survive a power cut, a full disk or a failing drive\nis decided in large part by choices made when the file system was created and\nmounted, and some of those choices cannot be taken back later.\n\nCreation fixes capacity in two currencies. Blocks hold the contents of files,\nand inodes hold the files themselves. mke2fs, the tool that creates ext2, ext3\nand ext4 file systems, creates one inode for every so many bytes of space, and\nits manual warns that this bytes-per-inode ratio cannot be changed once the file\nsystem exists. A volume can therefore run out of room for new files while it\nstill has room for their contents, which surprises anyone who watches only the\npercentage of space in use.\n\nMounting decides what a crash costs. ext4 keeps a journal, and its documentation\nlists three data modes. The default, `data=ordered`, forces file data out to the\nmain file system before the metadata that refers to it is committed to the\njournal. `data=writeback` drops that ordering, and the documentation warns that\nafter an unclean shutdown, files written shortly before it may expose stale\ndata, which it notes can be a security risk in some cases. `data=journal` sends\nthe data through the journal as well, and it is deprecated, with support due to\nbe removed in January 2028. The `errors=` option decides what the file system\ndoes when it finds an error in itself: remount read-only, carry on, or panic and\nhalt the machine.\n\nRecovery depends on it too. When a file system is damaged, the contents of its\nfiles may still be on the disk while the structure that names them is broken,\nand that is the ground data recovery works on. The portfolio entry on\n[recovering data from SD cards, hard disks, SSDs and RAID](/portfolio/recovered-data-from-sd-cards-hdds-ssds-and-raid/)\nsays each kind of medium breaks down differently and has to be coaxed into\nreturning its data differently, and that Mac file systems bring quirks of their\nown. What counted there was choosing the approach that suited the medium on the\nbench, more than any single technique.\n\n## What it looks like in practice\n\nTake a new partition, `/dev/sdb1`, that is to hold a service's data under\n`/srv/data`. Creating an ext4 file system on it and mounting it by hand takes\nthree commands:\n\n```sh\nmke2fs -t ext4 -L data /dev/sdb1\nmkdir -p /srv/data\nmount -t ext4 /dev/sdb1 /srv/data\n```\n\n`-t ext4` names the type, as in the kernel's own ext4 documentation, and `-L`\ngives the file system a label, which mke2fs limits to 16 bytes. Everything else\ncomes from defaults; in the configuration shipped with e2fsprogs, for example,\neach inode takes 256 bytes. Two `df` commands then show the two kinds of\ncapacity:\n\n```sh\ndf -hT /srv/data\ndf -i /srv/data\n```\n\nThe first prints the file system's type and its blocks in use and available, in\nunits built on powers of 1024 (`-H` would use powers of 1000). The second lists\ninodes in place of blocks: how many there are, how many are used and available,\nand the percentage in use.\n\nA mount made by hand lasts until the next reboot. To make it permanent, the file\nsystem gets a line in `/etc/fstab`, the file that mount, umount and fsck read in\norder:\n\n```text\nLABEL=data  /srv/data  ext4  defaults,nofail  0  2\n```\n\nThe first field names the file system by its label rather than as `/dev/sdb1`.\nThe fstab manual recommends `LABEL=` or `UUID=` there, because device names\noften follow the order in which hardware happened to be detected and can change\nwhen disks are added or removed. `defaults` usually means read-write plus the\nkernel's other standard options, and `nofail` tells mount not to report an error\nif the device does not exist. The fifth field is read by dump(8), and 0 leaves\nthe file system out. The sixth gives fsck the order of checks at boot: 1 for the\nroot file system, 2 for the others and 0 for none. On a system run by systemd,\nthe manual recommends `systemctl daemon-reload` after an edit. `mount -a` then\nmounts every entry not marked `noauto`, which makes a mistake in the new line\nshow up while someone is still at the keyboard.\n\nWatching the space is part of running one. The portfolio entry on [dead-man's-switch host monitoring](/portfolio/built-dead-mans-switch-host-monitoring/) names running out of disk as one of the two realistic ways a 464 MB machine with a forge and a web server on it can die, beside running out of memory, and points out that neither failure announces itself. Its answer is a small script that a timer starts four times an hour, at a slightly shifted moment each time, to measure free disk and available memory and to ping an outside service only while both stay above their thresholds, so the alarm comes from the pings stopping. A check of that shape can read the inode column of `df -i` as well as the space column, since either one can reach its limit first.\n\n## Where it goes wrong\n\nMost file system trouble arrives as a full disk, a machine that will not mount\nwhat it mounted yesterday, or data missing after a crash, and much of it traces\nback to a setting nobody looked at when the file system was made.\n\n**The disk is full with space to spare.** Every file needs an inode, and mke2fs\nmakes a fixed number of them when it creates the file system. A volume that\nholds millions of small files can use up its inodes while `df -h` still shows\nfree space, and from then on the volume refuses every file it is asked to\ncreate. The fix is to watch `df -i` beside `df -h`, and for a volume meant for\nmany small files to set the ratio with `-i`, or the count with `-N`, when\nrunning mke2fs, since the ratio cannot be changed afterwards. Resizing the file\nsystem keeps the ratio and adds or removes inodes to match.\n\n**A check runs on a mounted file system.** The e2fsck manual says that running\nit on a mounted file system is in general not safe. The one exception is `-n`,\nwhich opens the file system read-only and answers no to every question, and even\nthen the results it prints are not valid while the file system is mounted. When\ne2fsck asks whether to go ahead on a mounted file system, the manual's answer is\nno. The fix is to unmount first, or, for the root file system, to let the check\nrun at boot, which is what the sixth field of fstab arranges.\n\n**“Read-only” writes to the disk.** Mounting ext4 with `ro` does not stop it\nwriting: the documentation notes that it replays the journal, and so writes to\nthe partition, although the mount is read-only. That matters most on a disk\nbeing rescued, where any write may land on something still needed. The options\n`ro,noload` prevent the writes, at a price the same page spells out: after an\nunclean unmount, skipping the replay leaves the file system with\ninconsistencies. The fix for a disk whose contents matter more than its uptime\nis to mount it `ro,noload`, copy off what is needed, and treat what is read as\npossibly inconsistent.\n\n**A disk changes its name.** A line that mounts `/dev/sdb1` mounts whatever the\nkernel calls `/dev/sdb1` today, and the fstab manual warns that this can change\nwhen disks are added or removed. A new disk can then be mounted where the old\none belongs, or the old one can be missing at boot. The fix is `LABEL=` or\n`UUID=` in the first field, with labels set by `mke2fs -L` or later by a tool\nsuch as `e2label`.\n\n**Power fails between the write and the disk.** By default ext4 commits its\njournal every five seconds, so a power cut can lose the last five seconds of\nmetadata changes, while the journal keeps the file system itself undamaged.\nFile data can go further back: with delayed allocation, writing it out begins\nonly after the interval set in `/proc/sys/vm/dirty_expire_centisecs`. The\ndocumentation calls applications that replace files without `fsync()` broken,\nand ext4's default `auto_da_alloc` option detects the two usual patterns,\nwriting a new file and renaming it over the old one or truncating and rewriting\nin place, to avoid files that come back empty after a crash. The fix is in the\nprogram that writes the file: call `fsync()` before telling anyone the data is\nsaved, rather than leaning on that safety net.\n\n**Timestamps stop in 2038.** The mke2fs manual says that file systems with\n128-byte inodes cannot hold timestamps later than January 19, 2038, while inodes\nof 256 bytes or more support extended timestamps. New file systems get 256 bytes\nby default, but an old one, or one made with `-I 128`, may still carry the small\nsize. The fix is to find those file systems before the date does; the ext4\ndocumentation shows `tune2fs -I 256` converting a file system created with\n128-byte inodes.\n\n## Further reading\n\n- [Definitions, POSIX.1-2024 (The Open Group Base Specifications Issue 8)](https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/V1_chap03.html#tag_03_153)\n  — the definitions of file system, file, directory, hard link and mount point.\n- [Overview of the Linux Virtual File System](https://docs.kernel.org/filesystems/vfs.html)\n  — how the kernel's VFS resolves a path and hands the work to a file system.\n- [ext4 General Information](https://docs.kernel.org/admin-guide/ext4.html)\n  — creating and mounting ext4, its data modes, `commit=` and `ro` with the\n  journal.\n- [mke2fs(8)](https://man7.org/linux/man-pages/man8/mke2fs.8.html)\n  — the bytes-per-inode ratio, inode size, the 2038 limit and volume labels.\n- [e2fsck(8)](https://man7.org/linux/man-pages/man8/e2fsck.8.html)\n  — checking ext2, ext3 and ext4, and why never on a mounted file system.\n- [fstab(5)](https://man7.org/linux/man-pages/man5/fstab.5.html)\n  — the six fields, `LABEL=` and `UUID=`, `nofail` and the order of boot\n  checks.\n\n\u003chttps://engineer.company/glossary/file-system/\u003e\n","date_modified":"2026-11-08T02:22:23Z","description":"What a file system is, how files, directories and inodes fit together, how ext4 is created, mounted and checked on Linux, and where it goes wrong.","formats":{"gemtext":"https://engineer.company/glossary/file-system/index.gmi","gopher":"https://engineer.company/glossary/file-system/gophermap","html":"https://engineer.company/glossary/file-system/","json":"https://engineer.company/glossary/file-system/index.json","markdown":"https://engineer.company/glossary/file-system/index.md","pdf":"https://engineer.company/glossary/file-system/index.pdf"},"kind":"page","language":"en","title":"What is a file system?","url":"https://engineer.company/glossary/file-system/","version":1}