; Date: Sun Jul 21 2019
Reflinks are an extremely interesting feature - it is an implementation of "Copy on Write" for files in the file system. You create a reflink using the command cp --reflink=always, and the two files act as if they're linked together (no extra disk space consumed) but as soon as you edit one they become two files. With reflinks one could easily set up a clone of a directory structure to edit something in the clone without modifying the original files. XFS is one of the file systems which supports reflinks, so it is worthwhile to know how to format a drive with the XFS filesystem and with the reflinks feature enabled.
In this case I have an Intel NUC running Ubuntu. I have installed a spinning hard drive in an external case, and attached that to a USB port on the NUC.
The first question is, how do you know the device name for the drive? There's two ways I know of. One is to look in
/var/log/syslog for a message like this:
Jul 21 21:53:53 nuc2 kernel:
The device name (
sda) is there. The second is to look for all the
/dev/sdXYZZY devices and see which pops up when you attach the drive.
Once you've determined the device name ...
To initialize a Linux system for
reflinks, we must format a disk volume using one of the supported file systems. In this case we are using XFS.
$ sudo mkfs.xfs -m reflink=1 -f /dev/sda meta-data=/dev/sda isize=512 agcount=4, agsize=9768182 blks = sectsz=4096 attr=2, projid32bit=1 = crc=1 finobt=1, sparse=0, rmapbt=0, reflink=1 data = bsize=4096 blocks=39072726, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=19078, version=2 = sectsz=4096 sunit=1 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0
On Linux the
reflink=1 option is required for the
reflink feature to be enabled in XFS when formatting the device with the file system.
Once you've done this you might find that Ubunto automounts the drive, and there are
syslog messages to this effect:
Jul 21 21:53:54 nuc2 systemd: Started Clean the /media/david/7032e168-9bd3-4295-a56c-dc3b73e625bb mount point. Jul 21 21:53:54 nuc2 udisksd: Mounted /dev/sda at /media/david/7032e168-9bd3-4295-a56c-dc3b73e625bb on behalf of uid 1000
In my case I wanted a cleaner looking pathname for the drive, so I unmounted the drive and remounted it to a nicer path.
$ sudo umount /mnt/xfs $ sudo mount /dev/sda /mnt/xfs
This is pretty straight-forward.
Ideally should I have used
fdisk to set up partitions? I don't rightly know the answer to that, since the difference between
/dev/sdaN is miniscule.
As a long time Mac user, I'm pining for some more user-friendly indicator that a device has been connected to the computer. Shouldn't there be a program to query the attached disks?
In any case - Reflinks are a very cool addition to file systems. There is a lot of potential uses for Reflinks.