Linux Disk Commands: Difference between revisions

From Atari Wiki
Jump to navigation Jump to search
(Add link to Atari hard disk mounting script for Linux)
 
(14 intermediate revisions by 4 users not shown)
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''' is part of the '''util-linux''' package.
   
== Reading the 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
<pre>
 
cp /dev/fd0 image.st
 
</pre>
 
 
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:
 
 
<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 skewing of the disk is beyond the
 
capabilities of the hardware. 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 the Image ==
+
== 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 [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.
To write the image to a disk, first make sure that the disk has the right format, then copy the image back to the appropriate floppy device.
 
   
  +
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 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:
 
   
  +
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 [https://github.com/util-linux/util-linux 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'''.
<pre>
 
#!/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}'
 
</pre>
 
   
  +
First, we'll create the additional floppy devices required by running as root:
Paste the script into a file 'imgstats', then use the following command to make the file executable:
 
   
  +
/usr/sbin/MAKEFLOPPIES
<pre>
 
chmod 700 imgstats
 
</pre>
 
   
  +
Note that the floppy devices this creates are temporary and will be destroyed by a reboot or powering off.
You can then use the script to analyse a floppy disk image in .ST 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.
<pre>
 
./imgstats image.st
 
Sides: 2 Sectors: 9 Tracks: 80
 
</pre>
 
   
  +
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'''.
The disk can be formatted with superformat. You specify the disk and the size in the same way as for setfdprm:
 
   
  +
fdformat /dev/fd0_type4
<pre>
 
superformat /dev/fd0 dd ds sect=10 cyl=80
 
</pre>
 
   
  +
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:
Linux will generally trust whatever the disk boot sector says the size of the disk is, rather than looking around the disk. You can probe the disk for its size with various low-level floppy disk controller commands if need be - there's a [http://fdutils.linux.lu/disk-id.html tutorial] in the fdutils documentation. If you know how many sectors and tracks the disk has had formatted on it, regardless of what disk image was written to it, you can set the parameters directly (they should last until you take the disk out):
 
   
  +
dd if=diskimage.st of=/dev/fd0
<pre>
 
setfdprm /dev/fd0 dd ds sect=10 cyl=82
 
</pre>
 
   
  +
Replace '''diskimage.st''' with the filename of the image you want to write to disk.
Generally, you should only do this when you're sure that the number of sectors is the same and the number of tracks is sufficient. If in doubt, reformat the disk to the right size before writing the image.
 
   
  +
Note that there is no need to specify the geometry of the floppy when using dd.
To write the image:
 
   
<pre>
 
cp image.st /dev/fd0
 
</pre>
 
   
 
== Using the Disk Directly ==
 
== Using the Disk Directly ==
Line 75: Line 46:
 
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'.
   
 
== Using a Disk Image ==
 
== Using a Disk Image ==
  +
  +
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 [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
   
 
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>
 
  +
mkdir files
mdir -i image.st ::/
 
  +
mcopy -i image.st -s ::/ files
</pre>
 
   
  +
[https://www.seniorlinuxadmin.co.uk/atari-fs.html This script] lets you mount Atari ST hard disk images under Linux.
<pre>
 
mkdir files
 
mcopy -i image.st -s ::/ files
 
</pre>
 
   
  +
== HxCFloppyEmulator ==
There are some other disk image formats, such as MSA and DIM.
 
   
  +
[https://github.com/jfdelnero/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.
MSA is the format created by the Magic Shadow Archiver, it's very popular for use with emulators. [http://thothy.atari.org/ Thothy] has created a Linux program to convert between the '.ST' format and the '.MSA' format.
 
   
  +
== imgstats ==
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:
 
  +
  +
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.
   
  +
[[Category: Disk Imaging]]
<pre>
 
dd if=image.dim of=image.st bs=32 skip=1
 
</pre>
 

Latest revision as of 13:30, 5 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

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

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

This script lets you mount Atari ST hard disk images under Linux.

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.