The extended file system version 2 has long been the de facto standard for Linux. It was the first stable file system that offered all the elements of a POSIX file system. However, these days a feature known as journaling has become an important option, which ext2 doesn't offer.
Note POSIX stands for portable operating system Interface for Unix. If any element running on Linux or any other Unix version is POSIX compliant, this means it will run without problems on any flavor of Unix.
In a journal, you can track all transactions with regard to open files. The advantage to this is that if anything goes wrong while working with a system, the only thing that is required to repair damage to a file system is to do a rollback based upon the information in the journal. Because ext2 doesn't have a journal, it is not a good choice for large volumes: larger volumes will always take longer to check if no journal is present. However, if a small (less than 500MB) volume is created, ext2 is still a good choice. The first reason is mainly that it doesn't make sense to create a journal on a small file system because the journal itself will occupy space; an average journal can be about 40MB in size. Other good reasons to use ext2 are that it is a mature file system, everyone knows how it works, it works on many distributions, and many utilities are available for managing an ext2 file system. Some advanced utilities are available for tuning and troubleshooting ext2 file systems as well:
e2fsck: This is the utility that is run automatically when an administrator activates the fsck command. This utility has some options that are specific to an ext2 file system. One of them is the -b option, which allows you to repair the file system in case the first sectors are damaged. In an ext2 file system, the critical information about the file system is written to the superblock. A backup superblock is always present; its exact location depends on the block size that is used. If 1KB blocks are used, the backup superblock is in block 8,193. If 2KB blocks are used, it is in 16,384. If 4KB blocks are used, you can find it in 32,768. For example, by running e2fsck -s 8193, you may be able to repair a file system that cannot be mounted anymore. Running e2fsck -D will cause e2fsck to optimize directories. It can do this by indexing them, compressing them, or using other optimization techniques.
tune2fs: The ext2 file system has some tunable parameters. For example, by using the maximum mount count option (set using the -c option), you can force the program e2fsck to run automatically every once in a while by forcing an integrity check. This option may sound good, but on a server where a file system is sometimes rarely remounted, it can make more sense to use the -i option to set an interval defined as a time period. For example, tune2fs -i 2m will force an e2fsck on your ext2 file systems every two months. The options to check the consistency of your ext2 file system automatically are not the only options you can use with tune2fs. The option -l will list all information from the file system's superblock. Another interesting option is the -L label option, which allows you to set a volume label. This can be useful if device names on your system change on a regular basis; by using volume names, you can use the name of the volume when mounting the file system in /etc/fstab instead of the name of the device on which the file system is created. The last interesting option is -m; you can use this option to set a percentage of reserved blocks for your ext2 file system. By default, the last 5 percent of available disk space is always reserved for the user root to prevent users from filling up the file system completely by accident. Use e2fsck -m 2 to decrease the amount of reserved disk space, for example.
dumpe2fs: Every file system maintains a lot of administrative information. ext2 does this in the file system superblock. This is an item in many file systems designed specifically to store administrative data. Also, block groups are used as groups of data files that ext2 can administer as one entity. If you need to see the information about this file system administration, use dumpe2fs followed by the name for which you want to dump the administrative information, as shown in Figure 8-1.
Note When using a tool such as dumpe2fs, you will see information about available inodes. Every file on every POSIX-compliant file system needs an inode to store its administrative information. On ext2 and ext3, inodes are created only when you are creating the file system. Normally one inode is created for about every four data blocks. However, if you create many small files, you can run into a situation where free disk blocks are still available but there are no more available inodes. This will make it impossible to create new files. As an administrator, you can use dumpe2fs to get an overview of the available inodes on your ext2 file system.
Figure 8-1. Use dumpe2fs to dump administrative information about your ext2 file system on the screen.
debugfs: The debugfs utility allows you to open the ext2 file system debugger. From this debugger, you can perform powerful tasks. To do this, some internal commands are available from the file system debugger. One of them is the lsdel command, which will list files that were recently deleted from your file system. After finding the inodes of these recently deleted files, you can use the dump command, followed by the number of the inode. For example, use dump <17468> /somefile to dump everything the inode refers to in the file /somefile that is created automatically. You must be aware, however, that this works only if you are acting quickly. When a file is removed on a Linux file system, the inode and blocks that were used by the file are flagged as available, and the next time data is written to the volume, they can be overwritten. Also, you should be aware of on disadvantage of the debugfs method—it doesn't know anything about file or directory names. Therefore, you can see the inode number of a deleted file but not its name, and that can make recovery rather difficult.
Fie Edit View Teimmal Tabs ±te(p laksmi:~ # dumpe2fs /dev/sdbl dumpe2fs 1.38 (3Q-Jun-2005) Filesystem volume name: <none>
Last mounted on: Filesystem UUID: Filesystem magic number Filesystem revision #: Filesystem features: Default mount options: Filesystem state: Errors behavior: Filesystem OS type: Inode count: Block count: Reserved block count: Free blocks: Free inodes: First block: Block size: Fragment size: Blocks per group: Fragments per group: Inodes per group: Inode blocks per group: Filesystem created: Last mount time: Last write time: Mount count: Maximum mount count: Last checked: Check interval: Next check after: Reserved blocks uid:
1024 1024 8192 8192 2048 256
Thu Jun 15 12:52:37 2006 n/a
Thu Jun 15 12:52:38 2006 O 28
Thu Jun 15 12:52:37 2006 15552000 (6 months) Tue Dec 12 11:52:37 2006 0 (user root)
To summarize, ext2 offers both advantages and disadvantages. It's advantageous when used for small volumes. However, if the size of a volume grows up to several gigabytes, ext2 is not recommended, because it can take ages to complete a file system check.
Was this article helpful?