BTRFS Subvolume name showing up as a folder in / directory

I am setting up a Fedora 36 kickstart configuration and have the following partitioning commands in the kickstart config file:

# Setup bootloader configuration
bootloader --location=mbr --boot-drive=sda --driveorder=sda --timeout=15

# Remove all partitions from the specified drive
clearpart --drives=sda --all

# EFI Partition (512 MB)
part /boot/efi --fstype="efi" --ondisk=sda --size=600 --fsoptions="umask=0077,shortname=winnt" --label=EFI

# Fedora OS Partition (75 GB)
part btrfs.fedora --fstype="btrfs" --ondisk=sda --size=76800 --fsoptions="noatime,compress-force=zstd:2,space_cache=v2"
btrfs / --label=FEDORA btrfs.fedora
btrfs /.snapshots --subvol --name=btrfs_sv_snapshots LABEL=FEDORA
btrfs /tmp --subvol --name=btrfs_sv_tmp LABEL=FEDORA
btrfs /var/log --subvol --name=btrfs_sv_var_log LABEL=FEDORA

# Home Data Partition (variable size)
part /home --fstype="xfs" --ondisk=sda --size=1024 --grow --label=HOME

When Fedora 36 is installed in a VM using a ks.cfg with the above commands in it, I see the following folders in my / directory:

[root@fedoravm ~]# ls -la /
total 48
dr-xr-xr-x.   1 root root  250 Jul  2 16:39 .
dr-xr-xr-x.   1 root root  250 Jul  2 16:39 ..
dr-xr-xr-x.   1 root root    0 Jan 20 03:04 afs
lrwxrwxrwx.   1 root root    7 Jan 20 03:04 bin -> usr/bin
dr-xr-xr-x.   1 root root  630 Jul  2 16:40 boot
drwxr-xr-x.   1 root root    0 Jul  2 16:38 btrfs_sv_snapshots
drwxrwxrwt.   1 root root 1032 Jul  2 16:40 btrfs_sv_tmp
drwxr-xr-x.   1 root root  158 Jul  2 16:40 btrfs_sv_var_log
drwxr-xr-x.  19 root root 3760 Jul  2 16:40 dev
drwxr-xr-x.   1 root root 2544 Jul  2 16:40 etc
drwxr-xr-x.   3 root root   16 Jul  2 16:40 home
lrwxrwxrwx.   1 root root    7 Jan 20 03:04 lib -> usr/lib
lrwxrwxrwx.   1 root root    9 Jan 20 03:04 lib64 -> usr/lib64
drwxr-xr-x.   1 root root    0 Jan 20 03:04 media
drwxr-xr-x.   1 root root    0 Jan 20 03:04 mnt
drwxr-xr-x.   1 root root    0 Jan 20 03:04 opt
dr-xr-xr-x. 208 root root    0 Jul  2 16:40 proc
dr-xr-x---.   1 root root  244 Jul  2 16:40 root
drwxr-xr-x.  29 root root  700 Jul  2 16:40 run
lrwxrwxrwx.   1 root root    8 Jan 20 03:04 sbin -> usr/sbin
drwxr-xr-x.   1 root root    0 Jul  2 16:38 .snapshots
drwxr-xr-x.   1 root root    0 Jan 20 03:04 srv
dr-xr-xr-x.  13 root root    0 Jul  2 15:40 sys
drwxrwxrwt.   1 root root 1032 Jul  2 16:40 tmp
drwxr-xr-x.   1 root root  100 Jul  2 16:39 usr
drwxr-xr-x.   1 root root  170 Jul  2 16:40 var

I was not expecting to see the following folders:

  • btrfs_sv_snapshots
  • btrfs_sv_tmp
  • btrfs_sv_var_log

I thought a btrfs subvolume name can be anything and doesn’t have to be a valid path. Should I have changed the --name parameter to a valid path for each subvolume ? e.g.

btrfs /.snapshots --subvol --name=/.snapshots LABEL=FEDORA
btrfs /tmp --subvol --name=/tmp LABEL=FEDORA
btrfs /var/log --subvol --name=/var/log LABEL=FEDORA

Here are details of my btrfs setup:

[root@fedoravm ~]# lsblk -ai
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda      8:0    0  127G  0 disk
|-sda1   8:1    0  600M  0 part /boot/efi
|-sda2   8:2    0   75G  0 part /var/log
|                               /tmp
|                               /.snapshots
|                               /
`-sda3   8:3    0 51.4G  0 part /home
sr0     11:0    1  670M  0 rom
zram0  252:0    0  3.7G  0 disk [SWAP]


[root@fedoravm ~]# btrfs filesystem show /
Label: 'FEDORA'  uuid: 97123c02-8461-4169-92ad-77e036169a4f
        Total devices 1 FS bytes used 662.70MiB
        devid    1 size 75.00GiB used 4.02GiB path /dev/sda2


[root@fedoravm ~]# btrfs subvolume get-default /
ID 5 (FS_TREE)


[root@fedoravm ~]# btrfs subvolume list -ta /
ID      gen     top level       path
--      ---     ---------       ----
256     25      5               btrfs_sv_var_log
257     23      5               btrfs_sv_tmp
258     13      5               btrfs_sv_snapshots
259     22      5               var/lib/portables


[root@fedoravm ~]# cat /etc/fstab
#
# /etc/fstab
#
UUID=97123c02-8461-4169-92ad-77e036169a4f /                       btrfs   noatime,compress-force=zstd:2,space_cache=v2 0 0
UUID=97123c02-8461-4169-92ad-77e036169a4f /.snapshots             btrfs   subvol=btrfs_sv_snapshots,noatime,compress-force=zstd:2,space_cache=v2 0 0
UUID=6809-442B          /boot/efi               vfat    defaults,uid=0,gid=0,umask=077,shortname=winnt 0 2
UUID=0f851e76-64dc-4897-8605-a40883430c5b /home                   xfs     defaults        0 0
UUID=97123c02-8461-4169-92ad-77e036169a4f /tmp                    btrfs   subvol=btrfs_sv_tmp,noatime,compress-force=zstd:2,space_cache=v2 0 0
UUID=97123c02-8461-4169-92ad-77e036169a4f /var/log                btrfs   subvol=btrfs_sv_var_log,noatime,compress-force=zstd:2,space_cache=v2 0 0

I am trying to setup a flat subvolume layout and it could be that I’ve used incorrect commands to do so.

From reading documentation on BTRFS subvolumes, I understood that “Every btrfs filesystem has a root subvolume, identified as ID=5.” but I thought this was not the same as the Linux / directory which is why I was not expecting to see the btrfs_* folders in my / directory.

btrfs subvolumes always show up in the filesystem. That is normal.

This is your problem. You haven’t created a flat layout, you have created a nested layout.

In a flat layout, you would create subvolumes like this(the names can be anything you want):
subvolume: root - mountpoint: /
subvolume: home - mountpoint: /home

However, in your setup, you mounted / directly on the root of the btrfs filesystem. That is why all the subvolumes you create are showing up in the filesystem.

1 Like

This is your problem. You haven’t created a flat layout, you have created a nested layout.

Thank you. I amended the partitioning commands in the kickstart config file to be as follows:

# Setup bootloader configuration
bootloader --location=mbr --boot-drive=sda --driveorder=sda --timeout=15

# Remove all partitions from the specified drive
clearpart --drives=sda --all

# EFI Partition (600 MB)
part /boot/efi --fstype="efi" --ondisk=sda --size=600 --fsoptions="umask=0077,shortname=winnt" --label=EFI

# Fedora OS Partition (75 GB)
part btrfs.fedora --fstype="btrfs" --ondisk=sda --size=76800 --fsoptions="noatime,compress-force=zstd:2,space_cache=v2"

# - BTRFS Volume (FS_TREE)
btrfs none --label=fedora_btrfs_vol btrfs.fedora

# - BTRFS Subvolumes
btrfs / --subvol --name=btrfs_sv_root fedora_btrfs_vol
btrfs /.snapshots --subvol --name=btrfs_sv_snapshots fedora_btrfs_vol
btrfs /tmp --subvol --name=btrfs_sv_tmp fedora_btrfs_vol
btrfs /var/cache --subvol --name=btrfs_sv_var_cache fedora_btrfs_vol
btrfs /var/lib/flatpak --subvol --name=btrfs_sv_var_lib_flatpak fedora_btrfs_vol
btrfs /var/lib/libvirt --subvol --name=btrfs_sv_var_lib_libvirt fedora_btrfs_vol
btrfs /var/log --subvol --name=btrfs_sv_var_log fedora_btrfs_vol
btrfs /var/spool --subvol --name=btrfs_sv_var_spool fedora_btrfs_vol
btrfs /var/tmp --subvol --name=btrfs_sv_var_tmp fedora_btrfs_vol

# Home Data Partition (variable size)
part /home --fstype="xfs" --ondisk=sda --size=1024 --grow --label=HOME

Here are the details of my btrfs setup after amending the partitioning commands:

[root@fedoravm ~]# ls -la /
total 16
dr-xr-xr-x.   1 root root  158 Jul  3 00:02 .
dr-xr-xr-x.   1 root root  158 Jul  3 00:02 ..
dr-xr-xr-x.   1 root root    0 Jan 20 03:04 afs
lrwxrwxrwx.   1 root root    7 Jan 20 03:04 bin -> usr/bin
dr-xr-xr-x.   1 root root  630 Jul  3 00:03 boot
drwxr-xr-x.  19 root root 3760 Jul  3 12:21 dev
drwxr-xr-x.   1 root root 2544 Jul  3 12:21 etc
drwxr-xr-x.   3 root root   16 Jul  3 00:03 home
lrwxrwxrwx.   1 root root    7 Jan 20 03:04 lib -> usr/lib
lrwxrwxrwx.   1 root root    9 Jan 20 03:04 lib64 -> usr/lib64
drwxr-xr-x.   1 root root    0 Jan 20 03:04 media
drwxr-xr-x.   1 root root    0 Jan 20 03:04 mnt
drwxr-xr-x.   1 root root    0 Jan 20 03:04 opt
dr-xr-xr-x. 204 root root    0 Jul  3 12:21 proc
dr-xr-x---.   1 root root  244 Jul  3 00:04 root
drwxr-xr-x.  29 root root  700 Jul  3 12:21 run
lrwxrwxrwx.   1 root root    8 Jan 20 03:04 sbin -> usr/sbin
drwxr-xr-x.   1 root root    0 Jul  3 00:01 .snapshots
drwxr-xr-x.   1 root root    0 Jan 20 03:04 srv
dr-xr-xr-x.  13 root root    0 Jul  3 11:21 sys
drwxrwxrwt.   1 root root  870 Jul  3 12:22 tmp
drwxr-xr-x.   1 root root  100 Jul  3 00:02 usr
drwxr-xr-x.   1 root root  170 Jul  3 12:21 var


[root@fedoravm ~]# lsblk -ai
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda      8:0    0  127G  0 disk
|-sda1   8:1    0  600M  0 part /boot/efi
|-sda2   8:2    0   75G  0 part /var/tmp
|                               /var/spool
|                               /var/log
|                               /var/lib/libvirt
|                               /var/lib/flatpak
|                               /var/cache
|                               /tmp
|                               /.snapshots
|                               /
`-sda3   8:3    0 51.4G  0 part /home
sr0     11:0    1  670M  0 rom
zram0  252:0    0  3.8G  0 disk [SWAP]


[root@fedoravm ~]# btrfs filesystem show /
Label: 'fedora_btrfs_vol'  uuid: d80b9165-6e85-4743-bbe4-441297fdab39
        Total devices 1 FS bytes used 693.35MiB
        devid    1 size 75.00GiB used 4.02GiB path /dev/sda2


[root@fedoravm ~]# btrfs subvolume get-default /
ID 5 (FS_TREE)


[root@fedoravm ~]# btrfs subvolume list -ta /
ID      gen     top level       path
--      ---     ---------       ----
256     36      5               <FS_TREE>/btrfs_sv_var_tmp
257     35      5               <FS_TREE>/btrfs_sv_var_spool
258     37      5               <FS_TREE>/btrfs_sv_var_log
259     25      5               <FS_TREE>/btrfs_sv_var_lib_libvirt
260     25      5               <FS_TREE>/btrfs_sv_var_lib_flatpak
261     35      5               <FS_TREE>/btrfs_sv_var_cache
262     36      5               <FS_TREE>/btrfs_sv_tmp
263     25      5               <FS_TREE>/btrfs_sv_snapshots
264     37      5               <FS_TREE>/btrfs_sv_root
265     35      264             btrfs_sv_root/var/lib/portables
1 Like

I suggest omitting this. It’s already the default mount option these days.

Yeah in otherwords, your kickstart is missing lines for the root and home subvolumes, mounted at / and /home respectively. The default installation uses those, and this kickstart is missing them, so you don’t get the system root in its own subvolume.

I suggest omitting this. It’s already the default mount option these days.

Ah ok thanks. Noted and changed in my setup.