20200719

SIMH Setup for 2.11BSD restoration project

SIMH Setup for 2.11BSD pl 0 Project

So, you'd like to do more than just follow along with my 2.11bsd as released project. You'd like to see if you can recreate the work I've done. So I've written up the setup I'm using in the hopes that it will be helpful to others. There's many other tutorials on how to do this generically, but there's some special needs for this project not adequately covered elsewhere. I've written up the instructions you'll need to manually install, as well as provided a script at the end of the blog to do the same if you are impatient and jump right in.

Please note: this bootstraps 2.11BSD pl 195. This is an older version of 2.11BSD that has different installation procedures than latter-day installation versions and should only be used for that version. Even 2.11BSD pl 0 willl have slightly different instructions since the disk partitioning scheme changed in patch 78 which changed the name of the /usr partition.

Machine Configuration

I've configured SIMH emulated the machine like so:
  1. PDP-11/93
  2. 4MB RAM
  3. 2 RD54 disk drives
  4. 1 TS11 tape drive
  5. Serial Console
I've not taken the time to configure the network. All data transfer is done via the tape drive. It's way faster. Here's a picture of what real hardware for this configuration would look like, more or less. The tape drive on top isn't really a TS11 (it's something better: a Cipher drive that can do 6250bps, is front-loading, and likely a tms drive since it supports TMSCP, but pretend with me it's a ts device since that's the path I tested). 

SIMH configuration

SET CPU 11/93, 4M
SET CPU IDLE

SET RQ  ENABLE
SET RQ0 ENABLE, RD54, WRITEENABLED
ATTACH RQ0 ./211bsd-195.rd54
SET RQ1 ENABLE, RD54, WRITEENABLED
ATTACH RQ1 ./extra-data.rd54

SET TS ENABLE
SET TS0 CAPAC=0,LOCKED
ATTACH TS0 ./211bsd-195.tap
; ATTACH TS0 ./src.tap
SET DLI ENABLE
SET DLO0 NODATASET,8B
SHOW DLO0
set console pchar=01000023600 ; allow vi/more to work

; echo "At the SimH prompt type: ra(0,0)unix"
; BOOT RQ0
The rest of this document will assume the above configuration. Later I'll have you change it by commenting out or uncommenting lines. Save the above file to something like 2.11bsd-195.ini (the name I'll assume below). Or see the last section for a short cut.

Obtaining the 2.11BSDpl195 Tape

This isn't as easy as it sounds. You can snag the raw bits from:
https://www.tuhs.org/Archive/Distributions/UCB/2.11BSD-pl195.tar
But that's not a tape. It has all the parts to make a tape if you had a real PDP-11 with a tape drive. So we'll have to fake it. I hacked the canonical perl script to do it. You can find the results at
so you'll need to fetch those two items and do the following:
% tar xf 2.11BSD-pl195.tar
% gunzip  *.gz
% perl mk211p195tape.pl
bootstrap: 18432 bytes = 36 records (blocksize 512 bytes)
mkfs.bin: 30720 bytes = 30 records (blocksize 1024 bytes)
restor.bin: 35840 bytes = 35 records (blocksize 1024 bytes)
icheck.bin: 32768 bytes = 32 records (blocksize 1024 bytes)
root.dmp: 4126720 bytes = 403 records (blocksize 10240 bytes)
usr.tar: 28835840 bytes = 2816 records (blocksize 10240 bytes)
sys.tar: 5212160 bytes = 509 records (blocksize 10240 bytes)
src.tar: 40622080 bytes = 3967 records (blocksize 10240 bytes)
 
which will give you the 211bsd-195.tap you need to do the install. That filename is hard coded in the perl script.

Following the Instructions?

The pdf/ps files that are included with the patch 195 tape are for a newer version, so there's mistakes in them. The errors stem from disklabeling. It doesn't exist in 195, so you have to use old-school fixed partitions. You can read about the background on this in a previous blog entry. But see below for a twist with the RD54 disks i'm using...

On newer versions, the first file on the tape is disklabel, followed by mkfs, etc. On this older one, there is no disklabel, so the first file is mkfs, etc. This makes all the other fielding off by one in the instructions. This blog, however has the numbers right. It also makes this blog not completely useful for the newest version without adjusting...

A Word on Device Names in Bootloader

Device Names in the boot loader and stand alone programs are different than normal in unix. They used to be common, but now are unfamiliar to many, even for sysadmin. They are of the form xx(u, s, extra)file.

The "xx" is the name of the device. Two names will be important for us. The tape is "ts" and the disk is "ra".

The "u" is the unit number. It is basically the same as today, but with some weird rules if you have more than one controller. In this install everything will be unit 0, even though we have two disks. The second disk is for the recovery and will only be used inside unix.

The "s" is for subunit. For tape drives, it is the file number on the tape, starting at 1. For those that might not know, a tape has a series of records on it. These records are separated by end of file marks. There is also an end of tape mark. Both unix and the stand alone programs present this to the user as a series of files. To read a file, you need to know it's location and record size (hence specifying them when we made the tape above.

For disk drives "s" is the partition. Since this version doesn't yet have disklabels, we are using the standard rd54 partition scheme shown below. We will use it for both disks so that the scratch disk will become a bootable drive when we are done. "file" is the path to the file to boot. It's only meaningful for disks.

Finally, the ",extra" is optional for when devices are at non-standard addresses, so we won't use them. For those that must know, it is the CSR of the controller.

Installing with SIMH

Use your favorite package manager to install simh. This will work with most of the recent versions of simh, so the specific version is unlikely to matter. Put the two files in the same directory. We'll be booting a number of times. The outline of what you'll be doing:
  1. Booting off tape into mkfs to create the door filesystem.
  2. Booting again off tape into restor to populate the filesystem.
  3. Booting again, this time off disk, to restore /usr and configure the system.
  4. Rebooting to make sure it is all setup right. 
Once we are done, the system will be setup how it needs to be to build everything. That stuff will be in a separate blog entry, since it's too long to include with this one.

Alternatively, you could run the expect script that does the rest of this blog for you.

Mkfs Boot

This one is very simple and straight forward. Here and below user input is in red. And <cr> means carriage return (or just hit the return key).
% pdp11 211bsd-195.ini

PDP-11 simulator V3.9-0
Disabling CR
Disabling RK
Disabling HK
Disabling TM
RQ: creating new file
RQ: creating new file
DLO0, 8b, no dataset, no logging
sim> boot ts
93Boot from ts(0,0,0172522)
: ts(0,1)
Boot: bootdev=01000 bootcsr=0172522
Mkfs
file system: ra(0,0)
file sys size: 15884
interleaving factor (m; 5 default): <cr>
interleaving modulus (n; 100 default): <cr>
isize = 10160
m/n = 5 100
Exit called

93Boot from ts(0,0,0172522)
:

The restor boot

Directly at the : prompt above, you should continue with the installation. The restor program takes the image on the tape and creates /.

93Boot from ts(0,0,0172522)
: ts(0,2)
Boot: bootdev=01000 bootcsr=0172522
Restor
Tape? ts(0,4)
Disk? ra(0,0)
Last chance before scribbling on disk. <cr>End of tape 

93Boot from ts(0,0,0172522)

Boot Unix

You should now be able top boot unix from the loader prompt. Note: there's no boot loader yet on the ra disk, so you can't boot off of 'RQ0' in simh just yet should you need to restart.
93Boot from ts(0,0,0172522)
: ra(0,0)unix
Boot: bootdev=02400 bootcsr=0172150

2.11 BSD UNIX #29: Tue Jul 12 19:51:16 PDT 1994
    sms1@sms.iipo.gtegsc.com:/usr/src/sys/GENERIC

ra0: RD54  size=311200 id: 40362564
ra0: type 2 partitions

phys mem  = 4186112
avail mem = 4002240
user mem  = 307200

Jul 18 09:59:12 init: configure system
hk ? csr 177440 vector 210 skipped:  No CSR.
ht ? csr 172440 vector 224 skipped:  No CSR.
ra 0 csr 172150 vector 154 vectorset attached
rl 0 csr 174400 vector 160 attached
tm ? csr 172520 vector 224 does not exist.
tms 0 csr 174500 vector 260 vectorset attached
ts 0 csr 172520 vector 224 attached
xp 0 csr 176700 vector 254 attached
erase, kill ^U, intr ^C
you should now be ready to install boot blocks and restore /usr and other filesystem(s), and configuring the system. Looking at the manual for ra(4), we find the RD54 has the following partitions;
          disk   start     end  length  comments
          ra?a       0   15883   15884  /
          ra?b   15884   32603   16720  swap
          ra?c   32604  331167  298564  /usr
          ra?d   unused
          ra?e   unused
          ra?f   unused
          ra?g   unused
          ra?h       0  331167  331168  whole disk
so we'll just need to create the /usr partition. However, turns out that the man page is wrong. This doesn't quite match the source to ra.c, nor does it quite match the disktab entry which says:
rd54|RD54|DEC RD54:\
        :ty=winchester:ns#17:nt#15:nc#1221:so:\
        :b0=/mdec/rauboot:\
        :pa#15884:ba#1024:fa#1024:\
        :pb#16720:bb#1024:fb#1024:\
        :pc#311200:bc#1024:fc#1024:\
        :pg#278596:bg#1024:fg#1024:
which I'll admit is a little hard to read. I misread it the first time. pX is the length of the X partition. The entire disk is 311200 blocks long, so the pc entry clearly is for that. The pg entry is what we want, since pa is for / and pb is for swap and if you add pa+pb+pg you get 311200. If, however, you look at the disktab from the initial revision of 2.11BSD (at least what I think it is), it matches the manual. So we're going to have to be careful when we boot the ur2.11BSD kernel once we get to that point (which we will in the 2.11BSD as released project, but won't in the rest of the installing 2.11BSDpl195). This mismatch, btw, is one of the many motivating factors for disk labels. Patch 78, btw, changed this without updating the man page. Fortunately, the only change for us if we wish to go backwards from 195 to 0 is to change the ra0g to ra0c in the /etc/fstab... but this digression has gone on too long...

Extract /usr, sources and minor config

Once we've booted to unix, we use a fairly familiar unix to extract things. The rest of the installation goes as follows
  1. Install new boot blocks
  2. Fix /dev/mt entries to match the TS-11 we have
  3. newfs and mount /usr (on /dev/ra0g)
  4. extract binaries from file 4, kernel/include src from file 5, and sources from file 6
  5. move sendmail out of the way so it doesn't hang the boot
  6. add /usr to the fstab
Here's the exact commands to do all that:
# dd if=/mdec/rauboot of=/dev/ra0a count=1
1+0 records in
1+0 records out
# cd /dev
# rm *mt*
# ./MAKEDEV ts0
# cd /
# newfs ra0g rd54
newfs: /etc/mkfs /dev/rra0g 139298 2 127
isize = 65488
m/n = 2 127
# mount /dev/ra0g /usr
# cd /usr
# mt -f /dev/rmt12 rew
# mt -f /dev/rmt12 fsf 5
# tar xpbf 20 /dev/rmt12
# cd /
# rm -f sys
# ln -s usr/src/sys sys
# cd /usr
# mkdir src
# cd src
# mt -f /dev/rmt12 rew
# mt -f /dev/rmt12 fsf 6
# tar xpbf 20 /dev/rmt12
# mt -f /dev/rmt12 rew
# mt -f /dev/rmt12 fsf 7
# tar xpbf 20 /dev/rmt12
# mv /usr/lib/sendmail /usr/lib/sendmail.off
# chmod 755 / /usr /usr/src /usr/src/sys
# echo /dev/ra0g:/usr:rw:1:2 >> /etc/fstab
# halt
syncing disks... done
halting

HALT instruction, PC: 000014 (MOV #1,13710)
sim> quit
and now you have a full system. 

Running 2.11BSD

You can now comment out the first ATTACH TS0 line and uncomment out the second. You can uncomment the last two lines, now when you run pdp11, you'll get output that looks like:
% pdp11 211bsd-195.ini

PDP-11 simulator V3.9-0
Disabling CR
Disabling RK
Disabling HK
Disabling TM
DLO0, 8b, no dataset, no logging
"At the SimH prompt type: ra(0,0)unix"

93Boot from ra(0,0,0172150)
: <cr>
: ra(0,0)unix
Boot: bootdev=02400 bootcsr=0172150

2.11 BSD UNIX #29: Tue Jul 12 19:51:16 PDT 1994
    sms1@sms.iipo.gtegsc.com:/usr/src/sys/GENERIC

ra0: RD54  size=311200 id: 40362564
ra0: type 2 partitions

phys mem  = 4186112
avail mem = 4002240
user mem  = 307200

Jul 19 10:04:46 init: configure system
hk ? csr 177440 vector 210 skipped:  No CSR.
ht ? csr 172440 vector 224 skipped:  No CSR.
ra 0 csr 172150 vector 154 vectorset attached
rl 0 csr 174400 vector 160 attached
tm ? csr 172520 vector 224 does not exist.
tms 0 csr 174500 vector 260 vectorset attached
ts 0 csr 172520 vector 224 attached
xp 0 csr 176700 vector 254 attached
erase, kill ^U, intr ^C
and you have a new system. ^D at the # prompt above gets you to the login: prompt.
# ^D Fast boot ... skipping disk checks
checking quotas: done.
Assuming non-networking system ...
usage: hostid [hexnum or internet address]
preserving editor files
clearing /tmp
standard daemons: update cron accounting.
starting lpd
starting local daemons:.
Sun Jul 19 10:06:06 PDT 2020


2.11 BSD UNIX (my.domain.name) (console)

login: root
Last login: Sun Jul 19 06:15:39 on console
2.11 BSD UNIX #29: Tue Jul 12 19:51:16 PDT 1994
[1] root--> df
Filesystem    kbytes    used   avail capacity  Mounted on
/dev/ra0a      15247    3504   11743    23%    /
/dev/ra0g     135203   73761   61442    55%    /usr
[2] root--> 
And now you have a 2.11BSD patchlevel 195 that you can use to run my bootstrap scripts.

Shortcut All of the Above

Or, you can shortcut all this stuff. As I've said above, I've written an expect script that will do all the tedious typing above. While all this typing recalls the manual nature of Unix installations in a by-gone day, it's rather a pain to do more than once. So i automated it. Just clone my mk211bsd github repo, fetch the tape and run the expect script and all this will happen for you. Since the output is the same, i've not included in these instructions.

% mkdir mk211bsd
% github clone https://github.com/bsdimp/mk211bsd
% cd mk211bsd/195
% tar xvf 2.11BSD-pl195.tar
% unzip *.gz
% perl mk211p195tape.pl
% expect 211bsd-195.expect
And you'll be able to skip directly to the "Running 2.11BSD" section since the expect script should do all the typing for you. I've run this script about a dozen times now, and think I have all the kinks worked out. This will give anybody that wants to help out with my 2.11BSD as released project the same setup that I'm using to bootstrap a 2.11BSD pl 0 userland. I'll describe how to do that in a future blog.

Just Following Along

I'll blog about my big progress, and tweet about my small. I'm @bsdimp on Twitter.

5 comments:

Unknown said...

I've manged to duplicate your set up and watched your expect script install 2.11 BSD pl 195. Very nice! Looking forward to following along and doing more.

Steve Falco said...

Typo in "tar xvf 211BSD-pl195.tar"

It should be "tar xvf 2.11BSD-pl195.tar"

(Note the missing . after the "2")

Steve Falco said...

Also, the "unzip *.xz" should be "gunzip *.gz". Then it worked for me.

bsdimp2 said...

Thanks Steve! I've fixed those silly mistakes.

Decuser said...

Thanks Warner. This is quite clear and works exactly as advertised. I really appreciate your highlighting the user entered stuff in red, makes it much easier to follow.