Ext2 and Ext3

team bbl


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 Organization

Ext2 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 System

When 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 System

The 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.

 # 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 System

The 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 Ext3

You 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 Ext3

There are three ways to tune an Ext3 file system:

  1. When the file system is created, which is the most efficient way

  2. Through the tuning utility tune2fs, which can be used to tune the file system after it has been created

  3. Through options that can be used when the file system is mounted

All three of these tuning options are discussed in the next sections.

Creating an Ext3 Partition

The 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.

 # 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 Ext3

This section explains how to convert an Ext2 file system to Ext3:

  1. Make a backup of the file system.

  2. 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:

     # tune2fs -j /dev/hdb3 

    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.)

  3. Change the entry for /dev/hdb3 in the /etc/fstab file from ext2 to ext3.

  4. 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:

     # mount /dev/hdb3 on /test type ext3 (rw) 

Using a Separate Journal Device on an Ext3 File System

The 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 Utilities

The 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.

    team bbl



    Performance Tuning for Linux Servers
    Performance Tuning for Linux Servers
    ISBN: 0137136285
    EAN: 2147483647
    Year: 2006
    Pages: 254

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net