Difficulty: Intermediate
Estimated Time: 10-15 min

Copy-on-Write filesystems have the nice property that it is possible to "clone" files instantly, by having the new file refer to the old blocks, and copying (possibly) changed blocks. This both saves time and space, and can be very beneficial in a lot of situations (for example when working with big files). In Linux this type of copy is called "reflink". We will see how to use it on the XFS filesystem.

Deduplicate Data With XFS And Reflinks

Step 1 of 5

Step 1

Create a virtual block device

Linux supports a special block device called the loop device, which maps a normal file onto a virtual block device. This allows for the file to be used as a "virtual file system".

  1. Create a file of size 1G:

    fallocate -l 1G disk.img

    du -hs disk.img

  2. Create a loop device with this file:

    sudo losetup -f disk.img

    The option -f finds an unused loop device.

  3. Find the name of the loop device that was created:

    losetup -a