Notes on FreeBSD UFS partition schema Jun 1 2020

Sometimes deciding on a partition schema could be a confusing, here are my notes on partitioning a GPT disk. I hope you find them useful.

I will advice creating a virtual machine using FreeBSD and take it for a spin. It would be nice if we had lots of physical devices we could work with to gain more experience, but a virtual machine will do.

Before we begin, make sure you have a copy of FreeBSD. You can download it from here. My architecture is amd64 so that’s what I’ll use.

Ok, let’s begin.

Partition schema

As you might know, I use Parallels on macOS to handle all my virtual machine needs. Parallels is user friendly and already provide basic setups for popular operating systems (Like Ubuntu, Debian, Windows, etc.), but they don’t have one for FreeBSD. That is ok because we are going to create a custom virtual machine, where we’ll practice partitioning our disk.

Launch Parallels and create a new virtual machine. You can go to the menu and click File > New ..., or click the plus sign on the top right corner on Parallels Control Center.

Now:

  1. Select “Install Windows or another OS from a DVD or image file”.
  2. Click continue.
  3. Select “Choose Manually”.
  4. Explore your file system in search for the FreeBSD12 ISO.
  5. Select the correct ISO, and you’ll see a message “Unable to detect operating system”. That’s ok
  6. Click continue.
  7. Select FreeBSD from the “other” category in the dropdown.
  8. Click ok.
  9. Name your Virtual Machine. I’ll call mine “FreeBSD 12 UFS”. You can name yours anything you prefer.
  10. Select where to save it and click create.

You’ll see your virtual machine start, but it’ll be stuck with an error. Stop your virtual machine by going into Actions > Stop on the main menu.

We need to make a change to the boot flags, so our virtual machine starts using EFI. Open settings for your virtual machine. Click in the settings, go to Hardware and select Boot Order.

Expand Advanced settings and add the following to Boot flags:

1
    vm.bios.efi = 1

We could also change the size of the virtual machine’s hard disk. Changing the size of your hard drive is optional, the virtual machine won’t use the 64GB (default) that has defined as the hard disk size. It’ll only use whatever space you are using.

Start your virtual machine and begin the installation.

When you get to partitioning, Let’s review our options.

We are going to do the partitioning manually. We are going to create the following partitions:

That means we are going to create six(seven if you create the dump partition) different partitions on our virtual disk.

But first, let’s discuss some details.

Why would we want to have separate partitions?

The simple reason is for organisation, but also data protection. If one filesystem gets corrupted, you’ll “only” lose that partition. It is also useful when you are updating the system to have the operating system and the userland separated. If we have them separated, we don’t have to rebuild userland software when we break our operating system, we just reinstall.

Another critical question is, what size should we make each partition?

Let’s talk about each of the partitions.

EFI

Type: efi

200MB should be enough for the boot manager for our GUID Partition Table (GPT) physical disk layout. I’m assuming we are using EFI. But I guess if you are still using MBR 512kb will suffice. The EFI partition is the one that your computer’s EFI(or BIOS if you are using MBR) will reach first for the system bootstrapping. From here it’ll jump to where you have a bootable operating system(e.g. your /boot ).

Swap

Type: freebsd-swap

Label: swap0

Some people used to recommend having at least the same swap size than the amount of physical memory but twice was often recommended. That is outdated advice. Now swap is mostly determined by the event when we want to do a full memory dump if there is a kernel panic.

If we follow that advice, the size still depends on what type of dumps are you planning on doing. If you need a full dump, set the same amount of physical memory. If you are using a minimal dump, it should be somewhere around 250MB and 1GB3. For our case, let’s go with the advice(by Michael W. Lucas) to set 1GB for every 10GB of physical memory.

/ (root partition)

Type: freebsd-ufs

Label: root

The root directory is small. It should only include the boot image and some files that don’t change often but are critical for the correct operation of the system. We can set it up to be 2GB. That should be enough for a few custom Kernels (My current Kernel sits at 67MB) plus configuration files, etc.

/tmp

Type: freebsd-ufs or maybe tmpfs

Label: tmp

Programs typically save temporary files in this partition. So it depends on the applications you run, but 500MB to 1GB should be enough.

/var

Type: freebsd-ufs

Label: var

This partition is referred by the FreeBSD Handbook as “Multi-purpose log, temporary, transient, and spool files”. So you could find mail, logs, printing queues, etcetera in this partition. You can also subdivide it. That means you can create a partition for /var/mail or another for /var/log, depending on your needs. In my current setup, I’ll just leave a “big” /var partition that encompasses all. I’ll just give it 5GB, that should be enough for my use.

/usr

Type: freebsd-ufs

Label: usr

In a typical installation here is where you’ll find the bulk of data. All your applications will be installed here and also your users’ home directory. You could also create a specific partition for users’ directory by creating a /home, but I’ll leave it under /usr/home. It is harder to calculate how much space to reserve for this partition. It’ll depend on your usage. If you build ports, you might need some additional space every time you download and build a new port. If your users store a lot of files, you’ll have to take that into account. I’ll just use the rest of my disk, in my case the reset of the 64Gb that Parallels assigns by default.

After setting up our partition, proceed with the installation. And test everything out.

Final Thoughts

It is difficult to define hard rules on the correct sizing of each partition. I would suggest creating a couple of virtual machines. Use different partition schemas, run some “development” environment where you can monitor the size of your partitions and see what works best for you. The advice in these notes is just a rule of thumb, but nothing serious or authoritative. There are probably hundreds of different possible workable schemas. This one is just the one I like at the moment.

Keep in mind what your goal is, or what your server is going to doing. For example, imagine we separate /home and /usr. And imagine that you like to build all your apps using ports instead of packages (LibreOffice and such). Every time you download all the code to build ports, you’ll need a couple of GBs, but once your build is complete, your need for space is less. So you could have defined a “big” /usr with 10Gb that you would only use while building the ports, then that space will be unutilised, maybe it’ll be better if you also shared that space with /home. In that case, having /home under /usr might be a better idea.

Something I didn’t mention was the use of labels, but you should use labels in your disks that will make referencing them much more easy.

You see, there are many considerations and many possible solutions, there is no one and only correct answer.

I hope this was useful.


  1. https://www.freebsd.org/doc/handbook/dirstructure.html 

  2. https://www.freebsd.org/doc/handbook/dirstructure.html 

  3. Reference from “Absolute BSD: The Ultimate Guide to Freebsd”, by Michael W. Lucas. You should really read this book. 


** If you want to check what else I'm currently doing be sure to follow me on twitter @rderik or subscribe to the newsletter. If you want to send me a direct message you can send it to derik@rderik.com.