20.9. UFS Journaling Through GEOM

Beginning with FreeBSD 7.0, support for UFS journals is available. The implementation is provided through the GEOM subsystem and is configured using gjournal(8).

Journaling stores a log of file system transactions, such as changes that make up a complete disk write operation, before meta-data and file writes are committed to the disk. This transaction log can later be replayed to redo file system transactions, preventing file system inconsistencies.

This method provides 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 create an image of the file system, a log is stored in disk space specifically 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. It is 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:


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


Alternatively, this function can 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. In this example, 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

This command will create a UFS2 file system on the journaled device.

mount the device at the desired point with:

# mount /dev/da4.journal /mnt


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, the journal may be kept on another disk. In this configuration, 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, gjournal will fail if it is unable to create the 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. Refer to the article Implementing UFS Journaling on a Desktop PC for detailed instructions.

All FreeBSD documents are available for download at http://ftp.FreeBSD.org/pub/FreeBSD/doc/

Questions that are not answered by the documentation may be sent to <freebsd-questions@FreeBSD.org>.

Send questions about this document to <freebsd-doc@FreeBSD.org>.