n8blog
distraction in action

So I've finally given up on Linux on my Mac. I'm running out of space in my
main partition and I haven't booted into Linux in almost a year, so it's time
to say goodbye to Linux and reclaim the 20GB or so that I gave it when I first
bought my PowerBook.

Last week I started the process of reformatting. I have four partitions devoted to Linux, and the obvious thing to do would be to combine them into one big partition and mount this under OS X. But I've never much liked dealing with separate partitions. One example of the annoyance involved is that my iTunes library is about 15GB and growing. If I was to move it to a 20GB data partition it would run out of space in the not-too-distant future. One interesting idea is take a data partition and add it seamlessly to my iTunes library, such that new files are created on the new partition but old files stay where they are. That way I could selectively “grow” certain directories without having to commit their contents entirely to one or the other partition. This is exactly what a union mount does.

To learn about union mounts type man mount and look for the union option. Here's what you'll find:

   union   Causes the namespace at the mount point to appear as the
           union of the mounted filesystem root and the existing
           directory.  Lookups will be done in the mounted filesys-
           tem first.  If those operations fail due to a non-exis-
           tent file the underlying directory is then accessed.  All
           creates are done in the mounted filesystem.

Sounds great, eh? It did to me, so I gave it a shot, union mounting a 5GB data partition on my iTunes Music directory:

sudo mount -t hfs -o union /dev/disk0s14 ~n8gray/Music/iTunes/iTunes\ Music

From the terminal's point of view, everything worked splendidly! I created a few files, unmounted the data partition, then re-mounted it elsewhere, and sure enough the files were created in the data partition. I was getting ready to break out the champagne when I noticed that the Finder was acting a bit strangely. For example, when I unmounted the union mount, my entire iTunes Music directory disappeared! Needless to say, I found this a little unsettling, but poking around with the terminal revealed that everything was still there and the Finder was just confused.

Further testing revealed the following interesting behaviors:

  • When the data partition is mounted on a directory, the Finder displays that directory as a network mount and doesn't show the files from the
    underlying directory. They're still there, and iTunes has no trouble
    finding them.
  • Once it's mounted, the filesystem can be really hard to unmount! The Finder and mds have a tendency to grab files on it and
    not let go. Examples include .Trashes and .Spotlight-V100. The Finder
    also shows a new “untitled” fixed disk on the desktop and in the disk
    sidebar. I think this may only happen after you perform some operation
    through the finder, such as deleting a file.
  • If you create a file in a directory under the one the mount is on, it gets created in the original filesystem. For example, if you
    mount onto a directory with a foo subdirectory, then
    type touch foo/bar then bar will be created
    on the original filesystem, not the union mounted one. If you create
    the file with touch bar then it gets created on the union
    mounted filesystem.

The moral of the story? The Finder is lame. (I guess we already knew that.) It doesn't support a really cool feature of the OS, so I'm stuck futzing with symlinks. It really makes me wish the Finder wasn't so deeply embedded in the OS and I could just remove it, but alas, that's thinking “too different” for the Mac world.

For more info about union mounts, see Amit Singh's ultra-informative article, What is Mac OS X?, and this article at rentzsch.com.

  Comments:

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Please type this word with the letters reversed: live