While browsing the ZFS man page recently, I made an interesting discovery: ZFS can export block devices from a zpool, which means you can separate "ZFS the volume manager" from "ZFS the filesystem". This may well be old news to many; however I haven't seen many references to this on the web, so thought I'd post a quick blog update.
The example used in this post is the creation of a mirrored zpool which is then used to create a block device, on top of which I'll create a UFS filesystem. The reasons for doing this are many and varied : you may have an application that needs UFS (particularly forcedirectio); you may need to create a block device for some reason but all your storage is currently tied up in zpools; or you just need a quick block device to use for testing.
Using ZFS as a volume manager also has it's advantages over something like SVM (formerly "DiskSuite"). The management features are much improved (along with a browser-based GUI, if that's your thing) and you also gain access to ZFS features which operate at the volume manager layer and aren't dependant on the filesystem parts of ZFS. This includes features such as end-to-end error checking and recovery, along with snapshots.
Read on for the full update...
First, as I don't have any spare disks available, I'll create some files to use as pseudo disks. One of the many cool things about ZFS is that you can use it on anything from files like this for testing, to USB keyfobs, to honking great storage arrays. As a proof of concept, all I need is a couple of 100Mb files, which I'll then use to create a ZFS mirrored pool. I don't actually gain any redundancy here, but you can see how this could be used in a real-life scenario :
[mark@solaris:~] # mkfile 100m disk1 [mark@solaris:~] # mkfile 100m disk2 [mark@solaris:~] # sudo zpool create test mirror $PWD/disk1 $PWD/disk2
Now we can see the "test" pool is online and view it's status :
[mark@solaris:~] # zpool list NAME SIZE USED AVAIL CAP HEALTH ALTROOT test 95.5M 52.5K 95.4M 0% ONLINE - [mark@solaris:~] # zpool status test pool: test state: ONLINE scrub: none requested config:
NAME STATE READ WRITE CKSUM test ONLINE 0 0 0 mirror ONLINE 0 0 0 /export/home/mark/disk1 ONLINE 0 0 0 /export/home/mark/disk2 ONLINE 0 0 0
errors: No known data errors [mark@solaris:~] # zfs list NAME USED AVAIL REFER MOUNTPOINT test 75.5K 63.4M 24.5K /test
So I have around 63Mb to play with. Right now, I could just proceed as normal and create a few ZFS filesystems, but instead I'll create a block volume. This is done by using the "-V" flag with "zfs create", and specifying a size for our block device :
Now we've got our snapshot, we can delete that "testfile", as it's safely on the snapshot. The process of taking the snapshot created another block device under /dev/zvol, which can be mounted read-only :