My btrfs subvolume setup

Discussion in 'General Linux Discussion' started by Daerandin, Mar 17, 2021.

  1. Daerandin

    Daerandin Well-Known Member

    Joined:
    Oct 18, 2013
    Messages:
    1,157
    Likes Received:
    258
    Trophy Points:
    83
    Location:
    Northern Norway
    Home page:
    I've been using btrfs for a few years now, although I have not been making extensive use of the subvolume snapshot feature yet. Mostly I have had system root on one subvolume, and /home on another subvolume.

    If you are unfamiliar with what subvolumes are, you can think of them as hard drive partitions. They are not exactly partitions, but you mount them as partitions. They do share the same hard drive space, but are separate when mounted individually.

    However, a recent issue with a couple of package upgrades on Arch pushed me into setting up a bit more complicated setup with snapshots. The update issue I had turned out to not be that complicated, but just to ensure that I always have the ability to boot into a fully functional system to troubleshoot, I went ahead with this. First my subvolume setup:

    / - The root directory obviously needs to be a subvolume

    /home - home is kept separate on its own subvolume

    /var - mostly kept separate so that logs are consistent, and not different between my snapshots, this is also true for the package database

    /var/lib/pacman - This is required specifically for Arch's package manager

    Then I snapshot the root partition (/) and /var/lib/pacman, I also keep the kernel and initramfs that coincides with the version of the snapshot. I then have a separate boot entry which utilizes the snapshots instead of the main subvolumes. So if I boot up with the snapshots, my system will be at the state it was in when I took the snapshots. But all my files in /home are unaffected, meaning I would not lose progress in games.

    The reason for keeping /var/lib/pacman on its own subvolume has to do the Arch's package manager, pacman. The files here need to be in sync with the snapshot I take of root (/), so I need to snapshot this along with root. Otherwise, pacman would incorrectly detect the versions of installed packages and system.

    It gives me peace of mind that I can go back to an earlier state in case something goes wrong.
  2. booman

    booman Grand High Exalted Mystic Emperor of Linux Gaming Staff Member

    Joined:
    Dec 17, 2012
    Messages:
    8,339
    Likes Received:
    624
    Trophy Points:
    113
    Location:
    Linux, Virginia
    Home page:
    Once again... hardcore Linux at its best!
    Your setup reminds me of a Solaris Unix server I had to support when working at the newspapers back in 2011-2016.
    I am no Unix expert, so I had to contact vendors when something went wrong. But there were times when I had to SSH into it and us vi to edit a cron job or something on those lines.

    It had a bunch of partition-like volumes for everything...
    • /
    • /home
    • /var
    • /logs
    And others I couldn't remember. There were times when one of them would fill up and the database would halt completely. Everyone would call me and say "my software is locked up", but later I found that if someone ran a report that generated a loop of some kind, this would fill up that volume. Then the system would automatically empty it after 15 minutes.

    Most of my systems are one HHD and I partition only the following:
    • /boot
    • /
    • swap
    But in the future I would love to have two SSD's in each PC with the following partitions:
    • /boot
    • swap
    • /
    • /home
    I found this to be extremely valuable because I have almost 500GB of games on each PC. So in the scenario I need to restore, repair or even do a fresh install of Mint, I can do it without touching the /home drive so I don't have to install/copy all the games again.

    Linux is awesome!

    I know a lot of people are scared because its different and they don't know how to troubleshoot Linux, but once you get the hang of the basics, its very flexible and forgiving.

    You probably remember this post: Upgrading with Linux is Painless!
  3. Daerandin

    Daerandin Well-Known Member

    Joined:
    Oct 18, 2013
    Messages:
    1,157
    Likes Received:
    258
    Trophy Points:
    83
    Location:
    Northern Norway
    Home page:
    I do so completely agree that I love how you can customize and create solutions to tackle any scenario.

    Not to mention, I simply love doing this kind of thing.

    Btrfs subvolumes share partition space (when they are on the same partition of course), which means you only need to worry about space if the actual drive partition is filling up. You can create a limit on the storage space available to a subvolume, but personally I don't want to do it. Additionally, that is a feature that is not yet considered stable by the btrfs devs. Before I try out anything new with Btrfs I check the official btrfs wiki if a feature is considered stable and if there are any known gotchas to look out for.
    booman likes this.
  4. booman

    booman Grand High Exalted Mystic Emperor of Linux Gaming Staff Member

    Joined:
    Dec 17, 2012
    Messages:
    8,339
    Likes Received:
    624
    Trophy Points:
    113
    Location:
    Linux, Virginia
    Home page:
    When I install Mint as a fresh install, there is an LVM option instead of partitioning as ext4
    Is LVM similar to subvolumes?
  5. Daerandin

    Daerandin Well-Known Member

    Joined:
    Oct 18, 2013
    Messages:
    1,157
    Likes Received:
    258
    Trophy Points:
    83
    Location:
    Northern Norway
    Home page:
    An LVM partition can contain multiple other logical partitions and filesystems. LVM lets you be very flexible in that you could easily reallocate unused space on one partition to create a new partition. Not exactly like Btrfs subvolumes, but it gives you a lot of flexibility. In many cases where you might want to change your partitioning layout, using LVM can be make it easier as you can easily and safely resize existing partitions within the LVM container.

    LVM also lets you treat multiple hard drives as one large drive, as multiple hard drives can be part of a single LVM volume. LVM also supports snapshots, although I don't know how it works on LVM.

    But I want to point out that it is fundamentally very different from btrfs. Btrfs is a filesystem, like ext4. It just happens to have some different features. LVM is not a filesystem, but it can contain one or more virtual partitions that you can format with any filesystem you want.
    booman likes this.
  6. booman

    booman Grand High Exalted Mystic Emperor of Linux Gaming Staff Member

    Joined:
    Dec 17, 2012
    Messages:
    8,339
    Likes Received:
    624
    Trophy Points:
    113
    Location:
    Linux, Virginia
    Home page:
    Ah, thank you for the detailed information.
    I've always just partitioned with ext as explained before. I didn't use LVM because I didn't fully understand what it was doing.

Share This Page