Creating an Adhoc File-Backed ZFS-Volume
Mounting a disk-spanning, logical volume with ZFS on top of existing filesystems
In order to run another backup for a dying NAS system, I recently found myself in need of some 700 Gigs of free space to copy files to. A FreeBSD system had 650 GB available, but that left me at least 50 GB short - plus another 50 GB in order to not clog up all of the root partition.
I had a spare 250 GB harddisk laying around. It was old but it would do for the
few days I was planning to keep the backup on that machine, so I hotswapped it
into the machine, ran
newfs and mounted it into that system’s VFS.
I had 600 + 250 = 850 GB disk space available then, but on two separate filesystems. I probably could have created a few symlinks at this point, but that felt too manual and I didn’t know how rsync (the backup tool of choice) would handle that.
The Last Word in Filesystems
Enter ZFS. I’ve heard all the praise, but safe playing with FreeBSD Jails on ZFS using ezjail where I basically just copied stuff from the Interwebs, I had no prior first hand experience. I’m certainly not doing ZFS’ capabilities proper justice since I’m only interested in its logical volume management here (I really like Linux’ LVM and its fancy GTK2 GUI but alas, no Linux machine available).
I wanted to create a logical volume on top of two existing UFS mounts. Much to my surprise, it was super easy!
ZFS On Disk Images
Start by creating sparse images – one 600 GB, the other 200 GB – on the respective mounted filesystems (output omitted):
I could have created a ZFS on one of the two hard disks (or their partitions/slices), but erasing / resizing the other was not an option and so I decided to be symmetric on that one.
The next and already last step is to create a volume backed by these image files:
The new filesystem is mounted as
/zvol0 (or whatever you passed to
zpool list gives you details about your newly created volume.
See the zpool docs for
additional available commands like adding devices to glue even more disk space
onto your logical volume.
Now, obviously creating a filesystem on top of another one isn’t made for high-performance file access (if nothing else, you add an unnecessary level of indirection when accessing the physical media) but it helped me combining free disk space on several hard disks into one filesystem and it’s a great and save way of playing around with ZFS.
Btw, everything should work with Linux as well but I don’t know which distros support ZFS or what you’ll have to do to make it work. FreeBSD ships with ZFS support out of the box. You can even make ZFS your root filesystem … which is something I really wanna do once I have become more familiar with ZFS.comments powered by Disqus