|
As mentioned previously, Ext2 was the de facto file system for Linux. Although Ext2 lacks some of the advanced features, such as extremely large files and extent mapped files of XFS, JFS, and others, it is a reliable, stable, and still available out-of-the-box file system for all Linux distributions. The real weakness of Ext2 is fsck: the bigger the Ext2 file system, the longer it takes fsck to run. Longer fsck times translate into longer down times. Ext2 OrganizationExt2 is divided into a number of block groups. Each block group holds a copy of the super block, inode, and data blocks, as shown in Figure 11-3. The block groups keep the data blocks close to the file inodes and the file inodes close to the directory inodes. Figure 11-3. Structure of the Ext2 file system.Block groups thus minimize positioning time, which reduces access time to the data. Each group contains the super block and information about the other block groups, enabling the file system to have a better chance to be covered if a block group is damaged. The inode for Ext2 is 128 bytes in size. Figure 11-4 shows the layout of the Ext2 inode structure. Figure 11-4. Ext2 inode structure.Ext2 directories are tracked with a singly linked list. Each entry in the directory has the fields that are shown in Figure 11-5. Figure 11-5. Ext2 directory structure.Figure 11-6 illustrates blocks, inodes (with a number of metadata attributes), directories, and their relationships. Figure 11-6. Blocks, inodes, directories, files, and their relationships.Block Allocation in the Ext2 File SystemWhen sequentially writing to a file, Ext2 preallocates space in units of eight contiguous blocks. Unused preallocation blocks are released when the file is closed, so space isn't wasted. This method prevents or reduces fragmentation, a condition under which many of the blocks in the file are spread throughout the disk because contiguous blocks aren't available. Contiguous blocks increase performance because when files are read sequentially there is minimal disk head movement. Fragmentation of filesthat is, the scattering of files into blocks that are not contiguousis a problem that all file systems encounter. Fragmentation is caused when files are created and deleted. The fragmentation problem can be solved by having the file system use advanced algorithms to reduce fragmentation. The problem can also be solved by using the defrag file system utility, which moves the fragmented files so that they have contiguous blocks assigned to them. A defragmentation tool available for Ext2 is called defrag.ext2. Creating an Ext2 File SystemThe program that creates Ext2 and (Ext3) file systems is called mke2fs. Two additional commands can be used to create an Ext2/Ext3 file system: mkfs.ext2 and mkfs t ext2. The rest of this section looks at some of the key options that are available with the mkfs command:
For a complete listing of the options to mkfs.ext2, see the mkfs.ext2 man page. The following example uses the default when issuing mkfs on the device /dev/hdb2. The block size defaults to 4096, and the number of inodes created is 502944. # mkfs.ext2 /dev/hdb2 mke2fs 1.32 (09-Nov-2002) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 502944 inodes, 1004062 blocks ... Next, set the block size to 1024 with the b 1024 option, and set the file system type with the T news option. The number of inodes created is 1005568. # mkfs -t ext2 -b 1024 -T news /dev/hdb2 mke2fs 1.32 (09-Nov-2002) Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) 1005568 inodes, 4016250 blocks ... Ext3 Extensions for the Ext2 File SystemThe Ext3 file system provides higher availability without impacting the robustness (at least, the simplicity and reliability) of Ext2. Ext3 is a minimal extension to Ext2 to add support for journaling. Ext3 uses the same disk layout and data structures as Ext2, and it is forward- and backward-compatible with Ext2. Migrating from Ext2 to Ext3 (and vice versa) is quite easy; it can even be done in-place in the same partition. The other three journaling file systems require the partition to be formatted with their mkfs utility. If you want to adopt a journaling file system but don't have free partitions on your system, Ext3 could be the journaling file system to use. Kernel Configuration Support for Ext3You can select Ext3 options from the File Systems section of the configuration menu and enable the following option: Ext3 journaling file system support (CONFIG_EXT3_FS=y,m,n) Click y next to the Ext3 entry if you want to build Ext3 into the kernel. Click m next to the Ext3 entry if you want to build Ext3 as a module. The n option is used if support for Ext3 is not needed. Other options are available in the Ext3 selection for Ext3 configuration. If you need any of these options, select them here. Working with Ext3There are three ways to tune an Ext3 file system:
All three of these tuning options are discussed in the next sections. Creating an Ext3 PartitionThe program that creates Ext3 file systems is called mke2fs. You can also use the mkfs.ext3 and mkfs t ext3 commands to create an Ext3 file system. The rest of this section looks at some of the key options that are available with the mkfs command:
For a complete listing of the options to mkfs.ext3, see the mkfs.ext3 man page. The following example uses the default when issuing mkfs on the device /dev/sdb1. The block size is 1024, and the number of inodes created is 128016. # mkfs.ext3 /dev/sdb1 mke2fs 1.28 (31-Aug-2002) Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) 128016 inodes, 511984 blocks ... After the Ext3 file system is formatted, it is good practice to eliminate the automatic checking of the file system (the file system is automatically checked every 23 mounts or 180 days, whichever comes first). To eliminate the automatic checking, use the tune2fs command with the c option to set checking to 0. # tune2fs c 0 /dev/sdb1 tune2fs 1.28(31-Aug-2002) Setting maximal mount count to -1 Converting an Ext2 File System to Ext3This section explains how to convert an Ext2 file system to Ext3:
Using a Separate Journal Device on an Ext3 File SystemThe first thing you need to do to use an external journal for an Ext3 file system is to issue the mkfs command on the journal device. The block size of the external journal must be the same block size as the Ext3 file system. In the following example, the /dev/hda1 device is used as the external log for the Ext3 file system: # mkfs.ext3 -b 4096 -O journal_dev /dev/hda1 # mkfs.ext3 -b 4096 -J device=/dev/hda1 /dev/hdb1 Ext2/Ext3 UtilitiesThe e2fsprogs package contains various utilities for use with Ext2 and Ext3 file systems. The following is a short description of each utility:
For more information, see the man page for each utility. |
|