Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Create OS 9 style .img disk images with OS X System
I know that I'm not the only one out there who uses OS 9 once in a while. Not everyone has upgraded their software to Mac OS X, so whether you are trying to be compatible with other people, or just taking care of your own computers, it's nice to be able to support OS 9. Of course, one of the things it'd be nice to do is to be able to create Mac OS 9 compatible disk images. That way, if you have to use OS 9 to recover from a backup, you can do it. Handily, OS X can open the .img files, too! However, creating them is a different story. For a long time, the only way I found was to boot up in OS 9 and make the images there. At long last, I have now found a way to do it directly in Mac OS X. As is true with most things in OS X, there are two methods: GUI and CLI.

One last thing, before we begin. All this is done under OS 10.2 I sincerely hope that Apple has made the process work correctly in 10.3 or 10.4 (yet to be released) so that you can simply image a folder as an NDIF image. Until then, read the rest of the hint...

GUI Method
This part essentially walks you through the making your nice image. It's really easy, and you should have no trouble whatsoever with it as long as you follow the instructions. You only have to type one command in the Terminal, and that's only once ... never again. Before you begin, as always, it's a good idea to read through the entire process. Here are the steps:

  1. If you've never done this before, you get to do your one step in the Terminal now. After doing this once, you can skip this step. All you have to do is open Mac OS X's Terminal (located in /Applications -> Utilities) and type in defaults write com.apple.DiskCopy expert-mode 1 and hit return. There. That wasn't so bad.
  2. Now, you can go fire up Disk Copy. On the way there, check to see how big the files are that you want to put on the image are.
  3. In Disk Copy, create a new image, which should be approximately 1% larger in size than your files (in order to make sure it's big enough). Tell Disk Copy to make it a Sparse Disk Image (.sparseimage) with no partition map.
  4. Disk Copy should create the image and mount it in the Finder for you. On my computer, the system puts up an error saying something along the lines of "you have inserted a disk that Mac Os X cannot read. What do you want to do?" The Ignore button seems to work well for me. Anyway, select all your files that should be on the disk image and copy them over to the disk image.
  5. Unmount the image. If you accidentally made your image too small, I think sparse disk images are supposed to be resizable so you can try to do that if you like.
  6. Back in Disk Copy, select the "Convert Image..." option. Select the sparse disk image and convert it to one of the NDIF formats (all of them are OS 9 disk image formats). For the things I do, NDIF Compressed is the best setting, but feel free to experiment.
  7. Now you get to wait for a long time while disk copy makes your image. As far as I can tell, it's not any faster in OS 9, so that must just be the way it is.
  8. When Disk Copy finishes, you are pretty much done. You should go and delete the .sparseimage file, since you don't need it anymore. If you find that Disk Copy's expert mode drives you bonkers, you can change things back by typing defaults delete com.apple.DiskCopy expert-mode in the Terminal.
CLI method
Just a quick note before we start, this section is not for people who are easily intimidated, scared, or otherwise destabilized by advanced ideas. Everything in this method is in the Terminal -- everything. You can even log in in console mode if you like (at the login screen, select other, and type ">console" as the username and leave the password blank. At the prompt, you can then enter your username and password. Keep in mind that the Terminal gives no visual as you type a password, but it does see you typing.)

This part is also where I get to explain to you all why you cannot simply use Disk Copy to create the image in one go, but have instead to create a special sparseimage first and then convert that to an NDIF. The main reason is that NDIF images don't support partition maps. Apparently Disk Copy's normal mode of operation is to create a .sparseimage with a partition map (CD I think) with your files and then convert that into the final image, unless your original image is a UDIF read/write (possibly a UDIF read only). UDIF is the format of a .dmg disk image. Well, when you try to use it to image a folder to an NDIF image, Disk Copy still makes the .sparseimage the normal way, and then proceeds on to converting to an NDIF. BAM. Dead stop. You can't convert an image with a partition map to a format that doesn't support the partition map. Ouch.

Anyway, the point of all this is that if you want to make a nice NDIF, you have to do it by hand ... or at least, make a .sparseimage with no partition map, and then convert it to an NDIF. Fun, fun!
  1. Our first step is to find out how big the disk image needs to be. du -s imagedirectory will return a number which is the number of 512 byte sectors in that directory.
  2. Good. Now you know how big our first image needs to be. Let's make it: hdiutil create -sectors number -type SPARSE -fs HFS+ -volname volumename -layout NONE imagelocation. The number of sectors should be about 1% larger than the number that du returned. Give it whatever volume name and image location you'd like.
  3. Wasn't that fun? Onward: hdiutil mount imagelocation
  4. now, use cp to copy all your files into /Volumes/volname ... something like cp -R ~/* /Volumes/myimage/
  5. hdiutil unmount /Volumes/volname
  6. hdiutil convert imagelocation -format imageformat -o outputfile. In this case, imagelocation is the location of the .sparseimage file and outputfile is the location-to-be of the .img file. imageformat should be one of: RdWr (NDIF read/write), Rdxx (NDIF read only), ROCo (NDIF Compressed), Rken (NDIF compressed, KenCode)
  7. rm sparseimagelocation -- the sparse image isn't really of any use, unless you want to make another copy of the image in a different format right away, so you might as well delete it.
That's it, you're done ... you've got a perfectly functional .img file on your desktop waiting for you, provided you've typed everything right, and your system is set up the same way as mine. Remember, man is your friend, and hdiutil will print out help if you just type in hdiutil verb

All of the above was taken almost directly from one of my personal pages. My email can be found if you go up a couple levels from that URL...
    •    
  • Currently 2.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (4 votes cast)
 
[19,404 views]  

Create OS 9 style .img disk images with OS X | 8 comments | Create New Account
Click here to return to the 'Create OS 9 style .img disk images with OS X' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Create OS 9 style .img disk images with OS X
Authored by: JJCortes on Jun 07, '04 03:29:19PM

Be careful ! All .img disk images have a resource fork which will be lost if you transmit them by Internet or thru a PC network. Without this tiny resource fork, it's impossible to open a .img disk file. That is the reason why Apple created .dmg disk images.
If you still use img disk images, first compact them in a .sit or .hqx archive.



[ Reply to This | # ]
Create OS 9 style .img disk images with OS X
Authored by: webbix on Jun 07, '04 04:06:00PM

Also, curious if you had any issues with 'cp' as that will not copy resource fork info either as I understand. Using 'cp' will typically get you a generic file that may not open as expetced.

Also have a question regarding the change to defaults; any additional information on exactly what I am doing when I run this command? Is this a 'hidden' funtion as in several of the 'debug' menus?

I run hdiutil from the CLI regularly as there is not option to make a sparseimage from any other utility.



[ Reply to This | # ]
Create OS 9 style .img disk images with OS X
Authored by: smichr on Oct 21, '04 10:47:39AM

In the script I wrote below, the cp copied files to an image that were "plain vanilla" when they got there--just a s you noted. There is a post at the following address that tlaks about using the "ditto -rsrcFork" command rather than "cp" to get the resources copied with the file.

http://www.macosxhints.com/article.php?story=20030512084055685 that



[ Reply to This | # ]
Create OS 9 style .img disk images with OS X
Authored by: simsamsep on Jun 07, '04 04:58:07PM

I use the shareware 'DropDMG'. It creates different types of .dmg images as well as .img and .smi images, and it converts between the different kinds of images.



[ Reply to This | # ]
Create OS 9 style .img disk images with OS X
Authored by: fotmasta on Jun 08, '04 11:28:48AM

One nice thing about the old .img files was that the resource fork remembered the window size, position, and open/close status with the image.

Any .dmg I create always opens the root level window of the disk as soon as it's mounted.



[ Reply to This | # ]
Create OS 9 style .img disk images with OS X
Authored by: kyngchaos on Jun 11, '04 10:19:46AM

For Mac OS 10.3, the first command to get the extra disk formats for Disk Utility is:

defaults write com.apple.DiskUtility advanced-image-options 1

I think you could still do use the hint verbatim in 10.3 if you copy Disk Copy from a 10.2 install.



[ Reply to This | # ]
Create OS 9 style .img disk images with OS X
Authored by: smichr on Oct 12, '04 08:51:53PM
This script which has been tested under 10.2.8 follows the described hints and automates the process of creating a .img file *of the current directory*. To use it, make it an executable script somewhere in the search path. In the Terminal, cd to the directory of which you want an image. Execute the 'makeimg' script and you should see a *.img file appear on the desktop. The script fails if the *.img file already exists. example of setup and usage: with the makeimg file and the folder that you want to make an img file of on your desktop (say the folder is called ToIMG), open a terminal session

% chmod +x ~/Desktop/makeimg
% cd ~/Desktop/toIMG
% ../makimg
The output of the process will be shown, and the caution provided in this thread about tranmitting .img files via Internet is echoed to the screen. The default format for the .img is Rdxx, but you can change that by providing an option from the command line. The format you specify will be tested to see if it is one of the 4 allowable formats. e.g.,

% ../makeimg ROCo
will create a compressed disk img on the desktop. Use at your own risk. Modify at will.

#! /bin/sh
#                        makeimg
#                        -------
#
# version 1.0 (10/12/04)
# Christopher P. Smith
#
# This script was inspired by the Mac OS X Hints article, 
#   Create OS 9 style .img disk images with OS X
#   Mon, Jun  7 '04 at 10:26AM  from: Anonymous
#   (forums.macosxhints.com)

echo This script will turn the current directory into a .img
echo file on the desktop.
echo "Continue? [yN]"
read YN
if [ "$YN" != "Y" -a "$YN" != "y" ]; then
 exit 1
fi

FMT=Rdxx
if [ "$1" != "" ]; then
 FMT=$1
fi

#       check to see that it is valid

VALID=""
for VAR in "RdWr" "Rdxx" "ROCo" "Rken"; do
 if [ "$VAR" = "$FMT" ]; then
   VALID=$VAR
 fi
done
if [ "$VALID" = "" ]; then
  echo Invalid image type. Options are:
  echo   'RdWr (NDIF read/write)'
  echo   'Rdxx (NDIF read only)'
  echo   'ROCo (NDIF Compressed)'
  echo   'Rken (NDIF compressed, KenCode)'
  exit
fi

#       get only the folder name

DIR=`echo $PWD | sed s'/.*\///g'`

#       parse the directory size to obtain the leading number on the line

BLK=`du -s | sed s'/[^0-9].*//'`

#       hdiutil says that a 4 MB minimum is needed, but when I try to use
#       that, it objects. So use 9000 sectors or a 1% increase over present
#       size 

SIZE=`calc -p "ceil(max($BLK*1.01,9000))"`
hdiutil create -sectors $SIZE -type SPARSE -fs HFS+ \
        -volname "$DIR" -layout NONE ../"$DIR"

#
#        Mounting here *and* grabbing the disk reference so it
#        can be detached later (e.g. /dev/disk1)
#
DISK=`hdiutil mount ../"$DIR".sparseimage  | sed s'/ .*//'`
cp -R * /Volumes/"$DIR"
hdiutil unmount /Volumes/"$DIR"
hdiutil convert ../"$DIR".sparseimage -format $FMT -o ~/Desktop/"$DIR"
rm ../"$DIR".sparseimage

#       Without this, the disks build up in /dev as can
#       be seen with the "hdiutil info" command

hdiutil detach $DISK

#       Wrap up message (as on the OSXHints page)

echo 
echo CAUTION: before sending this .img disk image through the 
echo Internet or a PC network, compact it into a .sit or .hqx 
echo archive. If you don\'t, the resource fork will be lost and 
echo it will not be possible to open the .img file.



[ Reply to This | # ]
Create OS 9 style .img disk images with OS X
Authored by: mzs on Jan 20, '09 09:17:13PM

With 10.5 it seems you do not need to create the sparse image first. This worked for me yesterday and it created foo.img:

$ hdiutil create -srcfolder foo -format ROCo -fs HFS+ -layout NONE foo

For it to open with Disk Copy 6.3.3 in OS 9 you need to make sure that the resource fork is preserved. The way that PC Exchange stores the resource fork vs how OS X does on a FAT formated USB stick is different, so the simple solution to that was to mac binary encode it before copying:

$ macbinary encode foo.img

Then I copied over the foo.img.bin file to the OS 9 machine. Then I was able to use StuffIt Expander 5.5 to extract foo.img from foo.img.bin and then I was able to mount the foo.img disk image.



[ Reply to This | # ]