Instantly share code, notes, and snippets.

@scottsb / forked from Hais/
Last active Oct 31, 2018

What would you like to do?
Create and manage a case-sensitive disk-image on macOS (OS X).
# ---------------------------------------------------------
# Customizable Settings
# ---------------------------------------------------------
# ---------------------------------------------------------
# Functionality
# ---------------------------------------------------------
create() {
hdiutil create -type SPARSE -fs 'Case-sensitive Journaled HFS+' -size ${VOLUME_SIZE} -volname ${VOLUME_NAME} ${VOLUME_PATH}
automount() {
cat << EOF > "/tmp/com.${VOLUME_NAME}.plist"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
sudo cp "/tmp/com.${VOLUME_NAME}.plist" "/Library/LaunchDaemons/com.${VOLUME_NAME}.plist"
rm "/tmp/com.${VOLUME_NAME}.plist"
noautomount() {
sudo rm -f "/Library/LaunchDaemons/com.${VOLUME_NAME}.plist"
detach() {
m=$(hdiutil info | grep "${MOUNT_POINT}" | cut -f1)
if [ ! -z "$m" ]; then
sudo hdiutil detach $m
attach() {
sudo hdiutil attach -notremovable -nobrowse -mountpoint ${MOUNT_POINT} ${VOLUME_PATH}
compact() {
hdiutil compact ${VOLUME_PATH} -batteryallowed
help() {
cat <<EOF
usage: casesafe <command>
Possible commands:
create Initialize case-sensitive volume (only needed first time)
automount Configure macOS to mount the volume automatically on restart
noautomount Stop macOS from mounting the volume automatically on restart
mount Attach the case-sensitive volume
unmount Detach the case-sensitive volume
compact Remove any uneeded reserved space in the volume
config Show current configuration and instructions on changing
help Display this message
config() {
cat <<EOF
The behavior of the script may be modified by seting the following environment variables.
If not set the script will use sane defaults.
Location where case-sensitive volume will be mounted
Current effective value: ${MOUNT_POINT}
Location where image file should be stored
Current effective value: ${VOLUME_PATH}
Name of case-sensitive workspace as visible in macOS Finder app
Current effective value: ${VOLUME_NAME}
Maximum size of volume (will auto-grow up to this)
Current effective value: ${VOLUME_SIZE}
invalid() {
printf "casesafe: '$1' is not a valid command.\n\n";
case "$1" in
create) create;;
automount) automount;;
noautomount) noautomount;;
mount) attach;;
unmount) detach;;
compact) compact;;
config) config;;
help) help;;
'') help;;
*) invalid $1;;

This comment has been minimized.

swinton commented Sep 17, 2016

This is great, thank you for providing it 🙇


This comment has been minimized.

jeiros commented Oct 18, 2016

This saved my butt today!
🙏 God bless 🙏


This comment has been minimized.

hoppinjohnz commented Jan 11, 2017

Thanks for sharing this improved disk image script. It solved my problem of developing applications in Java with Mac OS X. Well done.


This comment has been minimized.

joshka commented Apr 28, 2017

Thanks for sharing this. For multiple mounts, it seems that you would need to update: to include ${VOLUME_NAME}


This comment has been minimized.

crdesai commented Nov 15, 2017

Thanks for the script. It helped me resolve an issue I was facing with my package. I enabled automount while creating the volume at this time. However, I do not need the volume anymore. How can I make sure OS does not automount it when i restart my machine?


This comment has been minimized.


scottsb commented Nov 16, 2017

@joshka, this wasn't really intended to support multiple mounts, but I don't see any harm in that suggestion, so I'll update it.

@crdesai, I just updated this to include a "noautomount" subcommand as well.


This comment has been minimized.

strogonoff commented May 19, 2018

SPARSEBUNDLE might be a better choice than SPARSE. The bundle appears to split the image into chunks, and therefore works better with backup software which only needs to update the changed chunks after the first copy.

See also:


This comment has been minimized.

tpinne commented Sep 27, 2018

I'm experiencing very very veeeeery bad IO performance since I updated to macOS Mojave. Anyone experiencing the same problem?


This comment has been minimized.

djedi commented Oct 31, 2018

I'm having a number of issues since installing Mojave. I can't seem to mount at all right now. The process just hangs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment