4 Copying Files By Using Shared Data Blocks
Use the cp
command with the --reflink
option to
create lightweight copies of a file within an XFS file system.
Note the reflink feature is enabled by default in Oracle Linux when
formatting by using the mkfs.xfs
command.
The --reflink
option takes advantage of the copy-on-write mechanism to
save disk space and to perform almost instantaneous copy operations. The XFS 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 file system makes copies of the blocks before
they're written to, preserving the other file's content.
For more information on how the reflink feature works, see https://blogs.oracle.com/linux/xfs-data-block-sharing-reflink.
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.