finding root filesystem of a subvolume?
How do I find the root filesystem of a subvolume?
Example:
root@fex:~# df -T Filesystem Type 1K-blocks Used Available Use% Mounted on - - 1073740800 104244552 967773976 10% /local/.backup/home
root@fex:~# btrfs subvolume show /local/.backup/home
/local/.backup/home
Name: home
uuid: f86a2db0-6a82-124f-9a71-1cd4c20fd6fb
Parent uuid: ba4d388f-44bf-7b46-b2b8-00e2a9a87181
Creation time: 2017-08-10 22:19:15
Object ID: 383
Generation (Gen): 148
Gen at creation: 148
Parent: 5
Top Level: 5
Flags: readonly
Snapshot(s):I know, the root filesystem is /local, but who can I show it by command?
Signature · 6 lines
Ullrich Horlacher Server und Virtualisierung Rechenzentrum TIK Universitaet Stuttgart E-Mail: [email protected] Allmandring 30a Tel: ++49-711-68565868 70569 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ REF:<[email protected]>
Quoted 6 lines · Ulli Horlacher
How do I find the root filesystem of a subvolume?
Example:root@fex:~# df -T Filesystem Type 1K-blocks Used Available Use% Mounted on - - 1073740800 104244552 967773976 10% /local/.backup/home
I've never seen the "- -" output from df before. Is this a bind
mount or something?
Quoted 15 lines
root@fex:~# btrfs subvolume show /local/.backup/home
/local/.backup/home
Name: home
uuid: f86a2db0-6a82-124f-9a71-1cd4c20fd6fb
Parent uuid: ba4d388f-44bf-7b46-b2b8-00e2a9a87181
Creation time: 2017-08-10 22:19:15
Object ID: 383
Generation (Gen): 148
Gen at creation: 148
Parent: 5
Top Level: 5
Flags: readonly
Snapshot(s):Quoted 1 line
I know, the root filesystem is /local, but who can I show it by command?
Probably in /proc/self/mountinfo -- that should give you the full
set of applied mount options, plus the original source for the mount (which will be a block device for most filesystem mounts, a path for bind mounts, or something FS-specific for network filesystems).
Hugo.
Signature · 4 lines
Hugo Mills | And what rough beast, its hour come round at last / hugo@... carfax.org.uk | slouches towards Bethlehem, to be born? http://carfax.org.uk/ | PGP: E2AB1DE4 | W.B. Yeats, The Second Coming
Quoted 11 lines · Hugo Mills
Quoted 6 lines · Ulli Horlacher
How do I find the root filesystem of a subvolume?
Example:root@fex:~# df -T Filesystem Type 1K-blocks Used Available Use% Mounted on - - 1073740800 104244552 967773976 10% /local/.backup/homeI've never seen the "- -" output from df before. Is this a bind
mount or something?
No, /local/.backup/home is just a btrfs subvolume
Quoted 3 lines
Quoted 1 line
I know, the root filesystem is /local, but who can I show it by command?
Probably in
/proc/self/mountinfo
root@fex:~# grep home /proc/self/mountinfo root@fex:~# grep btrfs /proc/self/mountinfo 31 22 0:23 / /backup rw,relatime - btrfs /dev/sdf1 rw,compress=zlib,space_cache 32 22 0:26 / /local rw,relatime - btrfs /dev/sde1 rw,compress=zlib,space_cache
No information about the subvolume /local/.backup/home
It seems, I have to scan the subvolume path upwards until I found a real mount point,
Signature · 6 lines
Ullrich Horlacher Server und Virtualisierung Rechenzentrum TIK Universitaet Stuttgart E-Mail: [email protected] Allmandring 30a Tel: ++49-711-68565868 70569 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ REF:<[email protected]>
Quoted 2 lines · Ulli Horlacher
It seems, I have to scan the subvolume path upwards until I found a real mount point,
I think searching /proc/mounts for the same device and subvol=/ in options is most straightforward. But what makes you think it's mounted at all?
--
With Best Regards,
Marat Khalili
Quoted 7 lines · Marat Khalili
Quoted 2 lines · Ulli Horlacher
It seems, I have to scan the subvolume path upwards until I found a real mount point,
I think searching
/proc/mountsfor the same device and subvol=/ in options is most straightforward.
I have no subvol=/ option at all:
root@fex:~# grep btrfs /proc/mounts /dev/sdf1 /backup btrfs rw,relatime,compress=zlib,space_cache 0 0 /dev/sde1 /local btrfs rw,relatime,compress=zlib,space_cache 0 0
Quoted 1 line
But what makes you think it's mounted at all?
I am only interested in mounted volumes.
Signature · 6 lines
Ullrich Horlacher Server und Virtualisierung Rechenzentrum TIK Universitaet Stuttgart E-Mail: [email protected] Allmandring 30a Tel: ++49-711-68565868 70569 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ REF:<[email protected]>
Quoted 1 line
I have no subvol=/ option at all:
Probably depends on kernel, but I presume missing subvol means the same as subvol=/ .
Quoted 1 line
I am only interested in mounted volumes.
If your initial path (/local/.backup/home) is a subvolume but it's not itself present in /proc/mounts then it's probably mounted as a part some higher-level subvolume, but this higher-level subvolume does not have to be root. Do you need volume root or just some higher-level subvolume that's mounted?
--
With Best Regards,
Marat Khalili
Quoted 6 lines · Ulli Horlacher
Quoted 5 lines · Hugo Mills
Quoted 3 lines · Ulli Horlacher
How do I find the root filesystem of a subvolume?
Example:
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
root@fex:~# df -T Filesystem Type 1K-blocks Used Available Use% Mounted on - - 1073740800 104244552 967773976 10% /local/.backup/homeI've never seen the "- -" output from df before. Is this a bind
mount or something?No, /local/.backup/home is just a btrfs subvolume
It arguably shouldn't be showing up here then if it's not been explicitly mounted. I'm betting you're running OpenSUSE or SLES and they finally got their df integration done, as that df output absolutely matches the type of brain-dead handling of BTRFS I'm coming to expect out of them.
Note to SUSE people reading this: You should be including actual information for at least the Type field, and ideally the Filesystem field too. People expect this to behave reasonably, and not listing any info about where the 'mount' originated or what it is is not reasonable.
Quoted 11 lines · Austin S. Hemmelgarn
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
root@fex:~# df -T Filesystem Type 1K-blocks Used Available Use% Mounted on - - 1073740800 104244552 967773976 10% /local/.backup/homeI've never seen the "- -" output from df before. Is this a bind
mount or something?No, /local/.backup/home is just a btrfs subvolume
It arguably shouldn't be showing up here then if it's not been explicitly mounted. I'm betting you're running OpenSUSE or SLES
No:
root@fex:~# cat /etc/os-release NAME="Ubuntu" VERSION="14.04.5 LTS, Trusty Tahr" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 14.04.5 LTS" VERSION_ID="14.04" HOME_URL="http://www.ubuntu.com/" SUPPORT_URL="http://help.ubuntu.com/" BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
root@fex:~# df -T /local/.backup/home Filesystem Type 1K-blocks Used Available Use% Mounted on - - 1073740800 104252160 967766336 10% /local/.backup/home
root@fex:~# type df df is hashed (/bin/df)
root@fex:~# dpkg -S /bin/df coreutils: /bin/df
Signature · 6 lines
Ullrich Horlacher Server und Virtualisierung Rechenzentrum TIK Universitaet Stuttgart E-Mail: [email protected] Allmandring 30a Tel: ++49-711-68565868 70569 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ REF:<[email protected]>
Quoted 31 lines · Ulli Horlacher
Quoted 11 lines · Austin S. Hemmelgarn
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
root@fex:~# df -T Filesystem Type 1K-blocks Used Available Use% Mounted on - - 1073740800 104244552 967773976 10% /local/.backup/homeI've never seen the "- -" output from df before. Is this a bind
mount or something?No, /local/.backup/home is just a btrfs subvolume
It arguably shouldn't be showing up here then if it's not been explicitly mounted. I'm betting you're running OpenSUSE or SLES
No:
root@fex:~# cat /etc/os-release NAME="Ubuntu" VERSION="14.04.5 LTS, Trusty Tahr" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 14.04.5 LTS" VERSION_ID="14.04" HOME_URL="http://www.ubuntu.com/" SUPPORT_URL="http://help.ubuntu.com/" BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"root@fex:~# df -T /local/.backup/home Filesystem Type 1K-blocks Used Available Use% Mounted on - - 1073740800 104252160 967766336 10% /local/.backup/home
Quoted 6 lines
root@fex:~# type df df is hashed (/bin/df)root@fex:~# dpkg -S /bin/df coreutils: /bin/df
Hmm, now I'm really confused, I just checked on the Ubuntu 17.04 and 16.04.3 VM's I have (I only run current and the most recent LTS version), and neither of them behave like this.
Quoted 1 line
Hmm, now I'm really confused, I just checked on the Ubuntu 17.04 and 16.04.3 VM's I have (I only run current and the most recent LTS version), and neither of them behave like this.
Was also shocked, but:
Quoted 7 lines
$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16.04.3 LTS Release: 16.04 Codename: xenial
Quoted 5 lines
$ df -T | grep /mnt/data/lxc$ df -T /mnt/data/lxc Filesystem Type 1K-blocks Used Available Use% Mounted on - - 2907008836 90829848 2815107576 4% /mnt/data/lxc
--
With Best Regards,
Marat Khalili
Quoted 7 lines · Austin S. Hemmelgarn
Quoted 3 lines
root@fex:~# df -T /local/.backup/home Filesystem Type 1K-blocks Used Available Use% Mounted on - - 1073740800 104252160 967766336 10% /local/.backup/homeHmm, now I'm really confused, I just checked on the Ubuntu 17.04 and 16.04.3 VM's I have (I only run current and the most recent LTS version), and neither of them behave like this.
I have this kind of output on all of my Ubuntu hosts:
root@moep:~# grep PRETTY_NAME /etc/os-release PRETTY_NAME="Ubuntu 16.04.3 LTS"
root@moep:~# df -T /usb/UF/tmp/blubb Filesystem Type 1K-blocks Used Available Use% Mounted on - - 12581888 3690524 7253700 34% /usb/UF/tmp/blubb
root@moep:~# btrfs subvolume show /usb/UF/tmp/blubb
/usb/UF/tmp/blubb
Name: blubb
UUID: ecf8c804-d4a3-9948-89fe-b0c1971c25cb
Parent UUID: -
Received UUID: -
Creation time: 2017-08-22 12:54:16 +0200
Subvolume ID: 262
Generation: 23
Gen at creation: 22
Parent ID: 5
Top level ID: 5
Flags: -
Snapshot(s):root@moep:~# dpkg -l | grep btrfs ii btrfs-tools 4.4-1ubuntu1 amd64 Checksumming Copy on Write Filesystem utilities
Signature · 6 lines
Ullrich Horlacher Server und Virtualisierung Rechenzentrum TIK Universitaet Stuttgart E-Mail: [email protected] Allmandring 30a Tel: ++49-711-68565868 70569 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ REF:<[email protected]>
Quoted 34 lines · Ulli Horlacher
Quoted 7 lines · Austin S. Hemmelgarn
Quoted 3 lines
root@fex:~# df -T /local/.backup/home Filesystem Type 1K-blocks Used Available Use% Mounted on - - 1073740800 104252160 967766336 10% /local/.backup/homeHmm, now I'm really confused, I just checked on the Ubuntu 17.04 and 16.04.3 VM's I have (I only run current and the most recent LTS version), and neither of them behave like this.
I have this kind of output on all of my Ubuntu hosts:
root@moep:~# grep PRETTY_NAME /etc/os-release PRETTY_NAME="Ubuntu 16.04.3 LTS"root@moep:~# df -T /usb/UF/tmp/blubb Filesystem Type 1K-blocks Used Available Use% Mounted on - - 12581888 3690524 7253700 34% /usb/UF/tmp/blubbroot@moep:~# btrfs subvolume show /usb/UF/tmp/blubb /usb/UF/tmp/blubb Name: blubb UUID: ecf8c804-d4a3-9948-89fe-b0c1971c25cb Parent UUID: - Received UUID: - Creation time: 2017-08-22 12:54:16 +0200 Subvolume ID: 262 Generation: 23 Gen at creation: 22 Parent ID: 5 Top level ID: 5 Flags: - Snapshot(s):
Quoted 3 lines
root@moep:~# dpkg -l | grep btrfs ii btrfs-tools 4.4-1ubuntu1 amd64 Checksumming Copy on Write Filesystem utilities
Hmm, interesting. Are you using qgroups by chance?
Quoted 35 lines · Austin S. Hemmelgarn
Quoted 34 lines · Ulli Horlacher
Quoted 7 lines · Austin S. Hemmelgarn
Quoted 3 lines
root@fex:~# df -T /local/.backup/home Filesystem Type 1K-blocks Used Available Use% Mounted on - - 1073740800 104252160 967766336 10% /local/.backup/homeHmm, now I'm really confused, I just checked on the Ubuntu 17.04 and 16.04.3 VM's I have (I only run current and the most recent LTS version), and neither of them behave like this.
I have this kind of output on all of my Ubuntu hosts:
root@moep:~# grep PRETTY_NAME /etc/os-release PRETTY_NAME="Ubuntu 16.04.3 LTS"root@moep:~# df -T /usb/UF/tmp/blubb Filesystem Type 1K-blocks Used Available Use% Mounted on - - 12581888 3690524 7253700 34% /usb/UF/tmp/blubbroot@moep:~# btrfs subvolume show /usb/UF/tmp/blubb /usb/UF/tmp/blubb Name: blubb UUID: ecf8c804-d4a3-9948-89fe-b0c1971c25cb Parent UUID: - Received UUID: - Creation time: 2017-08-22 12:54:16 +0200 Subvolume ID: 262 Generation: 23 Gen at creation: 22 Parent ID: 5 Top level ID: 5 Flags: - Snapshot(s):
Quoted 4 lines
Quoted 3 lines
root@moep:~# dpkg -l | grep btrfs ii btrfs-tools 4.4-1ubuntu1 amd64 Checksumming Copy on Write Filesystem utilitiesHmm, interesting. Are you using qgroups by chance?
I get this behaviour (the "- -") only if it's a non-mounted
subvolume:
hrm@amelia:~ $ df -T .
Filesystem Type 1K-blocks Used Available Use% Mounted on/dev/sdb1 btrfs 117220284 95271852 18611060 84% /home
hrm@amelia:~ $ sudo btrfs sub crea foo
Create subvolume './foo'
hrm@amelia:~ $ df -T ./foo
Filesystem Type 1K-blocks Used Available Use% Mounted on
- - 117220284 95271880 18611032 84% /home/hrm/foo
hrm@amelia:~ $ sudo mkdir foo/bar
hrm@amelia:~ $ df -T foo/bar
Filesystem Type 1K-blocks Used Available Use% Mounted on
- - 117220284 95271852 18611060 84% /home/hrm/foo
hrm@amelia:~ $ mkdir foo2
hrm@amelia:~ $ sudo mount /dev/sdb1 ./foo2 -o subvol=home/hrm/foo
hrm@amelia:~ $ df -T foo2
Filesystem Type 1K-blocks Used Available Use% Mounted on/dev/sdb1 btrfs 117220284 95272384 18610528 84% /home/hrm/foo2
Hugo.
Signature · 4 lines
Hugo Mills | "Your problem is that you have a negative hugo@... carfax.org.uk | personality." http://carfax.org.uk/ | "No, I don't!" PGP: E2AB1DE4 | Londo and Vir, Babylon 5
Quoted 60 lines · Hugo Mills
Quoted 35 lines · Austin S. Hemmelgarn
Quoted 34 lines · Ulli Horlacher
Quoted 7 lines · Austin S. Hemmelgarn
Quoted 3 lines
root@fex:~# df -T /local/.backup/home Filesystem Type 1K-blocks Used Available Use% Mounted on - - 1073740800 104252160 967766336 10% /local/.backup/homeHmm, now I'm really confused, I just checked on the Ubuntu 17.04 and 16.04.3 VM's I have (I only run current and the most recent LTS version), and neither of them behave like this.
I have this kind of output on all of my Ubuntu hosts:
root@moep:~# grep PRETTY_NAME /etc/os-release PRETTY_NAME="Ubuntu 16.04.3 LTS"root@moep:~# df -T /usb/UF/tmp/blubb Filesystem Type 1K-blocks Used Available Use% Mounted on - - 12581888 3690524 7253700 34% /usb/UF/tmp/blubbroot@moep:~# btrfs subvolume show /usb/UF/tmp/blubb /usb/UF/tmp/blubb Name: blubb UUID: ecf8c804-d4a3-9948-89fe-b0c1971c25cb Parent UUID: - Received UUID: - Creation time: 2017-08-22 12:54:16 +0200 Subvolume ID: 262 Generation: 23 Gen at creation: 22 Parent ID: 5 Top level ID: 5 Flags: - Snapshot(s):Quoted 4 lines
Quoted 3 lines
root@moep:~# dpkg -l | grep btrfs ii btrfs-tools 4.4-1ubuntu1 amd64 Checksumming Copy on Write Filesystem utilitiesHmm, interesting. Are you using qgroups by chance?
I get this behaviour (the "- -") only if it's a non-mounted
subvolume:hrm@amelia:~ $ df -T .
Filesystem Type 1K-blocks Used Available Use% Mounted on/dev/sdb1btrfs 117220284 95271852 18611060 84% /homehrm@amelia:~ $ sudo btrfs sub crea foo
Create subvolume './foo'hrm@amelia:~ $ df -T ./foo
Filesystem Type 1K-blocks Used Available Use% Mounted on
- - 117220284 95271880 18611032 84%/home/hrm/foohrm@amelia:~ $ sudo mkdir foo/bar
hrm@amelia:~ $ df -T foo/bar
Filesystem Type 1K-blocks Used Available Use% Mounted on
- - 117220284 95271852 18611060 84%/home/hrm/foo
Quoted 8 lines
hrm@amelia:~ $ mkdir foo2
hrm@amelia:~ $ sudo mount
/dev/sdb1./foo2 -o subvol=home/hrm/foohrm@amelia:~ $ df -T foo2
Filesystem Type 1K-blocks Used Available Use% Mounted on/dev/sdb1btrfs 117220284 95272384 18610528 84%/home/hrm/foo2
Wait, I think I see what's up here. I was just calling df -T without pointing at the subvolume (which correctly ignores it because it's not actually mounted). It looks like this is a side effect of the (rather irritating) fake mount-point behavior of subvolumes.
Quoted 5 lines
How do I find the root filesystem of a subvolume?
Example:root@fex:~# df -T Filesystem Type 1K-blocks Used Available Use% Mounted on - - 1073740800 104244552 967773976 10% /local/.backup/home
[ ... ]
Quoted 1 line
I know, the root filesystem is /local,
That question is somewhat misunderstood and uses the wrong concepts and terms. In UNIX filesystems a filesystem "root" is a directory inode with a number that is local to itself, and can be "mounted" anywhere, or left unmounted, and that is a property of the running system, not of the filesystem "root". Usually UNIX filesystems have a single "root" directory inode.
In the case of Btrfs the main volume and its subvolumes all have filesystem "root" directory inodes, which may or may not be "mounted", anywhere the administrators of the running system pleases, as a property of the running system. There is no fixed relationship between the root directory inode of a subvolume and the root directory inode of any other subvolume or the main volume.
Note: in Btrfs terminology "volume" seems to mean both the main volume and the collection of devices where it and subvolumes are hosted.
Quoted 1 line
but who can I show it by command?
The system does not keep an explicit record of which Btrfs "root" directory inode is related to which other Btrfs "root" directory inode in the same volume, whether mounted or unmounted.
That relationship has to be discovered by using volume UUIDs, which are the same for the main subvolume and the other subvolumes, whether mounted or not, so one has to do:
* For the indicated mounted subvolume "root" read its UUID.
* For every mounted filesystem "root", check whether its type is 'btrfs' and if it is obtain its UUID.
* If the UUID is the same, and the subvolume id is '5', that's the main subvolume, and terminate.
* For every block device which is not mounted, check whether it has a Btrfs superblock.
* If the type is 'btrfs' and the volume UUIS is the same as that of the subvolume, list the block device.
In the latter case since the main volume is not mounted the only way to identify it is to list the block devices that host it.
Quoted 15 lines · Peter Grandi
Quoted 5 lines
How do I find the root filesystem of a subvolume?
Example:root@fex:~# df -T Filesystem Type 1K-blocks Used Available Use% Mounted on - - 1073740800 104244552 967773976 10% /local/.backup/home[ ... ]
Quoted 1 line
I know, the root filesystem is /local,
That question is somewhat misunderstood and uses the wrong concepts and terms. In UNIX filesystems a filesystem "root" is a directory inode with a number that is local to itself, and can be "mounted" anywhere, or left unmounted, and that is a property of the running system, not of the filesystem "root". Usually UNIX filesystems have a single "root" directory inode.
Quoted 7 lines
In the case of Btrfs the main volume and its subvolumes all have filesystem "root" directory inodes, which may or may not be "mounted", anywhere the administrators of the running system pleases, as a property of the running system. There is no fixed relationship between the root directory inode of a subvolume and the root directory inode of any other subvolume or the main volume.
Actually, there is, because it's inherently rooted in the hierarchy of the volume itself. That root inode for the subvolume is anchored somewhere under the next higher subvolume. It's the same concept as nested data-sets in ZFS, BTRFS just inherently exposes them at the appropriate location in the hierarchy and allows intermediary directories.
Quoted 4 lines
Note: in Btrfs terminology "volume" seems to mean both the main volume and the collection of devices where it and subvolumes are hosted.
Standard terminology from what I've seen uses 'volume' in the same way it's used for ext4, XFS, LVM, MD, and similar things, namely a BTRFS 'volume' is the collection of devices as well as the sum total of all subvolumes on those devices. This ends up meaning that it implicitly refers to the top-level subvolume when there are no other subvolumes, and as a result it's come to sometimes mean the top-level subvolume (though I rarely see that usage, and would actively discourage it).
Quoted 7 lines
Quoted 2 lines
but who can I show it by command?
The system does not keep an explicit record of which Btrfs "root" directory inode is related to which other Btrfs "root" directory inode in the same volume, whether mounted or unmounted.
Again, it does, it's just not inherently exposed to userspace unless you mount the top-level subvolume (subvolid=5 and/or subvol=/ in mount options). Mount the top level subvolume (once you know what volume the subvolume is on), and call btrfs subvolume list on it. The top level N part of the output from that tells you what the next subvolume up the hierarchy is for each subvolume, and the path part at the end tells you the location within that next higher subvolume where this one is rooted. The output may not make sense though if you don't have the root subvolume mounted (because it may be non trivial to trace things up the tree).
Quoted 15 lines
That relationship has to be discovered by using volume UUIDs, which are the same for the main subvolume and the other subvolumes, whether mounted or not, so one has to do:
* For the indicated mounted subvolume "root" read its UUID.
* For every mounted filesystem "root", check whether its type is 'btrfs' and if it is obtain its UUID.
* If the UUID is the same, and the subvolume id is '5', that's the main subvolume, and terminate.
* For every block device which is not mounted, check whether it has a Btrfs superblock.
* If the type is 'btrfs' and the volume UUIS is the same as that of the subvolume, list the block device.
Quoted 2 lines
In the latter case since the main volume is not mounted the only way to identify it is to list the block devices that host it.
Or alternatively, repeatedly call btrfs filesystem show on the path, removing one component from the end each time until you get a zero return code. The path you called it on that got a zero return code is where the mount is (and thus what filesystem that subvolume is part of), and the output just gave you a list of devices it's on.
Quoted 5 lines · Austin S. Hemmelgarn
Or alternatively, repeatedly call
btrfs filesystem showon the path, removing one component from the end each time until you get a zero return code. The path you called it on that got a zero return code is where the mount is (and thus what filesystem that subvolume is part of), and the output just gave you a list of devices it's on.
"btrfs filesystem show" is relative slow (2.6 s),
"btrfs subvolume show" is MUCH faster (0.02 s).
In perl I have now:
$root = $volume;
while (btrfs subvolume show "$root" 2>/dev/null !~ /toplevel subvolume/) {
$root = dirname($root);
last if $root eq '/';
}
Signature · 6 lines
Ullrich Horlacher Server und Virtualisierung Rechenzentrum TIK Universitaet Stuttgart E-Mail: [email protected] Allmandring 30a Tel: ++49-711-68565868 70569 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/ REF:<[email protected]>
Quoted 9 lines · On Tue, 22 Aug 2017 17:45:37 +0200 Ulli Horlacher…
In perl I have now:
$root = $volume;
while (btrfs subvolume show "$root" 2>/dev/null!~ /toplevel subvolume/) {
$root = dirname($root);
last if $root eq '/';
}
If you are okay with rolling your own solutions like this, take a look at "btrfs filesystem usage <path>". It will print the blockdevice used for mounting the base FS. From that you can find the mountpoint via /proc/mounts.
Performance-wise it seems to work instantly on an almost full 2TB FS.
Signature · 2 lines
With respect, Roman
[ ... ]
Quoted 8 lines
Quoted 3 lines
There is no fixed relationship between the root directory inode of a subvolume and the root directory inode of any other subvolume or the main volume.
Actually, there is, because it's inherently rooted in the hierarchy of the volume itself. That root inode for the subvolume is anchored somewhere under the next higher subvolume.
This stupid point relies on ignoring that it is not mandatory to mount the main volume, and that therefore "There is no fixed relationship between the root directory inode of a subvolume and the root directory inode of any other subvolume or the main volume", because the "root directory inode" of the "main volume" may not be mounted at all.
This stupid point also relies on ignoring that subvolumes can be mounted *also* under another directory, even if the main volume is mounted somewhere else. Suppose that the following applies:
subvol=5 /local
subvol=383 /local/.backup/home
subvol=383 /mnt/home-backup
and you are given the mountpoint '/mnt/home-backup', how can you find the main volume mountpoint '/local' from that?
Please explain how '/mnt/home-backup' is indeed "inherently rooted in the hierarchy of the volume itself", because there is always a "fixed relationship between the root directory inode of a subvolume and the root directory inode of any other subvolume or the main volume".
[ ... ]
Quoted 3 lines
Again, it does, it's just not inherently exposed to userspace unless you mount the top-level subvolume (subvolid=5 and/or subvol=/ in mount options).
This extra stupid point is based on ignoring that to "mount the top-level subvolume" relies on knowing already which one is the "top-level subvolume", which is begging the question.
[ ... ]
Quoted 22 lines · Peter Grandi
[ ... ]
Quoted 8 lines
Quoted 3 lines
There is no fixed relationship between the root directory inode of a subvolume and the root directory inode of any other subvolume or the main volume.
Actually, there is, because it's inherently rooted in the hierarchy of the volume itself. That root inode for the subvolume is anchored somewhere under the next higher subvolume.
This stupid point relies on ignoring that it is not mandatory to mount the main volume, and that therefore "There is no fixed relationship between the root directory inode of a subvolume and the root directory inode of any other subvolume or the main volume", because the "root directory inode" of the "main volume" may not be mounted at all.
This stupid point also relies on ignoring that subvolumes can be mounted *also* under another directory, even if the main volume is mounted somewhere else. Suppose that the following applies:
Quoted 6 lines
subvol=5 /local subvol=383 /local/.backup/home subvol=383 /mnt/home-backupand you are given the mountpoint '
/mnt/home-backup', how can you
find the main volume mountpoint '/local' from that?Assuming/mnt/home-backupis mounted and visible in/proc/mounts(your
explanation requires it was either mounted directly via a subvol option or indirectly via a bind mount), then the following generic method works (and should always work on a modern kernel):
1. Find it in /proc/mounts or the output of mount run without any arguments.
2. If the mount type is 'bind', the device field will point to the source directory. Using any method you like, figure out what the actual mount point that is under is, and repeat from step one with that mount point.
3. If the mount type is 'btrfs', and 'subvolid=5' is present in the mount options (this gets added automatically on any recent kernel), you just found the top level subvolume.
4. If the mount type is 'btrfs', and 'subvolid=5' is not present in the mount options, scan /proc/mounts for other entries with the same device value (this is going to be consistent).
5. If another entry does exist, and has 'subvolid=5' in the mount options, that's the top level subvolume.
6. If other entries exist, but 'subvolid=5' not in the mount options for any of them, or no other entries exist, the top level volume isn't mounted, and you can view it by mounting the device with 'subvolid=5'.
In the event that you need to know where the next higher level subvolume is mounted instead of the root subvolume for the volume, you can use the same method, but add the following after step two to figure out what subvolid to look for:
2b. Run btrfs subvol show on the mount point (it by definition has to be a subvolume because it's mounted and it's not a bind mount in userspace). Find the 'Top level ID' (note that this just points to the next higher subvolume, not the root subvolume) value in the output, and use that instead of 5 when looking for 'subvolid=' options.
Quoted 6 lines
Please explain how '
/mnt/home-backup' is indeed "inherently rooted in the hierarchy of the volume itself", because there is always a "fixed relationship between the root directory inode of a subvolume and the root directory inode of any other subvolume or the main volume".
You did one of three things to mount that:
1. You used a bind mount directly. In this case, you're not changing the relation at all of the subvolume (which is technically not what's mounted in this case because a bind mount operates at the VFS layer and knows nothing about subvolumes) and it's parent subvolumes.
2. You mounted using 'subvol=.backup/home'. This in and of itself should pretty concisely explain that there is a hierarchical relationship between subvolumes. That path indicates the path in the hierarchy of the volume itself used to access the subvolume.
3. You mounted using 'subvolid=383'. This is the only case where there isn't a hierarchical relationship, and just uses the tree ID to reference the subvolume. This is the only case where there isn't some direct reference to the parent subvolume.
Note also that this relation is not inherent to the subvolume, but to it's parent. Just like a symbolic link, the reference is in the containing object, not the referenced object (although subvolumes do store info about what their parent subvolume is).
Quoted 10 lines
[ ... ]
Quoted 3 lines
Again, it does, it's just not inherently exposed to userspace unless you mount the top-level subvolume (subvolid=5 and/or subvol=/ in mount options).
This extra stupid point is based on ignoring that to "mount the top-level subvolume" relies on knowing already which one is the "top-level subvolume", which is begging the question.
You have information in /proc/mounts as to what is mounted. Trace your particular path up to that, and then mount the indicated block device with -o subvolid=5. The subvolume with ID 5 is _ALWAYS_ the top level subvolume for the volume, that's inherently hard coded in the filesystem format, so if that's all you want it's trivial to get it.
Quoted 41 lines · Austin S. Hemmelgarn
On 2017-08-22 13:41, Peter Grandi wrote:
[ ... ]Quoted 11 lines
This stupid point relies on ignoring that it is not mandatory to mount the main volume, and that therefore "There is no fixed relationship between the root directory inode of a subvolume and the root directory inode of any other subvolume or the main volume", because the "root directory inode" of the "main volume" may not be mounted at all.
This stupid point also relies on ignoring that subvolumes can be mounted *also* under another directory, even if the main volume is mounted somewhere else. Suppose that the following applies:
Quoted 7 lines
subvol=5 /local
subvol=383 /local/.backup/home
subvol=383/mnt/home-backupand you are given the mountpoint '
/mnt/home-backup', how can you find the main volume mountpoint '/local' from that?Assuming/mnt/home-backupis mounted and visible in/proc/mounts(yourexplanation requires it was either mounted directly via a subvol option or indirectly via a bind mount), then the following generic method works (and should always work on a modern kernel):
1. Find it in/proc/mountsor the output ofmountrun without any arguments.
2. If the mount type is 'bind', the device field will point to the source directory. Using any method you like, figure out what the actual mount point that is under is, and repeat from step one with that mount point.
3. If the mount type is 'btrfs', and 'subvolid=5' is present in the mount options (this gets added automatically on any recent kernel), you just found the top level subvolume.
4. If the mount type is 'btrfs', and 'subvolid=5' is not present in the mount options, scan/proc/mountsfor other entries with the same device value (this is going to be consistent).
5. If another entry does exist, and has 'subvolid=5' in the mount options, that's the top level subvolume.
6. If other entries exist, but 'subvolid=5' not in the mount options for any of them, or no other entries exist, the top level volume isn't mounted, and you can view it by mounting the device with 'subvolid=5'.
Quoted 9 lines
In the event that you need to know where the next higher level subvolume is mounted instead of the root subvolume for the volume, you can use the same method, but add the following after step two to figure out what subvolid to look for:
2b. Runbtrfs subvol showon the mount point (it by definition has to be a subvolume because it's mounted and it's not a bind mount in userspace). Find the 'Top level ID' (note that this just points to the next higher subvolume, not the root subvolume) value in the output, and use that instead of 5 when looking for 'subvolid=' options.
In order to have a complete view of all mounts, this is what btrbk does here (which basically matches Austins explanation):
1. Buld a complete tree from:
# btrfs subvolume list -a -u /mnt/home-backup
2. Correlate all subvolume ID's with mount points (second column) and "subvolid=" from mount options:
# cat /proc/self/mounts
Now you have a complete view of all mounts. In order to query a given subvolume, fetch "Subvolume ID" (or "UUID") from:
# btrfs subvolume show /local/.backup/home
see: https://github.com/digint/btrbk/blob/v0.25.1/btrbk
(I apologize that Github has broken display of perl source files at the time being...)