I don't actually use gjournal anymore, we have ZFS now and for everything else, UFS has it's own journalling. --Tykling 02:38, 11 November 2010 (UTC)
Journaling file systems are designed to write any pending io writes to a journal (log) before actually writing the metadata and actual data to the disk. If a power outage or similar occurs, the journal can be used to re-run the transactions that were lost - or at least check that the data was written as intended. gjournal means the end of having to run fsck after a crash, since you know the data on the disk is always in sync, something most admins will gladly welcome.
Journaling system partitions on the boot disk
Sysinstall doesn't currently have a way to install FreeBSD to a journaled device. You will need to create extra partitions to contain the journals in the partitioning part of the sysinstall process. The handbook does not recommend journaling small file systems, so /usr and /var are candidates for journaling on a default partition scheme. The recommended approach is to create extra swap partitions to contain the journals in sysinstall, and after the installation is completed to remove the extra swap partitions from /etc/fstab so they won't be used for swap, and reboot. You need one journal partition per partition you want journaling enabled on, so in the default case two extra swap partitions should be created. The size depends on the expected load on the file system, not the size of the file system. A very busy file system needs to have a journal 3.3x the size of available system memory. More on journal sizes [here]. So, step by step:
- Install FreeBSD as you normally would, but create an extra swap partition per partition you want journaled. After the install remove the extra swap partitions from fstab. Also add geom_journal_load="YES" to /boot/loader.conf or the gjournal system will not load at boot time.
- Use the following approach for each partition you want journaled, substituting the device names for your own of course. In this example the data partition normally mounted on /var is ad0s1d and the journal partition is da0s1e:
Start journaling da0s1d using da0s1e as the journal partition:
gjournal label -f da0s1d da0s1e
Enable journaling on the new filesystem, and disable soft updates:
tunefs -J enable -n disable da01sd.journal
Mount the new journaled filesystem:
mount -o async /dev/da0s1d.journal /var
All that remains is to change the entry for /var in /etc/fstab to point to the new journaled device /dev/da0s1d.journal. Remember to also add async to the mount options, so they read rw,async instead of just the default rw.
Adding an new journaled disk to an existing system
This is a lot easier than enabling journaling on an existing filesystem. Make sure geom_journal_load="YES" is in /boot/loader.conf. Then add the new disk to the system, reboot to single user mode and follow the steps below:
Create the journal for the disk device, using ad1 as both data provider and journal provider:
gjournal label /dev/ad1
Run newfs on the new journaled device. In this example I reduce minfree to 5% instead of the default 8% to safe some disk space, since this is not a system critical disk. See the newfs man page for more information on minfree.
newfs -O 2 -m 5 -J /dev/ad1.journal
Mount the new journaled device somewhere:
mount -o async /dev/ad1.journal /newdisk
All that remains is to add an entry for /newdisk in /etc/fstab to point to the new journaled device /dev/ad1.journal. Remember to also add async to the mount options, so they read rw,async instead of just the default rw.