Managing RAID on Linux - Derek Vadala [108]
ext2 Organization
Each ext2 filesystem contains a superblock. The superblock contains general information about the filesystem, including its block size, the total number of inodes and blocks in the filesystem, and information about the state of the filesystem. The superblock is essential for successfully mounting an ext2 filesystem. The superblock is stored at the beginning of a filesystem, at an offset of 1024 bytes from the start of the device. Because of its importance, backup copies of the superblock are stored throughout the filesystem in block groups.
Block groups are collections of blocks that further organize an ext2 filesystem. In addition to containing a fixed amount of blocks, each block group originally stored a backup copy of the superblock. However, this method wasted space, and now backup copies are stored only in block groups 0 and 1, as well as block groups that are powers of 3, 5, and 7. This distribution conserves space, while insuring that a usable copy of the superblock is always intact. In the event that the superblock becomes corrupt, a mount option allows system administrators to specify an alternate superblock location.
Each block group begins with a group descriptor, which contains a block bitmap, an inode bitmap, and an inode table. (The group descriptor follows the superblock backup on block groups that contain a backup of the superblock.) The block and inode bitmaps are simply bit patterns that identify which blocks and inodes in the current block group have been allocated. The inode table contains pointers to data blocks in the current block group.
Block groups help improve disk performance in two ways. First, because each block group has its own inode table, the time between looking up an inode and retrieving data blocks is decreased. Imagine if the inode table were centralized, for example, at the beginning of the disk. The time needed to move the actuator arm to the inode table and then back out to data blocks would significantly impact performance.
Block groups also help improve performance by keeping data in the same block group as its inodes and by attempting to store an entire file in the same block group. Overall, block groups help reduce the number of seeks a hard disk needs to make when locating and accessing files.
Creating an ext2 Filesystem
The mke2fs command is used to create ext2 filesystems on disk partitions or RAID devices. In addition, ext2 users have several other commands at their disposal to manage ext2 filesystems. Of particular note is tune2fs, which allows administrators to configure tunable ext2 parameters that don't require re-initialization of the filesystem. tune2fs, as well as many other useful ext2 utilities, is available as part of the e2fsprogs package, which is included with most distributions and is available from http://e2fsprogs.sourceforge.net.
By default, mke2fs creates a filesystem on the specified device, using a block size of 4096 bytes.
# mke2fs /dev/md0
Use the -b flag to change the default block size.
# mke2fs -b 1024 /dev/md0
Normally, the number of inodes is automagically computed by mke2fs, based on the block size chosen (8192 bytes for each inode, by default). However, if the values that mke2fs computes are inadequate, the ratio of inodes to bytes can be altered as well. Note that the ratio of bytes to inodes should never be smaller than the block size. As the number of bytes per inode increases, you are left with fewer inodes; as the number decreases (or approaches the block size), more inodes are created. Here is an example