20.8 UFS Journaling Through GEOM

With the release of FreeBSD 7.0, the long awaited feature of journals has been implemented. The implementation itself is provided through the GEOM subsystem and is easily configured via the gjournal(8) utility.

What is journaling? Journaling capability stores a log of file system transactions, i.e.: changes that make up a complete disk write operation, before meta-data and file writes are committed to the disk proper. This transaction log can later be replayed to redo file system transactions, preventing file system inconsistencies.

This method is yet another mechanism to protect against data loss and inconsistencies of the file system. Unlike Soft Updates which tracks and enforces meta-data updates and Snapshots which is an image of the file system, an actual log is stored in disk space specifically reserved for this task, and in some cases may be stored on another disk entirely.

Unlike other file system journaling implementations, the gjournal method is block based and not implemented as part of the file system - only as a GEOM extension.

To enable support for gjournal, the FreeBSD kernel must have the following option - which is the default on FreeBSD 7.0 and later systems:


If journaled volumes need to be mounted during startup, the geom_journal.ko kernel module will also have to be loaded, by adding the following line in /boot/loader.conf:


Alternatively, this function can also be built into a custom kernel, by adding the following line in the kernel configuration file:


Creating a journal on a free file system may now be done using the following steps, considering that the da4 is a new SCSI disk:

# gjournal load
# gjournal label /dev/da4

At this point, there should be a /dev/da4 device node and a /dev/da4.journal device node. A file system may now be created on this device:

# newfs -O 2 -J /dev/da4.journal

The previously issued command will create a UFS2 file system on the journaled device.

Effectively mount the device at the desired point with:

# mount /dev/da4.journal /mnt

Note: In the case of several slices, a journal will be created for each individual slice. For instance, if ad4s1 and ad4s2 are both slices, then gjournal will create ad4s1.journal and ad4s2.journal.

For better performance, keeping the journal on another disk may be desired. For these cases, the journal provider or storage device should be listed after the device to enable journaling on. Journaling may also be enabled on current file systems by using tunefs; however, always make a backup before attempting to alter a file system. In most cases, the gjournal will fail if it is unable to create the actual journal but this does not protect against data loss incurred as a result of misusing tunefs.

It is also possible to journal the boot disk of a FreeBSD system. Please refer to the article Implementing UFS Journaling on a Desktop PC for detailed instructions on this task.