22

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?

4
  • 1
    I feel like this might be an XY question — why do you want this?
    – grg
    May 7, 2014 at 11:53
  • 1
    @grgarside I'd like to mount various dumps of floppis, hds, what so ever. Why does that matter?
    – bot47
    May 7, 2014 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, 2014 at 18:37
  • 1
    Duplicate of serverfault.com/questions/174909/mount-block-file-on-osx
    – bot47
    May 7, 2014 at 18:52

4 Answers 4

36

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

2
  • 1
    Mount as you like? After your attach command I can see it in DiskUtility under "Disk Images" and as "Apple read/write Media", however the MOUNT icon is disabled. When I click on the media to the left, I see the correct size of the image, but with Uninitialised.... so what now?
    – basZero
    Feb 2 at 20:13
  • @basZero You'd omit the -nomount option, and it'll simply mount the drive file automatically. If you already ran this with the -nomount option, you can detach the file using the device name the first command returned. E.g., in my case, It attached the loop file as /dev/disk27, so you can sudo hdituil detach /dev/disk27 to remove that unmounted disk, then do a sudo hdiutil attach -imagekey diskimage-class=CRawDiskImage YOUR_IMAGE_FILE_THINGIE Apr 8 at 12:03
21

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.

8
  • 1
    Are you sure that dmgs don't habe a structure? They can be compressed, encrypted and have checksums...
    – bot47
    May 24, 2015 at 17:35
  • 4
    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. May 25, 2015 at 14:08
  • 6
    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, 2016 at 0:14
  • 2
    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, 2017 at 10:16
  • 1
    Very nice solution, I have just used it myself to take a look into my dd backup of my SSD before installing macOS... It's simpler than losetup and shit on Linux. Dec 30, 2020 at 13:23
7

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

5
  • This nearly fits my needs. Do you know a way to do directly mount them?
    – bot47
    May 7, 2014 at 18:40
  • @Max Could you clarify what you mean by 'directly'?
    – grg
    May 7, 2014 at 18:40
  • I want to treat a file as if it was a character device and use mount on it.
    – bot47
    May 7, 2014 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, 2014 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.
    – bot47
    May 7, 2014 at 18:48

You must log in to answer this question.

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