Creating an MS-DOS floppy image from a directory in Unix

For a long time I have needed a way to transfer data into my DOS virtual machines. I came somewhat close to a solution by using Keka to archive directories as ISO files, but I was unable to create what I truly needed – a floppy disk image containing the archived contents of a directory. Well, now I’ve found a way to do just that, partly by doing some research on Google and partly by just figuring stuff out on my own.

The first thing you need to do is create a 1.44 MB empty file with an extension of .ima, .img, or some other raw floppy image extension. This can be done using dd, with the following command:


dd if=/dev/zero of=floppy.img bs=1024 count=1440

I took a screenshot of the output of dd for a visual:

dd

The next step is to format the file with an MS-DOS FAT filesystem.  The easiest way to do this is in DOS.  So insert the blank disk image in the VM and type format a:

format

Now you have a blank floppy image and are ready to add files to it.  To verify that the floppy had been formatted, I ran a hexdump in the Unix terminal.

hexdump

Next you need to mount the floppy image.  The easiest way to do this is to just double click on its icon in the GUI, then copy and paste the files from the source directory or directories to the directory that the image is mounted on.  I tested this first with a couple of simple standalone programs – Visicalc and DOS Cal:

adrive

Now I have installed two programs: CAL.EXE and VC.COM. Indeed, when I go to the C: drive and type cal, the program starts.

cal

Just a side note here: the default path in MS-DOS is set to C:\DOS, so if you want to run programs from a different directory you need to edit the search path in the AUTOEXEC.BAT file:

edit-path

For some reason, my DOS VM would only read the first floppy image that I created. Creating further floppy images using the same technique resulted in an Abort-Retry-Fail error message. To work around this, I have written a C program that automates the process of creating and formatting the floppy image, using the hexdump of the original image. That way I know the file will be exactly the same and I’ll be able to create multiple floppy images for software that requires a multi-disk installation. I will talk about this program, as well as MS-DOS 6.22, MS-DOS disk labels, and some additional software that I’ve installed in the next few blog entries. For now, farewell.

Advertisements

Some hacking – Using Keka to import data from OS X to my VMs

Ever since I started using VirtualBox, I have needed a way to get data from my host operating system (Mac OS X) to the guests. This data includes drivers that I want to install in the guest, and programs and games that I want to run in the guest.

Sure there’s Guest Additions, but that has its own problems. For one thing, it only works with Mac, Windows, and Linux guests; there’s no drag-and-drop feature for things like DOS. Secondly, it requires the guest to have Internet access so you can install the guest addition drivers; if I have Internet access, then all I need to do is just email the files to myself in the host and download them in the guest. So basically, guest additions are merely a convenience that makes the already possible more practical; they do not enable you to do anything you couldn’t do before.

I realized my best bet for guests that either don’t have networking drivers installed or aren’t in the Mac/Windows/Linux category would be to find a way to turn the directories in my OS X filesystem into disk images, either floppy images or ISO files, so I could then insert them into the virtual drives of my VMs. I found a utility called Keka, which can be downloaded here. Keka is a file compression, extraction, and archiving utility for OS X. It can archive or compress files in several formats, and it can extract even more formats. Formats it creates include zip, gzip, bzip2, 7zip, tar, DMG, and ISO.

Keka

Though it is a graphical program, the interface for Keka isn’t particularly intuitive. It allows you to select a format to archive a directory to, but gives no indication of how to select a directory for archiving.  Through wild guesswork I discovered that you can do this by dragging the icon for the directory into the Keka window, after which it will automatically create an archive in the selected format.  Who knew?

The next step is of course to insert the newly created ISO into my virtual machines.  I can only do this with VMs that recognize optical disks, obviously, so MS-DOS 5.0 doesn’t work.  However, I was able to import Deluxe Paint into my FreeDOS VM.  I’m in the process of trying to import Norton Commander.

Storage

As an experiment, I tried converting some of the DOS folders to ISO files and using them to install software directly, as if they were floppies.  This didn’t work, because the installers require the disk to be mounted on drive A.  Obviously I wouldn’t be able to just change the extension, because it would still have the ISO-9660 filesystem, rather than the FAT filesystem, and it wouldn’t be recognized as a floppy.

Yeah, I kinda figured that wouldn’t work.

I’ve also tried using some software and games in VMs that I’m running on live ISOs, but there were some problems.  First, VirtualBox only allows for one optical drive.  You can work around this limitation by adding a USB drive and telling the VM to treat it as an optical drive, but when I did this, the VM tried to boot from the wrong ISO.  Maybe I should select the “Live CD/DVD” option.

Some DOS games I’ve been playing

Today I’m going to talk about gaming. I’m gonna talk about fun and games. Specifically retro games that I’ve been playing in DOSBox and Boxer (a DOSBox clone for Mac OS X). Here are some of the games I’ve been playing:

Wolfenstein 3D

138372-004-5998C878

This is a game set in World War II. You are an American soldier who has just escaped from a cell in an underground Nazi fortress, and you must make your way out of the fortress to retrieve the secret Nazi plans for the Allies. This is a FPS and was actually the first 3D game to reach any level of success.  I’ve only gotten to Level 2 so far.

Cyberdogs

cyberdogs1

Cyberdogs-Level2

This is a 2D FPS where the goal is to collect a certain number of objects and find the doorway to the next level without being killed by an enemy.  There are actually two modes to this game – single player or two player, but I’ve only played single player.  I’ve found that the most effective way to kill bad guys is to just run at them with a chainsaw.  The first screenshot is from Level 1 and the second screenshot is from Level 2.

Commander Keen: Goodbye Galaxy

Commander-Keen-3

Commander-Keen-4

This came free with my installation of Boxer.  It’s about a boy genius who has constructed his latest invention, a faster-than-light radio receiver, and has picked up plans to destroy the Milky Way.  This game is less about killing bad guys and more about bouncing around and eating candy.

Here’s something I found amusing.  If you don’t touch the keyboard for a while, Commander Keen sits down and starts reading a book.

Commander-Keen-5

Nethack

Nethack

This is an ASCII game where you go through several levels of a dungeon in search of the Amulet of Yendor.  It’s an RPG that allows you to select your character’s race, occupation, and alignment.  I recently chose a samurai character, because I’m into Japanese culture.  I had stopped playing this game a while back, because my CPU fan started going crazy every time I did, but since then I have gotten one of those perforated boards to put my laptop on, and I no longer have that problem.

A Tale of Three DOS’s

This is a story of how I got into DOS. The story begins back in Summer 2009 when I first started playing with the DOS prompt in Windows. I actually preferred the Unix CLI because it was more rich in features, but the DOS prompt had its own charm to it. The font was aesthetically pleasing, and the format of the commands had a certain novelty to it (and I’m a sucker for novelty). I actually started playing with the DOS prompt in my Java class. It wasn’t my first experience with it, as we had written programs that ran in DOS in my C++ class the previous Fall. But it was my first time experimenting with the commands.

I was greatly intrigued by the DOS command line and wanted to learn more, and in early 2010 I started looking for a DOS emulator that I could run on my Mac. I found Boxer and then DOSBox, and soon I started playing a slew of MS-DOS games – Duke Nukem 3D, Kingdom of Kroz, Nethack, and Stargoose to name a few.

Eventually I wanted to try the real MS-DOS. I downloaded an archive for the MS-DOS 5.0 installers from vetusware.com, and also downloaded VirtualBox so I could run the DOS. I had to get help from the VirtualBox forums as to how to use the floppy disk images that came in the archive; they were in the .IMA format, which I was completely unfamiliar with. I thought I needed an ISO file, but it turned out I didn’t. I just inserted the floppy images into the virtual machine’s floppy drive.

Here ‘s a slideshow of the installation process for MS-DOS 5.0:

This slideshow requires JavaScript.

Of all the operating systems I’ve installed, I would say MS-DOS was probably the easiest.  It required very little configuration and I didn’t have to partition the drive beforehand.

In later versions of MS-DOS (including 5.0), the default configuration is for DOS to boot into a semi-graphical shell called DOS Shell, which can be activated manually with the dosshell command.

MS-DOS-Shell

The weird thing is, I had had a dream a few months earlier of using MS-DOS with a graphical interface.  This was exciting, because it was like my dream had become a reality.  Only in the dream, the DOS shell was all greyscale, so I set DOS Shell to black and white, 4-color to make it more like my dream.

I have a lot of dreams about old computers and old operating systems, and one of the recurring themes in my dreams is DOS.

If you’ve ever used both the DOS prompt and the real MS-DOS, you will know that MS-DOS is nothing like the DOS prompt in modern Windows.  It’s a whole lot more.  A list of some of the commands in MS-DOS:

backup and restore MS-DOS’s equivalent of the Backup and Restore Center
doskey A useful utility for things like command history, macros, etc.
qbasic A BASIC interpreter for MS-DOS
undelete Instant data recovery; undeletes a file that has been deleted

There are also some nifty programs and games written with QBASIC. Since they’re not in binary form, you can modify them yourself with the QBASIC editor. One that I started using was Microsoft Money Manager.

Money1

Money2

Money3

At this point I wanted to explore some of the other DOS’s out there.  I was very interested in DR-DOS and PC-DOS.  I had downloaded and used the default text editor for PC-DOS and found it to be a lot more full-featured than MS-DOS Editor.

The next DOS that I downloaded was DR-DOS.  Again, I downloaded it from Vetusware.  The installer came in the form of five floppy images with the extension .144, a rather obscure format and one that VirtualBox doesn’t recognize.  I was faced with the challenge of converting these images to a format recognized by VirtualBox.  To achieve that end, I wrote this shell script (thanks to the people in the VirtualBox community for supplying the dd command):


#!/bin/bash
# One-time script converts .144 floppy images
# to .IMA floppy images.

for (( i=1;i<=5;i++ ))
do
        touch disk0${i}.ima;
        dd if=disk0${i}.144 of=disk0${i}.ima bs=512 count=2880;
done

DR-DOS is somewhat harder to install than MS-DOS. It makes you partition the hard drive and select a partition before installing the OS, though much of this process is automated.

This slideshow requires JavaScript.

It took a couple of tries, but I eventually got it installed.  I found the OS to be rather delightful.  It has a few additional commands that MS-DOS 5.0 doesn’t have (I don’t know about 6.22).  For example, there is the stacker command, which activates the stacker driver, a disk compression utility.  I plan to explore this at a later date.  Also, the help is a lot more comprehensive, featuring not just a list of commands, but an entire book on DR-DOS and its features.  There’s networking with Personal Netware, which I’m not sure I’d be able to do in VirtualBox, but it’s worth exploring.

DR-DOS 1

DR-DOS 2

DR-DOS 3

The other DOS I tried was FreeDOS.  This is a fully modern open-source clone of MS-DOS that combines features of DOS with some Linux-like features.

This is the FreeDOS startup screen.  From here you can either install FreeDOS from an install disk, boot from a live version, or boot from the hard drive.

VirtualBox_FreeDOS 1

Here’s a brief slideshow of the FreeDOS installation process:

This slideshow requires JavaScript.

One of the things I really like about the FreeDOS installation is that it comes with 4DOS preinstalled, and it gives you the option of booting into either 4DOS or the default FreeDOS shell.  4DOS is a shell for FreeDOS that emulates some Unix-like features, as well as giving you some options that are pretty much unique to 4DOS.  One of these is the ability to add descriptions to your files, with the describe command, so that when you type dir, you get something like this:

4DOS

I just thought this was so cool, because no other shell lets you do this; no other shell that I know of anyway.

Well, that’s about all I have to talk about for now.  This entry has dragged on long enough, and I think I will say goodbye now.  Goodbye now.