Ext2 and Ext3As 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.![]() Figure 11-4. Ext2 inode structure.![]() Figure 11-5. Ext2 directory structure.![]() Figure 11-6. Blocks, inodes, directories, files, and their relationships.[View full size image] ![]() 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:The -b block-size option specifies the block size in bytes. Valid block size values are 1024, 2048, and 4096 bytes per block.The -N number-of-inodes option specifies the number of inodes.The -T fs-type option specifies how the file system will be used. The valid options are as follows:news creates one inode per 4KB block.largefile creates one inode per megabyte.largefile4 creates one inode per 4 megabytes. 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. 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.
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: 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: When the file system is created, which is the most efficient wayThrough the tuning utility tune2fs, which can be used to tune the file system after it has been createdThrough options that can be used when the file system is mountedAll 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:The -b block-size option specifies the block size in bytes. Valid block size values are 1024, 2048, and 4096 bytes per block.The -N number-of-inodes option specifies the number of inodes.The -T fs-type option specifies how the file system will be used. The valid options are as follows:news creates one inode per 4KB block.largefile creates one inode per megabyte.largefile4 creates one inode per 4 megabytes. 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. 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.
Converting an Ext2 File System to Ext3This section explains how to convert an Ext2 file system to Ext3:Make a backup of the file system.Add a journal file to the existing Ext2 file system you want to convert by running the tune2fs program with the -j option. You can run tune2fs on a mounted or unmounted Ext2 file system. For example, if /dev/hdb3 is an Ext2 file system, the following command creates the log: If the file system is mounted, a journal file named .journal is placed in the root directory of the file system. If the file system is not mounted, the journal file is hidden. (When you mount an Ext3 file system, the .journal file appears. The .journal file can indicate that the file system is indeed of type Ext3.)Change the entry for /dev/hdb3 in the /etc/fstab file from ext2 to ext3.Reboot and verify that the /dev/hdb3 partition has type Ext3 by typing mount and examining the output. The output should include an entry like the following:
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:
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: badblocks. Searches for bad blocks on a device. chattr. Changes the file attributes on an Ext2 or Ext3 file system.compile_et. Converts a table, listing error-code names and associated messages into a C-source file that is suitable for use with the com_err library.debugfs. A file system debugger for examining and changing the state of an Ext2 file system.dumpe2fs. Prints the super block and blocks group information for the file system present on a specified device.e2fsck and fsck.ext2. Checks, and optionally repairs, an Ext2 file system.e2image. Saves critical Ext2 file system data to a file.e2label. Displays or changes the file system label on the Ext2 file system. fsck.ext3. Checks, and optionally repairs, an Ext3 file system.lsattr. Lists the file attributes on an Ext2 file system.mk_cmds. Takes a command table file as input and produces a C-source file as output, which is intended for use with the subsystem library, libss.mke2fs. Creates an Ext2 file system. mkfs.ext2 is the same as mke2fs.mkfs.ext3. Creates an Ext3 file system.mklost+found. Creates a lost+found directory in the current working directory on an Ext2 file system. mklost+found preallocates disk blocks to the directory to make it usable by e2fsck.resize2fs. Resizes Ext2 file systems.tune2fs. Adjusts tunable file system parameters on an Ext2 file system.uuidgen. Creates a new universally unique identifier (UUID) using the libuuid library. For more information, see the man page for each utility. |
Ext2 and Ext3As 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.![]() Figure 11-4. Ext2 inode structure.![]() Figure 11-5. Ext2 directory structure.![]() Figure 11-6. Blocks, inodes, directories, files, and their relationships.[View full size image] ![]() 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:The -b block-size option specifies the block size in bytes. Valid block size values are 1024, 2048, and 4096 bytes per block.The -N number-of-inodes option specifies the number of inodes.The -T fs-type option specifies how the file system will be used. The valid options are as follows:news creates one inode per 4KB block.largefile creates one inode per megabyte.largefile4 creates one inode per 4 megabytes. 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. 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.
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: 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: When the file system is created, which is the most efficient wayThrough the tuning utility tune2fs, which can be used to tune the file system after it has been createdThrough options that can be used when the file system is mountedAll 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:The -b block-size option specifies the block size in bytes. Valid block size values are 1024, 2048, and 4096 bytes per block.The -N number-of-inodes option specifies the number of inodes.The -T fs-type option specifies how the file system will be used. The valid options are as follows:news creates one inode per 4KB block.largefile creates one inode per megabyte.largefile4 creates one inode per 4 megabytes. 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. 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.
Converting an Ext2 File System to Ext3This section explains how to convert an Ext2 file system to Ext3:Make a backup of the file system.Add a journal file to the existing Ext2 file system you want to convert by running the tune2fs program with the -j option. You can run tune2fs on a mounted or unmounted Ext2 file system. For example, if /dev/hdb3 is an Ext2 file system, the following command creates the log: If the file system is mounted, a journal file named .journal is placed in the root directory of the file system. If the file system is not mounted, the journal file is hidden. (When you mount an Ext3 file system, the .journal file appears. The .journal file can indicate that the file system is indeed of type Ext3.)Change the entry for /dev/hdb3 in the /etc/fstab file from ext2 to ext3.Reboot and verify that the /dev/hdb3 partition has type Ext3 by typing mount and examining the output. The output should include an entry like the following:
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:
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: badblocks. Searches for bad blocks on a device. chattr. Changes the file attributes on an Ext2 or Ext3 file system.compile_et. Converts a table, listing error-code names and associated messages into a C-source file that is suitable for use with the com_err library.debugfs. A file system debugger for examining and changing the state of an Ext2 file system.dumpe2fs. Prints the super block and blocks group information for the file system present on a specified device.e2fsck and fsck.ext2. Checks, and optionally repairs, an Ext2 file system.e2image. Saves critical Ext2 file system data to a file.e2label. Displays or changes the file system label on the Ext2 file system. fsck.ext3. Checks, and optionally repairs, an Ext3 file system.lsattr. Lists the file attributes on an Ext2 file system.mk_cmds. Takes a command table file as input and produces a C-source file as output, which is intended for use with the subsystem library, libss.mke2fs. Creates an Ext2 file system. mkfs.ext2 is the same as mke2fs.mkfs.ext3. Creates an Ext3 file system.mklost+found. Creates a lost+found directory in the current working directory on an Ext2 file system. mklost+found preallocates disk blocks to the directory to make it usable by e2fsck.resize2fs. Resizes Ext2 file systems.tune2fs. Adjusts tunable file system parameters on an Ext2 file system.uuidgen. Creates a new universally unique identifier (UUID) using the libuuid library. For more information, see the man page for each utility. |