Showing posts with label V7/x86. Show all posts
Showing posts with label V7/x86. Show all posts

Tuesday, November 6, 2012

V7/x86: Adding the current subdirectory to the prompt

The .cshrc script for the C shell in default guest account in V7/x86 is pretty spare. One of the first things I wanted to change after switching over to C shell is the prompt. I'd like the prompt to display the current subdirectory as I navigate the file system.

I want to go from this:

% cd src
%

To something like this:

/usr/guest% cd src
/usr/guest/src% 

The Unix V7 "pwd" command returns the current directory path. We can use this in our .cshrc script to include it's output in the prompt.

% pwd
/usr/guest
%

A great reference that helped me figure this out is the Unix FAQS at http://www.cs.albany.edu/~wuye/unixfaqs.html

Open .cshrc with the "vi" editor and move to the bottom of the file. Add the following text and save.

# add the current directory path to the prompt
alias setprompt 'set prompt="`pwd`% "'
setprompt
alias cd 'chdir \!* && setprompt'

The "alias" command gives us to create a new command that is composed of other commands. We've created the command "setprompt" so that we can use it twice without accidentally changing it between each use.

On the next line we call "setprompt" to display the current path when we login.

On the third line, we create a new alias for the "cd" command that will change the directory and reset the prompt to include the changed directory path.

Editing the .cshrc script
Logout and log back in and you'll see the following:

It works!


Monday, November 5, 2012

V7/x86: Changing the User's Shell

"And in her ears the little Seashells, the thimble radios tamped tight, and an electronic ocean of sound, of music and talk and music and talk coming in, coming in on the shore of her unsleeping mind. The room was indeed empty. Every night the waves came in and bore her off on their great tides of sound, floating her, wide-eyed, toward morning. There had been no night in the last two years that Mildred had not swum that sea, had not gladly gone down in it for the third time." - Fahrenheit 451 by Ray Bradbury
The default shell in Unix V7 is the Bourne shell (sh). It replaced an earlier shell and has itself been replaced by a long line of shells over the years. V7/x86 also includes the C shell (csh).
The computing history has produced a lot of wordplay like this. For example, GNU is a recursive acronym for "GNU's Not Unix!", YACC is Yet Another Compiler Compiler, and GIMP is the GNU Image Manipulation Program. I had once created a PHP based template processor years ago called YATP - Yet Another Template Parser.
The C shell included several improvements over the Bourne shell. The script syntax was more like the C programming language whereas the Bourne took its inspiration from Algol 68. There were improvements in history tracking as well as others, you can read the details in the link above.

The user can drop into another shell from within a shell just by executing the desired shell program. For the C shell, just type in the following command. The prompt will change from the Bourne shell '$' to '%'.

$ /bin/csh
%

This is convenient for occasionally switching shells, but what if we want to change the user account default shell?

User account information is stored in the passwd file found in /etc. Passwd contains the user's login name, password, and other information including the program to use as shell. You can read more about it in the passwd man page.

Changing the user's default shell is pretty simple. Switch to the root account with "su", edit the /etc/passwd file with "vi", find the line for the desired user account, and add the path to the shell program at the end of the line.

guest::7:3::/usr/guest:/bin/csh

Change the shell for "guest" to "/bin/csh".
Exit the root account, logout of your account, and log back in. You should now be in the new default shell.

Running the C shell by default


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