Saturday, January 31, 2009

Since I have been in an experimental mood lately, I convinced myself to redo the /home partition on my FreeBSD machine to enable journaling. It went pretty smoothly, though since the disk was fully partitioned, it did mean doing a dump and a restore. Fortunately, though /home is relatively large, it doesn't have much stuff in it, so a dump of it fit in the free space on /usr (if this hadn't been the case, I would have just used an external disk over USB). So here's what I did:

1. Boot into single user mode.

2. fsck -p && mount -a

3. umount /home

4. dump 0af /usr/home.dump /home

Now, at this point we're actually going to destroy the existing /home partition, so make sure the dump worked correctly first. In this case, my home partition was on /dev/ad0p5.

5. gjournal load

6. gjournal label -f /dev/ad0p5

I didn't bother specifying a -s argument, so the default journal size of 1 GB will be in effect.

7. newfs -J -L home /dev/ad0p5.journal

8. At this point, /dev/ufs/home should reappear. Edit /etc/fstab and find the line that mounts /home and change 'rw' to 'rw,async' since with journaling enabled we'll be using an asynchronous mount.

9. mount /home . Now type 'mount' and make sure that both 'asynchronous' and 'journal' show up in the list of mount options for /home.

10. cd /home && restore -rf /usr/home/dump

11. Edit /boot/loader.conf and add a line that says geom_journal_load="YES"

12. reboot.

So why bother? Because now /home will not need to have an fsck performed on it ever again.