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?
-
1I 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?– bot47May 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
-
1Duplicate of serverfault.com/questions/174909/mount-block-file-on-osx– bot47May 7, 2014 at 18:52
4 Answers
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
-
1Mount 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 withUninitialised
.... so what now?– basZeroFeb 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 cansudo hdituil detach /dev/disk27
to remove that unmounted disk, then do asudo hdiutil attach -imagekey diskimage-class=CRawDiskImage YOUR_IMAGE_FILE_THINGIE
Apr 8 at 12:03
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.
-
1Are you sure that dmgs don't habe a structure? They can be compressed, encrypted and have checksums...– bot47May 24, 2015 at 17:35
-
4Firstly, 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
-
6Late 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. Jul 14, 2016 at 0:14
-
2Truly awesome solution. I enjoy using the command line, but nothing beats something you can remember and do so quickly from the UI.– LaXNov 15, 2017 at 10:16
-
1Very 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
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
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?– bot47May 7, 2014 at 18:40
-
-
I want to treat a file as if it was a character device and use
mount
on it.– bot47May 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 anddd
the raw image onto it, then mount this dmg, but I'd like to mount it directly, something likemount -t hfs <path-to-file-created-using-dd> /mountpoint
. Though, this is not possible, asmount
only works with devices, not with usual files. On Linux I'd use loop-devices, pointing them to the file and usemount
on them afterwards.– bot47May 7, 2014 at 18:48