Benches macOS

3

Syntax to use hdiutil to convert .img to …

apple Verified

Imported from the Apple Support Forums via the Wayback Machine 🔗

I have a large set of old .img files made from floppy disks back in 1998, and they no longer open under Mojave. I can use the Disk Utility application to convert the files, individually, to .dmg files, but it's tedious. I should be able to use the terminal command "hdiutil convert" to do that to all files in the tree. However, the manpage doesn't guide, it gives cryptic format options :

UDRW - UDIF read/write image
                      UDRO - UDIF read-only image
                      UDCO - UDIF ADC-compressed image
                      UDZO - UDIF zlib-compressed image
                      UDBZ - UDIF bzip2-compressed image (macOS 10.4+ only)
                      UFBI - UDIF entire image with MD5 checksum
                      UDRo - UDIF read-only (obsolete format)
                      UDCo - UDIF compressed (obsolete format)
                      UDTO - DVD/CD-R master for export
                      UDxx - UDIF stub image
                      UDSP - SPARSE (grows with content)
                      UDSB - SPARSEBUNDLE (grows with content; bundle-backed)
                      RdWr - NDIF read/write image (deprecated)
                      Rdxx - NDIF read-only image (Disk Copy 6.3.3 format)
                      ROCo - NDIF compressed image (deprecated)
                      Rken - NDIF compressed (obsolete format)
                      DC42 - Disk Copy 4.2 image

I can probably hack my way through the "right" combination, but I'm hoping that someone in this forum with deeper knowledge of formats and terminal commands can quickly respond, so that others might benefit.

3 replies

Sign in or join Beachball Help to reply.

  1. 0

    ⁤aaplCore

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    In many cases you can just rename .IMG to .DMG and it will work.

  2. 0

    jburbaum

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Thanks. I kind of obsessed with this for a short while, and wrote a little Python code to generate the commands (since hdutil doesn't accept wildcards, apparently). There's probably a more elegant way to do it, but, here's what I ended up doing:

    1. Go to the root directory, and create a long version "directory.txt" file with the Terminal command "ls -lR > directory.txt"
    2. Run the following Python code, and direct the output to a second file:

    fhand = open("directory.txt")

    rootdir="./"

    dirtag=rootdir

    for line in fhand:

    line = line.rstrip()

    if line.startswith("./"): dirtag = line.replace("./",rootdir).replace(":","/")

    if line.find('.img') == -1: continue

    file_in = (dirtag+line[line.find("1998")+5:])

    file_out = file_in.replace(".img",".dmg")

    print ("hdiutil convert '"+file_in+"' -format UFBI -o '"+file_out+"'")

    3) chmod the output file to make it executable ("chmod +x <outputfile>) after adding "#!/bin/sh" as the first line

    4) run the executable

    It worked. If I were to rewrite it, I probably would have moved the input file to an archive, but I was able to use the Finder easily for that.

  3. 0

    ⁤aaplCore

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    You can use this command in the Terminal app to convert all .img files to .dmg in working directory.

    mdfind -0 "kMDItemFSName == '*.img'" | 
    xargs -0 -IX bash -c 'hdiutil convert "X" -format UFBI -o "X.dmg" 2>&1'