Although ext4 external journal gives nice performance boost it is not trivial to implement due to some caveats.
First problem is persistence of journal device. On GNU/Linux systems
with multiple hard disks device assignment is done in random order.
There is no guarantee that /dev/sda
will map to the same device on
next reboot unless you introduce a custom udev rules. ext4 do not
understand UUID so external journal must be placed only to
persistent device that do not change on every reboot.
Our solution is to create "linear" mdadm device and put ext4 journal
to one of its partitions. The only inconvenience of this method is that
(re-)partitioning of mdadm devices may require reboot. It is important
to create mdadm device using --metadata=1.0
to put metadata to the
end of device in order to avoid suboptimal alignment.
Second very obscure problem is that default mount options will not work
with external journal: journal_async_commit
mount option must be used
if ext4 journal is placed to another device. Without
journal_async_commit
ext4 partition will eventually become read-only.
This may happen after hours in operation or sooner following heavy IO.
Apparently external journal can't be updated in synchronous manner so
sooner or later ext4 switches to read-only mode following journal commit
error. When this happen an offline file system repair i.e. fsck
will
be required to recover.
Worth mentioning that although external journal uses little bandwidth it is often written so only industrial quality SLC Solid-Stade drives are suitable for external journal unless you decide to use a fast rotational device for that matter.
When the journal device is lost:
Remove invalid journal:
tune2fs -O ^has_journal /dev/ext4-device
and run fsck
to check/repair file system.
Internal journal can be created with the following command:
tune2fs -O has_journal /dev/ext4-device
.
To create ext4 external journal
First format a dedicated partition for ext4 journal:
mke2fs -O journal_dev /dev/ext4-journal-device
Then remove internal journal as described above and make it again:
tune2fs -J device=/dev/ext4-journal-device /dev/ext4-device
New file system can be created as easy as follows:
mkfs.ext4 -J device=/dev/ext4-journal-device /dev/ext4-device
Conclusion:
Knowing the above caveats it is easy enough to activate external journal
on ext4. Remember to use persistent device for external journal and
always mount with -o journal_async_commit
if ext4 is configured with
external journal.