40

How can block files be mounted on osx? I tried

hdiutil attach filename

however this is terminating with

hdiutil: attach failed - not recognized

hdiutil only seems to work for iso/dmg images. On ubuntu the block file can easily be mounted with

mount -o loop filename mountpoint

Background: I used vdfuse (http://forums.virtualbox.org/viewtopic.php?f=26&t=33355&start=0) to mount virtual disk files (e.g. vhd). vdfuse itself works fine and the partitions contained in the virtual disc appear as block files on the mount point.

VHD File -> /my/mountpoint/Partition1, Partition2, ...

On ubuntu the block files can be mounted via

mount -o loop /my/mountpoint/Partition1

however the -o loop option does not exist on osx.

2 Answers 2

65

hdiutil was the right way to go but a crucial ingredient are the parameters.

The command

hdiutil attach -imagekey diskimage-class=CRawDiskImage -nomount filename

perfectly mounts the block file as a block file system. Afterwards you can mount any fs like Chris S pointed out.

3
  • 26
    Just in case anyone gets stuck here... this command will give you something like /dev/disk1. You can run hdiutil mount /dev/disk1 to actually see the files inside. It will print out the location of the mount point, something like /Volumes/Untitled
    – Sam
    Jan 30, 2012 at 19:55
  • Doing this gives me 3 devices for partitions with filesystem, but does not expose the 4th empty partition. Is it possible to expose empty partitions, too for creating filesystems on them?
    – andig
    Jan 10, 2021 at 13:40
  • @Sam in my case i got /dev/disk3 and I tried to type hdiutil mount /dev/disk3 and it gives me hdiutil: mount failed - No such file or directory
    – Zenko
    Feb 28, 2021 at 1:25
1

Doesn't the partition have a filesystem? Usually you mount it with something like mount -t ntfs /my/mountpoint/Partition1 /mnt

2
  • thanks, this would be usually the way to go. however this would require /my/mountpoint/Partition1 to be a block device... It the same reason you cannot mount an iso by mount /path/to/iso /path/to/mountpoint Aug 26, 2010 at 18:26
  • 1
    Why not just make a memory-disk device that's file backed? Off the top of my head I think it's hdid /my/file and it will return a block device name.
    – Chris S
    Aug 26, 2010 at 20:18

You must log in to answer this question.

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