MacPorts on Snow Leopard without changing your current drive’s filesystem.

I had been experiencing a LOT of trouble with MacPorts on OS X after upgrading to Snow Leopard. As it turns out, I apparently was bitten by the perennial case-insensitive filesystem, which of course is the default option when one installs OS X (or has it installed for them via Apple).

So I followed the instructions on Konstantin Läufer’s Blog: Prerequisites for Building OpenWRT SDK on Snow Leopard with a slight amendment, given that I was completely unwilling to change the host filesystem for no particularly compelling reason. (Yes, I am a Unix guy, but I really don’t care about case-sensitivity when I am not doing programming.)

Enter disk images, which is perhaps one of the best OS X features that is taken for granted and can be a true life saver at times. With an disk image, you can create a filesystem that differs from the host as an read-write image, mount it, and use it from the OS or any application–seamlessly. So here are the steps to get /opt/local to live inside a case-sensitive filesystem but be exposed through the host filesystem (so that MacPorts can be maintained properly):

  1. Launch Disk Utility (Applications -> Utilities -> Disk Utility)
  2. At your discretion, create either a regular read/write image or sparseimage. Sparse images are the preferred option, especially if you want room for growth. Make sure you enable the case-sensitive option, which is needed for MacPorts (at this time).
  3. I suggest putting the image somewhere intelligent like your home directory -> Disk Images (create a folder). You may also want to turn off backups of this directory in Time Machine, if you are updating MacPorts frequently. It is easy to put an entire folder under an exclusion list in Time Machine.
  4. When you created the disk image in step 2, you likely gave it a name. I named my image MacPorts. Upon creation, the image should mount automatically and will stay mounted until you unmount it. In my case, I see the following when I go into Terminal:

    /dev/disk3s2 on /Volumes/MacPorts (hfs, local, nodev, nosuid, journaled, noowners, mounted by gkt)

  5. So by way of example, I did the following. You may opt to do something different, depending on your needs:

    mkdir -p /Volumes/MacPorts/opt/local
    Make sure /opt does not exist. (I will let you decide how to do this!)
    ln -s /Volumes/MacPorts/opt /opt

  6. At this point /opt/local is living on your disk image. You may now proceed with the MacPorts installation on Snow Leopard.
Update: One thing I discovered after making this posting, of course, is that there is seemingly no “nice” way to make disk images mount at boot time. I still haven’t figured this out. However, I have discovered that for the most common use (i.e. when I am logged in on my desktop), I just need to make sure there is a proper script that runs at boot time to ensure the MacPorts volume is mounted.
So to get this working, you just need a tiny bit of AppleScript code. You can actually record the actions using the AppleScript Editor in OS X. Then you end up with a script that looks like this:
tell application “Finder”
activate
set target of Finder window 1 to folder “gkt” of folder “Users” of startup disk
open document file “MacPorts.sparseimage” of folder “Disk Images” of folder “gkt” of folder “Users” of startup disk
close Finder window 1
end tell
Pretty slick. Then all you need to do is compile it into an Application (a .app) bundle. Drag the bundle to the “dock” and right click, Open at Login. That’s it. You’ll have the bundle mounted when you log in to your desktop and be available immediately.

Post a Comment

Your email is never shared. Required fields are marked *

*
*