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.
/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.