Linux Disk Commands: Difference between revisions

From Atari Wiki
Jump to navigation Jump to search
(Edit Hxc description)
(Add note about 820 Kb floppy compat)
Line 1: Line 1:
 
== Linux floppy disk devices ==
 
== 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.
+
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''' is part of the '''util-linux''' package.
   
 
== Reading an image ==
 
== Reading an image ==
   
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
 
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:
+
The correct disk geometry is usually autodetected. If this doesn't happen, you can set the format manually.
   
  +
You may want to inspect the layout of the current disk first:
setfdprm /dev/fd0 dd ds sect=10 cyl=82
 
  +
  +
getfdprm /dev/fd0
  +
  +
This example sets 10 sectors, 82 tracks/cylinders, double density:
  +
 
setfdprm /dev/fd0 dd sect=10 cyl=82
   
 
Note that sectors count from 1, but cylinders count from 0.
 
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.
+
Alternately, you can try using a different floppy device that specifies the geometry of the disk, if such devices are available. See '''Writing an image''' below for details.
   
 
== Fast Format ==
 
== Fast Format ==
Line 23: Line 29:
 
== Writing an image ==
 
== 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.
+
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 [https://github.com/keirf/greaseweazle greaseweazle] and the [https://amiga.robsmithdev.co.uk/ 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.
 
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.
Line 48: Line 54:
 
Sides: 2 Sectors: 10 Tracks: 80
 
Sides: 2 Sectors: 10 Tracks: 80
   
Refer to the [http://www.fifi.org/cgi-bin/info2www?(fdutils)geometry+list 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.
+
Refer to the [http://www.fifi.org/cgi-bin/info2www?(fdutils)geometry+list 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. Not all disks and drives will be able to reliably handle 820 Kb floppies.
   
 
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:
 
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:

Revision as of 08:55, 2 August 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 is 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 correct disk geometry is usually autodetected. If this doesn't happen, you can set the format manually.

You may want to inspect the layout of the current disk first:

getfdprm /dev/fd0

This example sets 10 sectors, 82 tracks/cylinders, double density:

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

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

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

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. Not all disks and drives will be able to reliably handle 820 Kb floppies.

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.