E is for Ext3fs Part 2

In Part 1 of this article, we discussed some basics of the ext* filesystems in Linux. In this section we’ll have some good old filesystem fun. The most commonly used tools for working with Linux filesystems are mke2fs (create ext2/ext3 filesystem), tune2fs (adjust filesystem parameters) and e2fsck (check and repair filesystem.)

Example: /var doesn’t have a journal and really needs one as this host is syslog server for the net and /var is a mess when system crashes.

[root@princess etc]# tune2fs -j /dev/hda3
tune2fs 1.27 (8-Mar-2002)
Creating journal inode: done
This filesystem will be automatically checked every 20 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

Be sure to change “ext2” to “ext3” in /etc/fstab for the next reboot.

CAUTION! Although this may be desirable for large file systems with journals which can take hours to fsck, remember that filesystem corruption can be caused by hardware failures or kernel bugs that might go unnoticed if not for the periodic filesystem checks at reboot. Replaying your journal won’t help you in these cases! If you disable them, send yourself a cron job to remind yourself to schedule downtime to check the filesystem manually a couple times a year at least.
Example: 180 GB file system with journal. Takes hours to fsck.

[root@duchess root]# tune2fs -c 0 -i 0 /dev/md0
tune2fs 1.27 (8-Mar-2002)
Setting maximal mount count to -1
Setting interval between check 0 seconds

By the way, you can view your filesystem settings by running:

tune2fs -l /dev/device

There are three mount options for the journal modes. They are:
data=writeback — does no journalling of data; metadata only. fastest. data corruption possible in system crash.
data=ordered — default. strictly speaking only journals metadata but uses transactions to protect data as well. slightly slower than writeback mode. Because of the way the blocks to be written to disk are ordered in this mode, it offers all the protection of full data journalling mode when files are being appended to; corruption is possible when files are being overwritten.
data=journal — full journalling of data and metadata. Should be slowest because data is written twice, once to journal & once to final location. However some tests have shown that its performance surpasses the other two modes in busy interactive environments where disks are being read from & written to at same time. Also requires the largest disk footprint for journal.
Example: Change journal mode to data=writeback for a filesystem containing database files where i/o performance has to be great. Risk of corruption is mitigated by the fact that the db is keeping redo logs on separate filesystem. Not that I’m recommending this.

1. Edit /etc/fstab
change this:

LABEL=/u01              /u01                    ext3    defaults        1 2

to this:

LABEL=/u01              /u01                    ext3    data=writeback  1 2

2. Unmount the filesystem, then remount it. The output of mount now shows the specified mount option:

[root@countess root]# mount
/dev/sda1 on / type ext3 (rw)
none on /proc type proc (rw)
usbdevfs on /proc/bus/usb type usbdevfs (rw)
none on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda7 on /opt type ext3 (rw)
none on /dev/shm type tmpfs (rw)
/dev/sda6 on /tmp type ext3 (rw)
/dev/sda3 on /usr type ext3 (rw)
/dev/sda5 on /var type ext3 (rw)
/dev/sdb1 on /u01 type ext3 (rw,data=writeback)

Familiarize yourself by reading the tune2fs and mke2fs man pages with options that are tuneable and options that can only be set at filesystem creation time, like the number of inodes. And be very very careful when manipulating the filesystems on any production system.