Sunday, November 4, 2012

V7/x86: Unix Version 7 on a virtual machine

You can never really go back. Or can you?

My first computer programming experience was on a Texas Instruments TI 99/4a home computer. As many kids did back then, I taught myself BASIC programming on it.

Later, at the local community college, I took my first programming course on a PDP-11 minicomputer. It was a course in BASIC again. But I also fiddled around with C. I didn't start learning C until a course at Michigan State University using Xenix and I think the lab microcomputer had a Motorola 68020. At least that's what I used to learn assembly with. The course at MSU was interesting. We started with Assembly on the 68020, then after a week or two started reading the intermediate compiler output from C to learn both C and Assembly. Then I continued with Unix and C at Northern Michigan University on a VAX.

The VAX was a pretty cool machine. I learned quite a bit about Unix at NMU. Such a simple and elegant operating system. Once I left college, I started programming in DOS on personal computers. After moving from Borland's C compiler to Microsoft C,  I've always worked in a Microsoft development environment. But I've really do miss that first experience with Unix.

The Unix Seventh Edition Manual can be found at http://cm.bell-labs.com/7thEdMan/. There is a really nice PDF version available through a link at the site.

They say you can never go back, and I suppose that's true. That first experience is special because it was your first after all. But sometimes it's fun to dig out that old computer (you do still have your first computer don't you? I still have that same TI.) Unfortunately, I don't have a working VAX or PDP like this guy.

Back to the Future...

Recently I came across Robert Nordier's website where he has an x86 port of Unix Version 7. Unix V7 is considered by many greybeards to be the pinnacle of Unix and the last true Unix version. I'm more familiar with a slightly newer version and have some experience with Linux, but it's enough like my first Unix that it just feels right.
V7/x86 running on VirtualBox
As Robert states, the virtual machine download he has is probably the easiest way to try it out. Although I could scrounge up an old laptop, running it in VirtualBox on my current laptop is convenient.

You can find Robert's V7/x86 - x86 port of UNIX V7 at http://www.nordier.com/v7x86/index.html.

VirtualBox can be found at http://www.oracle.com/technetwork/server-storage/virtualbox/downloads/index.html

Robert has an article explaining how to setup V7/x86 on VirtualBox and documentation for booting it up, so I won't repeat all the details here.

I stumbled a bit getting things working correctly. Some of it I was able to figure out by Googling. I also resorted to sending a couple of emails to Robert asking for help. He was very gracious in his response. It's interesting just how much I've forgotten the mundane day to day details. Thanks Robert!

How do I transfer files to this thing?

I did run into some trouble getting files from a floppy disk image. Creating the image is pretty easy. Using it in V7/x86 was a bit confusing at first. I'm using a Macbook, so if you're using Windows or Linux I'm afraid I can't help you there.

How to create a floppy disk image.

Open a terminal window and type in the following command.

$ dd if=/dev/zero bs=1024 count=1440 > fdisk.img


Creating the image file.


This will create a 1.44 MB floppy disk image file called fdisk.img. Now you need to format the disk with the MSDOS FAT file system. Open "Disk Utility" and, from the "File" menu select "Open Disk Image...".
Open Disk Image

Select the fdisk.img file you created with the dd command. Disk Utility will attach the file and display an error message indicating it cannot attach the image because it has no mountable file systems. Click "OK".
Of course it's not mountable. We haven't erased it yet.

You'll see that fdisk.img has been added on the left. Select it, select "Erase" from the options across the top, select "MS-DOS (FAT)" from the "Format" drop down list, then click the "Erase" button near the bottom of the window.
Preparing to format the floppy image.

You'll be asked if you want to erase the disk. Double check to make sure you've selected the correct image and click "Erase". I'm not sure why they bother asking since the disk is unformatted - how could you lose any data?
Yep, I'm sure

You're freshly formated MS-DOS (FAT) disk will be mounted and displayed on your desktop. You can now open it and copy files to it. The dos file utilities in V7/x86 are pretty simple. Just make sure you use short files names (8.3) without subdirectories.
Untitled floppy disk image

I copied the FORTRAN 77 source code files for the game Adventure (Colossal Cave). You can get the source here http://simh.trailing-edge.com/software.html.
Adventure source code ready to go.

How to add a floppy disk to the virtual machine

Start VirtualBox and select your V7/x86 virtual machine.
VirtualBox Manager

Click the "Settings" icon and then the "Storage" icon. If a "Floppy" controller isn't available in the storage tree, add one by clicking the "Add New Controller" icon on the bottom of the screen. Then click the "Add New Attachement" icon and select the fdisk.img file. Your floppy image created earlier will now be listed under the storage tree.

VirtualBox storage with fdisk.img attached to the Floppy controller

How to access your floppy disk from V7/x86

Robert has some great documentation that introduces V7/x86 and explains how to get started, including details on the boot sequence.

I'll just go over enough to show how to get to the files on the floppy. The floppy disk is available in /dev/fd0.

I was a bit confused how to access the floppy. I thought I needed to mount the device, which didn't work. The fatdir command returned a read error. After Googling and finding nothing, I sent an email to Robert. He responded the same day with instructions and a screen shot describing exactly what I needed to do. I was over complicating things. The fat* commands access the floppy directly on /dev/fd0, no mount is needed.

Start your V7/x86 virtual machine. You'll be presented with the BOOT prompt.

BOOT prompt after machine startup
Press the ENTER key to continue. This will drop you into single user mode.

Single User Mode
You'll want to switch to multi-user mode and login to a user account. V7/x86 comes with a guest account without a password. Press Ctrl+D to switch to multi-user mode.

Muli-User Mode

fatdir, fatget, and fatput

Login to the quest account. V7/x86 provides simple MS-DOS FAT floppy access through three commands: fatdir, fatget, and fatput.

Fatdir lists the files on the  floppy disk.

$ fatdir /dev/fd0

Fatget copies files from the floppy disk.

$ fatget /dev/fd0 advent.f

Fatput copies files from your system to the floppy disk.

$ fatput /dev/fd0 foo.txt

Fatdir and fatget work fine. For some reason fatput isn't working. I get a "Cannot open" error. I'll update this post if/when I figure out the issue. To use fatput, you need write access to /dev/fd0, which the guest account does not have. If you "su" to root you'll have write access. To grant the guest account write access, use chmod from root.

$ su
Password:
# chmod a+rw /dev/fd0
# ^d
$ fatput /dev/fd0 foo.txt

The fatdir command

3 comments:

  1. When FAT did not refer to a weight problem... ;)

    ReplyDelete
  2. Holy Crap you're old. At least you can work with a 1.44MB floppy, and don't have to worry about meddling with the older stuff!

    ReplyDelete
  3. I might try using the virtual serial port to setup a terminal interface. I think that's old school enough for ya.

    ReplyDelete