0

I have a btrfs file system on my media server. It was my first time setting up a system with btrfs and I thought it would be a good idea to separate different types of media into different subvolumes, so that I could create snapshots for them separately. There are two sub volumes:

/downloads
/movies`

A program I'm running (sonarr to be excact) automatically downloads movies and tries to create a hard copy between /downloads/movie and /media/movie once completed. Turns out hard links between btrfs subvolumes are not possible, so sonarr falls back to copying. This unnecessarily creates two copies of a file which hogs up the disk space.

I've tried solving this by using out-of-band deduplication, as in-band dedupliocation is not yet supported as far as I'm aware. Using duperemove I get around 2GB/hour of data that's freed, but it's too slow for me.

I've decided it would be a good idea to dump the subvolume setup I had before and use a single btrfs volume for everything. Looking at the man page of btrfs subvolume it looks like all the data in subvolume is lost when it is deleted. Is there a way to "transfer" data ownership from a subvolume to the parent volume before deleting the subvolume so that I could keep the data?

2

I do not know much about btrfs, yet. Just started to learn it a few hours ago! But I think I can answer your question.

I don't know sonarr but maybe you could tell it to create a reflink when copying. The copy command would look something like this:

$ cp --reflink=always /downloads/file-to-copy /movies/

This will create a copy on the other subvolume but due to the "copy on write" mechanism of btrfs, it does not use more space until one of the files is modified. If you do not modify the files (renaming is okay) this would be just as the hardlink solution.

To get rid of the subvolumes but keep the files, you should be able to simply move (mv) the files to another directory inside the parent subvolume, delete the subvolume and rename the new directory just like the subvolume was named.

Alternatively you can use the reflink method from above to clone the files into a new directory on the parent subvolume, rename the subvolume, rename the new directory like the subvolume was named and test out if everything works, then delete the subvolume.

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.