Planning my next btrfs install: subvolumes, snapshots, and encryption
I'm switching to btrfs for the first time, mostly to take advantage of snapshotting system and config files so I can play around with some tweaks. I have some questions:
-
Although I've read that subvolumes are like partitions, I'm wondering what caveats or gotchas I should be aware of that I should consider before I start making subvolumes to replace all my partitions. I've read that people regret creating too many or too few subvolumes--why might they feel this way? For example, I see some people creating a subvolume for every top-level directory (/opt, /var, etc.), while others might only have the 2 subvolumes (/ and /home).
-
Why exactly are snapshots not backups (i.e. how are they different? How can they be less space than an actual copy itself?) If I have the current state and a snapshot at any point of that location, can I always restore it?
-
A snapshot is only applied on files of the same directory level, right? Meaning it doesn't snapshot all the contents of a directory recursively, but only the top-level stuff within that directory? How would one create a snapshot (or manage a bunch of snapshots) of all the config files that might be in different locations?
-
I have a 512 GB SSD and I currently plan on having 3 actual partitions--an EFI system partition because I use UEFI, an 8 GB swap partition because btrfs doesn't support swap files, and a 30 GB SSD btrfs system partition. That leaves over 400 GB of unallocated data I can use for whatever I want and that's the problem--I want to encrypt as much of my SSD as possible but I don't have current plans to utilize this space. For example, I might want to dual-boot Windows in the future, install a bunch of VMs on my system partition that is using btrfs (so I will need to expand the 30 GB). Is it possible to have everything to be encrypted now but still be able to create new partitions or expand on an existing partition (the btrfs one) while "keeping the drive encrypted" (i.e. without having the encrypt the entire drive again)?
About this post
- Posted
- Archived
- Score
- 35 · 100% up
- Kind
- Text
- ID
- 577vd4
15 comments
Subvolume are kinda like partition, but they share the space. On a 500GB hard drive with 2 subvolumes, both subvolume will have 500GB free. If I create a 1GB file in one, 1GB is marked as used for both (1/500 and 1/500). The only advantage that come to mind with multiple subvolume is snapshots.
When you make a snapshot, a new subvolume is created (AFAIK a snapshot is just a copy of a subvolume). You can then mount both individually (but usually you'll make a read only snapshot). Both the subvolume and the snapshot will share the sames files addresses on the hard drive, so not using more space. If you modify a file, a new copy will be made, the address on the RW subvolume will point to it. The snapshot will still point to the old address containing the old data.
A snapshot is applied to a subvolume. All files in it, recursively, will be snapshoted. BUT it doesn't make a snapshot of any subvolume in the subvolume being snapshoted. Yes, a subvolume can contain subvolumes along with normal files and directories. That probably why you read that it isn't recursive.
Probably, but I'm not sure how to expand a encrypted partition.
Be sure to disable Copy-On-Write (CoW) because by default btrfs doesn't overwrite the old data when you modify a file. It make a copy then switch the address. (Like a snapshot, but the snapshot keep the old address while the subvolume's address get updated).
Some others that might be worthwhile to some people:
quota groups are applied to subvolumes. You might want to do this as a last line of defense against a runaway process from filling up a disk with data of some sort, if you are running software where that might be a worry, or have some other reason for limiting the maximum size of a particular set of data.
it's not implemented yet, but eventually it will be possible to enable transparent compression per subvolume. You might choose to enable or disable it for some subvolumes (e.g. a subvolume with mainly files that are already compressed would not benefit from compression, but a subvolume with your log files or database stuff probably would)
subvolumes can be relocated more quickly than actually moving a directory (sorta like a bind mount), which might be useful occasionally
a nested subvolume will not be included in a snapshot of its parent, which also could be useful for some situations
Why would you want that in general? For specific files or applications with a high write-to-read ratio, that makes sense. But in general? For a desktop?
If some files get screwed up you can roll them back as though they were backed up. But if your harddrive catches fire or a magnetic wizard removes the data from the disk, your data is gone, unless it is backed up somewhere else.
So snapshots depend on the data it is a snapshot of and without it, they are useless? In other words, I can't install Arch on another system and restore a snapshot that was taken from my other system?
You can do that with
btrfs-sendandbtrfs-receive. Thing is, when you say "snapshot", you're referring to in-filesystem snapshots, which are an entirely different thing.I'm not sure what you're asking. A snapshot is exactly what it sounds like - a freeze frame of the data inside a subvolume at the exact moment the snapshot was taken. This exists at the filesystem level. It allows you to quickly revert those contents back to how they were at the time of the snapshot, because changes exist as deltas from the snapshot, like an overlay of changes.
I mean, technically speaking, you could indeed copy the snapshot to another system and use it there - a snapshot is really just another subvolume that's hidden "behind" the subvolume it's a snapshot of. But there's no magic to it, and you get no benefits from doing that as compared to just copying the files any other way.
It's not a backup because it exists on the same physical disk as the rest of the data. If that disk melts, your snapshot melted along with it, so it does you no good for that purpose.
Deleted before we saved it.
Anwering question 1: Firstly, they'll all be btrfs. You might not want that for eg. VMs, databases, etc.. Though it's also possible to disable COW on a file/directory on btrfs. And too many subvolumes may be a bother because of snapshotting, you'll have to do it for each subvolume separetely.
Question 2: Snapshots aren't backups because if there's some regression in the btrfs driver which corrupts your drive, or if your hard drive starts to fail, you just lost everything. So you shouldn't rely on it to keep your data safe.
Question 3: No, it applies to all files under that directory. That's the whole point of snapshotting. But it won't snapshot other subvolumes under it.
Question 4: Yes. You can just create the encrypted volume and btrfs partition the size you want, and both can be expanded later, it's pretty simple. See this for more details (Ubuntu wiki, but applies directly to Arch - there's a page for resizing LV-on-LUKS on the Arch wiki, but it's pretty bad and is only correct for shrinking, since enlarging requires you to do it in the inverse order).
I've always been led to believe that swap on a ssd is a bad idea. That said, I rarely would end up even using swap in my use, so it wouldn't really be wearing the drive.
Also, this thread has been a good read, I'm looking to do btrfs and snapshots on my next install.
It's not about wearing, it's about swap partitions ot having TRIM support
What about swapfiles? Is that supported under TRIM?