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

haravikk

macrumors 65832
Original poster
May 1, 2005
1,504
26
This is quite an unusual case. But quite simply; I'm using a script to mount some disk-images at start-up, triggered as a LaunchDaemon.

Now, as far as I can tell these images launch exactly as expected, but when I go looking for them they aren't mounted at all (they aren't even attached) and I can't for the life of me figure out why.

I'm going to try to extract the relevant parts of my shell script only, so to keep it short I'll be skipping much of the error-checks that I have as I'm happy that they're working as expected anyway.

The variable IMAGEFILE is a path to a disk-image (sparse bundles in my case) and MOUNTPOINT is the folder I want to attach the image to.

Code:
# Attach the image-file
DISKS=`hdiutil attach -drivekey system-image=yes -nomount "$IMAGEFILE"`

# This ad-hoc function lets us get a disk identifier in spite of 
# variable scoping issues due to use of a pipe
fnGetDisk() {
	echo "$1" | while read IDENTIFIER TYPE NAME
	do
		if [ "Apple_HFS" = "$TYPE" ]; then
			echo $IDENTIFIER
			break
		fi
	done
}

# Find an HFS volume to mount
DISK=$(fnGetDisk "$DISKS")

# Store permissions from mount point
eval `stat -s "$MOUNTPOINT"`
OWNER="$st_uid:$st_gid"
PERMS="$st_mode"

# Mount the RAM disk to the target mount point
mount -t hfs -o union,nobrowse,noatime $DISK "$MOUNTPOINT"

# Restore permissions for mount point
chown $OWNER "$MOUNTPOINT"
chmod $PERMS "$MOUNTPOINT"
Now, I have error tests and echo statements for every major part, but everything appears to be working and Console shows nothing but success messages, yet two of the three images I'm mounting aren't there after starting up. I've been unable to determine why the third image is attached by the first two are not.

In my specific case I'm using disk images to replace certain commonly accessed folders, in order to avoid writing to my SSD (the disk images are on another volume). The specific folders I'm switching out are:
/private/tmp (using a RAM disk)
/var/run (another RAM disk)
/var/db (persistent disk image)
/var/folders (persistent disk image)
/var/log (persistent disk image)

Now, the two RAM disks work fine, so I've omitted that part from the code. However, /var/db and /var/folders, despite appearing to successfully mount, are unmounted by the time I've logged in.

Particularly unusual is that /var/log is getting the disk identifier of disk14, despite appearing last in the log, while the /var/db and /var/folders are getting disk15 and disk16 respectively. However, by the time I've finished logging in these two identifiers are taken by my two core storage (encrypted) volumes. So this seems to suggest that /var/db and /var/folders somehow aren't mounting, yet not providing any meaningful error (seems unlikely) or they're being unmounted very early on.

If I run the script manually then they mount as expected, so something weird is going on during startup.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.