With the release of FreeBSD 7.0, the long awaited feature of UFS 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 at the end sector
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 7.X systems:
options UFS_GJOURNAL
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 label /dev/da4
# gjournal load
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 with journaling being made active.
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. In the case of the command being run twice, the
result will be “journals”.
Under some circumstances, 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.