Using links in linux


Create a UNIX soft link for Oracle files

In Oracle environments with multiple $ORACLE_HOME directories, it is often challenging to find the certain Oracle parameter files.  There are some files such as listener.ora and tnsnames.ora that should only have a single copy on a UNIX server, regardless of how many databases reside on the server.

For example, if we have a UNIX server with Oracle8, Oracle8i and Oracle9i installed, we may want to create a common location for generic file that are used by every database on the server.  These generic files include the following:

* tnsnames.ora – Each UNIX server should only have one tnsnames.ora file.

* listener.ora – Each server should only have one listener.ora file

* sqlnet.ora – There should only be a single sqlnet.ora file on a server.

To make these singular file, we must trick the Oracle software into thinking that the files are in their default directory ($ORACLE_HOME/network/admin), while in reality they exist in a common directory.

The common directories depend on the dialect of UNIX.

* /etc                  – This is used by HP/UX, Linux and AIX

* /var/opt/oracle       – This directory is used by Solaris

To create this illusion, the Oracle DBA must use soft links to make each $ORACLE_HOME have access to the proper file (Figure 10-1).

Figure 1: Using the UNIX soft link with Oracle

As we noted, it is important to have a single tnsnames.ora file of each server.  In UNIX, the search order for finding the tnsnames.ora file is as follows:

1. Search $TNS_ADMIN

2. Search /etc  (or /var/opt/oracle in Solaris)

3. Search $ORACLE_HOME/network/admin

The soft links are create by going to each $ORACLE_HOME/network/admin directory on the UNIX server and using the ln –s command to create a soft link for the tnsnames.ora and listener.ora files:

Symbolic links are like shortcuts or references to the actual file or directory. Most of the time these links are transparent when working with them through other programs. For example you could have a link to a directory to one hard drive inside a directory that lies on a different hard drive and an application will still treat it the same.

Symbolic links are used all the time to link libraries and make sure files are in consistent places without moving or copying the original. Links are often used to “store” multiple copies of the same file in different places but still reference to one file.

The Difference Between Soft and Hard Links
Hard links
Only link to a file not a directory
Can not reference a file on a different disk/volume
Links will reference a file even if it is moved
Links reference inode/physical locations on the disk
Symbolic (soft) links
Can link to directories
Can reference a file/folder on a different hard disk/volume
Links remain if the original file is deleted
Links will NOT reference the file anymore if it is moved
Links reference abstract filenames/directories and NOT physical locations. They are given their own inode

A symbolic link, also termed a soft link, is a special kind of file that points to another file, much like a shortcut in Windows or a Macintosh alias. Unlike a hard link, a symbolic link does not contain the data in the target file. It simply points to another entry somewhere in the file system. This difference gives symbolic links certain qualities that hard links do not have, such as the ability to link to directories, or to files on remote computers networked through NFS. Also, when you delete a target file, symbolic links to that file become unusable, whereas hard links preserve the contents of the file.

To create a symbolic link in Unix, at the Unix prompt, enter:

  ln -s source_file myfile

Replace source_file with the name of the existing file for which you want to create the symbolic link (this file can be any existing file or directory across the file systems). Replace myfile with the name of the symbolic link. The ln command then creates the symbolic link. After you’ve made the symbolic link, you can perform an operation on or execute myfile, just as you could with the source_file. You can use normal file management commands (e.g., cp, rm) on the symbolic link.

Note: If you delete the source file or move it to a different location, your symbolic file will not function properly. You should either delete or move it. If you try to use it for other purposes (e.g., if you try to edit or execute it), the system will send a “file nonexistent” message.

Practice Makes Perfect

To really grasp the concept of symbolic links lets give it a shot.

Go into the tmp directory:

cd /tmp

Make a directory

mkdir original

Copy over the host.conf file or any file to test with.

cd original
cp /etc/host.conf .

List the contents and take note of the inode (first column)

ls -ila

Create a symbolic link to host.conf called linkhost.conf

ln -s host.conf linkhost.conf

Now do list out the inodes

ln -ila

Notice how the inode for the link is different.

Now create a hard link to the same file

ln host.conf hardhost.conf

Now list the inoes one more time

ln -ila

Notice how the inode numbers are exactly the same for the hard link and the actual file.

Leave a comment