blob: b9714569e472b7469911f22ecefd48eaefd84a90 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001
2The Second Extended Filesystem
3==============================
4
5ext2 was originally released in January 1993. Written by R\'emy Card,
6Theodore Ts'o and Stephen Tweedie, it was a major rewrite of the
7Extended Filesystem. It is currently still (April 2001) the predominant
8filesystem in use by Linux. There are also implementations available
9for NetBSD, FreeBSD, the GNU HURD, Windows 95/98/NT, OS/2 and RISC OS.
10
11Options
12=======
13
14Most defaults are determined by the filesystem superblock, and can be
15set using tune2fs(8). Kernel-determined defaults are indicated by (*).
16
17bsddf (*) Makes `df' act like BSD.
18minixdf Makes `df' act like Minix.
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020check=none, nocheck (*) Don't do extra checking of bitmaps on mount
21 (check=normal and check=strict options removed)
22
Matthew Wilcox9c3ce9e2015-02-16 15:59:31 -080023dax Use direct access (no page cache). See
24 Documentation/filesystems/dax.txt.
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026debug Extra debugging information is sent to the
27 kernel syslog. Useful for developers.
28
29errors=continue Keep going on a filesystem error.
30errors=remount-ro Remount the filesystem read-only on an error.
31errors=panic Panic and halt the machine if an error occurs.
32
33grpid, bsdgroups Give objects the same group ID as their parent.
34nogrpid, sysvgroups New objects have the group ID of their creator.
35
36nouid32 Use 16-bit UIDs and GIDs.
37
38oldalloc Enable the old block allocator. Orlov should
39 have better performance, we'd like to get some
40 feedback if it's the contrary for you.
41orlov (*) Use the Orlov block allocator.
42 (See http://lwn.net/Articles/14633/ and
43 http://lwn.net/Articles/14446/.)
44
45resuid=n The user ID which may use the reserved blocks.
46resgid=n The group ID which may use the reserved blocks.
47
48sb=n Use alternate superblock at this location.
49
50user_xattr Enable "user." POSIX Extended Attributes
51 (requires CONFIG_EXT2_FS_XATTR).
52 See also http://acl.bestbits.at
53nouser_xattr Don't support "user." extended attributes.
54
55acl Enable POSIX Access Control Lists support
56 (requires CONFIG_EXT2_FS_POSIX_ACL).
57 See also http://acl.bestbits.at
58noacl Don't support POSIX ACLs.
59
60nobh Do not attach buffer_heads to file pagecache.
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062grpquota,noquota,quota,usrquota Quota options are silently ignored by ext2.
63
64
65Specification
66=============
67
68ext2 shares many properties with traditional Unix filesystems. It has
69the concepts of blocks, inodes and directories. It has space in the
70specification for Access Control Lists (ACLs), fragments, undeletion and
71compression though these are not yet implemented (some are available as
72separate patches). There is also a versioning mechanism to allow new
73features (such as journalling) to be added in a maximally compatible
74manner.
75
76Blocks
77------
78
79The space in the device or file is split up into blocks. These are
80a fixed size, of 1024, 2048 or 4096 bytes (8192 bytes on Alpha systems),
81which is decided when the filesystem is created. Smaller blocks mean
82less wasted space per file, but require slightly more accounting overhead,
83and also impose other limits on the size of files and the filesystem.
84
85Block Groups
86------------
87
88Blocks are clustered into block groups in order to reduce fragmentation
89and minimise the amount of head seeking when reading a large amount
90of consecutive data. Information about each block group is kept in a
91descriptor table stored in the block(s) immediately after the superblock.
92Two blocks near the start of each group are reserved for the block usage
93bitmap and the inode usage bitmap which show which blocks and inodes
94are in use. Since each bitmap is limited to a single block, this means
95that the maximum size of a block group is 8 times the size of a block.
96
97The block(s) following the bitmaps in each block group are designated
98as the inode table for that block group and the remainder are the data
99blocks. The block allocation algorithm attempts to allocate data blocks
100in the same block group as the inode which contains them.
101
102The Superblock
103--------------
104
105The superblock contains all the information about the configuration of
106the filing system. The primary copy of the superblock is stored at an
107offset of 1024 bytes from the start of the device, and it is essential
108to mounting the filesystem. Since it is so important, backup copies of
109the superblock are stored in block groups throughout the filesystem.
110The first version of ext2 (revision 0) stores a copy at the start of
111every block group, along with backups of the group descriptor block(s).
112Because this can consume a considerable amount of space for large
113filesystems, later revisions can optionally reduce the number of backup
114copies by only putting backups in specific groups (this is the sparse
115superblock feature). The groups chosen are 0, 1 and powers of 3, 5 and 7.
116
117The information in the superblock contains fields such as the total
118number of inodes and blocks in the filesystem and how many are free,
119how many inodes and blocks are in each block group, when the filesystem
120was mounted (and if it was cleanly unmounted), when it was modified,
121what version of the filesystem it is (see the Revisions section below)
122and which OS created it.
123
124If the filesystem is revision 1 or higher, then there are extra fields,
125such as a volume name, a unique identification number, the inode size,
126and space for optional filesystem features to store configuration info.
127
128All fields in the superblock (as in all other ext2 structures) are stored
129on the disc in little endian format, so a filesystem is portable between
130machines without having to know what machine it was created on.
131
132Inodes
133------
134
135The inode (index node) is a fundamental concept in the ext2 filesystem.
136Each object in the filesystem is represented by an inode. The inode
137structure contains pointers to the filesystem blocks which contain the
138data held in the object and all of the metadata about an object except
139its name. The metadata about an object includes the permissions, owner,
140group, flags, size, number of blocks used, access time, change time,
141modification time, deletion time, number of links, fragments, version
142(for NFS) and extended attributes (EAs) and/or Access Control Lists (ACLs).
143
144There are some reserved fields which are currently unused in the inode
145structure and several which are overloaded. One field is reserved for the
146directory ACL if the inode is a directory and alternately for the top 32
147bits of the file size if the inode is a regular file (allowing file sizes
148larger than 2GB). The translator field is unused under Linux, but is used
149by the HURD to reference the inode of a program which will be used to
150interpret this object. Most of the remaining reserved fields have been
151used up for both Linux and the HURD for larger owner and group fields,
152The HURD also has a larger mode field so it uses another of the remaining
153fields to store the extra more bits.
154
155There are pointers to the first 12 blocks which contain the file's data
156in the inode. There is a pointer to an indirect block (which contains
157pointers to the next set of blocks), a pointer to a doubly-indirect
158block (which contains pointers to indirect blocks) and a pointer to a
159trebly-indirect block (which contains pointers to doubly-indirect blocks).
160
161The flags field contains some ext2-specific flags which aren't catered
162for by the standard chmod flags. These flags can be listed with lsattr
163and changed with the chattr command, and allow specific filesystem
164behaviour on a per-file basis. There are flags for secure deletion,
165undeletable, compression, synchronous updates, immutability, append-only,
166dumpable, no-atime, indexed directories, and data-journaling. Not all
167of these are supported yet.
168
169Directories
170-----------
171
172A directory is a filesystem object and has an inode just like a file.
173It is a specially formatted file containing records which associate
174each name with an inode number. Later revisions of the filesystem also
175encode the type of the object (file, directory, symlink, device, fifo,
176socket) to avoid the need to check the inode itself for this information
177(support for taking advantage of this feature does not yet exist in
178Glibc 2.2).
179
180The inode allocation code tries to assign inodes which are in the same
181block group as the directory in which they are first created.
182
183The current implementation of ext2 uses a singly-linked list to store
184the filenames in the directory; a pending enhancement uses hashing of the
185filenames to allow lookup without the need to scan the entire directory.
186
187The current implementation never removes empty directory blocks once they
188have been allocated to hold more files.
189
190Special files
191-------------
192
193Symbolic links are also filesystem objects with inodes. They deserve
194special mention because the data for them is stored within the inode
195itself if the symlink is less than 60 bytes long. It uses the fields
196which would normally be used to store the pointers to data blocks.
197This is a worthwhile optimisation as it we avoid allocating a full
198block for the symlink, and most symlinks are less than 60 characters long.
199
200Character and block special devices never have data blocks assigned to
201them. Instead, their device number is stored in the inode, again reusing
202the fields which would be used to point to the data blocks.
203
204Reserved Space
205--------------
206
207In ext2, there is a mechanism for reserving a certain number of blocks
208for a particular user (normally the super-user). This is intended to
Matt LaPlante992caac2006-10-03 22:52:05 +0200209allow for the system to continue functioning even if non-privileged users
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210fill up all the space available to them (this is independent of filesystem
211quotas). It also keeps the filesystem from filling up entirely which
212helps combat fragmentation.
213
214Filesystem check
215----------------
216
217At boot time, most systems run a consistency check (e2fsck) on their
218filesystems. The superblock of the ext2 filesystem contains several
219fields which indicate whether fsck should actually run (since checking
220the filesystem at boot can take a long time if it is large). fsck will
221run if the filesystem was not cleanly unmounted, if the maximum mount
222count has been exceeded or if the maximum time between checks has been
223exceeded.
224
225Feature Compatibility
226---------------------
227
228The compatibility feature mechanism used in ext2 is sophisticated.
229It safely allows features to be added to the filesystem, without
230unnecessarily sacrificing compatibility with older versions of the
231filesystem code. The feature compatibility mechanism is not supported by
232the original revision 0 (EXT2_GOOD_OLD_REV) of ext2, but was introduced in
233revision 1. There are three 32-bit fields, one for compatible features
234(COMPAT), one for read-only compatible (RO_COMPAT) features and one for
235incompatible (INCOMPAT) features.
236
237These feature flags have specific meanings for the kernel as follows:
238
239A COMPAT flag indicates that a feature is present in the filesystem,
240but the on-disk format is 100% compatible with older on-disk formats, so
241a kernel which didn't know anything about this feature could read/write
242the filesystem without any chance of corrupting the filesystem (or even
243making it inconsistent). This is essentially just a flag which says
244"this filesystem has a (hidden) feature" that the kernel or e2fsck may
245want to be aware of (more on e2fsck and feature flags later). The ext3
246HAS_JOURNAL feature is a COMPAT flag because the ext3 journal is simply
247a regular file with data blocks in it so the kernel does not need to
248take any special notice of it if it doesn't understand ext3 journaling.
249
250An RO_COMPAT flag indicates that the on-disk format is 100% compatible
251with older on-disk formats for reading (i.e. the feature does not change
252the visible on-disk format). However, an old kernel writing to such a
253filesystem would/could corrupt the filesystem, so this is prevented. The
254most common such feature, SPARSE_SUPER, is an RO_COMPAT feature because
255sparse groups allow file data blocks where superblock/group descriptor
256backups used to live, and ext2_free_blocks() refuses to free these blocks,
257which would leading to inconsistent bitmaps. An old kernel would also
258get an error if it tried to free a series of blocks which crossed a group
259boundary, but this is a legitimate layout in a SPARSE_SUPER filesystem.
260
261An INCOMPAT flag indicates the on-disk format has changed in some
262way that makes it unreadable by older kernels, or would otherwise
263cause a problem if an old kernel tried to mount it. FILETYPE is an
264INCOMPAT flag because older kernels would think a filename was longer
265than 256 characters, which would lead to corrupt directory listings.
266The COMPRESSION flag is an obvious INCOMPAT flag - if the kernel
267doesn't understand compression, you would just get garbage back from
268read() instead of it automatically decompressing your data. The ext3
269RECOVER flag is needed to prevent a kernel which does not understand the
270ext3 journal from mounting the filesystem without replaying the journal.
271
272For e2fsck, it needs to be more strict with the handling of these
273flags than the kernel. If it doesn't understand ANY of the COMPAT,
274RO_COMPAT, or INCOMPAT flags it will refuse to check the filesystem,
275because it has no way of verifying whether a given feature is valid
276or not. Allowing e2fsck to succeed on a filesystem with an unknown
277feature is a false sense of security for the user. Refusing to check
278a filesystem with unknown features is a good incentive for the user to
279update to the latest e2fsck. This also means that anyone adding feature
280flags to ext2 also needs to update e2fsck to verify these features.
281
282Metadata
283--------
284
285It is frequently claimed that the ext2 implementation of writing
286asynchronous metadata is faster than the ffs synchronous metadata
287scheme but less reliable. Both methods are equally resolvable by their
288respective fsck programs.
289
290If you're exceptionally paranoid, there are 3 ways of making metadata
291writes synchronous on ext2:
292
293per-file if you have the program source: use the O_SYNC flag to open()
294per-file if you don't have the source: use "chattr +S" on the file
295per-filesystem: add the "sync" option to mount (or in /etc/fstab)
296
297the first and last are not ext2 specific but do force the metadata to
298be written synchronously. See also Journaling below.
299
300Limitations
301-----------
302
303There are various limits imposed by the on-disk layout of ext2. Other
304limits are imposed by the current implementation of the kernel code.
305Many of the limits are determined at the time the filesystem is first
306created, and depend upon the block size chosen. The ratio of inodes to
307data blocks is fixed at filesystem creation time, so the only way to
308increase the number of inodes is to increase the size of the filesystem.
309No tools currently exist which can change the ratio of inodes to blocks.
310
311Most of these limits could be overcome with slight changes in the on-disk
312format and using a compatibility flag to signal the format change (at
313the expense of some compatibility).
314
315Filesystem block size: 1kB 2kB 4kB 8kB
316
317File size limit: 16GB 256GB 2048GB 2048GB
318Filesystem size limit: 2047GB 8192GB 16384GB 32768GB
319
320There is a 2.4 kernel limit of 2048GB for a single block device, so no
321filesystem larger than that can be created at this time. There is also
322an upper limit on the block size imposed by the page size of the kernel,
323so 8kB blocks are only allowed on Alpha systems (and other architectures
324which support larger pages).
325
Michael Shieldsce05b2a2009-06-17 16:26:22 -0700326There is an upper limit of 32000 subdirectories in a single directory.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
328There is a "soft" upper limit of about 10-15k files in a single directory
329with the current linear linked-list directory implementation. This limit
330stems from performance problems when creating and deleting (and also
331finding) files in such large directories. Using a hashed directory index
332(under development) allows 100k-1M+ files in a single directory without
333performance problems (although RAM size becomes an issue at this point).
334
335The (meaningless) absolute upper limit of files in a single directory
336(imposed by the file size, the realistic limit is obviously much less)
337is over 130 trillion files. It would be higher except there are not
338enough 4-character names to make up unique directory entries, so they
339have to be 8 character filenames, even then we are fairly close to
340running out of unique filenames.
341
342Journaling
343----------
344
345A journaling extension to the ext2 code has been developed by Stephen
346Tweedie. It avoids the risks of metadata corruption and the need to
347wait for e2fsck to complete after a crash, without requiring a change
348to the on-disk ext2 layout. In a nutshell, the journal is a regular
349file which stores whole metadata (and optionally data) blocks that have
350been modified, prior to writing them into the filesystem. This means
351it is possible to add a journal to an existing ext2 filesystem without
352the need for data conversion.
353
354When changes to the filesystem (e.g. a file is renamed) they are stored in
355a transaction in the journal and can either be complete or incomplete at
356the time of a crash. If a transaction is complete at the time of a crash
357(or in the normal case where the system does not crash), then any blocks
358in that transaction are guaranteed to represent a valid filesystem state,
359and are copied into the filesystem. If a transaction is incomplete at
360the time of the crash, then there is no guarantee of consistency for
361the blocks in that transaction so they are discarded (which means any
362filesystem changes they represent are also lost).
363Check Documentation/filesystems/ext3.txt if you want to read more about
364ext3 and journaling.
365
366References
367==========
368
369The kernel source file:/usr/src/linux/fs/ext2/
370e2fsprogs (e2fsck) http://e2fsprogs.sourceforge.net/
371Design & Implementation http://e2fsprogs.sourceforge.net/ext2intro.html
372Journaling (ext3) ftp://ftp.uk.linux.org/pub/linux/sct/fs/jfs/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373Filesystem Resizing http://ext2resize.sourceforge.net/
Randy Dunlap98766fb2005-11-21 21:32:31 -0800374Compression (*) http://e2compr.sourceforge.net/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
376Implementations for:
Jody McIntyreab03eca2009-03-12 17:39:23 -0400377Windows 95/98/NT/2000 http://www.chrysocome.net/explore2fs
378Windows 95 (*) http://www.yipton.net/content.html#FSDEXT2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379DOS client (*) ftp://metalab.unc.edu/pub/Linux/system/filesystems/ext2/
Jody McIntyre1db4b2d2009-03-23 13:13:34 -0400380OS/2 (+) ftp://metalab.unc.edu/pub/Linux/system/filesystems/ext2/
Jody McIntyreab03eca2009-03-12 17:39:23 -0400381RISC OS client http://www.esw-heim.tu-clausthal.de/~marco/smorbrod/IscaFS/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
Jody McIntyre1db4b2d2009-03-23 13:13:34 -0400383(*) no longer actively developed/supported (as of Apr 2001)
384(+) no longer actively developed/supported (as of Mar 2009)