MacOS Catalina, 10.15.6

Given a .dmg file, foo.dmg, I want to be able to attach it so that its contents will be visible in the Finder application under the Locations section with an arbitrary name, bar.

When I attach/mount it with the command

$ hdiutil attach foo.dmg

It's being mounted by default under /Volumes/foo and is visible in MacOS Finder application under the Locations section as foo. I don't care what is the directory name (on disk) it's being mounted under in the /Volumes but I care about the name of the volume visible in the Finder under the Locations section.

Is it possible to do (programmatically) either

  • attach the foo.dmg under a different name (that will be visible in the Finder's Locations section).
  • rename the volume once it has been mounted with the default name.
  • modify the foo.dmg file to amend its volume name to be used when mounting (however my understanding is that the volume name is baked into the .dmg file at the creation time and I have no control of it)

When running

$ diskutil list

I can see the mounted disk image:

/dev/disk2 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        +494.4 MB   disk2
   1:                  Apple_HFS foo                     494.4 MB   disk2s1

Running command

$ diskutil rename /Volumes/foo "/Volumes/bar"      

gives me /Volumes/bar does not appear to be a valid volume name for its file system because of the naming limitations (having a / in the name)

and running

$ diskutil rename /Volumes/foo "bar"      

fails because one cannot write under the root (/) - Failed to rename volume: Read-only file system (49182).

1 Answer 1


It sounds like your disk image is in a non-writable format.

If this is the case, try converting your disk image to a writable one, using Images > Convert in Disk Utility's menu bar, and selecting "read/write" in the ensuing Save dialog's popup menu for format. Then, you should be able to rename the mounted volume to bar using the Finder or the diskutil rename command.

After your volume is renamed, you can convert the disk image back to the format you currently have it in.

Another alternative would potentially be to use Disk Utility to create a new read-only disk image from scratch (Using File > New Image > Image from Folder…) from the files in the mounted volume at /Volumes/foo. You would choose the name bar.dmg, which would cause Disk Utility to name the inner mountable volume bar. Then, you would rename your disk image file to foo.dmg.

Both of these paths would get you to your stated goal of having a file named foo.dmg mount a volume named bar with the files currently inside your volume named foo.

I hope one of them works for you!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .