ext2, or second extended file system, is a file system for the Linux kernel. It was initially designed by French software developer Rémy Card as a replacement for the extended file system (ext). Having been designed according to the same principles as the Berkeley Fast File System from BSD, it was the first commercial-grade filesystem for Linux.[7]

ext2
Developer(s)Rémy Card
Full nameSecond extended file system
IntroducedJanuary 1993 with Linux
Preceded byextended file system
Succeeded byext3
Partition IDsEBD0A0A2-B9E5-4433-87C0-68B6B72699C7 (GPT)
0x83 (Master Boot Record)
Apple_UNIX_SVR2 (Apple Partition Map)
Structures
Directory contentsTable
File allocationbitmap (free space), table (metadata)
Bad blocksTable
Limits
Max volume size2–32 TiB
Max file size16 GiB – 2 TiB
Max no. of files1018
Max filename length255 bytes
Allowed filename
characters
All bytes except NUL ('\0') and '/'
Features
Dates recordedmodification (mtime), attribute modification (ctime), access (atime)
Date rangeDecember 14, 1901 - January 18, 2038
Date resolution1 s
File system
permissions
Unix permissions, POSIX Access Control Lists (ACL)
Transparent
compression
No (Available through patches)
Transparent
encryption
No
Other
Supported
operating systems
Linux, BSD,[1][2] ReactOS,[3] Windows (through an IFS), macOS (through FUSE), HelenOS,[4] RIOT,[5] Zephyr[6]

The canonical implementation of ext2 is the "ext2fs" filesystem driver in the Linux kernel. Other implementations (of varying quality and completeness) exist in GNU Hurd,[8] MINIX 3,[9][10] some BSD kernels,[11][12][13] in MiNT,[14] Haiku[15] and as third-party Microsoft Windows[16] and macOS (via FUSE) drivers. This driver was deprecated in Linux version 6.9 in favor of the ext4 driver, as the ext4 driver works with ext2 filesystems.[17]

ext2 was the default filesystem in several Linux distributions, including Debian and Red Hat Linux, until supplanted by ext3, which is almost completely compatible with ext2 and is a journaling file system. ext2 is still the filesystem of choice for flash-based storage media (such as SD cards and USB flash drives)[citation needed] because its lack of a journal increases performance and minimizes the number of writes, and flash devices can endure a limited number of write cycles. Since 2009,[18] the Linux kernel supports a journal-less mode of ext4 which provides benefits not found with ext2, such as larger file and volume sizes.[19]

History

edit

The early development of the Linux kernel was made as a cross-development under the MINIX operating system. The MINIX file system was used as Linux's first file system. The Minix file system was mostly free of bugs, but used 16-bit offsets internally and thus had a maximum size limit of only 64 megabytes, and there was also a filename length limit of 14 characters.[20] Because of these limitations, work began on a replacement native file system for Linux.[20]

To ease the addition of new file systems and provide a generic file API, VFS, a virtual file system layer, was added to the Linux kernel. The extended file system (ext), was released in April 1992 as the first file system using the VFS API and was included in Linux version 0.96c.[21] The ext file system solved the two major problems in the Minix file system (maximum partition size and filename length limitation to 14 characters), and allowed 2 gigabytes of data and filenames of up to 255 characters. But it still had problems: there was no support of separate timestamps for file access, inode modification, and data modification.

As a solution for these problems, two new filesystems were developed in January 1993 for Linux kernel 0.99: xiafs and the second extended file system (ext2),[21] which was an overhaul of the extended file system incorporating many ideas from the Berkeley Fast File System. ext2 was also designed with extensibility in mind, with space left in many of its on-disk data structures for use by future versions.[citation needed]

Since then, ext2 has been a testbed for many of the new extensions to the VFS API. Features such as the withdrawn POSIX draft ACL proposal and the withdrawn extended attribute proposal were generally implemented first on ext2 because it was relatively simple to extend and its internals were well understood.

On Linux kernels prior to 2.6.17,[22] restrictions in the block driver mean that ext2 filesystems have a maximum file size of 2 TiB.

ext2 is still recommended over journaling file systems on bootable USB flash drives and other solid-state drives[by whom?]. ext2 performs fewer writes than ext3 because there is no journaling. As the major aging factor of a flash chip is the number of erase cycles, and as erase cycles happen frequently on writes, decreasing writes increases the life span of the solid-state device.[23] Another good practice for filesystems on flash devices is the use of the noatime mount option, for the same reason.

Beginning with Linux kernel 6.9, the ext2fs driver was deprecated and is no longer enabled in the default configuration. The central reason was that it did not support dates past 2038.[17] Users are recommended to upgrade to ext4.[24]

ext2 data structures

edit

The space in ext2 is split up into blocks. These blocks are grouped into block groups, analogous to cylinder groups in the Unix File System. There are typically thousands of blocks on a large file system. Data for any given file is typically contained within a single block group where possible. This is done to minimize the number of disk seeks when reading large amounts of contiguous data.

Each block group contains a copy of the superblock and block group descriptor table, and all block groups contain a block bitmap, an inode bitmap, an inode table, and finally the actual data blocks.

The superblock contains important information that is crucial to the booting of the operating system. Thus backup copies are made in multiple block groups in the file system. However, typically only the first copy of it, which is found at the first block of the file system, is used in the booting.

The group descriptor stores the location of the block bitmap, inode bitmap, and the start of the inode table for every block group. These, in turn, are stored in a group descriptor table.

Inodes

edit

Every file or directory is represented by an inode. The term "inode" comes from "index node" (over time, it became i-node and then inode).[25] The inode includes data about the size, permission, ownership, and location on disk of the file or directory.

Example of ext2 inode structure:

Quote from the Linux kernel documentation for ext2:[26]

There are pointers to the first 12 blocks which contain the file's data in the inode. There is a pointer to an indirect block (which contains pointers to the next set of blocks), a pointer to a doubly indirect block and a pointer to a trebly indirect block.

Thus, there is a structure in ext2 that has 15 pointers. Pointers 1 to 12 point to direct blocks, pointer 13 points to an indirect block, pointer 14 points to a doubly indirect block, and pointer 15 points to a triply indirect block.

Directories

edit

Each directory is a list of directory entries. Each directory entry associates one file name with one inode number, and consists of the inode number, the length of the file name, and the actual text of the file name. To find a file, the directory is searched front-to-back for the associated filename. For reasonable directory sizes, this is fine. But for very large directories this is inefficient, and ext3 offers a second way of storing directories (HTree) that is more efficient than just a list of filenames.

The root directory is always stored in inode number two, so that the file system code can find it at mount time. Subdirectories are implemented by storing the name of the subdirectory in the name field, and the inode number of the subdirectory in the inode field. Hard links are implemented by storing the same inode number with more than one file name. Accessing the file by either name results in the same inode number, and therefore the same data.

The special directories "." (current directory) and ".." (parent directory) are implemented by storing the names "." and ".." in the directory, and the inode number of the current and parent directories in the inode field. The only special treatment these two entries receive is that they are automatically created when any new directory is made, and they cannot be deleted.

Allocating data

edit

When a new file or directory is created, ext2 must decide where to store the data. If the disk is mostly empty, then data can be stored almost anywhere. However, clustering the data with related data will minimize seek times and maximize performance.

ext2 attempts to allocate each new directory in the group containing its parent directory, on the theory that accesses to parent and children directories are likely to be closely related. ext2 also attempts to place files in the same group as their directory entries, because directory accesses often lead to file accesses. However, if the group is full, then the new file or new directory is placed in some other non-full group.

The data blocks needed to store directories and files can be found by looking in the data allocation bitmap. Any needed space in the inode table can be found by looking in the inode allocation bitmap.

File-system limits

edit
Theoretical ext2 limits under Linux[27]
Block size: 1 KiB 2 KiB 4 KiB 8 KiB
max. file size: 16 GiB 256 GiB 2 TiB 2 TiB
max. filesystem size: 4 TiB 8 TiB 16 TiB 32 TiB

The reason for some limits of ext2 are the file format of the data and the operating system's kernel. Mostly these factors will be determined once when the file system is built. They depend on the block size and the ratio of the number of blocks and inodes.[citation needed] In Linux the block size is limited by the architecture page size.

There are also some userspace programs that cannot handle files larger than 2 GiB.

If b is the block size, the maximal file size is limited to min( ((b/4)3 + (b/4)2 + b/4 + 12) × b, (232 − 1) × 512 ) due to the i_block structure (an array of direct/indirect EXT2_N_BLOCKS) and i_blocks (32-bit integer value) representing the number of 1024 byte (1 kilobyte)[28] "blocks" in the file.[original research?]

The maximal number of sublevel-directories is 31998, due to the link-count limit.[citation needed] Directory indexing is not available in ext2, so there are performance issues for directories with a large number of files (>10,000). The theoretical limit on the number of files in a directory is 1.3 × 1020,[original research?] although this is not relevant for practical situations.

Note: In Linux 2.4 and earlier, block devices were limited to 2 TiB, limiting the maximal size of a partition, regardless of block size.[29]

Compression extension

edit

e2compr is a modification to the ext2 driver in the Linux kernel to support compression and decompression of files by the file system, without any support by user applications. e2compr is a small patch against ext2.

e2compr compresses only regular files; the administrative data (superblock, inodes, directory files, etc.) are not compressed (mainly for safety reasons). Access to compressed blocks is provided for read and write operations. The compression algorithm and cluster size is specified on a per-file basis. Directories can also be marked for compression, in which case every newly created file in the directory will be automatically compressed with the same cluster size and the same algorithm that was specified for the directory.

e2compr is not a new file system. It is only a patch to ext2 made to support the EXT2_COMPR_FL flag. It does not require user to make a new partition, and will continue to read or write existing ext2 file systems. One can consider it as simply a way for the read and write routines to access files that could have been created by a simple utility similar to gzip or compress. Compressed and uncompressed files coexist nicely on ext2 partitions.

The latest e2compr-branch is available for current releases of Linux 2.4, 2.6, and 3.0. The latest patch for Linux 3.0 was released in August 2011 and provides multicore and High memory support. There are also branches for Linux 2.0 and 2.2.

Under other operating systems

edit

Access to ext2 partitions under Microsoft Windows is possible through an Installable File System, such as ext2ifs[30] or ext2Fsd.[31] Filesystem in Userspace can be used on macOS.[32]

See also

edit

References

edit
  1. ^ "Chapter 8. Disks, File Systems, and Boot Loaders". www.freebsd.org. Retrieved 11 April 2018.
  2. ^ "ext2fs(5)". www.freebsd.org. Retrieved 11 April 2018.
  3. ^ "ReactOS 0.4.2 Released". reactos.org. Retrieved 17 August 2016.
  4. ^ "HelenOS Wiki: Ext4fs". www.helenos.com. Retrieved 6 November 2023.
  5. ^ "pkg/lwext4: add lightweight implementation of the ext2/3/4 filesystem". www.github.com. Retrieved 6 November 2023.
  6. ^ "subsys: fs: Implementation of ext2 file system". www.github.com. Retrieved 6 November 2023.
  7. ^ Mauerer, Wolfgang (2010). Professional Linux Kernel Architecture. John Wiley & Sons. ISBN 9781118079911.
  8. ^ "GNU Hurd/ hurd/ translator/ ext2fs". GNU Hurd. Retrieved 2024-02-10.
  9. ^ "MINIX Release 3.2.0". MINIX 3. Retrieved 2024-02-10.
  10. ^ "git.minix3.org Git - minix.git/tree - minix/fs/ext2/". MINIX 3 Source Code. Retrieved 2024-02-10.
  11. ^ "NetBSD src/sys/ufs/ext2fs/". NetBSD Source Code. Retrieved 2024-02-10.
  12. ^ "OpenBSD src/sys/ufs/ext2fs/". OpenBSD Source Code. Retrieved 2024-02-10.
  13. ^ "ext2fs « fs « sys - src - FreeBSD source tree". FreeBSD Source Code. Retrieved 2024-02-10.
  14. ^ "freemint/sys/xfs/ext2fs at master · freemint/freemint". FreeMiNT Source Code. Retrieved 2024-02-10.
  15. ^ "ext2 « file_systems « kernel « add-ons « src - haiku - Haiku's main repository". Haiku Source Code. Retrieved 2024-02-10.
  16. ^ "matt-wu/Ext3Fsd: Ext2/3/4 file system driver for Windows". matt-wu/Ext3Fsd. Retrieved 2024-02-10.
  17. ^ a b Larabel, Michael (2024-03-26). "Linux 6.9 Deprecates The EXT2 File-System Driver". Phoronix. Retrieved 2024-03-26.
  18. ^ "ext4: Allow ext4 to run without a journal". Linux kernel source tree. Retrieved 12 January 2021.
  19. ^ "Linux File Systems: Ext2 vs Ext3 vs Ext4". www.thegeekstuff.com. Retrieved 2020-07-13.
  20. ^ a b Strobel, Stefan; Uhl, Thomas (1994). Linux—Unleashing the Workstation in Your PC. Springer-Verlag. p. 54.
  21. ^ a b Jones, M. Tim (17 February 2009). "Anatomy of ext4". IBM Developer Works. Archived from the original on 2015-02-20. Retrieved 8 February 2012.
  22. ^ linux/kernel/git/torvalds/linux-2.6.git/commitdiff:, [PATCH] 2TB files: add blkcnt_t, Author:Takashi Sato, 26 Mar 2006 09:37:52 +0000 (01:37 -0800) — Commit allowing for large files, git.kernel.org
  23. ^ "Solid State Disk Drives". Super Talent Technology.
  24. ^ Opdenacker, Michael (2024-03-25). "ext2 filesystem driver now marked as deprecated - Bootlin's blog". Retrieved 2024-03-26.
  25. ^ "Programmer's Journal", Volume 5, 1987, p. 174
  26. ^ "The Second Extended File System". www.nongnu.org. Retrieved 2019-12-11.
  27. ^ "File system guide". Linux Reviews. Archived from the original on 2011-09-17. Retrieved 2008-01-24.
  28. ^ "Creating the Ext2 Filesystem - Understanding the Linux kernel, Second edition". www.oreilly.com. Retrieved 25 July 2023.
  29. ^ "The Second Extended File System". cscie28.dce.harvard.edu. Retrieved 2024-12-07.
  30. ^ Randall, Neil (September 18, 2007). "Linux: You Can Do It!". PC Magazine. Vol. 26, no. 18. p. 76.
  31. ^ Wallen, Jack (September 17, 2012). "Enable the mounting of ext2/3 file systems on a Windows machine". TechRepublic. Retrieved January 17, 2016.
  32. ^ Kessler, Topher (June 22, 2012). "How to manage Ext2/Ext3 disks in OS X". CNET. Retrieved January 17, 2016.
  33. ^ "The Second Extended Filesystem — the Linux Kernel documentation".

Notes

edit

Further reading

edit
edit
  • ext2fs user-space tools
  • Ext3Fsd GPL ext2/ext3 file system driver for Windows 2000/XP/2003/VISTA/2008 (opensource, supports read & write, works with FreeOTFE)