Linux Disk Commands: Difference between revisions

From Atari Wiki
Jump to navigation Jump to search
(A few tweaks to the disk imaging section)
(Edit Hxc description)
Line 1: Line 1:
== Device Concept ==
+
== Linux floppy disk devices ==
   
Linux generally makes heavy use of its filesystem, and access to hardware devices is no exception. For floppy disks, the raw content of the disk (i.e. without interpreting the disk as folders and files) is accessed through a device file. Traditionally, the first floppy drive is called '''/dev/fd0''' and the second is '''/dev/fd1'''. Reading data from these devices translates into accesses to the raw data on the floppy disk. The data is read in logical sector order, so the image will conform to the '.ST' format used by some emulators. The commands that manipulate the disk directly (e.g. setting the disk size) are from the fdutils package, and those that manipulate files within the image are from the mtools package.
+
The raw data stored on a floppy disk (i.e. without interpreting the disk as folders and files) is accessed through a device file. Traditionally, the first floppy drive is called '''/dev/fd0''' and the second is '''/dev/fd1'''. Reading data to or from these devices accesses the raw data on the floppy disk. The data is read in logical sector order, so the image will conform to the '''.ST''' format used by some emulators. The commands that manipulate the disk directly (e.g. setting the disk size) can be found in the the '''fdutils''' package, and those that manipulate files within the image are from the '''mtools''' package. '''fdformat''' can (or at least used to be) part of the '''util-linux''' package.
   
 
== Reading an image ==
 
== Reading an image ==
Line 7: Line 7:
 
The following command will create a disk image "image.st" for the disk in the first floppy drive:
 
The following command will create a disk image "image.st" for the disk in the first floppy drive:
   
 
dd if=/dev/fd0 of=image.st
<pre>
 
cp /dev/fd0 image.st
 
</pre>
 
   
 
The drivers for the disk drive usually detect the disk format correctly. If this doesn't happen, you can set the format manually. This example sets 10 sectors, 83 tracks, double-sided:
A better way would be using the disk dump utility 'dd', which works regardless of the filesystem:
 
   
 
setfdprm /dev/fd0 dd ds sect=10 cyl=82
<pre>
 
dd if=/dev/fd0 of=image.st
 
</pre>
 
   
 
Note that sectors count from 1, but cylinders count from 0.
The drivers for the disk drive usually sense the disk format correctly, detecting extra tracks and sectors. If this doesn't happen, you can set the format manually. This example sets 10 sectors, 83 tracks, double-sided:
 
   
  +
Altenately, you can try using a different floppy device that also specifies the geometry of the disk, if such devices are available. See '''Writing an image''' below for example devices.
<pre>
 
setfdprm /dev/fd0 dd ds sect=10 cyl=82
 
</pre>
 
 
Note that sectors count from 1, but cylinders count from 0.
 
   
 
== Fast Format ==
 
== Fast Format ==
   
Some disks formatted with Fastcopy III or Fastcopy Pro on the Atari ST are known to be unreadable on
+
Some disks formatted with Fastcopy III or Fastcopy Pro on the Atari ST are known to be unreadable on some PCs, even when accessing the disk controller directly. The problem lies with too short a track lead-in when using the "fast format" option, interfering with the usual process by which the disk controller locates sectors. For now, if you encounter this problem, you will have to copy the disk contents using an Atari ST or other hardware that does not suffer the same problem.
some PCs, even when accessing the disk controller directly. The problem lies with too short a track
 
lead-in when using the "fast format" option, interfering with the usual process by which the disk
 
controller locates sectors. For now, if you encounter this problem, you will have to copy the disk contents
 
using an Atari ST or other hardware that does not suffer the same problem.
 
   
 
== Writing an image ==
 
== Writing an image ==
Line 77: Line 65:
 
Linux has a suite of programs, mtools, that are designed to work with floppy disks and disk images. The commands mirror the old MS-DOS commands for working with disks. For example:
 
Linux has a suite of programs, mtools, that are designed to work with floppy disks and disk images. The commands mirror the old MS-DOS commands for working with disks. For example:
   
 
mdir a:
<pre>
 
mdir a:
 
</pre>
 
   
 
Will give a DOS-style directory listing for the disk in the first floppy drive.
 
Will give a DOS-style directory listing for the disk in the first floppy drive.
   
 
mkdir files
<pre>
 
mkdir files
+
mcopy -s a:/ files
mcopy -s a:/ files
 
</pre>
 
   
 
This command will copy the entire content of the disk, recursively, to the directory 'files'.
 
This command will copy the entire content of the disk, recursively, to the directory 'files'.
Line 94: Line 78:
 
Newer versions of mtools allow access to disk images as well as real floppy disks. Add the option '-i image.st' for whatever image you want to use, and use the drive letter ':' instead of a real drive letter. For example:
 
Newer versions of mtools allow access to disk images as well as real floppy disks. Add the option '-i image.st' for whatever image you want to use, and use the drive letter ':' instead of a real drive letter. For example:
   
 
mdir -i image.st ::/
<pre>
 
mdir -i image.st ::/
 
</pre>
 
   
  +
mkdir files
<pre>
 
 
mcopy -i image.st -s ::/ files
mkdir files
 
mcopy -i image.st -s ::/ files
 
</pre>
 
   
There are some other disk image formats, such as MSA and DIM.
+
There are alternate disk image formats, such as .MSA, .DIM and .STX.
   
 
MSA is the format created by the Magic Shadow Archiver, it's very popular for use with emulators.
 
MSA is the format created by the Magic Shadow Archiver, it's very popular for use with emulators.
The emulator [http://hatari.tuxfamily.org/ Hatari] ships with a program called hmsa that can be used to convert between the '.ST' format and the '.MSA' format.
+
The emulator [http://hatari.tuxfamily.org/ Hatari] ships with a program called '''hmsa''' that can be used to convert between the '''.ST''' format and the '''.MSA''' format.
  +
 
The DIM format is created using FastCopy. It is the same as the '''.ST''' format, but with some additional information in a 32-byte header. You can convert this with the following command, which simply strips off the first 32 bytes:
  +
 
dd if=image.dim of=image.st bs=32 skip=1
   
  +
== HxCFloppyEmulator ==
The DIM format is created using FastCopy. It is the same as the '.ST' format, but with some additional information in a 32-byte header. You can convert this with the following command, which simply strips off the first 32 bytes:
 
   
  +
[https://github.com/jfdelnero/HxCFloppyEmulator HxCFloppyEmulator] is an open source, cross platform tool that lets you convert disk images as well as browse and extract files.
<pre>
 
dd if=image.dim of=image.st bs=32 skip=1
 
</pre>
 
   
 
[[Category: Disk Imaging]]
 
[[Category: Disk Imaging]]

Revision as of 22:05, 30 July 2024

Linux floppy disk devices

The raw data stored on a floppy disk (i.e. without interpreting the disk as folders and files) is accessed through a device file. Traditionally, the first floppy drive is called /dev/fd0 and the second is /dev/fd1. Reading data to or from these devices accesses the raw data on the floppy disk. The data is read in logical sector order, so the image will conform to the .ST format used by some emulators. The commands that manipulate the disk directly (e.g. setting the disk size) can be found in the the fdutils package, and those that manipulate files within the image are from the mtools package. fdformat can (or at least used to be) part of the util-linux package.

Reading an image

The following command will create a disk image "image.st" for the disk in the first floppy drive:

dd if=/dev/fd0 of=image.st

The drivers for the disk drive usually detect the disk format correctly. If this doesn't happen, you can set the format manually. This example sets 10 sectors, 83 tracks, double-sided:

setfdprm /dev/fd0 dd ds sect=10 cyl=82

Note that sectors count from 1, but cylinders count from 0.

Altenately, you can try using a different floppy device that also specifies the geometry of the disk, if such devices are available. See Writing an image below for example devices.

Fast Format

Some disks formatted with Fastcopy III or Fastcopy Pro on the Atari ST are known to be unreadable on some PCs, even when accessing the disk controller directly. The problem lies with too short a track lead-in when using the "fast format" option, interfering with the usual process by which the disk controller locates sectors. For now, if you encounter this problem, you will have to copy the disk contents using an Atari ST or other hardware that does not suffer the same problem.

Writing an image

Reading and writing 800 and 820 Kb .st disk images, as commonly used by games, under Linux requires an internal floppy disk drive, connected via a floppy disk controller. There are adapters such as the greaseweazle and the DrawBridge that allow you to read and write ST floppy disks via USB but they are not covered here.

It's important to note this procedure only works with .st format disk images and not .stx, .msa or any other alternate ST disk image format and these instructions are for Debian Linux. The exact commands required may be slightly different for your Linux distro. I tested these commands under Debian 12 i386.

Unfortunately, recent releases of both Debian and Ubuntu Linux no longer include fdformat in their util-linux package so your best bet is probably to build the util-linux tools from source. After building util-linux, rather than doing a sudo make install just copy fdformat into your path eg /usr/local/sbin.

First, we'll create the additional floppy devices required by running as root:

/usr/sbin/MAKEFLOPPIES

You can find out some information about the image with the following handy script. It reads details from the bootsector to identify the sides, sectors and tracks on the disk:

#!/bin/sh
od -v -Ad -t u1 -w1 $1 | awk 'NR==20 {sl=$2} NR==21 {sh=$2} NR==25 {spt=$2}
NR==27 {s=$2; print "Sides: " s " Sectors: " spt " Tracks: " (sh * 256 + sl) / spt / s; exit}'

Paste the script into a file imgstats, then use the following command to make the file executable:

chmod 700 imgstats

You can then use the script to analyse a floppy disk image in .ST format:

./imgstats image.st
Sides: 2 Sectors: 10 Tracks: 80

Refer to the Geometry list section of the fdutils documentation to see which floppy types match which disk size and format. Many game disks use disk geometry 13 which is a 820KB, 3.5" DD floppy disk. Geometry type 30 ( /dev/fd0_type30) is used for 800 Kb disks.

You must low-level format your disk before you can use dd to image it onto the disk. To format a 820 Kb floppy using an internal PC floppy disk drive, run:

fdformat /dev/fd0_type13

Presuming that your disk formatted and passed verification OK and the write protection tab on the disk is off you can use dd to write the .st image onto your formatted disk by running:

dd if=diskimage.st of=/dev/fd0_type13

Replace diskimage.st with the filename of the image you want to write to disk.


Using the Disk Directly

Linux has a suite of programs, mtools, that are designed to work with floppy disks and disk images. The commands mirror the old MS-DOS commands for working with disks. For example:

mdir a:

Will give a DOS-style directory listing for the disk in the first floppy drive.

mkdir files
mcopy -s a:/ files

This command will copy the entire content of the disk, recursively, to the directory 'files'.

Using a Disk Image

Newer versions of mtools allow access to disk images as well as real floppy disks. Add the option '-i image.st' for whatever image you want to use, and use the drive letter ':' instead of a real drive letter. For example:

mdir -i image.st ::/
mkdir files
mcopy -i image.st -s ::/ files

There are alternate disk image formats, such as .MSA, .DIM and .STX.

MSA is the format created by the Magic Shadow Archiver, it's very popular for use with emulators. The emulator Hatari ships with a program called hmsa that can be used to convert between the .ST format and the .MSA format.

The DIM format is created using FastCopy. It is the same as the .ST format, but with some additional information in a 32-byte header. You can convert this with the following command, which simply strips off the first 32 bytes:

dd if=image.dim of=image.st bs=32 skip=1

HxCFloppyEmulator

HxCFloppyEmulator is an open source, cross platform tool that lets you convert disk images as well as browse and extract files.