osx - Trying to restore a Mac OS X system from DMG file fails

  • Phil Meadway

    I'm in a bit of a panic at the moment. My MacBOok was hanging and generally misbehaving so I decided it was time to do a clean install. I took 2 backups:

    1. Time Machine (happens anyway, but I ensured it was up to date)
    2. A complete disk image into a DMG file which I put on an external drive.

    I re-installed mac/os from a bootable USB image I made of 10.8.2. So far, so good. Then I went to recover my users, apps etc from Time Machine. Unfortunately Migration Assistant could not see the backup. It could see my wife's MacBook backup, but not mine.

    I went to the command line and found the backup on the AirPort Extreme disk and used cp -r to copy some files across, but this wasn't really what I wanted to do. I wondered if I could do this via Time Machine, so I enabled it. Big mistake! Time Machine kicked in for the first time and appears to have overwritten my backup! I now don't have my original files on the Time Machine backup.

    So, I tried doing a complete restore from the DMG file I created using Disk Utility – it would not mount the DMG file. After some investigation I discovered that this may be because I have multiple partitions in my DMG file.

    The situation I am in now is I can use

    hdid -nomount /Volumes/ExternalFreeAgent1TB/PipMacBookPro20121209.dmg

    to mount the dmg file. It shows up in diskutil list:

       #:,    TYPE NAME,                    SIZE,       IDENTIFIER
       0:,    GUID_partition_scheme,       *320.1 GB,   disk2
       1:,    EFI,                         209.7 MB,   disk2s1
       2:,    Apple_HFS Macintosh HD,      297.4 GB,   disk2s2
       3:,    Apple_Boot Recovery HD,      650.0 MB,   disk2s3
       4:,    Apple_HFS bootcamp,          21.7 GB,    disk2s4

    disk0 is the MB, disk1 is the external drive the DMG file is on, and disk2 is the DMG file itself.

    Trying to mount the partition I'm interested in fails:

    $ diskutil mount readOnly -mountPoint /Volumes/Old /dev/disk2s2
    Volume on disk2s2 failed to mount

    I'm at a loss as to what to do next. This is currently the only copy of my data (docs, emails, photos, music) going back 10 years or so any help would be greatly appreciated!

  • Answers
  • Andrea

    I just had the same problem and did not find anything useful first, but now came up with a solution myself. Like you, I first attach the drive using hdutil like you did (with -noverify to speed up the process). Instead of diskutil, I used mount_hfs like this:

    sudo mount_hfs -j -o rdonly /dev/disk3s2 ~/mountpoint

    Not sure if -j (ignore journal) is needed, but -o rdonly is required! ~/mountpoint is a directory I created beforehand.

  • Related Question

    osx - How do software .dmg files mount or work in OS X?
  • ymasood

    I am a new Mac user and have an iMac. Coming from the Windows world where everything is installer based, OS X seems to mount .dmg files and run them. I've seen this happen prior to an install and later it requests us to move an icon to the Applications folder.

    Can someone help me unclutter the install process on OS X? What or how does it work?

  • Related Answers
  • churnd

    DMG stands for Apple Disk Image. These are treated like a Volume of their own, but one that's contained in that file. Volumes on a Mac are basically any physical or virtual disk that can be mounted permanently or temporarily. The hard drive icon you see on your desktop (probably Macintosh HD unless you renamed it) is a volume. You can clone one volume to another easily, whether it be physical or virtual. This is one of the features that makes a Mac so powerful.

    These volumes are "mounted" or "unmounted" on the Mac OS. This is similar to Windows in that when a removable drive is plugged it, it's automatically assigned a drive letter (E:)... in other words, it's mounted. When you "safely remove" it, you're unmounting it. You must always unmount a drive on the Mac OS before removing it, whether it be physical or virtual.

    A DMG is similar to any other compressed file, like ZIP in Windows, but more powerful on the Mac OS. The DMG is a self contained volume formated HFS+ that retains file system attributes that are important. These are called resource forks and are usually invisible to Mac users. If you've ever copied a file from your Mac HD onto a FAT32 thumb drive, then plugged that drive into a Windows box and seen those pesky "._name" files, those are resource forks. They're important to a Mac as they contain metadata pertaining to the file itself.

    When you download a disk image containing an Application, the app should be copied to your Applications folder before running it. This is because most disk images are read-only, and running it from inside the disk image can produce undesirable results.

    Some Applications come in a package which are handled by the Macintosh Installer. These usually need to write system setting files that require administrative access and will prompt you for your password. Make sure you know where a package came from before giving it your administrative password.

    The application, when launched, will create a few files that it needs in your Library folder in your Users directory (your username... looks like a Home icon in Finder). Settings you change while using the application are stored into these files, so if you "uninstall" the application by moving it into the trash, then re-install it later, those settings are retained. This can be a good or bad thing, depending on what you want. If you want to completely remove an application along with all of it's settings pertaining to you and/or the system, first see if the Application came with an uninstaller. This might be in the application folder itself or in Utilities (Adobe is notorious for having it's own uninstallers). Usually, if an application was installed via Macintosh Installer, it will have it's own uninstaller or you can visit the company website for instructions on how to remove it. If it was a standalone application and you want to completely remove everything related to it, you can use a great free program such as AppCleaner to do this.

    Hope that helps some. Enjoy Mac!

  • caliban

    It works just as you've described. Most applications in OS X installs this way - open the .dmg, copy the app over, run. Some have installers, but not much.

    Essentially an app is a self contained binary, along with resources, etc etc. If you copy an application to a thumb drive and bring it to Windows, you will notice it is actually a folder containing files, e.g firefox.app*.*.

    So not to worry too much, you are doing it right.

  • Tadeusz A. Kadłubowski

    .dmg is a disk image. Something like a virtual disk. You can mount it as any other filesystem (USB stick, CD, whatever).

    You can use drag-and-drop to copy files from the mounted disk image to wherever you like. If the file is an application, then you usually drag-and-drop it to Applications.