Using Macintosh Disk Images under NetBSD

NetBSD has some useful tools for dealing with Macintosh disk image files. You can use these to copy files out of or into a Disk Copy disk image, or create a new disk image that can be mounted and read by Disk Copy on a Mac.

If you're used to using Disk Copy on the Mac, you may find using these commands a little involved, but they get the job done.

How to Mount and Read a Macintosh (HFS) Disk Image

  1. Configure a new vnode disk using the disk image as the contents:
    vnconfig -v -c vnd0d MacDisk.img
    
  2. Mount the vnode disk as an HFS volume:
    hmount /dev/vnd0d
    
  3. Do whatever you need to with the contents of the disk image (copy files in or out, delete files, etc.):
    hls
    hcopy "Docs:ReadMe" /tmp/readme
    ...
    
  4. When you've finished, unmount the HFS volume and unconfigure the vnode disk:
    humount
    vnconfig -v -u vnd0d
    

How To Create a New Macintosh Disk Image from a Directory

The easiest way to do this is to use mkhybrid. Here we're taking the directory tree starting at /tmp/mac/system and copying into a new HFS disk image at /tmp/test.img.

mkhybrid  -hfs  -hfs-volid "My Mac Disk"  -o /tmp/test.img  /tmp/mac/system

You can copy the image file to a Mac, set the Type and Creator to rohd and ddsk, and double-click the file to mount it with Disk Copy.

How To Create a New Macintosh Disk Image from Scratch

  • If necessary, determine the amount of space required for the stuff you intend to copy:
    du --block-size=1024 /tmp/mac/system
    
  • Create an empty file of the required size:
    dd if=/dev/zero of=/tmp/test.img bs=1024 count=6511
    

    (To create a 1.44 MB floppy image, use bs=512 and count=2880)

  • Configure a loopback file device for the blank disk image:
    vnconfig -v -c vnd0d /tmp/test.img
    
  • Create an HFS filesystem on the image:
    mkhybrid -hfs /dev/rvnd0d
    
  • Umount the HFS volume and unconfigure the vnode disk:
    humount
    vnconfig -v -u vnd0d
    
  • The new image can now be copied to a Macintosh and mounted using DiskCopy.