Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between hardlink and bind mount?

it might be a stupid question but:

http://dwaves.de/2015/05/26/linux-search-find-files-locate-find-linux-locate-scope/

bind mounts under linux:

as far as i understand it: you can mount the same dir in two different places.

but where is the difference to hardlinks?

The bind mounts. Since Linux 2.4.0 it is possible to remount part of the file hierarchy somewhere else. The call is:

mount –bind olddir newdir

is it just another way of making a folder accessible? (but its not actually using any network protocol because it's all local)

please provide some examples pros/cons.

thanks :)

like image 342
canoodle Avatar asked May 26 '15 09:05

canoodle


2 Answers

In general hard link is filesystem object, mount point - is kernel entity. Hardlink will persistent during reboot, mount point - isn't.

like image 106
declonter Avatar answered Oct 04 '22 01:10

declonter


The difference is that mount --bind works. Linux does not allow you to create hard links to directories.

Modern OS generally don't allow the manual creation of directory hard links because this can result in hard-to-detect cycles that would cause most recursive programs to choke. Such issues could enable DoS attacks and exploitable crashes.

mount --bind allows the same functionality, but in a safe way. Any directory mounted under itself will simply appear empty when you try to recurse into it, thereby breaking any such cycles.

You can also mount --bind individual files. In this case, the difference is that mount --bind works across filesystems.

like image 22
that other guy Avatar answered Oct 04 '22 01:10

that other guy