JeffTP

Squandering a perfectly good opportunity to shut up and listen.

Linux Partitioning

Published: 2024-02-29 • Reading time: 6 min

#linux #nixos #sysadmin

I've been toying with a move from Windows 10 to Linux for my home gaming desktop for several months now. When it comes to Linux, I've relied on two distributions over the last decade or so: Ubuntu and Alpine Linux. Alpine Linux, in particular, I rely on when I'm building single purpose virtual appliances.

Recently, I've been experimenting with Arch Linux and NixOS. As I hop from distro to distro, I've become very familiar with partitioning disks. Determining how to divide up your storage feels like an evergreen topic. It was important back when I was installing FreeBSD 2.2.6, and it's important now. Or at least it feels important.

Here's some of my thoughts about partitioning a drive in preparation for installing Linux...

Logical Volume Manager

For years now, I have almost always used LVM when partitioning my Linux boxes. The exception to this is when I build a one-shot virtual appliance with no expectations of needing to change the disk layout. For example, I don't bother with LVM with my Wireguard VPN appliance built with an Alpine Linux.

I use LVM because of the promise of volume snapshots and easy partition resizing. I don't think I've ever actually used either feature. And yet, I still spend the time during Linux installation to create a physical volume, logical volume, and then volume groups before formatting the volume groups, mounting partitions, and installing Linux.

The reason I continue to use LVM even though I have not needed its features is that I fear I will need the features the moment I don't have them available. In backpacking, this is called packing your fears. You carry extra gear you never use "just in case." So far, the extra weight of LVM hasn't deterred me from packing it.

Filesystems

I almost exclusively use the ext4 filesystem on Linux. I've used XFS when setting up NFS servers or Veeam backup repositories, but otherwise my go-to filesystem is ext4.

I've stuck to using ext4 because it's been reliable for me. When there have been problems, fsck has always been able to repair the damage. I shy aware from btrfs because I worry that it won't be reliable and it will be slow. I shy away from zfs because it lives outside the mainline Linux kernel, and on a single drive it's probably overkill.

My reliance on ext4 rather than a more advanced filesystem is potentially misguided when you consider how the Synology NAS that I back up to is running btrfs. I willfully choose not to look too deep into how Synology is handling RAID and btrfs because some days it's easier to just let something be magic. If I stare too closely at my NAS, I may discover that my NAS one sneeze away from complete data loss.

My self-delusion that everything is magic inside the Synology NAS is foolish. I have had to deal with a complete data loss scenario just a few years ago due to a single drive failure cascading into a two drive failure. My solution was to rebuild the NAS with two drive failure tolerance. Surely a two drive failure couldn't lead to a three drive failure during rebuild, right? Right?

It's really tempting to experiment with zfs or btrfs but for now, I'll be sticking with old reliable ext4.

Selecting a Linux Distro

While Arch Linux offers the ability to build a very custom Linux install, I've decided I really want to get to know NixOS better. For those unfamiliar with NixOS, it is a Linux distribution unlike any other because of how it manages packages.

As I understand it, and my understanding is in its infancy at this point, NixOS installs packages into the Nix Store and links to those packages to build the running system. This linking mechanism allows you to rollback the system to earlier working installations by changing the links to a prior state.

Additionally, the entire configuration for your NixOS installation is stored within a central configuration file. In theory, you can rebuild your entire NixOS system from this configuration file.

One major downside to NixOS is that the Nix Store itself can grow to unwieldy sizes, because unless you perform garbage collection, no package you install is ever removed, it's just not linked to by your current system. An additional downside is that the Nix configuration language is a functional domain specific language that at first glance appears pretty user hostile.

I'm unable to shake the allure of a single configuration file. So I simply must experience NixOS to either discover I hate it, or to become a member of the cult that flits around the Internet looking down upon the other distros with disdain and their primitive package management.

Partitioning

Since I'm jumping into a completely new distro experience, I'm going to stick with a partitioning layout I'm familiar with. I'm going to use LVM and ext4. Now all that remains is figuring out the partitions we're going to lay out on the disk.

After searching, and reading, and thinking, and waiting for the whole month of February to make a decision, I'm finally prepared to commit to a path forward. This too short thread on the NixOS forums played a huge role in my decision: Partitions layout advice for NixOS during installation. My setup was also influenced by this initial host setup script by Tristan Maat.

All said, my partitioning scheme will break out /nix into it's own partition. This way I can mount the partition noatime as suggested in the Storage optimization article on the NixOS Wiki.

Assuming a single disk my plan is:

  • /dev/sda1 -- /boot, 1 GB, FAT32
  • /dev/sda2 -- (LVM vg1), the rest, LVM
    • /dev/vg1/swap -- (swap), 8G, swap
    • /dev/vg1/nix -- /nix, 50G, ext4
    • /dev/vg1/root -- /, the rest, ext4

I'm not breaking out /home to it's own partition yet. Normally I run with a single / so I'd like to see if NixOS is comfortable in this setup. If not, the theory is I can backup my NixOS config, blow everything away, and rebuild quickly from my config. Only time will tell how well theory matches practice!