[HOWTO] Linux: Mount & create pcem images

Support and general discussion.
Post Reply
User avatar
TheMechanist
Posts: 71
Joined: Mon 03 Apr, 2017 6:59 pm
Contact:

[HOWTO] Linux: Mount & create pcem images

Post by TheMechanist »

Since it's not possible to use shared folders with pcem, mounting an image to copy software is necessary.

With Linux it's straight forward, if you pay attention to a few things - I struggled especially with a bootable image (offset parameter), so I hope it helps:

I. If you have created an image with pcem, you'll find an image file.

1. In terminal type:

Code: Select all

fdisk -l <your.img>
It tells you "sector size" and "start". "Start" is where the filesystem starts which depends on your image, e.g. if it's the boot image and OS.

If your image contains multiple partitions, they are all shown with their starting sectors. Note, that extended partitions are just structures for logical partitions, that can't be mounted; only mount partitions, for which fdisk identifies a filesystem.

Code: Select all

fdisk -l hdd2.img
Disk hdd2.img: 42 MiB, 44040192 bytes, 86016 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device     Boot Start   End Sectors  Size Id Type
hdd2.img1          17 41054   41038   20M  4 FAT16 <32M
hdd2.img2       41055 87107   46053 22.5M  5 Extended
hdd2.img5       41072 87107   46036 22.5M  4 FAT16 <32M
For the first partition, the offset would be 512 * 17 = 8407, for the second - logical drive - 512*41072 = 21028864.

Note: For me it didn't make a difference, if fdisk -l is invoked without special drive specs (see II.2.). Try it, maybe it makes a difference in some cases like using real disc images.

2. To mount it just type:

Code: Select all

mount -o loop,offset=<start*sectorsize> <your.img> <desired mount point>
The offset is essential to mount the image correctly !

3. If it requires root rights to do, just mount as root or check your distributions help, how to mount with user privileges (e.g. add to fstab).

If mounted as root, adding

Code: Select all

-o umask=000, ...


will allow everbody to read and write the image.

Running pcem with a mounted disc doesn't seem to work, so unmount the disc when starting pcem / exit pcem before mounting.

II. You can create an image with linux too.

1. Create an image file

Code: Select all

dd if=/dev/zero of=<your.img> bs=1M count=<desired MB>
2. Get ancient drive specs

Run pcem and check in BIOS, which drives are supported by your "computer". Most BIOS have a lot of predefined disc specs they accept.

E.g. Classical hard disc (nr. 14 in Amibios):

Code: Select all

42 MB, 733 cyclinders, 7 heads, 17 sectors, 512 bytes/sector
3. Create partition with fdisk

Code: Select all

fdisk -C <cylinders> -H <heads> -S <sectors> <your.img>
For MSDOS:
a. Press "c" for DOS compatibility
b. Press "n" to create a partition
c. Press "t" to change partition type to 6 (FAT16)
d. Press "w" to write changes

You'll have to format filesystem with MSDOS Format, mkdosfs doesn't seem to work for image

4. Add the disc to pcem in settings & BIOS
Last edited by TheMechanist on Sat 15 Apr, 2017 6:52 pm, edited 1 time in total.
Zup
Posts: 83
Joined: Mon 30 Nov, 2015 10:47 am

Re: [HOWTO] Linux: Mount & create pcem images

Post by Zup »

Note that the mount instruction will mount the first partition. If you have more than one partition, you'll need other instruction to access other partitions.
User avatar
TheMechanist
Posts: 71
Joined: Mon 03 Apr, 2017 6:59 pm
Contact:

Re: [HOWTO] Linux: Mount & create pcem images

Post by TheMechanist »

Zup wrote:Note that the mount instruction will mount the first partition. If you have more than one partition, you'll need other instruction to access other partitions.
It mounts the partition, which offset you calculated. If you have multiple partitions, fdisk -l will show all partitions and their starting sectors. Thanks for your hint, added it to howto ..
User avatar
ender
Posts: 51
Joined: Tue 14 Oct, 2014 12:51 pm

Re: [HOWTO] Linux: Mount & create pcem images

Post by ender »

If you want an easy way to mount partitions from a disk image, use losetup like this:

Code: Select all

losetup -P /dev/loopX /path/to/disk.img
You'll get partitions as /dev/loopXp1, /dev/loopXp2 etc., which you can then mount directly (mount /dev/loopXp1 /mnt/whatever). When you're done, remove the loop with

Code: Select all

losetup -d /dev/loopX
User avatar
JohnElliott
Posts: 113
Joined: Sun 31 Jan, 2016 7:29 pm

Re: [HOWTO] Linux: Mount & create pcem images

Post by JohnElliott »

If you want to access the contents of floppy images, the easiest way to do that is with mtools:

Code: Select all

mdir -i imagefile                       -- show contents
mcopy -i imagefile sourcefile ::        -- copy a file into the image
mcopy -i imagefile ::file .             -- copy a file out of the image
mdel -i imagefile ::file                -- delete a file from the image
(To create a new floppy image, I find it simplest to start with an existing one of the right size, copy it, and use mdel to delete the contents of the copy).
jschwart
Posts: 10
Joined: Sat 26 Nov, 2016 8:54 pm

Re: [HOWTO] Linux: Mount & create pcem images

Post by jschwart »

At some point I wrote a script to just copy files into an (almost) empty bootable image. I use it mainly to put existing dosemu installations into PCEM, but whenever I need to put a single file inside an existing PCEM installation, I just create a second image and use it as "drive d".

This script is here:
https://github.com/jschwartzenberg/dos- ... aster/pcem

It's really rough, but this works:
./copyfilesintoimage /tmp/somedirwith files /tmp/drived.img

The resulting drived.img can be easily loaded from PCEM.
teppic
Posts: 53
Joined: Tue 20 Jun, 2017 12:31 pm

Re: [HOWTO] Linux: Mount & create pcem images

Post by teppic »

As an addition to this, it's really easy to create 1.4/2.8mb floppy images and mount them.

First create the image:

Code: Select all

dd if=/dev/zero of=floppy.img bs=1440k count=1
(change to 2880k for 2.8mb)

Then create a DOS filesystem on the image:

Code: Select all

mkdosfs floppy.img
And then mount wherever you'd like:

Code: Select all

sudo mount -o loop floppy.img /mnt/floppy
You don't need fdisk or an offset since it's not partitioned. You can copy/unzip as you like, be sure to unmount it before you try to use it.
RealNC
Posts: 16
Joined: Tue 06 Nov, 2018 3:01 am

Re: [HOWTO] Linux: Mount & create pcem images

Post by RealNC »

I've been using loopback mount for other emulators too.

One thing that needs to be in Big Red Letters though is that you should only mount the DOS partition image when PCem is not running. Specifically, when the emulated machine that uses that image is not currently running. And, you should remember to unmount the image prior to booting the emulated machine.

If you don't, you will corrupt or destroy data in the image file.
Mangalon
Posts: 3
Joined: Sun 25 Nov, 2018 3:50 pm

Re: [HOWTO] Linux: Mount & create pcem images

Post by Mangalon »

Thanks Ander for sharing that loophole, I just tried it out and it worked fine for me.
win2k
Posts: 4
Joined: Wed 09 Jun, 2021 2:44 pm

Re: [HOWTO] Linux: Mount & create pcem images

Post by win2k »

I like using guestmount. It works equally well with PCem and Qemu images and doesn't require any special permissions.
User avatar
TheMechanist
Posts: 71
Joined: Mon 03 Apr, 2017 6:59 pm
Contact:

Re: [HOWTO] Linux: Mount & create pcem images

Post by TheMechanist »

You can use this tool too, I use it as daily driver for cross platform dev & testing

https://pcem-emulator.co.uk/phpBB3/view ... p42#p15414
cricket
Posts: 17
Joined: Mon 18 Apr, 2022 9:33 pm

Re: [HOWTO] Linux: Mount & create pcem images

Post by cricket »

To mount VHD files, vdfuse still works on the latest Devuan (no systemd)
https://sourceforge.net/projects/vdfuse/
Post Reply