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


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: 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 | # ]