10

I'd like to mount a raw dump of a disk, e. g. like those created by dd? Is there something like a loop device in OS X?

  • 1
    I feel like this might be an XY question — why do you want this? – grg May 7 '14 at 11:53
  • 1
    @grgarside I'd like to mount various dumps of floppis, hds, what so ever. Why does that matter? – Max Ried May 7 '14 at 12:29
  • Well, I have an answer, but since I'm not sure why you want this, I don't know if it's suitable. – grg May 7 '14 at 18:37
  • 1
21

For those encountering the same problem:

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

then mount it as you like.

Source: https://serverfault.com/questions/174909/mount-block-file-on-osx

6

This is funny because it's actually really really simple. Rename it to a .dmg extension, as a DMG is a raw image too.

In contrast to the above solution, this will work on dd rips of entire drives in addition to partitions.

  • 1
    Are you sure that dmgs don't habe a structure? They can be compressed, encrypted and have checksums... – Max Ried May 24 '15 at 17:35
  • 3
    Firstly, there is a DMG file format family, but it's basically DD in it's core before crypto etc. See here for more info: newosxbook.com/DMG.html The important bit is in the second paragraph. Basic Hdiutil created DMGs are actually just renamed RAW dumps, with no identifying header, footer, metadata or wrapping of any sort. If and when you then try to compress/encrypt the data, a trailing block is created with instructions on how to crypto/comp format. When the mounter is done decrypting, it's a DD again. – user1901982 May 25 '15 at 14:08
  • 3
    Late to the party but figured it was worth adding a +1 here. I just did this with a raw disk image from a 20 year old PC and it worked perfectly. – Matt Lacey Jul 14 '16 at 0:14
  • 1
    Truly awesome solution. I enjoy using the command line, but nothing beats something you can remember and do so quickly from the UI. – LaX Nov 15 '17 at 10:16
2

The hdiutil command given above is correct, however, newer Mac SSDs have a 4096 byte block size and hdiutil defaults to 512 for disk images so if you attempt to mount a 4096 byte block size image it will look like nonsense to the system.

Adding -blocksize 4096 to the command will let you work with an image created from a newer Mac:

hdiutil attach -blocksize 4096 -noverify -nomount diskimage.img
1

You can create a disk image of the disk using Disk Utility. Select the disk or the disk's partition in the list on the left, then File → New → Disk Image from <disk1>.

Once the image is created, you can mount it like any other volume and if you selected read/write you can read/write to the image like a mounted volume. The image is mounted in the same place as the original disk would be: /Volumes/diskname.

  • This nearly fits my needs. Do you know a way to do directly mount them? – Max Ried May 7 '14 at 18:40
  • @Max Could you clarify what you mean by 'directly'? – grg May 7 '14 at 18:40
  • I want to treat a file as if it was a character device and use mount on it. – Max Ried May 7 '14 at 18:41
  • @Max I'm still not certain what you mean :) You can use mount on the mounted image like any other image and it is shown alongside the physical disks connected — what exactly of mount do you want to use? – grg May 7 '14 at 18:44
  • I have raw images created with dd for example. I want to mount those. I could create a dmg and dd the raw image onto it, then mount this dmg, but I'd like to mount it directly, something like mount -t hfs <path-to-file-created-using-dd> /mountpoint. Though, this is not possible, as mount only works with devices, not with usual files. On Linux I'd use loop-devices, pointing them to the file and use mount on them afterwards. – Max Ried May 7 '14 at 18:48

You must log in to answer this question.

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