[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Hard links - How do they work



Keith Bainbridge wrote: 
> As promised:
> I said sometime in this thread that timeshift (and Back in Time) use hard
> links to create progressive copies of the system. The more I think about how
> hard links reportedly work, I reckon it can't be simply hard links.
> 
> So I'm starting a new thread on that topic.
> 
> My understanding is that a hard link (ln with no option) will list the file
> in another directory, but the file remains the same no matter where I may
> edit it.    I use cp -lru as a quick and dirty way to protect me against
> accident deleting a file. (Sym-link doesn't give that protection, but does
> allow me to keep my home on a separate partition so that a fresh install is
> a LOT easier; but that is another topic)

A hard link is a name for a file -- it points to the first inode. Most
files only have one name, but they can have many. Hard links can be in
many directories, but must stay on the same filesystem. If you
mv the file by any of its links on the same filesystem, all the
links remain valid. When the last name for a file is deleted,
the file is deleted. Now you know why deleting a file is
sometimes called "unlinking".

A symbolic link is a tiny file that contains a path to a file.
The kernel reads the path, then looks for the substitute file.
This can fail. But -- it can cross filesystems, even filesystems
of completely different types. If you move the symbolic link, it
continues to point to the same path. If you move the referenced
file, the symbolic links are no longer valid.


> Snapshots reportedly hard link the directory/ies (generally means /  but not
> limited ). a new snapshot copies the latest set and then updates any new
> files in the base.    The more I try to visualise that process the more I
> reckon there must be more to it

"snapshot" is not a single definition; the software you are using
produces different results.

rsnapshot/rsync, lvm, btrfs and zfs, for example, each use completely
different mechanisms with different semantics.

It looks like timeshift uses either rsync or btrfs snapshots,
and backintime uses rsync, so first you would need to define which of those you are using
and in what mode.

-dsr-


Reply to: