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).

You must log in to answer this question.

Browse other questions tagged .