* Can I convert an existing directory into a subvolume?
@ 2014-04-15 13:10 Bob Williams
2014-04-15 14:16 ` Hugo Mills
2014-04-15 14:46 ` Chris Murphy
0 siblings, 2 replies; 4+ messages in thread
From: Bob Williams @ 2014-04-15 13:10 UTC (permalink / raw)
To: linux-btrfs
Hi,
I'm new to btrfs, just dipping my toes in the water...
I've got two partitions, / on /dev/sda2 and /home on /dev/sda3, both
formatted as btrfs in a new openSUSE 13.1 installation. I copied the
whole of /home (4 users) into the btrfs formatted /home partition from
an ext4 backup.
I would like to create snapshots of /home/user/Documents for example,
but I understand these have to be subvolumes first. Googling tells me I
can't convert a conventional subdirectory into a subvolume, so I'm
guessing I'll have to create a new /home/user/Documents subvolume and
then copy all the contents from the subdirectory. Correct? Then delete
the subdirectory?
Can the subvolume have the same name as the subdirectory it is
replacing, or should it be called something like 'tempDocs', and then
renamed back to 'Documents' after the original has gone?
Bob
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Can I convert an existing directory into a subvolume?
2014-04-15 13:10 Can I convert an existing directory into a subvolume? Bob Williams
@ 2014-04-15 14:16 ` Hugo Mills
2014-04-15 14:23 ` Bob Williams
2014-04-15 14:46 ` Chris Murphy
1 sibling, 1 reply; 4+ messages in thread
From: Hugo Mills @ 2014-04-15 14:16 UTC (permalink / raw)
To: Bob Williams; +Cc: linux-btrfs
[-- Attachment #1: Type: text/plain, Size: 2390 bytes --]
On Tue, Apr 15, 2014 at 02:10:54PM +0100, Bob Williams wrote:
> Hi,
>
> I'm new to btrfs, just dipping my toes in the water...
>
> I've got two partitions, / on /dev/sda2 and /home on /dev/sda3, both
> formatted as btrfs in a new openSUSE 13.1 installation. I copied the
> whole of /home (4 users) into the btrfs formatted /home partition from
> an ext4 backup.
>
> I would like to create snapshots of /home/user/Documents for example,
> but I understand these have to be subvolumes first. Googling tells me I
> can't convert a conventional subdirectory into a subvolume, so I'm
> guessing I'll have to create a new /home/user/Documents subvolume and
> then copy all the contents from the subdirectory. Correct? Then delete
> the subdirectory?
That's one way. You can refine the "copy all the contents" step by
using cp --reflink=always, which will make reflink (CoW) copies of the
data, which is vastly faster than an ordinary copy, as long as you're
not trying to take the data across a mount point.
Another way is to make a snapshot of the subvolume containing the
thing you want to convert, and then delete the pieces you don't want
(possibly rearranging the contents of the new subvol in the process).
So, assuming you have your original subvol mounted on /home, and you
want to turn /home/bob into a subvol, it would go something like this:
# btrfs sub snap /home /home/bob-temp
# rm -rf /home/bob-temp/hugo /home/bob-temp/fred /home/bob-temp/wilma
# mv /home/bob-temp/bob/* /home/bob-temp/
# rmdir /home/bob-temp/bob
# mv /home/bob /home/bob-old
# mv /home/bob-temp /home/bob
Both your approach and the one above involve deleting large
quantities of things, so be careful you don't delete too much. :)
> Can the subvolume have the same name as the subdirectory it is
> replacing, or should it be called something like 'tempDocs', and then
> renamed back to 'Documents' after the original has gone?
It'll have to have a different name temporarily. Subvolumes live in
the same namespace as the rest of the filesystem objects (like files
and directories).
Hugo.
--
=== Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk ===
PGP key: 65E74AC0 from wwwkeys.eu.pgp.net or http://www.carfax.org.uk
--- I believe that it's closely correlated with ---
the aeroswine coefficient.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 811 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Can I convert an existing directory into a subvolume?
2014-04-15 14:16 ` Hugo Mills
@ 2014-04-15 14:23 ` Bob Williams
0 siblings, 0 replies; 4+ messages in thread
From: Bob Williams @ 2014-04-15 14:23 UTC (permalink / raw)
To: linux-btrfs
On 15/04/14 15:16, Hugo Mills wrote:
> On Tue, Apr 15, 2014 at 02:10:54PM +0100, Bob Williams wrote:
>> Hi,
>>
>> I'm new to btrfs, just dipping my toes in the water...
>>
>> I've got two partitions, / on /dev/sda2 and /home on /dev/sda3, both
>> formatted as btrfs in a new openSUSE 13.1 installation. I copied the
>> whole of /home (4 users) into the btrfs formatted /home partition from
>> an ext4 backup.
>>
>> I would like to create snapshots of /home/user/Documents for example,
>> but I understand these have to be subvolumes first. Googling tells me I
>> can't convert a conventional subdirectory into a subvolume, so I'm
>> guessing I'll have to create a new /home/user/Documents subvolume and
>> then copy all the contents from the subdirectory. Correct? Then delete
>> the subdirectory?
>
> That's one way. You can refine the "copy all the contents" step by
> using cp --reflink=always, which will make reflink (CoW) copies of the
> data, which is vastly faster than an ordinary copy, as long as you're
> not trying to take the data across a mount point.
>
> Another way is to make a snapshot of the subvolume containing the
> thing you want to convert, and then delete the pieces you don't want
> (possibly rearranging the contents of the new subvol in the process).
> So, assuming you have your original subvol mounted on /home, and you
> want to turn /home/bob into a subvol, it would go something like this:
>
> # btrfs sub snap /home /home/bob-temp
> # rm -rf /home/bob-temp/hugo /home/bob-temp/fred /home/bob-temp/wilma
> # mv /home/bob-temp/bob/* /home/bob-temp/
> # rmdir /home/bob-temp/bob
> # mv /home/bob /home/bob-old
> # mv /home/bob-temp /home/bob
>
> Both your approach and the one above involve deleting large
> quantities of things, so be careful you don't delete too much. :)
>
>> Can the subvolume have the same name as the subdirectory it is
>> replacing, or should it be called something like 'tempDocs', and then
>> renamed back to 'Documents' after the original has gone?
>
> It'll have to have a different name temporarily. Subvolumes live in
> the same namespace as the rest of the filesystem objects (like files
> and directories).
>
> Hugo.
>
Many thanks for your useful and clear answer. Off to play ;-)
Bob
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Can I convert an existing directory into a subvolume?
2014-04-15 13:10 Can I convert an existing directory into a subvolume? Bob Williams
2014-04-15 14:16 ` Hugo Mills
@ 2014-04-15 14:46 ` Chris Murphy
1 sibling, 0 replies; 4+ messages in thread
From: Chris Murphy @ 2014-04-15 14:46 UTC (permalink / raw)
To: Btrfs BTRFS
On Apr 15, 2014, at 7:10 AM, Bob Williams <linux@barrowhillfarm.org.uk> wrote:
> Hi,
>
> I'm new to btrfs, just dipping my toes in the water...
>
> I've got two partitions, / on /dev/sda2 and /home on /dev/sda3, both
> formatted as btrfs in a new openSUSE 13.1 installation. I copied the
> whole of /home (4 users) into the btrfs formatted /home partition from
> an ext4 backup.
>
> I would like to create snapshots of /home/user/Documents for example,
> but I understand these have to be subvolumes first. Googling tells me I
> can't convert a conventional subdirectory into a subvolume, so I'm
> guessing I'll have to create a new /home/user/Documents subvolume and
> then copy all the contents from the subdirectory. Correct? Then delete
> the subdirectory?
Create a new subvolume, move files into the new subvolume as if it were a directory, remove old directory, rename subvolume to the name of the deleted directory.
btrfs subvolume create /home/user1/Documentss
mv /home/user1/Documents/* /home/user1/Documentss/
rmdir /home/user1/Documents
mv /home/user1/Documentss /home/user1/Documents
One possible gotcha is the ownership of the subvolume at creation time. If you do this as root then you need to chown after you're done; or you need to be logged in as the user who will own the Documents directory in each of the four cases. If you're using SELinux another gotcha is with copying files, which causes them to inherit the security context of the directory copied into, whereas mv preserves existing context. You can just restorecon -Rv /home/user once you're done to make sure the subvolume and its contents have the right labeling.
Chris Murphy
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-04-15 14:46 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-15 13:10 Can I convert an existing directory into a subvolume? Bob Williams
2014-04-15 14:16 ` Hugo Mills
2014-04-15 14:23 ` Bob Williams
2014-04-15 14:46 ` Chris Murphy
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.