* How to convert a directory to a subvolume
@ 2022-04-30 20:08 John Center
2022-04-30 20:14 ` Hugo Mills
2022-05-01 5:05 ` Chris Murphy
0 siblings, 2 replies; 8+ messages in thread
From: John Center @ 2022-04-30 20:08 UTC (permalink / raw)
To: linux-btrfs
Hi,
I just installed Ubuntu 22.04 with a btrfs raid1 root filesystem. I want to convert a directory, like /opt, into a subvolume. I haven’t been having much luck. /opt is empty right now, so it’s a good candidate for conversion. Could someone please explain how to do it? I’ve been at a dozen different websites, & tried different variations of the “btrfs subvolume create” command, but nothing works when I go to mount it. I think I’m missing something simple, but not sure what it is.
Thanks!
-John
Sent from my iPad
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: How to convert a directory to a subvolume 2022-04-30 20:08 How to convert a directory to a subvolume John Center @ 2022-04-30 20:14 ` Hugo Mills 2022-05-02 0:02 ` John Center 2022-05-01 5:05 ` Chris Murphy 1 sibling, 1 reply; 8+ messages in thread From: Hugo Mills @ 2022-04-30 20:14 UTC (permalink / raw) To: John Center; +Cc: linux-btrfs On Sat, Apr 30, 2022 at 04:08:59PM -0400, John Center wrote: > Hi, > > I just installed Ubuntu 22.04 with a btrfs raid1 root filesystem. I want to convert a directory, like /opt, into a subvolume. I haven’t been having much luck. /opt is empty right now, so it’s a good candidate for conversion. Could someone please explain how to do it? I’ve been at a dozen different websites, & tried different variations of the “btrfs subvolume create” command, but nothing works when I go to mount it. I think I’m missing something simple, but not sure what it is. You can't convert a directory into a subvolume. Since the directory in question is empty, just delete it and create a subvol there instead: # rmdir /opt # btrfs sub create /opt If there's stuff in there, you need to create the subvolume with a different name, copy the contents of the directory into it (optionally with --reflink=always) and then delete the original directory and move the subvolume into its place. Hugo. -- Hugo Mills | UNIX: British manufacturer of modular shelving units hugo@... carfax.org.uk | http://carfax.org.uk/ | PGP: E2AB1DE4 | ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to convert a directory to a subvolume 2022-04-30 20:14 ` Hugo Mills @ 2022-05-02 0:02 ` John Center 2022-05-02 13:16 ` Chris Murphy 0 siblings, 1 reply; 8+ messages in thread From: John Center @ 2022-05-02 0:02 UTC (permalink / raw) To: Hugo Mills, linux-btrfs Hi Hugo, Thanks for responding. I guess what I don't understand, @home is a subvolume, but it appears as /home when it is mounted via fstab. It has a top level ID of 5. If I create a subvolume for opt, it has a top level of 256. I've tried different variations of opt, /opt, & @opt, but they all appear as that variation under /: john@Mariposa:~$ sudo btrfs subvolume create /@opt Create subvolume '//@opt' john@Mariposa:~$ sudo btrfs subvolume list / ID 256 gen 5968 top level 5 path @ ID 257 gen 5968 top level 5 path @home ID 259 gen 5966 top level 256 path @opt john@Mariposa:~$ sudo btrfs subvolume delete /@opt Delete subvolume (no-commit): '//@opt' john@Mariposa:~$ sudo btrfs subvolume create /opt Create subvolume '//opt' john@Mariposa:~$ sudo btrfs subvolume list -t / ID gen top level path -- --- --------- ---- 256 5993 5 @ 257 5993 5 @home 260 5993 256 opt What I'm expecting is when I do the subvolume list, I would see something like this: john@Mariposa:~$ sudo btrfs subvolume list -t / ID gen top level path -- --- --------- ---- 256 5993 5 @ 257 5993 5 @home 260 5993 5 @opt I would also think the fstab would look something like this: UUID=ce05e908-2dce-4368-b864-2f29650185e8 / btrfs defaults,space_cache=v2,subvol=@ 0 1 # UUID=ce05e908-2dce-4368-b864-2f29650185e8 /home btrfs defaults,space_cache=v2,subvol=@home 0 2 # UUID=ce05e908-2dce-4368-b864-2f29650185e8 /opt btrfs defaults,space_cache=v2,subvol=@opt 0 2 I also thought I would have to mount the subvolume like a directory. So, what am I missing between what I'm seeing vs what I think I should be seeing? Thanks for your help! -John On 4/30/22 4:14 PM, Hugo Mills wrote: > On Sat, Apr 30, 2022 at 04:08:59PM -0400, John Center wrote: >> Hi, >> >> I just installed Ubuntu 22.04 with a btrfs raid1 root filesystem. I want to convert a directory, like /opt, into a subvolume. I haven’t been having much luck. /opt is empty right now, so it’s a good candidate for conversion. Could someone please explain how to do it? I’ve been at a dozen different websites, & tried different variations of the “btrfs subvolume create” command, but nothing works when I go to mount it. I think I’m missing something simple, but not sure what it is. > You can't convert a directory into a subvolume. > > Since the directory in question is empty, just delete it and create > a subvol there instead: > > # rmdir /opt > # btrfs sub create /opt > > If there's stuff in there, you need to create the subvolume with a > different name, copy the contents of the directory into it (optionally > with --reflink=always) and then delete the original directory and move > the subvolume into its place. > > Hugo. > ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to convert a directory to a subvolume 2022-05-02 0:02 ` John Center @ 2022-05-02 13:16 ` Chris Murphy 2022-05-02 15:37 ` John Center 0 siblings, 1 reply; 8+ messages in thread From: Chris Murphy @ 2022-05-02 13:16 UTC (permalink / raw) To: John Center; +Cc: Hugo Mills, Btrfs BTRFS On Sun, May 1, 2022 at 8:02 PM John Center <jlcenter15@gmail.com> wrote: > > Hi Hugo, > > Thanks for responding. I guess what I don't understand, @home is a > subvolume, but it appears as /home when it is mounted via fstab. It has > a top level ID of 5. If I create a subvolume for opt, it has a top > level of 256. I've tried different variations of opt, /opt, & @opt, but > they all appear as that variation under /: > > john@Mariposa:~$ sudo btrfs subvolume create /@opt > Create subvolume '//@opt' This is the mistake. Since @ is mounted at /, using /@opt actually means /@/@opt, thus it's been nested. > > john@Mariposa:~$ sudo btrfs subvolume list / > ID 256 gen 5968 top level 5 path @ > ID 257 gen 5968 top level 5 path @home > ID 259 gen 5966 top level 256 path @opt @opt was created inside @, that's why it looks like this. Thus, @opt is nested within @. Thus, @ and @home follow a flat layout. And @opt follows a nested layout. To continue with the flat layout for @opt you'd need to create the @opt subvolume in the top-level of the file system alongside @ and @home rather than within one of them. To create it in the top-level you need to mount the top-level somewhere, e.g. btrfs subvolume get-default / Assuming this refers to ID 5, then you just mount /dev/sdXY /mnt btrfs subvolume create /mnt/@opt And the fstab entry should be subvol=@opt If get-default reports a value other than 5, then you need to explicitly mount the top level: mount -o subvol=/ /dev/sdXY /mnt OR mount -o subvolid=5 /dev/sdXY /mnt OR mount -o subvolid=0 /dev/sdXY /mnt The top-level subvolume was assigned ID 5 during initial creation of the file system. Soon after, ID 0 was set up as an alias for 5 because maybe it'd be easier to remember. Note: The top-level nomenclature used by btrfs subvolume list is considered confusing, and I think it's going away in btrfs-progs soonish? The "top-level" of the file system is considered equivalent to subvolume ID 5, which has no name, cannot be renamed or removed, but can be snapshot, and is the subvolume created at mkfs time. Above, it sounds like there's multiple "top-level" subvolumes, e.g. 5 and 256. But in practice it's not how anyone is using the term "top level", which these days is intended to refer to just ID 5. The subvolume with no (explicit) name. > > john@Mariposa:~$ sudo btrfs subvolume delete /@opt > Delete subvolume (no-commit): '//@opt' > > john@Mariposa:~$ sudo btrfs subvolume create /opt > Create subvolume '//opt' Yep, / is still the @ subvolume here, because @ is bind mounted to / > So, what am I missing between what I'm seeing vs what I think I should > be seeing? It'd be neat if we had a way to create subvolumes in the top level directly without having to mount the top level. The FD variant of the C API found in libbtrfsutil suggests it's possible. And also we have a way to delete subvolumes by subvolid, even when they aren't locatable via the mounted file system hierarchy, using the --subvolid flag. -- Chris Murphy ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to convert a directory to a subvolume 2022-05-02 13:16 ` Chris Murphy @ 2022-05-02 15:37 ` John Center 2022-05-02 16:15 ` Chris Murphy 0 siblings, 1 reply; 8+ messages in thread From: John Center @ 2022-05-02 15:37 UTC (permalink / raw) To: Chris Murphy; +Cc: Hugo Mills, Btrfs BTRFS Hi Chris, Thanks for responding! Well, I made some progress: root@Mariposa:/# mount /dev/sda3 /mnt root@Mariposa:/# btrfs subvolume create /mnt/@opt Create subvolume '/mnt/@opt' root@Mariposa:/# btrfs subvolume list / ID 256 gen 11732 top level 5 path @ ID 257 gen 11733 top level 5 path @home ID 268 gen 11733 top level 5 path @opt Once I unmounted /mnt, I had to create the /opt directory again: root@Mariposa:/# umount /mnt root@Mariposa:/# mkdir opt Then I mounted /opt & it didn't complain: root@Mariposa:/# mount /opt root@Mariposa:/# btrfs subvolume list / ID 256 gen 11751 top level 5 path @ ID 257 gen 11751 top level 5 path @home ID 268 gen 11733 top level 5 path @opt So, is this correct? It would have been good if there was a direct way to add the level that you wanted the subvolume created & mounted with the btrfs command. So if I take a snapshot of @, /opt won't be included? That'd my goal. I've been using btrfs at a very basic level, added on top of an md raid1. It worked well for a number of years, but then I needed to replace the disks, I thought I'd go all in on btrfs. Thanks for your help! -John On 5/2/22 9:16 AM, Chris Murphy wrote: > On Sun, May 1, 2022 at 8:02 PM John Center <jlcenter15@gmail.com> wrote: >> Hi Hugo, >> >> Thanks for responding. I guess what I don't understand, @home is a >> subvolume, but it appears as /home when it is mounted via fstab. It has >> a top level ID of 5. If I create a subvolume for opt, it has a top >> level of 256. I've tried different variations of opt, /opt, & @opt, but >> they all appear as that variation under /: >> >> john@Mariposa:~$ sudo btrfs subvolume create /@opt >> Create subvolume '//@opt' > This is the mistake. Since @ is mounted at /, using /@opt actually > means /@/@opt, thus it's been nested. > >> john@Mariposa:~$ sudo btrfs subvolume list / >> ID 256 gen 5968 top level 5 path @ >> ID 257 gen 5968 top level 5 path @home >> ID 259 gen 5966 top level 256 path @opt > @opt was created inside @, that's why it looks like this. Thus, @opt > is nested within @. Thus, @ and @home follow a flat layout. And @opt > follows a nested layout. To continue with the flat layout for @opt > you'd need to create the @opt subvolume in the top-level of the file > system alongside @ and @home rather than within one of them. To create > it in the top-level you need to mount the top-level somewhere, e.g. > > btrfs subvolume get-default / > > Assuming this refers to ID 5, then you just > > mount /dev/sdXY /mnt > btrfs subvolume create /mnt/@opt > > And the fstab entry should be subvol=@opt > > If get-default reports a value other than 5, then you need to > explicitly mount the top level: > > mount -o subvol=/ /dev/sdXY /mnt OR > mount -o subvolid=5 /dev/sdXY /mnt OR > mount -o subvolid=0 /dev/sdXY /mnt > > The top-level subvolume was assigned ID 5 during initial creation of > the file system. Soon after, ID 0 was set up as an alias for 5 because > maybe it'd be easier to remember. > > Note: The top-level nomenclature used by btrfs subvolume list is > considered confusing, and I think it's going away in btrfs-progs > soonish? The "top-level" of the file system is considered equivalent > to subvolume ID 5, which has no name, cannot be renamed or removed, > but can be snapshot, and is the subvolume created at mkfs time. Above, > it sounds like there's multiple "top-level" subvolumes, e.g. 5 and > 256. But in practice it's not how anyone is using the term "top > level", which these days is intended to refer to just ID 5. The > subvolume with no (explicit) name. > > > >> john@Mariposa:~$ sudo btrfs subvolume delete /@opt >> Delete subvolume (no-commit): '//@opt' >> >> john@Mariposa:~$ sudo btrfs subvolume create /opt >> Create subvolume '//opt' > Yep, / is still the @ subvolume here, because @ is bind mounted to / > > >> So, what am I missing between what I'm seeing vs what I think I should >> be seeing? > It'd be neat if we had a way to create subvolumes in the top level > directly without having to mount the top level. The FD variant of the > C API found in libbtrfsutil suggests it's possible. And also we have a > way to delete subvolumes by subvolid, even when they aren't locatable > via the mounted file system hierarchy, using the --subvolid flag. > > > > ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to convert a directory to a subvolume 2022-05-02 15:37 ` John Center @ 2022-05-02 16:15 ` Chris Murphy 2022-05-02 18:51 ` John Center 0 siblings, 1 reply; 8+ messages in thread From: Chris Murphy @ 2022-05-02 16:15 UTC (permalink / raw) To: John Center; +Cc: Chris Murphy, Hugo Mills, Btrfs BTRFS On Mon, May 2, 2022 at 11:37 AM John Center <jlcenter15@gmail.com> wrote: > > Hi Chris, > > Thanks for responding! Well, I made some progress: > > root@Mariposa:/# mount /dev/sda3 /mnt > > root@Mariposa:/# btrfs subvolume create /mnt/@opt > Create subvolume '/mnt/@opt' > > root@Mariposa:/# btrfs subvolume list / > ID 256 gen 11732 top level 5 path @ > ID 257 gen 11733 top level 5 path @home > ID 268 gen 11733 top level 5 path @opt > > Once I unmounted /mnt, I had to create the /opt directory again: > > root@Mariposa:/# umount /mnt > > root@Mariposa:/# mkdir opt > > Then I mounted /opt & it didn't complain: > > root@Mariposa:/# mount /opt > root@Mariposa:/# btrfs subvolume list / > ID 256 gen 11751 top level 5 path @ > ID 257 gen 11751 top level 5 path @home > ID 268 gen 11733 top level 5 path @opt > > So, is this correct? Looks correct. You need to include something like 'mount | grep btrfs' to know for sure, that should show subvol and subvolid for each mount point. > It would have been good if there was a direct way > to add the level that you wanted the subvolume created & mounted with > the btrfs command. So if I take a snapshot of @, /opt won't be > included? Btrfs snapshots via the btrfs-progs CLI tool are not recursive. So whether the subvolumes are arranged in a nested or flat layout doesn't matter. There is a non-atomic recursive snapshot (create and remove) option in libbtrfs both for C API and Python bindings. >That'd my goal. I've been using btrfs at a very basic level, > added on top of an md raid1. It worked well for a number of years, but > then I needed to replace the disks, I thought I'd go all in on btrfs. > -- Chris Murphy ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to convert a directory to a subvolume 2022-05-02 16:15 ` Chris Murphy @ 2022-05-02 18:51 ` John Center 0 siblings, 0 replies; 8+ messages in thread From: John Center @ 2022-05-02 18:51 UTC (permalink / raw) To: Chris Murphy; +Cc: Hugo Mills, Btrfs BTRFS root@Mariposa:/# mount | grep btrfs /dev/sda3 on / type btrfs (rw,relatime,space_cache=v2,autodefrag,subvolid=256,subvol=/@) /dev/sda3 on /home type btrfs (rw,relatime,space_cache=v2,autodefrag,subvolid=257,subvol=/@home) /dev/sda3 on /opt type btrfs (rw,relatime,space_cache=v2,autodefrag,subvolid=268,subvol=/@opt) Thanks, Hugo & Chris! -John On 5/2/22 12:15 PM, Chris Murphy wrote: > On Mon, May 2, 2022 at 11:37 AM John Center <jlcenter15@gmail.com> wrote: >> Hi Chris, >> >> Thanks for responding! Well, I made some progress: >> >> root@Mariposa:/# mount /dev/sda3 /mnt >> >> root@Mariposa:/# btrfs subvolume create /mnt/@opt >> Create subvolume '/mnt/@opt' >> >> root@Mariposa:/# btrfs subvolume list / >> ID 256 gen 11732 top level 5 path @ >> ID 257 gen 11733 top level 5 path @home >> ID 268 gen 11733 top level 5 path @opt >> >> Once I unmounted /mnt, I had to create the /opt directory again: >> >> root@Mariposa:/# umount /mnt >> >> root@Mariposa:/# mkdir opt >> >> Then I mounted /opt & it didn't complain: >> >> root@Mariposa:/# mount /opt >> root@Mariposa:/# btrfs subvolume list / >> ID 256 gen 11751 top level 5 path @ >> ID 257 gen 11751 top level 5 path @home >> ID 268 gen 11733 top level 5 path @opt >> >> So, is this correct? > Looks correct. You need to include something like 'mount | grep btrfs' > to know for sure, that should show subvol and subvolid for each mount > point. > > > >> It would have been good if there was a direct way >> to add the level that you wanted the subvolume created & mounted with >> the btrfs command. So if I take a snapshot of @, /opt won't be >> included? > Btrfs snapshots via the btrfs-progs CLI tool are not recursive. So > whether the subvolumes are arranged in a nested or flat layout doesn't > matter. There is a non-atomic recursive snapshot (create and remove) > option in libbtrfs both for C API and Python bindings. > > >> That'd my goal. I've been using btrfs at a very basic level, >> added on top of an md raid1. It worked well for a number of years, but >> then I needed to replace the disks, I thought I'd go all in on btrfs. >> > ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to convert a directory to a subvolume 2022-04-30 20:08 How to convert a directory to a subvolume John Center 2022-04-30 20:14 ` Hugo Mills @ 2022-05-01 5:05 ` Chris Murphy 1 sibling, 0 replies; 8+ messages in thread From: Chris Murphy @ 2022-05-01 5:05 UTC (permalink / raw) To: John Center; +Cc: Btrfs BTRFS On Sat, Apr 30, 2022 at 4:09 PM John Center <jlcenter15@gmail.com> wrote: > > Hi, > > I just installed Ubuntu 22.04 with a btrfs raid1 root filesystem. I want to convert a directory, like /opt, into a subvolume. I haven’t been having much luck. /opt is empty right now, so it’s a good candidate for conversion. Could someone please explain how to do it? I’ve been at a dozen different websites, & tried different variations of the “btrfs subvolume create” command, but nothing works when I go to mount it. I think I’m missing something simple, but not sure what it is. https://btrfs.wiki.kernel.org/index.php/SysadminGuide#Nested If you're using the nested layout, you won't need to use /etc/fstab. When using the flat layout, subvolumes are mounted into position using fstab. -- Chris Murphy ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2022-05-02 18:51 UTC | newest] Thread overview: 8+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-04-30 20:08 How to convert a directory to a subvolume John Center 2022-04-30 20:14 ` Hugo Mills 2022-05-02 0:02 ` John Center 2022-05-02 13:16 ` Chris Murphy 2022-05-02 15:37 ` John Center 2022-05-02 16:15 ` Chris Murphy 2022-05-02 18:51 ` John Center 2022-05-01 5:05 ` Chris Murphy
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox