You are not logged in.

#1 2021-04-19 20:30:16

Durden
Member
Registered: 2011-06-19
Posts: 261

[solved] Understanding BTRFS and subvolumes

Hello there,

I have a partition layout that's basically just a / as btrfs and no subvolumes. I also have another system disk mounted as /mnt/data and btrfs with no subvolumes.

I've been trying to wrap my head around subvolumes and how they work and had a question about a root subvolume. Would I be able to set a root subvolume at / and mount it via the fstab and kernel params without having to reinstall the system?

Reading: https://wiki.archlinux.org/index.php/Btrfs#Subvolumes

It sounds almost like I can but I'm probably struggling a little bit on the whole concept of subvolumes. Mostly my interest here is in snapshotting and maybe using the Timeshift backup application to do some backups using the btrfs filesystem functionality. Any advice or even tutorials you may have would be greatly appreciated. Thanks!

Last edited by Durden (2021-04-20 13:30:43)

Offline

#2 2021-04-19 23:42:22

ratcheer
Member
Registered: 2011-10-09
Posts: 912

Re: [solved] Understanding BTRFS and subvolumes

First, you need to understand that a btrfs root subvolume is not the same thing as a Linux / mount point. Every btrfs filesystem has a root subvolume, which is ID level 5 in btrfs. It can also be addressed as ID 0, but it's really ID 5. All other btrfs subvolumes are subvolumes of this btrfs root subvolume.

I suspect you are asking about the Linux root subvolume, or / in Linux. And, to complicate things further, / can be in the btrfs root subvolume, or it can be a subvolume of it.

You need to understand this difference so you don't become confused by it.

Anyway, there is pretty good documentation at https://btrfs.wiki.kernel.org/index.php/SysadminGuide

My advice is to use the "flat" subvolume layout that is described in that guide, in which every subvolume you create is a direct child of the btrfs root subvolume. It is not necessary to use a flat layout, but it helps keep things manageable.

Last edited by ratcheer (2021-04-19 23:43:00)

Offline

#3 2021-04-20 10:11:02

adventurer
Member
Registered: 2014-05-04
Posts: 119

Re: [solved] Understanding BTRFS and subvolumes

If you want to use Timeshift it's important to note that it requires "an Ubuntu-type subvolume layout (with @ and @home subvolumes)."

You don't need to reinstall your system. Let's assume that your BTRFS root partition is /dev/sda2. In order to create a @ subvolume and several other subvolumes the following procedure should work:

sudo mount /dev/sda2 /mnt
sudo btrfs sub create /mnt/@
sudo btrfs sub create /mnt/@home
sudo btrfs sub create /mnt/@cache
sudo btrfs sub create /mnt/@log
sudo btrfs sub create /mnt/@tmp

... whatever ..

sudo umount /mnt

Then add the following entries to your fstab:

UUID=xyz /              btrfs   subvol=@,defaults,noatime,space_cache,autodefrag,compress=zstd 0 1
UUID=xyz /home          btrfs   subvol=@home,defaults,noatime,space_cache,autodefrag,compress=zstd 0 2
UUID=xyz /var/cache     btrfs   subvol=@cache,defaults,noatime,space_cache,autodefrag,compress=zstd 0 2
UUID=xyz /var/log       btrfs   subvol=@log,defaults,noatime,space_cache,autodefrag,compress=zstd 0 2
UUID=xyz /var/tmp       btrfs   subvol=@tmp,defaults,noatime,space_cache,autodefrag,compress=zstd 0 2

Needless to say, that you should replace xyz with your real UUID for your BTRFS partition which you can find with sudo blkid.

Execute sudo mount -a and sudo btrfs sub list / which displays your new subvolumes.

Last edited by adventurer (2021-04-20 10:12:07)

Offline

#4 2021-04-20 13:30:30

Durden
Member
Registered: 2011-06-19
Posts: 261

Re: [solved] Understanding BTRFS and subvolumes

Thanks ratcheer and adventurer! Very helpful!

Offline

#5 2021-04-20 21:12:21

Cvlc
Member
Registered: 2020-03-26
Posts: 273

Re: [solved] Understanding BTRFS and subvolumes

adventurer wrote:
UUID=xyz /              btrfs   subvol=@,defaults,noatime,space_cache,autodefrag,compress=zstd 0 1
UUID=xyz /home          btrfs   subvol=@home,defaults,noatime,space_cache,autodefrag,compress=zstd 0 2
UUID=xyz /var/cache     btrfs   subvol=@cache,defaults,noatime,space_cache,autodefrag,compress=zstd 0 2
UUID=xyz /var/log       btrfs   subvol=@log,defaults,noatime,space_cache,autodefrag,compress=zstd 0 2
UUID=xyz /var/tmp       btrfs   subvol=@tmp,defaults,noatime,space_cache,autodefrag,compress=zstd 0 2

Hi !

shouldn't the Fsck values be 0 instead of 2 in the above fstab ?

Offline

#6 2021-04-21 09:29:04

adventurer
Member
Registered: 2014-05-04
Posts: 119

Re: [solved] Understanding BTRFS and subvolumes

Cvlc wrote:

shouldn't the Fsck values be 0 instead of 2 in the above fstab ?

Good catch! Thanks!

Offline

Board footer

Powered by FluxBB