From: gt8134b@prism.gatech.edu (Howlin' Bob)
Newsgroups: comp.os.linux.announce
Subject: Mounting dosemu hdimage files
Date: 6 Jun 1993 18:28:13 -0400
Approved: linux-announce@tc.cornell.edu (Matt Welsh)
Message-ID: <1utr1t$kk3@theory.TC.Cornell.EDU>

Manipulation of dosemu's diskimage and hdimage files can be somewhat
painful, as all access must be done through dosemu.  A more convenient
solution would be to mount the file as a normal MSDOS filesystem and
manipulate it with the normal UNIX file commands.  Unfortunately, it
was heretofore impossible to mount files.

Some kernel patches written by Werner Almesberger and Ted Ts'o help to
alleviate this problem.  These patches, called the "loop" patches, add
a new device to the kernel.  This device, accessed through the
/dev/loopN block device special files (major number 12), allows one to
alias a file to a block device.  It also allows one to specify the
offset within the file at which to base the device (I think, but am not
sure, that the kind gentlemen added this capability just for us).
This is all we need to use the patches to access diskimage and hdimage
files. 

First off, ftp to tsx-11.mit.edu (or one of its mirrors), and cd to
/pub/linux/BETA/loop.  The loop patches are within.  Apply those to
your kernel, recompile it, and reboot.  Also make sure to compile
losetup, as that's the program you use to assign files to device
names.

To mount a diskimage file, simply do this:

    losetup /dev/loop0 diskimage
    mount -t msdos /dev/loop0 /mnt

And to unmount it:

    umount /mnt
    losetup -d /dev/loop0
    sync

hdimage files are somewhat trickier.  Before you run losetup to assign
the file to a loop device, you must first find the offset within the
hdimage file at which the desired partition starts.  The easiest way
to do that is to run the hdinfo program I wrote just for this purpose.
For example, running "hdinfo hdimage" (where hdimage is the hdimage
file distributed with dosemu) produces:

    Partition info for hdimage (a DOSEMU 0.49 hdimage file)
    =================================================
    Sector=17       Offset=8832         Type=0x01

This means that the first sector of the partition is 17, the byte
offset within hdimage is 8832 (decimal), and the partition type is 1.
NOTE: you cannot find the offset simply by multiplying Sector * 512.
There is also a 128-byte header at the beginning of hdimage files.
For me, running "hdinfo /dev/hda" produces:

    Partition info for /dev/hda 
    =================================================
    Sector=35       Offset=17920        Type=0x06
    Sector=148680   Offset=76124160     Type=0x05
           [Sector=148681   Offset=76124672     Type=0x81]
           [Sector=160971   Offset=82417152     Type=0x05]
    Sector=169161   Offset=86610432     Type=0x83

This output shows 3 primary partitions.  The second primary partition
is an extended-type partition with two logical partitions contained
within.  Of these partitions, you can only mount the first primary
partition, the two logical, and the last primary--the extended
partition is not mountable.

Now, let's say we want to mount hdimage.  First, we set up the loop
device like so:

    losetup -o 8832 /dev/loop0 hdimage

The offset 8832 is taken from the hdinfo output.  Now, we simply mount
the file.

    mount -t msdos /dev/loop0 /mnt

To unmount hdimage:

    umount /mnt
    losetup -d /dev/loop0
    sync

It's as simple as that!

NOTE: do not attempt to use dosemu to access a diskimage or hdimage
      file which is also mounted as a loop device.  If you need to use
      dosemu, unmount the file.


To get hdinfo, ftp to tsx-11.mit.edu and look in
/pub/linux/ALPHA/dosemu.  Retrieve the file called hdinfo.c and
compile it. 


Robert Sanders
gt8134b@prism.gatech.edu

P.S. I would appreciate someone rewriting this explanation and the
hdinfo.c program and sending them to me.  This is all I have time for
right now, but I would like to include a better version of this with
the next release of dosemu.

-- 
Send submissions for comp.os.linux.announce to: linux-announce@tc.cornell.edu
