Introduction
In this lab, we will explore the Linux mtools command, which is a collection of utilities to access MS-DOS disks from Unix without mounting them. We will start by installing the mtools package on Ubuntu 22.04, then delve into the various commands and options available within mtools. Finally, we will learn how to manage floppy disk images using mtools.
The mtools package needs to be installed on the system before it can be used. This lab provides step-by-step instructions on how to install the package and then demonstrates the practical usage of mtools commands for file and directory operations on MS-DOS disks.
Install mtools Package on Ubuntu 22.04
In this step, we will install the mtools package on the Ubuntu 22.04 environment. mtools is a collection of utilities to access MS-DOS disks from Unix without mounting them.
First, let's update the package index:
sudo apt-get update
Example output:
Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [114 kB]
Get:4 http://archive.ubuntu.com/ubuntu jammy-backports InRelease [99.8 kB]
Fetched 324 kB in 1s (324 kB/s)
Reading package lists... Done
Now, install the mtools package:
sudo apt update
sudo apt-get install -y mtools
Example output:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
libc6 libmagic-mgc libmagic1
Suggested packages:
mtools-doc
The following NEW packages will be installed:
libc6 libmagic-mgc libmagic1 mtools
0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
Need to get 632 kB of archives.
After this operation, 2,102 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://archive.ubuntu.com/ubuntu jammy/main amd64 libc6 amd64 2.35-0ubuntu3.1 [2,560 kB]
Get:2 http://archive.ubuntu.com/ubuntu jammy/main amd64 libmagic-mgc amd64 5.38-4 [276 kB]
Get:3 http://archive.ubuntu.com/ubuntu jammy/main amd64 libmagic1 amd64 5.38-4 [92.6 kB]
Get:4 http://archive.ubuntu.com/ubuntu jammy/main amd64 mtools amd64 4.0.26-1 [201 kB]
Fetched 632 kB in 1s (632 kB/s)
Selecting previously unselected package libc6.
(Reading database ... 24441 files and directories currently installed.)
Preparing to unpack .../libc6_2.35-0ubuntu3.1_amd64.deb ...
Unpacking libc6 (2.35-0ubuntu3.1) ...
Selecting previously unselected package libmagic-mgc.
Preparing to unpack .../libmagic-mgc_5.38-4_amd64.deb ...
Unpacking libmagic-mgc (5.38-4) ...
Selecting previously unselected package libmagic1.
Preparing to unpack .../libmagic1_5.38-4_amd64.deb ...
Unpacking libmagic1 (5.38-4) ...
Selecting previously unselected package mtools.
Preparing to unpack .../mtools_4.0.26-1_amd64.deb ...
Unpacking mtools (4.0.26-1) ...
Setting up libc6 (2.35-0ubuntu3.1) ...
Setting up libmagic-mgc (5.38-4) ...
Setting up libmagic1 (5.38-4) ...
Setting up mtools (4.0.26-1) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.1) ...
The mtools package is now installed on your Ubuntu 22.04 environment.
Explore mtools Commands and Options
In this step, we will explore the various commands and options provided by the mtools package.
First, let's check the available mtools commands:
mtools --help
Example output:
mtools version 4.0.26, dated 2019/11/29
Usage: mtools [options] command [arguments]
Options:
-V, --version print version information and exit
-h, --help print this help
-f, --config=FILE use FILE as the configuration file
-s, --safe disable all potentially dangerous commands
-q, --quiet suppress most warning messages
-v, --verbose enable verbose messages
-d, --debug enable debug messages
Commands:
mcopy copy file or directory
mmove move or rename file or directory
mdir display directory of MSDOS file
mtype display contents of file
mren rename file
mdel, mdelete delete file
mmd, mmkdir make directory
mrd, mrmdir remove directory
mformat format disk
mlabel set volume label
mattrib change file attribute bits
minfo print information about an MSDOS file or directory
mshortname display short 8.3 names
mtoolstest run internal consistency checks
mcheck check MSDOS filesystem consistency
As you can see, mtools provides a variety of commands for managing MS-DOS-based file systems, such as mcopy, mdir, mtype, and more.
Let's explore some of the commonly used mtools commands:
List the contents of an MS-DOS disk image:
mcopy -ml a:This command will list the contents of the "a:" drive, which typically represents an MS-DOS disk image.
Copy a file from the host system to an MS-DOS disk image:
mcopy example.txt a:This will copy the
example.txtfile from the current directory to the "a:" drive (MS-DOS disk image).Copy a file from an MS-DOS disk image to the host system:
mcopy a:example.txt .This will copy the
example.txtfile from the "a:" drive (MS-DOS disk image) to the current directory on the host system.Create a directory on an MS-DOS disk image:
mmd a:newdirThis will create a new directory named "newdir" on the "a:" drive (MS-DOS disk image).
Remove a directory from an MS-DOS disk image:
mrd a:newdirThis will remove the "newdir" directory from the "a:" drive (MS-DOS disk image).
Remember, the "a:" drive typically represents an MS-DOS disk image, and you can replace it with the appropriate drive letter or path to the disk image file.
Manage Floppy Disk Images with mtools
In this final step, we will learn how to manage floppy disk images using the mtools commands.
First, let's create a floppy disk image file:
dd if=/dev/zero of=floppy.img bs=1440k count=1
This will create a 1.44MB floppy disk image file named floppy.img.
Now, let's format the floppy disk image:
mformat a: -f 1440
This will format the "a:" drive (which represents the floppy.img file) with a 1.44MB capacity.
Next, let's copy a file to the floppy disk image:
mcopy example.txt a:
This will copy the example.txt file from the current directory to the "a:" drive (floppy disk image).
To verify the contents of the floppy disk image, we can use the mdir command:
mdir a:
Example output:
Volume in drive A has no label
Volume Serial Number is 0000-0000
Directory for A:/
example.txt 1024 2023-04-18 15:23
1 file
Finally, let's remove the file from the floppy disk image:
mdel a:example.txt
And verify that the file has been deleted:
mdir a:
Example output:
Volume in drive A has no label
Volume Serial Number is 0000-0000
Directory for A:/
0 files
That's it! You have now learned how to manage floppy disk images using the mtools commands.
Summary
In this lab, we learned how to install the mtools package on Ubuntu 22.04, which provides a collection of utilities to access MS-DOS disks from Unix without mounting them. We explored the various commands and options available in mtools and practiced managing floppy disk images using the provided tools. The lab covered the essential steps to get started with mtools and demonstrated its practical applications in working with MS-DOS-formatted storage devices on a Linux system.



