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.

  1. Create a 1GB file somewhere on your SSD:
    • fallocate -l 1G zil.img
  2. Mount the file as a loopback device:
    • sudo losetup -fP zil.img
  3. Find the name of the new loopback device:
    • losetup -a
  4. Add the new loopback device to your pool:
    • sudo zpool add your_pool log /dev/loop123
  5. Wait a few moments and then check it has been added using:
    • zpool status
  6. 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.


Share this post on…

  • Mastodon
  • Facebook
  • LinkedIn
  • BlueSky
  • Threads
  • Reddit
  • HackerNews
  • Lobsters
  • WhatsApp
  • Telegram

What are your reckons?

All comments are moderated and may not be published immediately. Your email address will not be published.

Allowed HTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <p> <pre> <br> <img src="" alt="" title="" srcset="">