Mount Atari ST disk image under Linux

November 21, 2019    Blog Post

Old computers are old and passionate …

I am a big FAN of classic computers and I still remember when I got my 1st Atari 800 XL with CX11 tape recorder.

But this is not about 8-bit Atari, but about its bigger brother Atari ST(s), and to be more specific about accessing files on a disk image with (Big)GEMDOS filesystem.

On one of still running Atari forums, someone asked about the possibility of mounting Atari ST hard drive image under Linux and accessing files on it. After a few not fully working tests, I was able to provide a simple, fully functional bash script that automates this process.

Atari ST/Falcon uses the FAT16 file system on its GEMDOS and Big GEMDOS partitions, which allows us to easily mount these partitions on Linux. The only problem may be the partition table format, which must be supported by the Linux Kernel (if I’m not mistaken).

Script

The whole script, which I called “matari.sh”, is simple and its full code is below:

#!/bin/bash
#
# Mount Atari partition under Linux
# by Monsoft (c) 29.10.2019
#
# Require: parted, losetup, awk, grep, cut and root privileges
#
# Usage: matari.sh hdimage [-u]
# -u    unmont partitions

IMAGE=$1
UMOUNT=$2

MPOINT=/mnt
DNAME=drive

if [ "$UMOUNT" == "-u" ];then
    for i in $(losetup -a |grep $IMAGE|cut -d":" -f1);do
            DNUM=${i: -1}
        umount $MPOINT/$DNAME$DNUM
            rm -rf $MPOINT/$DNAME$DNUM
    done
    losetup -D
    echo "All mounts have been removed"
else
    PART=($(parted $IMAGE unit b print| awk '/primary/ { print $2,$4 }'|tr -d B))

    PLEN=${#PART[@]}

    for (( i=0; i<$PLEN; i++ )); do
        PSTART=${PART[$i]}
        ((i++))
        PSIZE=${PART[$i]}
        losetup --find --offset $PSTART --sizelimit $PSIZE $IMAGE
    done

    for i in $(losetup -a |grep $IMAGE|cut -d":" -f1);do
        DNUM=${i: -1}
        mkdir $MPOINT/$DNAME$DNUM
        mount -t vfat $i $MPOINT/$DNAME$DNUM
    done
    echo "The Atari parition has been mounted under $MPOINT:"
    ls -l $MPOINT
fi

The script needs improvement, but should generally work.

I tested this script on hard disk images formatted and partitioned by AHDI and ICD applications and as far as I can see it works. I have not tested this script on partitions created by HDDriver because it is commercial software that I cannot access.

Testing

1st, I checked if I can access the image partition table and whether the partitions are listed using disktype:

# disktype hd80mb.image

--- hd80mb.image
Regular file, size 80.15 MiB (84038656 bytes)
ATARI ST partition map
Partition 1: 4.768 MiB (4999680 bytes, 9765 sectors from 2, bootable)
  Type "GEM" (Standard GEMDOS)
  FAT16 file system (hints score 3 of 5)
    Volume size 4.741 MiB (4971520 bytes, 4855 clusters of 1 KiB)
Partition 2: 28.61 MiB (29999616 bytes, 58593 sectors from 9767)
  Type "GEM" (Standard GEMDOS)
  FAT16 file system (hints score 3 of 5)
    Volume size 28.49 MiB (29874176 bytes, 29174 clusters of 1 KiB)
Partition 3: 38.15 MiB (40000000 bytes, 78125 sectors from 68360)
  Type "BGM" (Big GEMDOS)
  FAT16 file system (hints score 3 of 5)
    Unusual sector size 1024 bytes
    Volume size 38.06 MiB (39909376 bytes, 19487 clusters of 2 KiB)

Here we have 3 partitions: 2 x GEMDOS and 1 x Big GEMDOS.

Linux parted also shows Atari partitions, but disktype gives more information if you run it manually from the command line.

Now it’s time to mount the image:

# ./matari.sh hd80mb.image
Atari parition has been mounted under /mnt:
total 24
drwxr-xr-x 2 root root 8192 Jan  1  1970 drive0
drwxr-xr-x 2 root root 8192 Jan  1  1970 drive1
drwxr-xr-x 3 root root 8192 Jan  1  1970 drive2

And finally, access to files on the mounted image:

# find /mnt
/mnt
/mnt/drive0
/mnt/drive0/NEWDESK.INF
/mnt/drive2
/mnt/drive2/CHKDISK3
/mnt/drive2/CHKDISK3/CHKDISK3.PRG
/mnt/drive2/CHKDISK3/CHKDISK3.RSC
/mnt/drive1
/mnt/drive1/HDUTIL.PRG
/mnt/drive1/ICDBOOT.PRG
/mnt/drive1/ICDFMT.PRG
/mnt/drive1/ICDFMT.DAT

Please note that this simple script does not test many things, such as already used disk numbers, but you can simply modify it according to your needs. Of course, I can’t guarantee that it will work under your Linux distribution. I tested it on Debian 10 and Linux Mint 19.

Updates

Recently, I was contacted by Maarten (Many Thanks !!!), who found this blog useful during accessing his 30 years old Atari disk. He provided some additional informations, which I think are very useful. Part of his original email below:

The image I made had all bytes swapped, you could see a FAT-like structure, but filenames were all garbled. I rectified this with dd if=foo of=bar conv=swab which converts between little-endian and big-endian. After that, the image was recognized as a valid harddisk image.

My disk had 7 partitions, four of them logical. Your script didn’t find those, but that was easily fixed. However, 2 of the 4 logical partitions could not be mounted, they were not recognized. disktype would not recognize them. file did see them as FAT with uncommon options, but mount would not be persuaded to mount them.

# disktype $PARTITION3
Regular file, size 256.1 MiB (268509184 bytes)
# file $PARTITION3
$PARTITION3: , code offset 0+3, Bytes/sector 8192, sectors/cluster 2, root entries 256, sectors 32777 (volumes <=32 MB), Media descriptor 0xf8, sectors/FAT 4, sectors/track 0, dos < 4.0 BootSector (0), FAT (1Y bit by descriptor)
# mount $PARTITION3 /mnt/atari3
mount: wrong fs type, bad option, bad superblock on /dev/loop3, missing codepage or helper program, or other error.

I tried several options and tools, like ‘fatcat’ but none worked. Then I tried with mtools, thanks to https://strotmann.de/RecoveringAtariSTFirstWordPlus.html and lo and behold, with the added MTOOLS_SKIP_CHECK=1 the partitions were accessible and I could make recursive copies of them with:

# mcopy -i $PARTITION3 -sv ::  $target_path

So I managed to recover 615MB of files from a 30+ year old Quantum 1GB harddisk.