I've covered this in other articles here, but when I went searching
for something to point a customer at. I had a little trouble
finding it, so we'll do it here:
Let's say you have a system with a few filesystems. One of
those systems is getting tight on space, but the other has plenty of
room. You want to add a large amount of data, but it has to
be in the file system that's low on space. For example, it's
/home that is low on space, and it's /home/fred/drwaings that
needs more room.
There are several ways to handle that. First you could just move that "drawings" directory to /bigdrive/drawings and leave it at that. Any scripts that use /home/fred/drawings would need to be updated and any users who need access would have to get used to looking on /bigdrive. You could also just move all of fred: ~fred could now be /bigdrive/users/fred or whatever. If only Fred used these, that might be an easy solution: move him over, edit /etc/passwd to change his home directory (or use "usermod" to do it for you). Or..
You could use a symbolic link. This method starts by moving
"drawings" to /bigdrive as before:
mv /home/fred/drawings /bigdrive/drawings
And then:
ln -s /bigdrive/drawings /home/fred/drawings
For almost all uses, this is entirely transparent: no scripts
need to be modified, no users need to be notified or retrained.
Any action that accesses /home/fred/drawings will end up
accessing /bigdrive/drawings instead. Well, almost any action -
"ls -l" does work slightly differently after the move:
# before the link
$ ls -l drawings
total 53776
-rw-r--r-- 1 apl wheel 17086 Nov 12 09:46 01-04-06_0537.jpg
-rw-r--r-- 1 apl wheel 42590 Nov 12 09:46 12-28-05_0521.jpg
-rw-r--r-- 1 apl wheel 48270 Nov 12 09:46 12-28-05_1038.jpg
-rw-r--r-- 1 apl wheel 39134 Nov 12 09:46 12-28-05_1042.jpg
-rw-r--r-- 1 apl wheel 39138 Nov 12 09:46 12-28-05_1043.jpg
-rw-r--r-- 1 apl wheel 41874 Nov 12 09:46 12-28-05_1044.jpg
-rw-r--r-- 1 apl wheel 41578 Nov 12 09:45 12-28-05_1045.jpg
etc.
# after the link
$ ls -l drawings
lrwxr-xr-x 1 apl apl 9 Nov 22 08:10 tfoo -> /bigdrive/drawings
Also, "rm" won't complain if you just "rm /home/fred/drawings":
it won't warn about this being a directory - but it doesn't
remove /bigdrive/drawings, just the symbolic link in /home/fred.
But watch out: some Unixes have slightly different
treatments - see Different symbolic link behaviour.
But there's nothing else that would confuse a script or program ordinarily. A program can determine that it has crossed a symbolic link if it wants to, but there's seldom any reason to, so you are unlikely to have any issues.
Symbolic links can be confusing if you are running around with "cd". The issue is this: if you were sitting in /home/fred and then did "cd drawings", and you then "cd ..", where are you? Will "pwd" show /home/fred or /bigdrive?
Well, it depends on your shell and perhaps some environment variables. For example, with Bash, you could "set -P" to make "cd" follow the physical path for symbolic links. You can also just say "cd -P" or "cd -L" to have specific control if necessary.
Mac OS X has symbolic links, but it also has something similar called aliases that have some features symbolic links do not.
Way back when, Microsoft MSDOS had something that was a little bit like a Unix symbolic link. Actually, it was a way to "mount" drives, but they called it "JOIN". For example, you could "JOIN D: C:\NEWDRIVE", and then if you "CD \NEWDRIVE" you'd be sitting on D:. Hardly anybody ever used this, but it has been there just the same (there's a Unix "join" also, but that's a database like command that merges files based on a common key- see "man join").
More Articles by Anthony Lawrence - Find me on Google+
Have you tried Searching this site?
Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates
This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.
Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.
Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.
We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.
Click here to add your comments
Wed Nov 22 17:06:56 2006: BigDumbDinosaur
But there's nothing else that would confuse a script or program ordinarily.
Samba is a notable exception. Normally, Samba will not follow symbolic links that point to anywhere outside of the filespace already mapped into shares. If, for example, a SYMLINK to the new filespace was placed into a subdirectory already mapped to Windows as a share, the SYMLINK would be invalid -- Samba would not allow you to follow it. In this sort of situation you may have insert WIDE LINKS = YES in smb.conf in order to get to that storage. Experient carefully.
Thu Nov 23 02:13:27 2006: drag
It's probably worth mentioning the 'bind' mount option. Since you covered it before...
http://aplawrence.com/Linux/mount_bind.html
I don't have a OS X machine aviable to me right now, but I remember 'Finder' being very finicky about these sort of things. For instance using the commnand line to mount SMB shares would cause Finder to flip out.
If you go to your desktop and make some symbolic links from the bash shell will Finder be happy with that? Also I am curious about other types of special files like named pipes and such.
Also it's worth noting what Windows supports;
Windows supports 3 types of 'linking'; hardLinks, junctions, and symbolic Links
Hardlinks work the same way they do in Unix-land and is supported by NTFS. This allows you to have multiple file names for a single file.
Junctions are like mount points. Unlike unix-land were you can use any directory you have to create specific junctions and this allows you to do things like work around the 26 drive letter limitation or do things similar to 'mount --bind'.
http://support.microsoft.com/kb/205524 It's worth noting the limitations, some commands like to delete files recursively and if you use a junction to mount a volume and then try to delete that junction you may end up with a suprisingly lot of extra disk space.
Symbolic links are new to NTFS version 5.0 and SMB 2.0. NTFSv5 is aviable on XP-64 (I suppose the AMD64 version and maybe not the IA64) and SMB 2.0 and NTFSv5 for Windows Vista. (SMB2.0 will only be used between vista machines otherwise you fallback to regular smb)
These links are controlled via the mklink command..
Don't miss responses! Subscribe to Comments by RSS or by Email
Click here to add your comments
If you want a picture to show with your comment, go get a Gravatar