Table of Contents

Disk image on OSX

Backup and restore a disk image

Look in terminal the disk added

# mount
  /dev/disk0s2 on / (hfs, local, journaled)
  devfs on /dev (devfs, local, nobrowse)
  map -hosts on /net (autofs, nosuid, automounted, nobrowse)
  map auto_home on /home (autofs, automounted, nobrowse)
  /dev/disk1s1 on /Volumes/kernel (msdos, local, nodev, nosuid, noowners)

How is it partitioned

# ls /dev/disk1*
  disk1    disk1s1  disk1s2  disk1s3  disk1s4  

You can keep a copy of the actual content

# dd if=/dev/disk1 of=/tmp/myBackup
  3862528+0 records in
  3862528+0 records out
  1977614336 bytes transferred in 592.626715 secs (3337032 bytes/sec)

Or restore an image

# dd if=/tmp/myBackup of=/dev/disk1

Problems

During a Restore a disk image you can get such error Resource busy

# dd if=/tmp/myBackup of=/dev/disk1
  dd: /dev/disk1: Resource busy
  

If you try to unmount it, you will get the same error: Resource busy

# umount /Volumes/kernel/
  umount(/Volumes/kernel): Resource busy -- try 'diskutil unmount'

And if you try again, you will obtain a novel error: Operation not supported

# dd if=/tmp/myBackup of=/dev/disk1
  dd: /dev/disk1: Operation not supported

At this time, The /dev/disk1 is not present anymore. So, unplug and replug the card.

Again, if you try to to restore the file, you obtain:

# dd if=/tmp/myBackup of=/dev/disk1
  dd: /dev/disk1: Resource busy

Open the Disk Utility application (/Applications/Utilities/Disk Utility.app), and on your Disk drive, unmount any of it's partitions.

Do not eject the USB hard drive

Then you will be able to restore an image

# dd if=/tmp/myBackup of=/dev/disk1
  3862528+0 records in
  3862528+0 records out
  1977614336 bytes transferred in 592.626715 secs (3337032 bytes/sec)

During the restore process, you can check the status.

# pgrep -l '^dd$'
  10472 dd
# kill -SIGINFO 10472
  244697+0 records in
  244696+0 records out
  125284352 bytes transferred in 97.953448 secs (1279019 bytes/sec)

If you have a zipped image to restore, you can do

# unzip -p /tmp/myBackup.img.zip | dd of=/dev/disk1