0

I have got question how to create symbolic link from another symbolic link (with mount --bind command) under Debian.

They are two cases:

First case: I have got core data in /main/data. And in the folder "data" are some files(folders, files etc.). Where I created symbolic link to another folder such as:

mount --bind /main/data /user/admin

and next create another symbolic link not from core folder but from admin folder such as:

mount --bind /user/admin /public/user1

All work fine, because I created symbolic link of folder to folder BUT second case:

Second case: I want mount only single file from /main/data (by using mount --bind command such) as in first case. At first to admin and after mount whole folder to /user/admin to user1. At first I will need create blank file in /user/admin and after to mount core file. Steps under work good - example:

touch /user/admin/myNewFile.txt

mount --bind /main/data/information.txt /user/admin/myNewFile.txt

But last part are not working - example:

mount --bind /user/admin /public/user1

Last command mount folder from /user/admin to /public/user1 which cause mount all files and folders place in /user/admin. In /public/user1 will appear "myNewFile.txt" but this file is blank with 0 size.

Question is if there is any option of mount command to mount correctly or if there any other solution of this problem.

Thank you very much for your advice.

1 Answer 1

3

The mount --bind command creates bind mounts, not symbolic links; actual symbolic links are created using the ln -s command.

When you use mount --bind /main/data/information.txt /user/admin/myNewFile.txt, you are attaching a part of one filesystem (specifically, one file) on top of another filesystem. Although the contents of information.txt now appears at myNewFile.txt, that still does not make that file a part of the /user/admin filesystem. Usually it wouldn't matter, but for your last command, it will.

mount --bind /user/admin /public/user1 makes a bind mount of a single filesystem - any submount points within the original are not replicated... including the submount point /user/admin/myNewFile.txt.

If you want to replicate an entire directory tree using bind mounts, including any existing submounts like your /usr/admin/myNewFile.txt, then you must use mount --rbind instead:

mount --rbind /user/admin /public/user1

Your second case is analogous to what would happen if you did first:

mount --bind /main/data /user/admin

and then:

mount --bind /user /mnt

If you did this, you would probably find that /mnt/admin will be an empty directory. (Or if there are some files, you would find they are certainly not the up-to-date files from /main/data, but some old junk from way back when someone tried to use /user/admin without making sure mount --bind /main/data /user/admin was done first.)

When you make a regular mount, or mount --bind for a directory, you must first mkdir an empty directory at the destination. The mount command will then attach something else on top of that directory. Likewise, when doing mount --bind for a single file, you must first touch an empty file at the destination, so the mount command will have something to attach to. If you then mount --bind that part of the filesystem, those underlying empty directories/files are what you will see instead of the mounted filesystems/files in the original.

1
  • to telcoM: Thank you very much for exhasuting answer. You helped me a lot. Thanks
    – SED85
    Sep 9, 2021 at 9:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .