1

How can I create a btrfs subvolume such that it is the child of another specific subvolume? Or, how can I ensure that it will be created with parent/top level of 5, as many of my existing subvolumes are?

e.g., say I have:

# btrfs subvolume list -p -a -t -u /
ID      gen     parent  top level       uuid    path
--      ---     ------  ---------       ----    ----
257     80732   5       5               43d2daae-112f-ab49-931f-ddc9ba1c6ffd    <FS_TREE>/root
258     80732   5       5               01b630a4-608d-b44f-8f97-e9c371c7c759    <FS_TREE>/home
261     80731   257     257             0dbf3e8a-a9bf-2a4a-92fe-7661d48295f2    root/var/lib/machines

How can I create a new_subvolume such that it will show up as:

# btrfs subvolume list -p -a -t -u /
ID      gen     parent  top level       uuid    path
--      ---     ------  ---------       ----    ----
257     80732   5       5               43d2daae-112f-ab49-931f-ddc9ba1c6ffd    <FS_TREE>/root
258     80732   5       5               01b630a4-608d-b44f-8f97-e9c371c7c759    <FS_TREE>/home
261     80731   257     257             0dbf3e8a-a9bf-2a4a-92fe-7661d48295f2    root/var/lib/machines
262     80732   5       5               XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX    <FS_TREE>/new_subvolume

The root and home subvolumes got created somehow, I just want to duplicate how they got made.

1

There's no special method for doing that. To create subvolumes, just like regular files or directories, you need to have their parent mounted somewhere...

# mkdir /mnt/toplevel

# mount /dev/sda2 /mnt/toplevel -o subvolid=5

...and create a child subvolume in it:

# btrfs subvolume create /mnt/toplevel/new_subvolume

# ls -la /mnt/toplevel
total 16K
drwxr-xr-x 1 root root  36 Sep 10 15:13 ./
drwxr-xr-x 1 root root  26 Mar  1 14:18 ../
drwxr-xr-x 1 root root  14 Sep 10 15:48 home/
drwxr-xr-x 1 root root   0 Mar  1 14:19 new_subvolume/
drwxr-xr-x 1 root root 150 Feb 19 13:07 root/

# umount /mnt/toplevel

(Note: by default, subvolid=5 is already the default and doesn't need to be specified. I only added it in case you've done btrfs subvolume set-default earlier.)

  • All the btrfs subvolumes are all already mounted. I tried: mkdir /new_subvolume ; btrfs subvolume create /new_subvolume and got: ERROR: '/new_subvolume' exists. So, I deleted that directory, and tried just: btrfs subvolume create /new_subvolume ; btrfs subvolume list -p -a -t / and I got the new subvolume created, but with its parent & top level as 257, not 5. – courtlandj Mar 1 '16 at 15:37
  • I see now that I missed your instruction to create a new folder just to mount my btrfs ... fs. But I wonder why I need to do that, why doesn't creating a subvolume where it's already mounted, work? Seems that is a "special method for doing that" after all. – courtlandj Mar 1 '16 at 15:44
  • @courtlandj: Well, of course you can create subvolumes where it's already mounted – but the problem that your desired parent subvolume isn't mounted anywhere, only its children are. i.imgur.com/BxAlyR9.png (I can't see your system from here, but I'm guessing that only subvolumes 257 and 258 are actually mounted.) – grawity Mar 1 '16 at 17:47
  • I understand this better now, thank you. So, perhaps "special in the case of mounted at root"? – courtlandj Mar 1 '16 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.