Installing 386BSD on BOCHS

From Computer History Wiki
Revision as of 14:52, 12 April 2010 by Dugo (talk | contribs)
Jump to: navigation, search

This is the procedure that was used to install 386_BSD onto a patched version of the Bochs IA-32 emulator. This is based on ancient FAQs and trial & error. It is assumed you use a modern Linux with a kernel that features the ip_tables packet filter and TUN/TAP as host OS. If you want to use a different platform you can still follow the tutorial as a guideline but you are on your own figuring out how to get the emulator networked. A good starting point is http://bochs.sourceforge.net/doc/docbook/user/bochsrc.html#AEN1831

Special attention has been given to the ability to run the emulator in a terminal and in the background.

Watch out for leading spaces if you copy/paste anything from the boxes below, they tend to break here-documents.

Requirements

You will need the following to get a 386BSD system patched and installed:

  • A modern linux system with iptables
  • A working copy of gunzip
  • An http/ftp client like wget
  • An acceptable C compiler like gcc to compile Bochs
  • The curses/ncurses library for Bochs to simulate a monitor in a terminal
  • An ftp server for the distribution files

On a stock Basic Fedora Core 8 box you have these in no time with

yum -y install wget
yum -y install gcc
yum -y install gcc-c++
yum -y install ncurses-devel
yum -y install vsftpd

We will get to this later in the tutorial, but for those attempting to install on a different platform or those using this tutorial as a guide, you also need:

  • The bochs 2.4.2 sources
  • A patched pic.cc
  • The 386BSD distribution and patchkits


You can download the Bochs sources from sourceforge


A patched pic.cc can be found at


The 386BSD 0.1 distribution and patchkits can be found at


Preparing for installation

Get, patch, configure and compile Bochs

The Tiny 386BSD boot floppy does something odd. It writes 0x02 to port 20h of the emulated PIC. This causes Bochs to panic. The patch enables Bochs to continue in CLI mode. The available windows binary for Bochs comes up with a msgbox.

cd /usr/local/src
wget http://downloads.sourceforge.net/project/bochs/bochs/2.4.2/bochs-2.4.2.tar.gz
gunzip -c bochs-2.4.2.tar.gz |tar -xvf -
wget http://www.xs4all.nl/~dugo/pic.cc
mv -f pic.cc ./bochs-2.4.2/iodev/pic.cc
cd bochs-2.4.2
./configure --enable-cpu-level=3 \
            --enable-ne2000 \
            --with-term \
            --with-nogui \
            --enable-all-optimizations \
            --enable-docbook=no
make && make install

Get and serve the 386BSD distribution and patches

During installation the 386BSD distribution files and patches can be fetched with ftp. To facilitate this set up an anon ftpd that serves up the files. It should be possible to obtain these directly from minnie during install, but there are two problems. From the looks of it Warren Toomey never intended minnie to be a 386BSD install server. There is also a catch 22 in using the famous patchkits. Stock 386BSD 0.1 comes without gzip, the patches are gzipped, so here your chance to get around that.

echo listen=YES >> /etc/vsftpd/vsftpd.conf
vsftpd
cd /var/ftp
wget -r -np ftp://minnie.tuhs.org/BSD/386bsd-0.1/
wget -r -np ftp://minnie.tuhs.org/BSD/386bsd-patchkits/
mv minnie.tuhs.org/BSD ./
rmdir ./minnie.tuhs.org
cd /var/ftp/BSD/386bsd-patchkits
gunzip *gz

Prepare the host for networking Bochs

To make Bochs' ne2k work without a spare NIC in your host you need to set up tunneling.

echo alias char-major-10-200 tun >>/etc/modprobe.d/modprobe.conf.dist
depmod -a
ln -s /dev/net/tun /dev/net/tun0

Make a tunconfig script for bochs to fire off when the ne2k comes up. In this example 192.168.1.1 becomes the gw and you can pick an ip in 192.168.1.0/24 for the guest later.

# set up the bsd dir w/ tunconfig
cd; mkdir bsd; cd bsd
printf '#!/bin/bash\n/sbin/ifconfig ${1##/*/} 192.168.1.1\n' >tunconfig
cat >>tunconfig <<__EOF
# carnival, put your masks on and go
/sbin/iptables -D POSTROUTING -t nat -s 192.168.1.0/24 -d ! 192.168.1.0/24 -j MASQUERADE >& /dev/null
/sbin/iptables -t nat -s 192.168.1.0/24 -d ! 192.168.1.0/24 -A POSTROUTING -j MASQUERADE
echo 1 > /proc/sys/net/ipv4/ip_forward
__EOF
chmod +x tunconfig

Configure Bochs

The 386BSD installation fails on a box with a lot of mem, hence the `megs: 8' stanza in the bochs configuration.

cat >bochsrc <<__EOF
config_interface: textconfig
display_library: term
romimage: file=/usr/local/share/bochs/BIOS-bochs-legacy
cpu: count=1, ips=80000000, reset_on_triple_fault=0
megs: 8
vgaromimage: file=/usr/local/share/bochs/VGABIOS-lgpl-latest
vga: extension=none
floppya: 1_44=boot.img, status=inserted
ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
ata0-master: type=disk, path="disk.img", mode=flat, cylinders=1024, heads=16, spt=63, translation=none, model=generic
boot: disk, floppy
floppy_bootsig_check: disabled=0
log: bochsout.txt
panic: action=ask
error: action=report
info: action=report
debug: action=ignore
vga_update_interval: 400000
keyboard_serial_delay: 250
keyboard_paste_delay: 1000000
mouse: enabled=0
private_colormap: enabled=0
keyboard_mapping: enabled=0, map=
i440fxsupport: enabled=0
ne2k: ioaddr=0x300, irq=9, mac=fe:fd:00:00:00:01, ethmod=tuntap, ethdev=/dev/net/tun0, script=/root/bsd/tunconfig
com1: enabled=0
__EOF

Create Tiny 386BSD floppy

Prepare the 386BSD boot floppy to work on our emulated box that has a fancy 1.44MB floppy drive. The original floppy was intended for 1.2MB floppys, but who wants to be caught dead using these nowadays?

(cat /var/ftp/BSD/386bsd-0.1/bootable/dist.fs;dd if=/dev/zero bs=1 count=245760)>boot.img

Create a disk image

Make a disk that has the same geometry as in the configuration file, in this case 1024 cylinders, 16 heads and 63 sectors per track. This gets you a about 500 megabytes, go larger and you get yourself in heaps of trouble.

printf "hd\nflat\n504\ndisk.img\n" |bximage


First boot, Tiny 386BSD

Start up Bochs

You should now be ready to fire up bochs in your terminal and start your journey back in time.

bochs -q -f bochsrc

You should get the following output:


Plex86/Bochs VGABios 0.6c 08 Apr 2009
This VGA/VBE Bios is released under the GNU LGPL

Please visit :
 . http://bochs.sourceforge.net
 . http://www.nongnu.org/vgabios

NO Bochs VBE Support available!

Bochs BIOS - build: 09/28/09
$Revision: 1.235 $ $Date: 2009/09/28 16:36:02 $
Options: apmbios pcibios eltorito

ata0 master: generic ATA-6 Hard-Disk ( 504 MBytes)

Press F12 for boot menu.

Booting from Hard Disk...
Boot failed: not a bootable disk

Booting from Floppy...
386BSD Release 0.1 by William and Lynne Jolitz. [0.1.24 07/14/92 19:07]
Copyright (c) 1989,1990,1991,1992 William F. Jolitz. All rights reserved.
Based in part on work by the 386BSD User Community and the
BSD Networking Software, Release 2 by UCB EECS Department.
pc0<color> at 0x60 irq 1 on isa
wd0 <generic> at 0x1f0 irq 14 on isa
fd0 drives 0: 1.44M at 0x3f0 irq 6 drq 2 on isa
ne0 ethernet address fe:fd:00:00:00:01 at 0x300 irq 9 on isa
npx0 at 0xf0 irq 13 on isa
changing root device to fd0a

warning: no swap space present (yet)
386BSD Distribution Installation Floppy (Tiny 386BSD) Release 0.1

Please read the installation notes (type 'zmore INSTALL.NOTES')
and registration information (type 'more REGISTRATION') before use.
To install on hard disk drive, type 'install'.

erase ^?, werase ^H, kill ^U, intr ^C
#
|| style="background:#000000;"|  

Format drive and install the distribution utilities

At he promt give:

(echo y; echo y)|install

This will cause the installer to format the entire drive as it sees fit and install the distribution utilities on it. When the installer is finished Tiny 386BSD and Bochs will go down gracelessly.

Second boot, Base System

=== Finnish the installation.

Restart Bochs

Give another:

bochs -q -f bochsrc

..to boot the base system. After it finds the devices it will greet you with the following:

386BSD Base System Release 0.1

Congratulations, you've got 386BSD on the hard disk!
Please read the file REGISTRATION (e.g. type 'more REGISTRATION')
to discover how to become a part of the 386BSD user group.

To finish the installation, load the remaining distribution files into /tmp
and type 'extract' . To load the files from DOS floppies, type 'mread a:*.* /tmp.
'

If you should wish to uninstall 386BSD, delete the partition by using the
 DOS 5 FDISK program. If installed on the entire drive, use the FDISK/MBR
 to remove the 386BSD bootstrap from the drive.

erase ^?, werase ^H, kill ^U, intr ^C
#
|| style="background:#000000;"|  

Write an installer

The installed 386BSD kernel keeps kprinting `startartstartart' to your screen once network is up and running. This can get on your nerves, to work around this you can write an instsaller in a .netrc macro.

Change the ips below, 10.0.0.1 to where your ftpd lives, 192.168.1.1 to your gw and 192.168.1.2 to the ip you want to give the guest. Change odin into the name you want to give the guest.

echo "machine 10.0.0.1" >.netrc
echo "login ftp" >>.netrc
echo "password news@EU.net" >>.netrc
echo "macdef init" >>.netrc
echo "#" >>.netrc
echo "pasv" >>.netrc
echo "prompt" >>.netrc
echo "bin" >>.netrc
echo "lcd /tmp" >>.netrc
echo "cd BSD/386bsd-0.1/bindist/" >>.netrc
echo "mget *" >>.netrc
echo "cd ../etcdist/" >>.netrc
echo "mget *" >>.netrc
echo "cd ../srcdist/" >>.netrc
echo "mget *" >>.netrc
echo "cd ../../386bsd-patchkits" >>.netrc
echo "mget *tar" >>.netrc
echo "!echo odin |extract bin01" >>.netrc
echo "!csh -c \"limit openfiles 512; extract src01 ; extract etc01 ; tar -cf /dist.tar /tmp/ ; cp pk023.tar /pk023.tar ; cp pk023024.tar /pk023024.tar ; sync ; sync ; sync ; /sbin/shutdown -r now\"" >>.netrc
echo "quit" >>.netrc
echo "#newl" >>.netrc
echo "" >>.netrc
chmod 400 .netrc

Configure the network

Watch out for the startarts.

ifconfig ne0 192.168.1.2 netmask 255.255.255.0 up
route add default 192.168.1.1

Start the installation

Extract will complain with:

/tmp/install.src01: Can't open /tmp/install.src01
extract: Cannot execute installation script of distribution, failed

according to an ancient FAQ this is a joke from Jolitz. I don't get it.

Extract (or cat) also opens more files than the base sh can handle in case you were wondering about the use of csh.

ftp 10.0.0.1

When the macro is finnished Bochs will go down gracelessly.

Third boot, fsck

When you restart Bochs again with:

bochs -q -f bochsrc

386BSD will boot, fsck the disk and shut down again. Don't panic.


Fourth boot, multiuser mode

Restart Bochs

After another

bochs -q -f bochsrc

you boot into multisuser mode.

386BSD Release 0.1 by William and Lynne Jolitz. [0.1.24 07/14/92 19:07]
Copyright (c) 1989,1990,1991,1992 William F. Jolitz. All rights reserved.
Based in part on work by the 386BSD User Community and the
BSD Networking Software, Release 2 by UCB EECS Department.
pc0<color> at 0x60 irq 1 on isa
wd0 <generic> at 0x1f0 irq 14 on isa
fd0 drives 0: 1.44M at 0x3f0 irq 6 drq 2 on isa
ne0 ethernet address fe:fd:00:00:00:01 at 0x300 irq 9 on isa
npx0 at 0xf0 irq 13 on isa
Automatic reboot in progress...
/dev/rwd0a: 13409 files, 240517 used, 253130 free (674 frags, 31557 blocks, 0.1%
 fragmentation)                                                                
starting network                                                                
starting system logger.                                                        
checking for core dump...                                                      
preserving editor files                                                        
clearing /tmp                                                                  
standard daemons: update crond.                                                
starting network daemons: routed printer sendmail inetd.                        
starting local daemons:.                                                        
Wed Apr  8 13:16:44 PST 1970                                                    
                                                                                
   386BSD (odin) (console)

login:
|| style="background:#000000;"|  


386BSD 0.1 is installed now. You are at the point where Bill and Lynne Jolitz said "Cut the Tape" on 14th of July 1992. 386BSD 0.2 never happened. Now that you have 386BSD installed you can take the opportunity to travel forward in time to the birth of modern BSD. In 1992 and 1993 people released patchkits for 386BSD. In early 1993 David Greenman proposed a new operating system based on the patchkits with a new name: "FreeBSD." These steps will bring 386BSD up to the point where maintaining the patchkits became too cumbersome.

For more on this part of history read:

Apply the first patchkit

Login as root, no password, and install the first of the two patchkits.

exec sh
cd /
tar -xvf pk023.tar
mv patch dist
cd dist/bin
./mkpatchdirs
(echo y; echo; echo; echo IALL; echo y ; echo ; echo q)|./patches
./afterinstall.sh

Recompile the kernel

As instructed by mkpatchdirs, recompile the kernel. For Bochs the GENERICISA will do for now. There is something to be said for adjusting the kernel configuration, but this is left as an exercise better done later on.

rm -r /sys/compile/*
cd /sys/i386/conf
config GENERICISA
cd /sys/compile/GENERICISA
make depend
make
mv /386bsd /386bsd.old
cp 386bsd /386bsd
sync; sync; sync
shutdown -rf now


Fifth boot, GENERICISA

Upgrade the virtual machine and restart

Now that you have a proper kernel you can upgrade your machine to use some more than the 8 megs we gave it before.

sed -e's/megs: 8/megs: 256/' bochsrc >bochsrc256
bochs -q -f bochrc256

Buildworld

The system is in a bit of an odd state, the sources are patched but most of the binaries are still the same. So put your new memory to good use, log in as root and execute a buildworld. Note that this can take a while.

exec sh
cd /patch/bin
./buildworld.sh

TO BE CONTINUED