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

Wednesday, October 31, 2012

Things From My Desk: Star Trek Phaser


Star Trek is, without a doubt, my all-time favorite science fiction television program. Especially, the original series.

When they started promoting the latest movie, you could get a free Star Trek uniform shirt from Kellogg for a certain number of box tops. I cannot remember exactly how many, but I purchased enough Corn Flakes to start a survival shelter. Enough to get four shirts for my family.

Sean wasn't interested, but I got him a gold command shirt anyway. I've always wanted to be an engineer, so mine is read. I think Stacey and Lydia wanted medical and science (blue).

Today at work we had a Halloween dress up day. I was out of the office at a Microsoft sponsored event this morning so the kilt was out. Instead, I just dressed in a t-shirt and black jeans and tossed my Star Trek shirt and cheap costume phaser into my bag. A simple shirt change back a the office was all that was necessary.

Someday I'll spend the money on some TOS props. A hand phaser, tricorder, and communicator. I also think I'll make a Wrath of Khan style uniform jacket to go along with my kilt. Scotty didn't wear one in the movie, but a fan must have put one together judging from the image below. He did wear one in an episode of the original series. Not the same tartan as below but I think the MacQueen colors complement the uniform jacket.

Best of both worlds :-)

+ =

Tuesday, October 30, 2012

Nerd Craft: Star Trek Tribble - Initial Plans

Trouble with Tribbles

Update
You can buy your own from ThinkGeek for less than $20!

One of my favorite Star Trek TOS episodes is The Trouble with Tribbles. A Tribble is a small, soft, furry and gentle asexual animal that produces a soothing purring sound. That is, unless you are a Klingon. Mortal enemies of all Klingons, a tribble screams when they encounter a Klingon. The Klingon acts like a frightened child.

Anyway, I've always wanted a replica tribble. But not just some furry stuffed animal. I want one that screams, purrs and otherwise sounds like a tribble. Technology has finally caught up with my wishes and my pocketbook!





Unfortunately, we cannot genetically engineer pets, at least not tribbles. Glowing fish aren't my thing. I'll have to make a tribble puppet of some sort.

Here are the behaviors I want my tribble to express:
  • Purrs when petted or held
  • Screams at Klingons
And the ones that I'll have to leave until I get my genetic engineering chemistry set:
  • Consumes mass quantities of food
  • Procreates
  • Moves around
What I'll need:
  • Shaggy faux fur cloth for the pelt
  • Polyfill for stuffing
  • A couple of recordable sound chips for gift cards
  • A tilt switch
  • A pressure/contact switch
The faux fur and polyfill shouldn't be too hard to get at either a craft store or somewhere online. A simple baseball style pattern (two strips of fabric in the shape of teardrops attached with a neck) but elongated. 

Sound chips are available online. One will record and playback the purr, the other the scream.

Klingon agents and Tribbles don't get along


What's the tilt switch for? A Klingon detector isn't available so I'll fake it. If you pick up the tribble and keep it level it will just purr. If you hold it a steep angle, the tilt switch will disable the purr and activate the scream chip.

A simple tilt switch can be made with a small circuit board, a couple of stiff wire contacts, a metallic ball bearing, and a short tube. 
Most definitely not a Klingon







The pressure switch might be a bit trickier. I'll need something that doesn't require a lot of pressure, but just enough that the tribble doesn't randomly purr and run down the battery.



Monday, October 22, 2012

Things From My Desk: Star Trek Pez


Stacey gave this to me several years ago. The original Star Trek series will always be me favorite, but I did enjoy Next Generation and the latest movie.

The NASA Apollo missions, Star Trek, Space 1999, and Star Wars motivated me to read science fiction. At first just to get my science fiction fix. Later for the simple pleasure of reading.

Friday, October 19, 2012

Things From My Desk: Gimli


Gimli son of Glóin is a member of the Fellowship of the Ring in  J. R. R. Tolkien's Lord of the Rings.
I've had this since Peter Jackson's movie came out.

I think the movie exaggerated his characteristics making him appear rather comical. I don't think he carried around this many battle axes. The book only mentions one.

Sunday, September 30, 2012

Féileadh Mòr - Kilt Hose

Not too shabby
I made kilt hose from flannel "tartan"cloth. Unfortunately, wool tartan cloth is just too expensive for my Renaissance Faire garb. I'm sure some historical reenactors would say flannel is probably one of the worst fabrics I could pick, but it was the only thing available at a reasonable price. My great kilt requried at least eight yards of cloth. Someday, I'd love to make my garb from vegetable dye homespun wool - someday.

Since these hose are not knit, you need to cut on the bias so the fabric has some stretch. Don't bother trying to find a pattern. The easiest way to make them is to drape some scrap fabric around your leg and foot, pin it, and trim. You want to trim fairly close and with the seam along the back of your leg. Sew up the scrap, try them on, sew them a bit closer to take up any slack, and repeat. Stand with the pattern on to make sure you can flex your foot. If you trim too closely, you'll put too much stress on the heel. Resist the urge to cut out the bunched fabric on top of your ankle, I'll explain later.

When you've sewn them as close as you can, trim the excess fabric close to the seam. This will simplify tracing them onto papper to make a pattern. Give your pattern a half inch margin for the seam. This will give you some extra fabric to adjust the fit. It's much easier to cut excess fabric off than to add it back on.

My customized tartan kilt hose pattern
You'll notice the pattern is a single piece and does not have a seam in the front. The seam runs along the back. This keeps any mismatch with the tartan pattern along the back of the leg, under the foot, and over the toe. You want to place the pattern on your fabric with the long axis (this becomes the front of the hose) aligned along the bias of the fabric. With a tartan, especially one with a square pattern, this is easily accomplished by lining up corners in the pattern. 

If you are careful, you can pin the fabric along the back seam to match the tartan pattern. To get it right, the edges of the fabric might not be perfectly aligned, but the pattern has enough play in it to take this into account.

The bias cut fabric will be a lot stretchier than what you may be used to sewing. My scrap for the pattern was muslin and not cut on the bias. I found that I needed to sew the seam closer than the pattern to take up the slack. When you're done, just cut around your seam leaving about 1/4 inch of fabric. I used a straight stitch and went over it again to strengthen it a bit. Unless you had to cut a huge edge of fabric off, don't bother adjusting your pattern. You never know how stretchy the fabric for your next pair will be. Again, it easier to cut off excess fabric than to sew it back on.

Tartan kilt hose
I used some short pieces of jute to make simple garters to hold them up. Genetics and karate have given me fairly decent calves, so the twine did not need to be tight and they stayed up all day. Fabric will bunch over the top of the ankle, but it's not much and didn't bother me. Trimming to eliminate it would disrupt the tartan pattern.