6

It's clear, with cp --reflink foo bar I can copy a file on btrfs without wasting space. But how can I detect that the two files (foo and bar here) are using the same "space unit"?

If they were hardlinks, I would use [ foo -ef bar ] for comparing or stat -c%i foo to get a unique id (inode in this case).

Are there similar commands for btrfs reflinked files?

I want to apply this on a 300G volume which is virtually 6T in size due to deduplication, so I want to avoid checksumming...

  • see also https://unix.stackexchange.com/questions/225766/list-reflink-filenames-to-a-file-on-btrfs?rq=1, but it's not exactly the same question – Daniel Alder Oct 14 '18 at 14:02
  • 1
    I would suggest looking at how https://github.com/markfasheh/duperemove detects extents that are already shared. AFAIK, that's about the only way to do it reliably, though I unfortunately couldn't explain it to you because I don't fully understand it myself. – Austin Hemmelgarn Oct 15 '18 at 18:52

1 Answers1

1

Ok, this is probably the best so far: https://unix.stackexchange.com/a/277043/55508, by @pwaller

Further to my previous answer, I have just released fienode which computes a SHA1 hash of the physical extents of the file and can be used to find some (identical) reflink copies. Beware though, there are caveats (see the documentation). BTRFS decided to change some, but not all, of the physical extents of a refink copy I made without provocation or warning, causing the value to change.