Am Thu, 07 Sep 2017 17:46:27 +0200 schrieb Helmut Jarausch <jarau...@skynet.be>:
> Hi, > > sorry, this question is not Gentoo specific - but I know there are > many very knowledgeable people on this list. > > I'd like to "hard-link" a file X to Y - i.e. there is no additional > space on disk for Y. > > But, contrary to the "standard" hard-link (ln), file Y should be > stored in a different place (inode) IF it gets modified. > With the standard hard-link, file X is the same as Y, so any changes > to Y are seen in X by definition. > > Is this possible > - with an ext4 FS > - or only with a different (which) FS You can do this with "cp --reflink=always" if the filesystem supports it. To my current knowledge, only btrfs (since a long time) and xfs (in newer kernel versions) support it. Not sure if ext4 supports it or plans support for it. It is different to hard linking as the new file is linked by a new inode, thus it has it's own time stamp and permissions unlike hard links. Just contents are initially shared until you modify them. Also keep in mind that this increases fragmentation especially when there are a lot of small modifications. At least in btrfs there's also a caveat that the original extents may not actually be split and the split extents share parts of the original extent. That means, if you delete the original later, the copy will occupy more space than expected until you defragment the file: File A extent map: [1111][22 2 2][3333] File B extent map: [1111][22 2 2][3333] Modify b: [1111][22][4][2][3333] <- one block modified Delete file a: [----][22 2 2][----] <- extent 2 still mapped File b extent map: [1111][22][4][2][3333] So extent 2 is still on disk in its original state [2222]. Defragment file b: [1111][2242][3333] File a: [----][----][----] <- completely gone now -- Regards, Kai Replies to list-only preferred.