Hints and Tips Topic
   >  Mounting a New File System
   >  File System will not Mount
   >  Using Symbolic Links
   >  Kernel Panic - not syncing VFS
   >  Unmounting a File System


Using Symbolic Links

What are Symbolic Links?

A Symbolic Link in Linux, is simply a logical directory entry that points to another (-normally physical) file or a directory elsewhere; you can liken them to Shortcuts under Windows. At first reading, this seems to be of little use: why create one entry that points to another? Commonly, there are two main reasons:

  • You can add many logical links (-each with different names and in different locations) that point to the same physical file, directory or application. This means the real resource does not have to be duplicated, so saving space and easing maintenance or upgrades

  • You can alter your directory structure, placing files on different devices, without affecting the operation of your computer

A Symbolic Link in Linux, is simply a logical directory entry that points to another .. file or a directory

In this article, we will concentrate on the latter: using symbolic links to place files on different devices transparently.

Creating Symbolic Links

The syntax for creating a symbolic link is as follows:

ln -s <symbolic link name designator> <directory to link to>

For example:

ln -s myFilms /mnt/data01/users/store/Video

Creates an entry called myFilms in the current directory that, when referenced, will actually list the files from the /mnt/data01/users/store/Video directory. The usage is identical when linking to files as well as directories.

Note: if you ever need to remove a symbolic link, then you can just delete it (-using the rm command) without affecting the directory that the link points to.

Strategies to Deal with Lack of Disc Space

Suppose, for example, you have filled up your /home directory with all your uploaded photos. Under Linux, you have two main choices:

  1. You can attempt to extend the partition that the /home system resides on (-assuming you have spare space on the device you originally created it). The filesystem will also need to be unmounted first

  2. You can create a symbolic link to point a directory to a completely different device and then move your files off the original device to the new location

Option 1 is perfectly valid, but you needed to have held back some free space on that device when you originally set up the partitions. In addition, it is not risk-free: there is a (small) chance that the extend will fail, in which case all the data in the original partition could potentially be lost, so you need to back it all up first.

Option 2, however, is less risk and less work: granted, the performance may not be quite as good as keeping all the data together on the same physical device (-especially if that device is an SSD) but, for most users, this will be quite acceptable.

Using Symbolic Links to Place Files on a Different Device

Going back to our example of having filled up the /home/fredb/Pictures directory with all our uploaded photos; how would we use symbolic links to solve the problem? There are six steps:

  1. Set up the new destination directory for the photos. This could be anywhere, on any device - for example: $ mkdir /mnt/mydiscs/storage/photos

  2. Copy the photos from the current directory (/home/fredb/Pictures) to the new directory created in step 1: $ cp -pR /home/fredb/Pictures/* /mnt/mydiscs/storage/photos/

  3. Temporarily rename the original directory to something else (-this is just for safety's sake, in case anything goes wrong): $ mv /home/fredb/Pictures /home/fredb/Pictures.old

  4. Create the symbolic link with the same name as the old directory and point it to the new location: $ ln -s /home/fredb/Pictures /mnt/mydiscs/storage/photos

  5. Check that all the files are still listed if you access the original directory name: $ ls /home/fredb/Pictures. If you are affecting the /home directory, it's also advisable to try logging out and back in as the affected user to check all looks OK

  6. Once you are sure that nothing is missing in the new directory and everything looks good, you can delete the old directory to free up the disc space: $ rm -R /home/fredb/Pictures.old

Congratulations! You have now increased the available space on your /home filesystem by the size of it's /home/fredb/Pictures subdirectory!

HomeSite IndexDesktop GuideServer GuideHints and TipsHardware CornerVideo SectionContact Us

 sitelock verified Firefox Download Button