0

I hope this is not a duplicate, I searched but couldn't find an answer.

I'm using Linux Mint. I have a Data partition that mounts automatically on boot. I've created symlinks from this partition on my /home/user folder.

The problem is I have a 'www' folder on my Data partition (it's a backup of websites I need to restore), and I need to make a symlink of it on /home/user. I also need to symlink-it to /var/www/html so I can make changes to files/folders up in my server. Is it possible? what would be the best way to do it?

Previously I kept the 'www' folder directly on /home/user so I only needed one symlink. But now that I have a separate Data partition I don't know how to go about it. I could have only one symlink for the server, but I would have to manually copy/backup whatever new info was added, and I'd rather do that automatically, if there's a way.

2
  • Your terminology is a bit confusing. "Create a symlink from a partition (/data ?) on the folder /home/user folder" does you mean you create a symlink in the directory /home/user pointing to /data? And are you asking to create a link named /var/www/html that points to two different locations? Or do you want a symlink pointing to a symlink pointing to some real directory.
    – Anthon
    Jan 6, 2015 at 7:21
  • I get confused by it too, I might have switched terms. I have a folder on the Data partition with html files. I want to access them from my /home/user folder and also be able to work on them without copying them into /var/www/html and then back to my Data partition (where I want them stored). Hope it's clearer.
    – brunn
    Jan 6, 2015 at 7:31

3 Answers 3

1

yes it is possible to symlink one folder to several places. As far as I understand your question, you want two symlinks:

/home/user/www -> /mnt/partition/www
/var/www/html -> /mnt/partition/www

I'm happy to adjust my answer should this be different. However, the general procedure should be the same.

 ln -s /mnt/partition/www /home/user/www
 ln -s /mnt/partition/www /var/www/html

If you need the whole directory structure of /mnt/partition/www under /var/www/html and /home/user, as in two identical "folders" that keep each other in sync, take a look at bind mounts.

0

If I understand things correctly you have ( a bit abstracted ):

/data/html/xyz.html

you have a link in your home directory:

/home/user/html -> /data/html

so the data is actually stored on the separate partition /data

Now you could use the xyz.html file from /var/www/html by linking:

/var/www/html -> /data/html

The commands for that are:

cd /home/user
ln -s /data/html .
cd /var/www
ln -s /data/html .

There are however two problems I see with this setup.

  1. Your server might not be setup to follow a link under /var/www. E.g. Apache needs to have the +FollowSymLinks option in its configuration as this is a potential security risk.
  2. Every edited change is immediately "pushed" to the webserver. You should probably do this via some revision control system, so that at most commited material makes it on the website.

There are different ways of solving the above issues. If space on / is the reason for putting everything on /data I would make a /data/www and have the webserver server from there instead of /var/www (doing away with the need for following symlinks. I would also use mercurial to revision control the material under /data/html and have this cloned to a default location /data/www so that you can commit from /data/html (or /home/user/html) and once things are stable you do a commit and push, to have thing served from the website.

0

In linux, any physical storage can be assigned to any path in the filesystem any number of times. file paths are just inodes (handles/pointers) to the physical storage. You can map the same physical file/folder to different filesystem paths in at least 3 ways:

1) mounting. Just as you can mount an entire physical drive to a directory, you can also mount an arbitrary existing directory to another location (bind mount). This one is completely transparent to any application in the system, no program will actually notice the content in the directory is mounted from some other location. In your case, you can easily do

mount --bind /mnt/partition/www/ /var/www/html/

This is the best way of doing this, because webservers don't generally like following symlinks by default, because they can grant access to parts of the filesystem that shouldn't be accessed.

You can mount any folder to any other folder any number of times. The original directory does not even know it's mounted somewhere else, OS handles this.

2) symlinks. Symbolic links are just aliases. This is the weakest binding. Unlike mounting, symbolic links simply contain (basically in a text form) a path to which they point. This means you don't have to mount it at every boot (or when you need it), and the path may not even exist. It may also change. Most applications work with them as with regular files, but there are caveats: directory symlinks have some problems because when you go in, and come back again, you don't necessarily arrive at the same place. Also, applications are aware the file/directory is a link. To avoid cycles, the operating system limits the length of the chain of links to follow (almost never a problem, unless you abuse them very much). Of course, you can have as many links as you want, the original directory is not even aware of them.

ln -s /mnt/partition/www/ /var/www/html/

ln -s /mnt/partition/www/ /home/user/www/

3) hard links. Because filesystems on unixes are designed as a set of inodes that point to physical locations on the hard drive, every inode is just an address how to get there. So you can have many inodes (IN THE SAME FILESYSTEM) pointing to the same address. If you don't use -s switch on ln command, it creates a hard link (if possible). All filenames that point to the same physical storage are actually equivalent. There is no "original" file. All of them are the same file, there are just two or more names for the same thing. Because deletion actually only removes the inode (and marks the space as free only if NO inodes point to it), deleting one file doesn't remove the other. It just removes the name. Of course, if you remove all hard links, there are no inodes that tell you where to find the storage and it is finally lost (filesystem can then use the space for something else).

This doesn't help you in this case. Hard links only work within the same filesystem (same partition), because every partition has its own physical address management. But I included this just for completeness.

So... symlink anything to anything, you can even link to another link (this is how most of the libraries in /usr/lib are linked so that the generic library name is linked to the specific version that is installed). If you have root access, I suggest bind-mounting the directory that will be used by the web server, it's the more correct way of doing things. You probably won't ever need hard links, but you should know they exist.

You must log in to answer this question.

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