This week we’re joined by FreeBSD & OpenZFS developer, Allan Jude, to learn all about FreeBSD. Allan gives us a brief history of BSD, tells us why it’s his operating system of choice, compares it to Linux, explains the various BSDs out there & answers every curious question we have about this powerful (yet underrepresented) Unix-based operating system.
Allan Jude: ZFS and OpenZFS are licensed under the CDDL, which is a slightly modified version of the Mozilla Public License. And so the CDDL says - I’m not a lawyer; don’t take my legal advice. But in general, the license says that you can make a binary out of CDDL license code, and you can license that binary however you want, so that you can make a product out of it, or whatever. And so you can make a ZFS binary, a kernel module, or whatever, and license that even under the GPL, so it’d be compatible to integrate it into the Linux Kernel. But the GPL itself requires that any code you link into it has to be licensed under the GPL and the CDDL. It doesn’t let you just change the license on that code to be under the GPL. And so that’s where that kind of incompatibility comes in. But it’s not a very strong one, and Ubuntu is pretty sure that their legal way around it is working.
But because the FreeBSD license is literally two sentences, “Don’t take off the copyright” and “Reproduce the copyright”, it means that we could pull in all of ZFS, the codebase directly into FreeBSD. So if you go to the FreeBSD GitHub and the repo, under syscontrib there’s a directory called OpenZFS that has a whole copy of the ZFS source code. So this means ZFS is completely just built into FreeBSD. So the FreeBSD bootloader has full support for reading from a ZFS pool, and so you can boot directly off ZFS, even if you’re using all the advanced features of ZFS. So this allows a feature called boot environments, where your root filesystem, if it’s ZFS, it’s actually a virtual file system, and you can have multiple different ones, or you can clone it and take snapshots. So when I’m preparing to go to a conference or something, I have my laptop that runs FreeBSD, that I give my presentations off of, and I use a desktop most of the time when I’m at home… So I haven’t used my laptop much in the months between conferences. So I’m going to update the OS, because it’s been a while, but that’s when everything has the greatest chance to break, when you’re installing all these package updates, and so on.
So with ZFS I can take a snapshot of my root filesystem, and save that as “Before I broke everything.” And then update stuff. And it all seems to work. And I check at home, and I can play stuff on the TV, so my HDMI is working, everything’s fine. But say I fly to the conference, I get there, and something isn’t working right. I can just reboot in the bootloader, say “Hey, I want to use the image of before I broke everything, instead of the latest version of FreeBSD.” And it will roll back my root filesystem. But, importantly, it doesn’t roll back my home directory. So I still have the latest version of my slides, but I have an older version of my OS that still works, because whatever latent problem I found, that ex Windows didn’t want to support a certain resolution, or whatever broke. And so that can be really powerful.
Or if you’ve ever tried to update the firmware or the OS on like a little router or something, they often have two images; they always have like the one-year update, and then there’s like a spare one [unintelligible 00:31:15.20] switches to this, so that if you somehow botch the firmware update, they have a second firmware they can boot from in the meantime. So FreeBSD had a feature like that before it had ZFS called NanoBSD, that let you do that. You’d partition up your disk into two big partitions and one little one. And the little one would hold the configuration, and the two big ones would be like version A and version B of whatever you’re trying to install, whether it was a firewall, or a router, or whatever. And you’d be running off A, so you’d update B, and the next time you’d boot you’d switch to B, and then you can ping pong between these two images. But ZFS allows you to do that with an unlimited number of images. Because each is just this virtual file system in the pool, you can have as many of these as you want, and you can access them directly from the bootloader and decide which one you want to use.
[00:32:01.16] And when you’re switching to one, it doesn’t make the other ones go away. All the data is still there, because ZFS is copy on write, so only the bits you actually changed are taking space. So having seven copies of your operating system doesn’t take that much space, because you only have to store the differences, not all of the data seven times. And so that allows much deeper integration.
But also, if we go back – when we talked about the fact that the base system utilities, like top, for example, are not a separate package that came from a different maintainer somewhere. That is part of the FreeBSD operating system. So when you start top on FreeBSD, under the line where it tells you about how much free memory you have, it has two lines about ZFS, telling you “This is how much of your memory is being used by the [unintelligible 00:32:43.04] this much is for frequently used files, this much is for recently used files, and this much is data that’s pending being written. Here’s what your compression ratios are, and memory”, and all this other information that would only be there if you had ZFS. And because FreeBSD is integrated with ZFS, top can just be compiled against the version of ZFS [unintelligible 00:33:02.19] and be able to get that information all integrated.