Linux Disk Commands: Difference between revisions

From Atari Wiki
Jump to navigation Jump to search
(Improve wording of format types paragraph)
(Reword paragraph for choosing the correct geometry)
Line 27: Line 27:
 
Note that the floppy devices this creates are temporary and will be destroyed by a reboot or powering off.
 
Note that the floppy devices this creates are temporary and will be destroyed by a reboot or powering off.
   
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.
+
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.
   
All floppy drives and DD disks should handle 720 Kb, 3.5" DD "type4" floppy disks so format your disk as Type 4, as used in the following example command, if the .st file is 720 Kb or less. Use type 30 ('''/dev/fd0_type30''') if the .st file is approx 800 Kb and format disks as type 13 ('''/dev/fd0_type13''') for images that are 820 Kb and larger. Not all disks and drives will be able to reliably handle 800+ Kb floppies.
+
You have to low-level format your floppy disk first depending on the size of the disk image you wish to write to it. If the '''.st''' file is up to 369 Kb in size, such as the single sided EmuTOS floppy, use '''/dev/fd0_type3'''. If it is more than 370 Kb but less than ~720 Kb, use '''/dev/fd0_type4'''. If it is approx 800 Kb then use '''/dev/fd0_type30''' and if it is 820 Kb or larger then use '''/dev/fd0_type13'''.
   
 
fdformat /dev/fd0_type4
 
fdformat /dev/fd0_type4

Revision as of 11:44, 4 September 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

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/830+ 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. You can use HxCFloppyEmulator to convert .msa into .st images.

You have to low-level format every floppy disk with fdformat before you can use dd to write the data to the disk. 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

Note that the floppy devices this creates are temporary and will be destroyed by a reboot or powering off.

Refer to the Geometry list section of the fdutils documentation to see which floppy types match which disk size and format.

You have to low-level format your floppy disk first depending on the size of the disk image you wish to write to it. If the .st file is up to 369 Kb in size, such as the single sided EmuTOS floppy, use /dev/fd0_type3. If it is more than 370 Kb but less than ~720 Kb, use /dev/fd0_type4. If it is approx 800 Kb then use /dev/fd0_type30 and if it is 820 Kb or larger then use /dev/fd0_type13.

fdformat /dev/fd0_type4

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

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

Note that there is no need to specify the geometry of the floppy when using dd.


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 (eg convert .msa into .st) as well as browse and extract files.

imgstats

You can analyse the image with the following 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 +x imgstats

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

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

getfdprm and setfdprm

To inspect the layout of the current disk run:

getfdprm /dev/fd0

This example sets 9 sectors, 80 tracks/cylinders, double density:

setfdprm /dev/fd0 dd sect=9 cyl=80

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