ZFS - how to use a file as a ZIL
ZFS sometimes benefits from having a logging drive. Usually, you need to assign a whole device or partition to it. Unfortunately, I had already partitioned my SSD and didn't feel like repartitioning it.
So, here's how to create a file, mount it as a loopback, and then assign it to your ZFS pool as a logging drive.
- Create a 1GB file somewhere on your SSD:
fallocate -l 1G zil.img
- Mount the file as a loopback device:
sudo losetup -fP zil.img
- Find the name of the new loopback device:
losetup -a
- Add the new loopback device to your pool:
sudo zpool add your_pool log /dev/loop123
- Wait a few moments and then check it has been added using:
zpool status
- Note - the loop won't be recreated after a reboot, so your ZFS will be a bit grumpy. Remove it with:
sudo zpool remove data loop123
Is there any point in doing this? No, not really. In my brief experiments it didn't make any appreciable different to the speed of my writes. Your use-case may be different though.