5 Using Data Block Sharing to Copy Files

Use the cp command with the --reflink option to create lightweight copies of a file within the same subvolume of a Btrfs file system.

The --reflink option takes advantage of the copy-on-write mechanism to save disk space and to perform almost instantaneous copy operations. The Btrfs file system creates a new inode that shares the same disk blocks as the existing file, rather than creating a complete copy of the file's data or creating a link that points to the file's inode. The resulting file appears to be a copy of the original file, but the original data blocks aren't duplicated. If you write to one of the files after you have copied using the --reflink option, the Btrfs file system makes copies of the blocks before they're written to, preserving the other file's content.

To create a lightweight copy of a file named foo to a file named bar, run:

cp --reflink foo bar

The resulting file, bar, doesn't use any extra disk space and is created instantaneously, regardless of the size of the original file, foo. Disk space is used as each of the files is written to.