The OutRider Computing Journal

A free monthly column for users, administrators, programmers and hobbyists who use UNIXlike Operating Systems.

Home | Search | Site Map | Feedback | Subscriptions


Symbolic Linking

One of the hysterical things I have found about POSIX conformance is how "virtual" it seems to be to vendors and Operating System manufacturers. I mean most POSIX systems are simply symbolically linked so one can get there from here. What is even more fun (and yes I mean this sarcastically) is how confusing it can get when your dropping in and out of subshells or operate in a multi shell environment. I know few administrators and programmers who do not. The problem that comes into play is where the shell thinks it is relative to the inode tables.

Here is a quick example;

Let's say for the sake of argument that your OS is HP-UX 10.20 (or more affectionately known as HPSUX). The following symbolic link is set by default for "POSIX Conformance":

/usr/adm -> /var/adm

Now let's say you execute the following command:

cd /usr/adm

Then you get up, go get a cup of coffee, come back, and forgot where the heck you were so you do a simple pwd. Warning, results may vary, in some shells the printout to the screen might be:

/var/adm

While on others it is:

/usr/adm

Not a big deal - and no not really. But when you have users at the prompt they may quickly find themselves lost and in need of some explaining.

Good Linking Practices

Some of the best linking practices come into play with device drivers. GNU/Linux, ironic as it might sound, makes an intuitive and well done implementation of this on most distributions. Following are some rather simplistic symbolic links that make a whole lot of sense:

/dev/floppy -> /dev/fd0
/dev/cdrom -> /dev/hdc
/dev/cua0 -> /dev/modem

There is no reason not to take that a step further in the Unix world in general and many OS vendors do. I however came up with a list of even more useful symbolic links on an HP-UX 10.20 system (which should apply to many flavors of Unix as well). The reason was simple, I am not the only person who uses these devices and I know it would make life easier for other support folks. Here are a few examples:

/dev/rmt/6hc -> /dev/rmt/tape6
/dev/tty/tty0 -> /dev/tty/sysconsole

These two are also complimented by similar links on GNU/Linux Systems (like the CD device driver, Rockridge and Toshiba CD drivers, PFSd drivers etc).

Document, Document and More Document

Nothing kills me more than documentation. Unlike aliases or /usr/local/bin scripts, links are not self documenting in any form. If you use a lot of home-grown symbolic links or even add some to the system (for instance the linked startup files in /etc/rc and /sbin/rcX.d) then separate documentation needs to kept on where and why they are maintained.

The Dangers of Over-linking

Obviously there are a great many dangers to linking. Security is the big one. Once again, the wonderful POSIX conformance really enhanced our lives when vendors rushed to meet the guidelines by linking the crap out of the whole filesystem with little consideration for security. As a result, numerous holes were punched in filesystems by ambitious hackers who use links to get to what should have been completely restricted areas. HP-UX is notorious for that.

When to Alias, Script or Link

Well linking should only be done with very simple and static files. Device files are the best because they rarely change. Sometimes you have to link libraries to port in software or make it portable (to help the compilation process). Otherwise, anything that requires a set of commands needs to be aliased or scripted. Scripts should be used to perform a set of commands that are sometimes conditional. Aliases - which I personally abhor, should be used with great discrimination. A good example would be a command with a lot of arguments you use at least once a day. Like bdf -i or something. Otherwise just learn the bloody command!

Linking for Ease of Use

Many Unix systems have a support group. Out of that group there is usually one all powerful know it all. The rest may or may not know Unix all that well but are required to interact with hardware. That is where linking really comes into play. By using simple linking names you create a universal standard that is simple and not stored in everyone's alias file.


(C) Copyright 1999, 2000 OutRider
See OutRider Policies Document for more Information.
Modified on $Date: 1999/08/14 03:34:38 $ by Jason Fink ( jrf@diverge.org )