You are not logged in.

#1 2011-02-04 02:05:19

ANOKNUSA
Member
Registered: 2010-10-22
Posts: 2,141

Clarification on Btrfs Subvolumes

Howdy-ha, folks.  So, I just got myself a new Western Digital Advance Format HDD for my laptop.  While I first considered cloning my current drive, I decided instead to just reinstall by backing up/restoring the pacman cache, first formatting the drive as Btrfs.  I've hit a snag, though, because despite reading through the Brtfs wiki FAQ, Use Cases and Getting Started entries word-for-word (twice, even), the Arch wiki entry on Btrfs and searching the forums I can't quite wrap my head around subvolumes.  I understand that the general idea is to do away with multiple, partially-full partitions, but I can't figure out how subvolumes are mounted and used as an analog to partitions.

I plan to use Archboot to install, and up to this point have had separate partitions for /root and /home.  In order to mimic this with Btrfs, would I simply create two subvolumes at installation time--one for root to allow for snapshots, and one for my Home folder?  Would these actually be mounted in theoretically the same way as separate partitions?  I like to tinker, and 'till now have just used clonezilla to back-up my /root partition if something went wrong, leaving /home untouched.  Sorry, but I can't figure out how this might be done, as the wiki simply explains how to create a new subvolume in a certain location and mount it manually (since it isn't a new filesystem, it doesn't need an fstab entry); and how to delete a subvolume.  It also seems that the examples used in the Btrfs wiki are for an external device, which just seems to obfuscate things.  I'd really appreciate the help of someone experienced in this or a point in the right direction, though I suppose I could also just create two separate Btrfs partitions if I can't figure it out.  Thanks.

Offline

#2 2011-02-05 09:10:18

extofme
Member
From: here + now
Registered: 2009-10-10
Posts: 174
Website

Re: Clarification on Btrfs Subvolumes

think of the main/root FS (the one created by mkfs) as a "disk pool", like LVM or ZFS.  from this pool, you may carve out as many "subvolumes", ie. sub-filesystems, as you like, all sharing the same disk space/pool, yet each may be independently mounted, with their own mount options, and used in any way you wish.

the main/root FS (the "btrfs root") has an id of zero (subvolid=0).  as you create subvolumes, each one gets their own id, starting with 256:

$ btrfs subvolume list /
ID 260 top level 5 path .vols.260.fs
ID 261 top level 5 path .vols.261.fs
ID 262 top level 5 path .vols.262.fs

these subvolumes can be mounted by id (no matter where the actually are):

$ mount -o subvolid=260 <btrfs_device> /mnt

or by name (ONLY if they reside in the btrfs root; CANNOT be nested in directories):

$ mount -o subvol=.vols.260.fs <btrfs_device> /mnt

currently, only syslinux can boot from a btrfs /boot device, and ONLY if the kernel is in the btrfs root, ie. the kernel CANNOT be in a snapshot/subvolume.

subvolumes and snapshots are EXACTLY the same thing.  the only difference is a subvolume starts empty (explicitly created), and a snapshot starts non-empty (by using an exisint subvolume as a "base").  after a snapshot is taken, it's completely independent, and not tied to it's "base" in any way.

this is more advanced, but this wiki details the process of setting up a single device:

https://wiki.archlinux.org/index.php/In … Btrfs_root

i wrote much of it, and just followed it 2 hrs ago, so it should work fine.  if you just want to use subvols for different mount points, create a new one, get it's id or name, then mount it with the appropriate option (subvol=XX or subvolid=XX).  you may also use other mount options like ssd or compression if you wish on a per mount basis.  `man btrfs` for how to accomplish this.

C Anthony


what am i but an extension of you?

Offline

#3 2011-02-05 20:57:13

ANOKNUSA
Member
Registered: 2010-10-22
Posts: 2,141

Re: Clarification on Btrfs Subvolumes

Thanks, extofme.  This is still unfamiliar and so still a little confusing, but I think you've helped me along.  Two follow-ups:

1) It looks like subvolumes can be mounted by placing <subvol=xx> in the kernel line for GRUB; is that correct, or does this only apply to GRUB's root so it can find the kernel image? (I plan on using EXT2 for /boot, because I intend to trying to use an extra SD card for my boot partition smile )

2) Given that snapshots are essentially copies of the specified subvolume, is it necessary that the destination for the snapshot (in my case, an external drive) be formated to Btrfs?  Or would the fact that it's "not tied to its base in any way" work around this?

Thanks again for the help; I plan on working on this once I get back home.

Last edited by ANOKNUSA (2011-02-13 21:38:52)

Offline

#4 2011-02-13 21:41:21

ANOKNUSA
Member
Registered: 2010-10-22
Posts: 2,141

Re: Clarification on Btrfs Subvolumes

So as I write this, I think I may have found a solution to the first question, and have a functional system.  I used Archboot to install this setup:

$ btrfs sub li /
ID 256 top level 5 path root
ID 257 top level 5 path home

Which, when viewed from a LiveCD, looks essentially like this:

__actual root__
   |__subvbolume "root"
   |__subvolume "home"

Each of these is mounted via fstab in the respective part of the file system--or at least it seems so:

#/etc/fstab: static file system information
#
# <file system>        <dir>         <type>    <options>          <dump> <pass>
devpts                 /dev/pts      devpts    defaults            0      0
shm                    /dev/shm      tmpfs     nodev,nosuid        0      0
# DEVICE DETAILS: /dev/sda1 UUID=28a77746-673e-482c-b037-3eea590c0b14 LABEL=Boot
# DEVICE DETAILS: /dev/sda2 UUID=7caf3bbf-0d2c-4961-8693-962ebc365f20 LABEL=Arch
# DEVICE DETAILS: /dev/sda2 UUID=7caf3bbf-0d2c-4961-8693-962ebc365f20 LABEL=Arch
# DEVICE DETAILS: /dev/sda3 UUID=f6e8ba7e-0cae-429d-9a2b-e4bdf5d8be7d LABEL=Swap
LABEL=Arch / btrfs defaults,subvol=root,compress 0 1
LABEL=Arch /home btrfs defaults,subvol=home,compress 0 1
LABEL=Boot /boot ext2 defaults 0 1
LABEL=Swap swap swap defaults 0 0

This results in a seemingly ordinary filesystem when I'm logged into my desktop:

 /
├── bin
├── boot
├── dev
├── etc
├── home
├── lib
├── lib64
├── media
├── mnt
├── opt
├── proc
├── root
├── sbin
├── srv
├── sys
├── tmp
├── usr
└── var

/home
└── anoknusa
    ├── ABS
    ├── Desktop
    ├── Documents
    ├── Downloads
    ├── Music
    ├── Pictures
    ├── pkglist
    ├── Stuff
    ├── Torrents
    └── Videos

So, at this juncture I have what appear to be two separate snapshots mounted at separate points in order to create a single filesystem, just as I would had I mounted to separate partitions, and I'm left only wondering about the second question.

I'm still not entirely clear whether this will give me the desired effect.  Each subvolume rests at the same level of the fs tree; they're side-by-side, rather than having the "home" subvolume under the "root" subvolume.  Again, what I'm hoping for is the ability to take snapshots of "root" and "home" separately--as one would with separate partitions--so that taking a snapshot of "root" won't end up with my entire drive under it, and I can tinker without worrying about whether or not I'll have to spend two hours restoring a snapshot every few days.  I'm not sure if this would work while both snapshots are mounted, so I'm planning on testing this once my backups are done copying to my ~/  folder (I'm really no good when it comes to visualizing this sort of thing, and need to either see it in action or be told that it's gonna work by someone who's done this before). Hopefully, this works out as planned.  Any more advice from anyone would be greatly appreciated; thanks again.

Offline

#5 2011-02-14 16:41:11

extofme
Member
From: here + now
Registered: 2009-10-10
Posts: 174
Website

Re: Clarification on Btrfs Subvolumes

ANOKNUSA wrote:

I'm still not entirely clear whether this will give me the desired effect.  Each subvolume rests at the same level of the fs tree; they're side-by-side, rather than having the "home" subvolume under the "root" subvolume.  Again, what I'm hoping for is the ability to take snapshots of "root" and "home" separately--as one would with separate partitions--so that taking a snapshot of "root" won't end up with my entire drive under it, and I can tinker without worrying about whether or not I'll have to spend two hours restoring a snapshot every few days.  I'm not sure if this would work while both snapshots are mounted, so I'm planning on testing this once my backups are done copying to my ~/  folder (I'm really no good when it comes to visualizing this sort of thing, and need to either see it in action or be told that it's gonna work by someone who's done this before). Hopefully, this works out as planned.  Any more advice from anyone would be greatly appreciated; thanks again.

no, snapshots are not recursive.  even if home was physically under root (you could simply `mv` it there, subvols can be nested, but then it could only be mounted by id) it still would not be recursive; ie. snapshots are one subvol only, so it should do what you want.

to elaborate on your other post... yes the snapshot "receiver" needs to be a btrfs filesystem.  if fact it must be the SAME btrfs filesystem.  snapshots are local to the filesystem they are created from.  im not really knowledgeable here, but basically a btrfs filesystem is a set of various btrees for metadata, data, and other things like logs/fsync.  ALL of these trees are shared between subvolumes, except one; the subvolume tree itself.  probably not prefect but the jist of it is 80% is shared.

to maybe put it in frame better... subvolumes/snapshots are really more like namespaces than independent filesystems.  they act like filesystems.  they mount like filesystems.  but they are very much tied to the main filesystem that created them... but they are NOT tied to other subvolumes on the same FS.

make sense?

C Anthony


what am i but an extension of you?

Offline

#6 2011-02-14 17:45:26

ANOKNUSA
Member
Registered: 2010-10-22
Posts: 2,141

Re: Clarification on Btrfs Subvolumes

I believe so; it looks likes what I've got is what I want, and this last bit of info should be everything I need.  For the time being, it seems leaving "home" where it is won't cause any problems, so I won't bother physically moving it.  Most of the literature suggests--though it doesn't plainly say--that snapshots need to be placed elswhere in the same fs (~/Snaps, for example); however, it also seems that snapshots are essentially bundles of metadata that function in a (kinda) similar way to an rsync backup.  That is, the snapshot is essentially a bare-bones backup that only notes changes in the source subvolume, and therefore doesn't take up anywhere near the space a complete copy would.  Not a great analogy, but it's a start.  In any case, I'll just be backing up the "root" subvolume, with my home folder being backed up with backintime, so everything looks good. 

Of course, in the time between my last post and yours, I've managed to bork part of my installation, but since this isn't my production drive (yet) it's no big deal; I'll just deal with it this weekend. tongue  Thanks again, dude; once everything's up an running and I have a little experience, maybe I'll look into expanding the wiki.

Offline

#7 2011-02-14 17:59:19

extofme
Member
From: here + now
Registered: 2009-10-10
Posts: 174
Website

Re: Clarification on Btrfs Subvolumes

ANOKNUSA wrote:

... the snapshot is essentially a bare-bones backup that only notes changes in the source subvolume, and therefore doesn't take up anywhere near the space a complete copy would ...

im not an expert at this level by any means, but i just want to note that this is not the case; any shared data between volumes has no prejudice between "original" and "snapshot", and there is no comparing/bookkeeping.  it's more like a hardlink (it's actually a --reflink, see `man cp`); there is no "original", multiple inodes simply reference the same data until one decides to alter it.

i believe all the data for every subvolume is actually in one tree (the `extent tree` https://btrfs.wiki.kernel.org/index.php/Data_Structures)... FS/subvols are like a huge tree of symlinks into that data tree.

... for clarity's sake :-)

C Anthony

Last edited by extofme (2011-02-14 18:00:00)


what am i but an extension of you?

Offline

#8 2011-02-14 18:23:17

ANOKNUSA
Member
Registered: 2010-10-22
Posts: 2,141

Re: Clarification on Btrfs Subvolumes

extofme wrote:
ANOKNUSA wrote:

... the snapshot is essentially a bare-bones backup that only notes changes in the source subvolume, and therefore doesn't take up anywhere near the space a complete copy would ...

im not an expert at this level by any means, but i just want to note that this is not the case; any shared data between volumes has no prejudice between "original" and "snapshot", and there is no comparing/bookkeeping.  it's more like a hardlink (it's actually a --reflink, see `man cp`); there is no "original", multiple inodes simply reference the same data until one decides to alter it.

i believe all the data for every subvolume is actually in one tree (the `extent tree` https://btrfs.wiki.kernel.org/index.php/Data_Structures)... FS/subvols are like a huge tree of symlinks into that data tree.

... for clarity's sake :-)

C Anthony

Right on.  I think I mistakenly substituted "rsync" for "cp," but hardlinks were precisely the analogy I had in mind.  Again, I'll need to play around until it's all clear, but you've given me enough to work with.  Thanks a lot!

Offline

#9 2011-08-24 08:57:49

gour
Member
From: Croatia
Registered: 2007-07-28
Posts: 67

Re: Clarification on Btrfs Subvolumes

extofme wrote:

currently, only syslinux can boot from a btrfs /boot device, and ONLY if the kernel is in the btrfs root, ie. the kernel CANNOT be in a snapshot/subvolume.

What would be optimal/recommended setup for two hard disks in mirror mode:

1) having one btrfs (/ & /boot) partition + separate swap partition per disk where former mirror is done via btrfs' raid and the latter via mdadm (linux raid) or

2) having one btrfs partition (/) + separate partitions for swap & /boot per disk where 1st mirror is one via raid in btrfs and another via mdadm for swap & boot?



Sincerely,
Gour

Offline

Board footer

Powered by FluxBB