Managing RAID on Linux - Derek Vadala [112]
Creating an ext3 Partition
You can create ext3 partitions by adding parameters to the mke2fs command. Executing mke2fs -j creates an ext3 filesystem. For example:
# mke2fs -j /dev/md0
The program mkfs.ext3 is equivalent to executing mke2fs -j.
The size of the journal can be fine-tuned, but must be a minimum of 1024 blocks and cannot exceed 102,400 blocks. If you are using a block size of 2048 bytes, the minimum usable journal size is 2 MB and the maximum is 200 MB. By default, 8192 blocks are allocated (32 MB when using a 4 KB block size). The default block size for an ext3 filesystem, as for an ext2 filesystem, is 4096 bytes. Thus, the following example creates an ext3 filesystem with a journal size of 16 MB (4096 blocks * 4096 bytes per block).
# mke2fs -j -J size=16 /dev/md0
Converting an ext2 Filesystem to ext3
Perhaps the most convenient benefit of using ext3 is the ability to convert old ext2 partitions without destroying data or relying on a backup and restore process. Use the tune2fs command to add journal support to an existing ext2 partition. This method has been tested and proven safe by many users, but the paranoid should make certain they have backups.
# tune2fs -j /dev/md0
tune2fs 1.25 (20-Sep-2001)
Creating journal inode: done
While it's possible to upgrade a mounted ext2 partition, you will need to remount the filesystem as ext3 before journaling commences.
# umount /mnt/array
# mount -t ext3 /dev/md0 /mnt/ext3
Now that the filesystem has been upgraded, change your /etc/fstab entry to indicate that the partition is an ext3.
Tuning ext3 Features
You can make a variety of performance-tuning enhancements to the ext3 filesystem. Remember that in addition to the changes I've outlined in this section, the performance tweaks associated with ext2 (like the noatime mount option) also apply to ext3 partitions. In fact, using noatime on any journaling filesystem is strongly recommended. Because all changes to the filesystem are logged, the impact of access time updates is amplified. This is especially noticeable on heavily used systems.
Data journaling
By default, only metadata journaling is enabled for an ext3 filesystem. To enable data journaling, mount the filesystem with the option data=journal. For example:
# mount -t ext3 -o data=journal /dev/md0 /mnt/ext3
While data journaling should slow down the overall performance of your filesystem, there has been some suggestion that in certain situations it could improve performance. I recommend testing each option. The default ext3 operations (data=ordered) specify that data should be written to disk before metadata. This is the default because it offers the best trade-off between performance and reliability.
The data=writeback option provides the best overall performance, but impairs reliability a bit. Unlike ordered writes, writeback mode places no constraints on the order in which data and metadata are written to disk. While filesystem integrity is maintained using writeback mode, it's possible that some data will not be committed to disk in the event of a system crash, meaning that you could be left with some old data. Still, this sacrifice is worthwhile on systems that require the highest level of performance.
Use the following command to mount an ext3 filesystem in writeback mode:
# mount -t ext3 -o data=writeback /dev/md0 /mnt/ext3
Once you've decided on the best journaling mode, add the mount option into your /etc/fstab file so that it's always selected when the system restarts.
Using a separate journal device
To improve overall performance, try creating the journal for an ext3 partition on a separate device. For example, creating a journal on a small RAID-1 partition when the filesystem uses RAID-0 or RAID-5 for data adds some protection.
First, you need to create a journal device. This can be any block device attached to the system.