2

I have heavily fragmented (and 90% full) btrfs partition on my laptop. I'd like to perform defragmentation with the help of identical spare hard drive.

I already re-created partition table (GPT) and cloned non-btrfs file systems with the help of rsync.

I use btrfs snapshots and so cannot simply rsync the contents of the partition (it wouldn't fit on the target drive)

Would btrfs send & receive duplicate fragmentation of the files, or would it be equivalent to btrfs-aware rsync? I know that in the latter case it will not guarantee full defragmentation, but I hope get rid of 99% of it.

2
  • Just out of curiousty, why do you worry so much about defragmentation? I never had to worry about such a thing with linux systems. The linux kernel takes care of that in the background (to the best of my knowledge) ... Commented Apr 19, 2015 at 5:50
  • FWIW, I have a 50GB VirtualBox VDI file on my Btrfs that gets heavily framented (> 100.000 extents) every couple of weeks. Then, “btrfs send” becomes very slow on my AMD Turion CPU. Instead of 100MB/sec, it drops to 20MB/sec. After defragmenting, it is fast again. Commented Apr 3, 2021 at 17:06

2 Answers 2

0

Why don't use use btrfs' online defragmentation feature?

It is very safe compared to classic defragmentation methods, as btrfs just marks the fragmented blocks for CopyOnWrite. This means, that the fragmented block is deleted only when the copied block is known to be on disk. So even if the power is cut during your btrfs online defragmentation, you won't loose any data. You can continue exactly where you left off before the power cut.

1
  • From your link: Defragmenting a file which has a COW copy (either a snapshot copy or one made with cp --reflink or bcp) plus using the -c switch with a compression algorithm may result in two unrelated files effectively increasing the disk usage. OP uses snapshots which will make this an issue. Commented Aug 12, 2019 at 10:24
0

btrfs send and btrfs receive will create an unfragmented subvolume. However,

  • Use btrfs filesystem defragment if all you want to do is to defragment.
  • btrfs send and btrfs receive may create a fragmented subvolume if you use a parent for btrfs send that exists fragmented on the destination.
1
  • I don’t think that recent edits improved my answer. “btrfs send” will not create a subvolume as it now suggests, only “btrfs receive” does. Moreover, I did not mean the command btrfs send (monospace font), but Btrfs’s send/receive feature. Commented Apr 5, 2021 at 9:24

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.