Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

AmestrisXServe

macrumors 6502
Original poster
Feb 6, 2014
263
4
Easily Make Virtual Volumes Using Symlinks
How to overcome the post-merge jitters.

If you are like me, you will, over the course of years, have had many volumes on OSX. Some of these, over time, you will have by necessity, merged onto newer, and larger disks.

This can cause some problems with programmes that use direct pointers, such as iTunes, as the location of your files will change from (as an example) /Volumes/HDD-2/files to /Volumes/HDDNew/Archived/HDD-2/files.

In my most recent case, I had merged the volume 'Philosopher's Stone' to a volume titled 'Red Water'. The original path was /Volumes/Philosopher's Stone, however the new path is /Volumes/Fed Water/Philosopher's Stone (or, in my case, as 'Red Water' is my root volume, the path is /Philosopher's Stone).

Merging multiple volumes need not be painful, nor need it force you to manually reassign all of your fonts, videos, audio files, and so forth. It is rather simple to overcome this problem, but there is a disturbing lack of information on it available on the Internet, and few people will know off-hand that there is an easy-peasy solution.

Most of you know how to make an alias of files: Something that still lingers from the System 7 era, but the type of file created with this type of pointer is somewhat limited, especially if you are using networked file systems, and thus is not appropriate for using as a volume pointer.

The solution is to make a symlink: The pointer type used by UNIX and most UNIX-derived operating systems, including BSD/Dawrin, which is the core of OSX.

You can make a symlink from the command line (using Terminal), or by the SymlinkMaker plugin, however, as we will need to move the symlink to /Volumes, in order to 'fool' OSX into using it as the merged volume, we will need to drop to a CLI in any event, and it is easier to make it directly, rather than copying it; especially as if you use the wrong parameters with a cp command, OSX will try to follow the symlink during the copy, rather than copying a symlink directly.

Making a symlink is a very easy, effortless process, and it takes all of thirty seconds from opening Terminal, through to completing the process.

In my case, to make a symlink of /Volumes/Red Water/Philosopher's Stone, placed at /Volumes, I use this command:

ln -s "/Volumes/Red Water/Philosopher's Stone" "/Volumes/Philosopher's Stone"

This will generate a symlink with the filename Philosopher's Stone in the path /Volumes.

The formula for making a symlink is:

ln -s [source] [path/symlink-filename]

Thus, if I want to make a symlink of /home/Documents/Downloads as /home/NetFiles, I would type this:

ln - s /home/Documents/Downloads /home/NetFiles

This generates the symlink NetFiles in the path /home.

Using this, it is possible to create virtual volumes at the mountpoint /Volumes, that can be addressed as if they were disks. If you want to do real disk operations, such as Disk Utility recognising them as a mounted volume, other than general read/write file access, you will also need to modify your fstab to account for them.

Making the symlink only assists applications that use an absolute path as a pointer to files.

If you have ever merged multiple drives into one partition, and iTunes (or other software) yells at you because it can't find your files, this is a fas, and easy way to correct the problem. In my case, it also fixed Suitcase Fusion (a font manager), and a handful of other programmes, that rely on mountpoints and paths that no-longer exist, post-merge.

Another alternative, is to create a Sparse Disk Image, named as your old volume, and then copy, or move the contents of your old volume to this, and then mount the sparse disk image.

As sparse format images use only as much space as needed, you don't need to waste space, however, the maximum size of such an image is set on creation. They are R/W images, you can read, and write to it as normal, and set up an automount on login, if you need disk-level operations, such as using the area for swap space in Adobe CS.

If you are using 10.5, you can use the newer, Sparse bundle format, that uses directories on your media, instead of an image, so that the datum is available whether, or not, you mount the image.

For simple pointers however, the symlink trick works perfectly.


Persisting Across Reboots

Because MacOS can flush the contents of /Volumes on restarting, it is prudent to automate the process, so that it is not mandatory to execute the ln command each time you restart. Further, if any startup item or process requires the path that you are generating with the symlink, you want the link to exist for that process.

The best way to do this, is to create a simple shell script, that will execute on starting your system, before logging in. This will allow the path to exist for your login items, and is also very simple to create.

Creating The Shell Script
A shell script is a series of commands executed by the Console, that is automated to run in sequence. It is a plain text file, flagged as executable, that when run, sends those commands to the Console, as if you had entered each manually in a Terminal window.

To create this symlink shell script:

In terminal, type the following commands:

cd /System/Library/StartupItems
sudo mkdir scripts


Enter your password, when prompted.

Sudo nano symlink.sh

Enter your password, when prompted.
(The nano editor opens.)



In the nano editor, enter this:

#!/bin/bash
ln –s “/Volumes/[Disk]/[Path]” “/Volumes/[symlink]”


For example, to create a mountpoint of /Volumes/VirtualDisk, using the path /Volumes/MacHD/Merged/DiskTwo/ you would enter:

#!/bin/bash
ln –s “/Volumes/MacHD/Merged/DiskTwo/” “/Volumes/VirtualDisk”


Add an additional ln command entry, each on its own line, for each symlink that you need to create on startup.

Example:
#!/bin/bash
ln –s “/Volumes/MacHD/Merged/DiskTwo/” “/Volumes/VirtualDisk”
ln –s “/Volumes/MacHD/Merged/Hodgepodge/” “/Volumes/Hodgepodge”


Now, press Control + O to save the file, followed by Control + X to exit.

Back in Terminal, type this command:

sudo chmod a+x symlink.sh

Enter your password, when prompted.

This flags the shell script as executable, so that the system can run it on startup.

Your symlink.sh script will now run as soon as OSX loads, before you log into the system, relieving you of the task of manually assigning the virtual mountpoints at login. You can always edit the script later, by opening it in nano with sudo nano symlink.sh, and changing it you desire.

Example Symlink Shell Script

-XS
##30##

Document Revision 1.1
 
Last edited:
You may want to note that symlinked volumes in the Volumes folder are sometimes not kept across restarts. Necessitating the need to recreate or repoint the symlink.
 
I know: I'm planning to update this with a shell script to automate making the desired symlink, on startup, along with a basic tutorial, and possibly some fstab-related information, for anyone who needs it.

Update: Added semi-edited shell script tutorial, including setting as a pre-login start-up item.

I will delve into fstab related concerns if anyone is interested.

Please let me know if you see any technical errors: I will edit the column tomorrow, to clean up some rough edges.

I haven't any idea if this topic is at all useful to anyone else on the forum, and I am not even certain on what board it belongs best, but as I have used it in OSX 10.2 through 10.5, I posted it here, for my primary experience is with OSX PPC. I see no reason that it would not work in later versions of OSX, but as i don;t run anything later than 10.6, I can;t attest to the validity of that belief.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.