Index:
- Introduction to reflinks
- Loading xfs module with reflink support
- Installing progs/utils
- Creating a reflink file in xfs
- Testing xfs with xfstests
Note: the xfs reflink feature is not stable yet, the links given the tutorial points to custom source code, please make sure you know what you are doing.
Introduction to reflinks:
Reflink support transparent copy on write mainly useful for snapshotting, basically reflink point to same data blocks that are used by actual file, they use different inode numbers hence they can have different permissions to access same data blocks, although they may look similar to hardlinks but are more space efficient and can handle all operations that can be performed on a regular file, unlike hardlinks that are limited to unlink().
Loading xfs module with reflink support:
XFS is by default dynamic module in upstream linux kernel, if you are good at compiling and loading only xfs.ko from the source go ahead with that, this guide is for beginners .. Kernel Compilation for Xfs module:
# git clone https://github.com/djwong/linux
# git checkout for-dave
# cd linux/
# make distclean
# make mrproper
# cp /boot/config-`uname -r` .config
# make oldconfig
# dnf install ncurses-devel bc
# make menuconfig
# make bzImage
# make modules
# make modules_install
# make install
# reboot
After reboot you should see `uname -a` for ensuring what we compiled
is booted.
# lsmod # check xfs is loaded
|
Installing the progs/utils:
# git clone https://github.com/djwong/xfsprogs
# cd xfsprogs
# git checkout for-dave
# make install-dev
|
Creating a reflink file in xfs:
Allocating a file and formatted with xfs enabled with reflinks: # fallocate -l 5G ~/block-xfs.img # mkfs.xfs -m reflink=1 ~/block-xfs.img # mknod /dev/loop0 b 7 0 # losetup /dev/loop0 ~/block-xfs.img # mount /dev/loop0 /mnt # cd /mnt && mkdir -p dir1 # fallocate -l 512M dir1/file1 # cp --reflink=always dir1/file1 dir1/copy1 # ls -i dir1/file1 dir1/copy1 # du -sh dir1 There we go, we have different Inode numbers for 'copy1' and 'file1' both of them pointing to same data blocks, hence the size of dir1 should be 512M # umount /mnt # losetup -d /dev/loop0 |
Testing xfs with xfstests:
# git clone https://github.com/djwong/xfstests # cd xfstests # git checkout for-dave # make Create a config file: we require two partitions and two directories # fallocate -l 5G ~/block-xfs.img # fallocate -l 5G ~/block-xfs-scratch.img # mknod /dev/loop0 b 7 0 # mknod /dev/loop1 b 7 1 # losetup /dev/loop0 ~/block-xfs.img # losetup /dev/loop1 ~/block-xfs-scratch.img # mkdir -p /mnt/test # mkdir -p /mnt/scratch # pwd ~/xfstests Set up a config file # cat > local.config # Note: SCRATCH_DEV >will< get overwritten! # these are very limited variables defined, explore more @README export TEST_DEV=/dev/loop0 export TEST_DIR=/mnt/test export SCRATCH_DEV=/dev/loop1 export SCRATCH_MNT=/mnt/scratch ^ctrl+d # source local.config run the xfs tests # ./check # This will run all xfs tests To run one single test # ./check generic/001 use -g option to run in groups, There are many options and variables to run test, you can find more information in README docs |
One thought on “XFS reflinks tutorial”