Search UM  |  Disclaimer  |  Privacy  |  A-Z Directory  |  Contact UM  |  Faculties & Departments   
 photo
  Now Located in the ICT Building ...
[TSA]
 photo

NetBSD and Virtual PC


    [September 2002, New Stuff: the page rewrite didn't happen and no spare time is likely to be available for it any time soon. The kernel file below will allow you to run NetBSD 1.6 under VPC 4.0.

    The file netbsd.1.6/netbsd.1 is a more or less GENERIC NetBSD 1.6 kernel with a fix applied to allow the "de" ethernet interface to be used. The kernel was built on a Titanium G4 PowerBook running NetBSD 1.6 installed from a standard NetBSD 1.6 disribution CD.

    See also the XF86Config and synctime files in the section below and the README file available on the FTP site. ]


    [April 2001, New Stuff: Coming soon, a page rewrite and various updates for NetBSD 1.5 running under VPC 4.0. In the meantime, Connectix have released VPC 4.0.2 which offers support for the 1152x768 video mode available on the Titanium G4 PowerBook.

    The file linux/XF86Config will allow you to use the supplied RedHat Linux X server in 1152x768 mode. Installs as /etc/X11/XF86Config (save the original somewhere first).

    The file netbsd/XF86Config can be used with a default NetBSD 1.5 installation and the X server (make sure that /usr/X11R6/bin/X is a symbolic link to /usr/X11R6/bin/XF86_S3, optionally install .xinitrc in your home directory).

    The file netbsd/netbsd.0 is a GENERIC NetBSD 1.5 kernel with a fix applied to allow the "de" ethernet interface to be used. The kernel was built on a Titanium G4 PowerBook running NetBSD 1.5 installed from a standard NetBSD 1.5 disribution CD.

    The files linux/synctime, netbsd/synctime.elf and netbsd/synctime.aout (the .elf version is for NetBSD 1.5 and the .aout version is for NetBSD 1.4 and lower, and OpenBSD) force the Linux/*BSD system time to track the underlying Macintosh time. Without this daemon running, the emulated system time will drift due to lost interrupts, perhaps running slow by as much as 10-15%. To install this program, download the appropriate format file, rename and install it as /usr/local/sbin/synctime. Arrange for it to be called from /etc/rc.local, /etc/rc.d/rc.local or equivalent so that it runs at boot time.

    See also the OpenBSD on Virtual PC page for details on installing and using OpenBSD. ]





This page should provide you with enough information to run NetBSD version 1.3.2 under Connectix's Virtual PC 2.1 including a simple XFree86 X-window server.

Packages

"The NetBSD Project is a collective volunteer effort to produce a freely available and redistributable UNIX-like operating system. NetBSD runs on a broad range of hardware platforms and is highly portable. It comes with complete source code, and is user-supported."

Virtual PC is a commercial PC-harware emulator running on PowerPC CPUs under MacOS. In addition to emulating a Pentium processor with MMX instructions, Virtual PC emulates an accelerated SVGA card, ethernet controller, sound-blaster Pro sound card, IDE/ATAPI controller and PCI bridge interface.

"XFree86 is a freely redistributable implementation of the X Window System that runs on UNIX(R) and UNIX-like operating systems."

Hardware

As you might expect, the overall speed of the PC emulator is highly dependant on the speed of your PPC CPU, the amount of L2 cache and the amount of real RAM that you can allocate to the program. Blinding speed, however, is not necessary for running a simple UNIX environment for file editing, simple program development etc. It's also very useful to be able to do this on a Macintosh PowerBook away from any network connection (the ideal platform is probably a PowerBook G3 Series laptop). A quick non-scientific comparison on various NetBSD 1.3.N platforms gives the following results for the command string (CPU time in seconds, smaller is better):
% echo '2 ^ 100000' | /usr/bin/time bc |& grep user
    PowerMac 7300/200:	31.51 real        31.11 user         0.19 sys
    PowerBook G3S/250:	33.65 real        33.38 user         0.06 sys     
    Pentium/166MHz:		44.02 real        43.59 user         0.11 sys
    

Changes

Although NetBSD 1.3.2 almost works "out of the box" under Virtual PC, there are some issues due to the way the emulator works (eg: code caching), assumptions made by NetBSD or the way the hardware emulation differs in minor ways from real world hardware. To fix these issues, you need to download a customised NetBSD 1.3.2 kernel /netbsd and a new version of the runtime link-editor for dynamically linked programs /usr/libexec/ld.so, or you can get the source code or diffs and construct your own versions (eg: on a system already running NetBSD) using the source code changes. See below for more details about what needed to be changed.

In the various versions of the kernel, the following subsystems are known to be not working, the remaining problems are still under investigation
	NetBSD 1.3.2 (GENERIC) #0: Sun May 24 19:45:48 EDT 1998
	(generic 1.3.2 kernel in kern.tgz distribution set)

		PCI cards
		PS/2 Mouse driver
		ATAPI CD-ROM driver
		Tulip Ethernet driver
		npx FPU (Floating Point Unit) (uses software emulation)

	NetBSD 1.3.2 (VPC) #0: Tue Jul 14 14:46:31 EST 1998
	(in ftp://munnari.OZ.AU/mac/vpcbsd/kern.tgz.0)

		PS/2 Mouse driver
		ATAPI CD-ROM driver
		npx FPU (Floating Point Unit) (uses software emulation)

	NetBSD 1.3.2 (VPC) #1: Sun Jul 26 11:26:04 EST 1998
	(in ftp://munnari.OZ.AU/mac/vpcbsd/kern.tgz)

There are also some as yet unsolved issues with the XF86_S3 X-Windows server.

Installation

To do the installation, you will need to have already set up Virtual PC with Windows 95, have enough disk space to create a UNIX filesystem of at least 250Mb, a temporary scratch DOS filesystem of around 40Mb and have Fetch or another MacOS FTP client installed.
  • Make a new folder somewhere convenient, call it, say "NetBSD". Into this folder put a *copy* of the Virtual PC application and a copy of the file "Virtual PC 2.0 Preferences" from the Preferences Folder in the System Folder. Making copies of these files allows you to run either NetBSD or Windows without changing the VPC preferences each time.


  • Start Virtual PC whilst holding down the Option key. This brings up the "PC Preferences" dialog box. Select 'C Drive' and create a new file for the NetBSD filesystem, call it "NetBSD Image". This should be at least 250Mb (300Mb to include X-Windows), giving around 100 Mb of free UNIX filesystem space for the basic installation. Obviously bigger is better, depending on what you use the system for. Select 'D Drive' and create a new file for the scratch DOS filesystem, around 40Mb will do (80Mb including X-Windows), call it "DOS Scratch". This will be used to temporarily hold the NetBSD installation sets, the new kernel, ld.so and utility files. Select and set the other options as follows ... 'CD-ROM' - Standard IDE, 'Floppy' - Allow Booting, 'Video' - 2Mb, 'Ethernet' - Enabled. Hit the Restart button in the dialog box and then immediately Quit Virtual PC, we'll come back to it later.


  • Double click on the "DOS Scratch" file. This mounts the file as a volume called 'PC DISK' on the MacOS desktop. This will allow you to download the installation files and make them available to the NetBSD installation script.


  • Using a MacOS FTP client such as Fetch, download the NetBSD installation sets via anonymous FTP in binary mode. For a really basic (albeit almost unusable) installation, you will need the following sets If you also want the C compiler, download the file set For the UNIX manual entries and UNIX typesetting tools, download the sets For UNIX games, download the set For the X-Windows system, download the sets (there may be a mirror site closer to you than ftp.NetBSD.ORG, check for locations on the NetBSD web page).


  • You will also need to download the files The rawrite utility allows you to make a boot floppy from the boot.fs image using Windows or DOS. When you have the necessary NetBSD files, quit from your FTP client and drop the 'PC DISK' volume into the Trash (to disconnect from the 'DOS Scratch' image).


  • The next step is to make yourself a NetBSD boot floppy using the rawrite utility and the file boot.fs now on the 'DOS Scratch' filesystem. You will also need a 1.44Mb floppy (any format). Start your Windows 95 version of Virtual PC, holding down the option key. When you get the 'PC Preferences' dialog box select a new 'D-Drive' image as the 'DOS Scratch' image and hit the Restart button. When Windows is running, choose 'MS-DOS Prompt' from the Progams menu in the Start Menu. Enter the following DOS commands
    	d:
    	rawrite
    		boot.fs		(for source file name)
    		a:		(for destination drive)
    		ENTER		(after inserting floppy)
    	exit			(to exit DOS Prompt)
    
    Select the Virtual PC 'Eject Floppy' button and then shutdown Windows. You don't need to remove the 'DOS Scratch' filesystem from the Windows D-Drive yet as it may be useful at some time in the future.


  • You now have a NetBSD boot floppy. Run the copied version of Virtual PC in the NetBSD folder and *at the same time* reinsert the boot floppy. You should see the usual boot messages about NetBSD.
    	>> NetBSD/i386 BIOS Boot, Revision 2.2
    	>> (frank@struis, Tue May 12 13:01:43 MEST 1998)
    	>> Memory: 640/22528 k
    	etc.
    	booting fd0a:netbsd.gz
    	etc.
    
  • Assuming that all is well (the process waits at some of the stages, so be patient), you should get the 'NetBSD-1.3.2 Install System' page, select the installation options on the various pages as follows (use the arrow keys to move up and down the list and RETURN to make a selection, text you have to enter appears in bold, UNIX commands are preceeded with #)
    	a: Install NetBSD to hard disk	RETURN
    	b: Yes				(to continue)
    	wd0				(as the drive to install NetBSD)
    	b: Continue with install	(to accept the current geometry)
    	a: IDE				(as the kind of disk drive being used)
    	a: No				(to not exclude the last cylinder)
    	a: Use the entire disk		(remember this is the NetBSD Image file)
    	b: Yes				(to overwrite the non-NetBSD partition)
    	a: Standard			(assuming you don't want X-Windows)
    *OR*	b: Standard with X		(assuming you downloaded the X sets)
    	a: Partitions are ok		(probably safe to use the defaults)
    	mydisk				(as the disk name)
    	b: Yes				(to continue)
    Setting up the DOS partition table ...
    etc.
    Populating filesystems with bootstrapping binaries and config files...
    etc.
    	RETURN				(to proceed if no errors)
    	b: Custom installation		(if you don't want X yet)
    	Use the arrow keys to toggle all X related distribution sets
    	- and any sets that you didn't choose in the list above - to No.
    *OR*	a: Full installation		(to include X-Windows)
    	x: to exit
    	e: unmounted fs			(to select the DOS-Scratch filesystem)
    	a: Device			(set device to d: drive)
    	wd1e
    	b: Filesystem			(set filesystem type)
    	msdos
    	d: Continue			(to continue)
    	a: No				(don't want to see all file names)
    Extracting file /mnt2//kern.tgz ...
    Extracting file /mnt2//base.tgz ...	(this takes a while to complete)
    etc.
    	a: ok				(all unpacked successfully)
    Making device files ...
    	a: ok				(note the instructions!)
    	e: Utility menu			(some more housework to do first)
    	a: Run /bin/sh			(we need a shell to copy ld.so)
    
    	# mount /dev/wd0e /usr
    	# mount -t msdos /dev/wd1e /mnt
    	# cp /mnt/ld.so /usr/libexec/ld.so
    	# chown bin.bin /usr/libexec/ld.so
    	# chmod 555 /usr/libexec/ld.so
    	# sync
    	# exit
    
    	x: Exit				(back to Install System page)
    	d: Reboot the computer		(to boot the new kernel)
    Terminated
    #					(wait for 20 seconds or so)
    
  • When the machine has rebooted, login as root (no initial password), then do the following
    	# mount -t msdos /dev/wd1e /mnt
    	# cd /mnt
    	# view INSTALL
    
    to read all about what you have just done, but on a Macintosh instead of a PC ;-). In particular, read section 10. Finalizing your installation.


  • As for administering your personal UNIX machine, you're on your own, see one or more of the many UNIX administration books available. At the very least you should set up a root password using the passwd command
    	# passwd
    
    You can also edit the /etc/fstab file to have the 'DOS Scratch' file permanently available in the UNIX /d: directory. Add the line
    	/dev/wd1e /d: msdos rw,-u=0,-g=0 0 0
    
    to the fstab file, either using vi or ed, or by
    	# cat >> /etc/fstab
    	/dev/wd1e /d: msdos rw,-u=0,-g=0 0 0
    	^D
    
    Then make a /d: directory using
    	# mkdir /d:
    
  • To use the ATAPI CD-ROM (ie: really the Mac CD-ROM, requires (VPC) #1 kernel)
    	# mkdir /cdrom
    	# mount -t cd9660 /dev/cd0a /cdrom
    
  • To start the network, assuming you have been assigned an IP address of 192.43.207.21 via a gateway of 192.43.207.1, do the following commands as root
    	# ifconfig de0 inet 192.43.207.21 netmask 255.255.255.0 media utp up
    	# route add default 192.43.207.1
    
  • If you are running this on a laptop, you probably want to put these commands into a shell script in /usr/local/bin. If not, then you need to add a file called /etc/ifconfig.de0 with the content something like
    	192.43.207.21 netmask 255.255.255.248 broadcast 192.43.207.255 media utp
    
    This will cause the interface to be configured when the machine boots. You may also need to edit the file /etc/netstart.
    To be able to use a Domain Name Server for the internet, create a file called /etc/resolv.conf with the content
      search somedomain.com nameserver 192.43.207.22
Where somedomain.com is your local domain, and 192.43.207.22 is the IP address of your local nameserver host (you can have multiple nameserver entries).

  • Currently you can only run a 640 x 480, 16 colour X-Windows system, but this is better than just the raw console. To setup the X-Server, perform the following steps to: install the X configuration file, link the default X-server to the VGA X-Server, create a mouse device, include the X binaries in your path, include the X libraries in the default search path and start the X-Server. (NB: if you are doing this after rebooting with the changed fstab, substitute /d: for /mnt in the first line below)
    	# cp /mnt/XF86Config.vga16 /etc/XF86Config
    	# rm /usr/X11R6/bin/X
    	# ln -s /usr/X11R6/bin/XF86_VGA16 /usr/X11R6/bin/X
    	# ln /dev/pms0 /dev/mouse
    	# set path=($path /usr/X11R6/bin)
    	# touch /etc/ld.so.conf
    	# cat >> /etc/ld.so.conf
    	/usr/X11R6/lib
    	^D
    	# ldconfig
    	# rehash
    	# startx
    
    You can also install another window manager (such as fvwm2) and get virtual display panels. Information on doing this is outside the scope of this document.
  • Backing up your UNIX "partition"

    Since your UNIX filesystem is simply a large Macintosh file, you can easily make backup copies by copying the "NetBSD Image" file to another machine or hard disc. You should have some backup regime!

    Porting Issues

    To help in porting other versions of UNIX to Virtual PC, the following issues need to be addressed.
    • The VPC PCI cards like to be configured using PCI_CONF_MODE 1, not mode 2 which is the default in NetBSD. In the file /usr/src/sys/arch/i386/pci/pci_machdep.c you can redefine PCI_CONF_MODE (there is an option to do this in the kernel config file but it ends up defining PCI_CONF_MODE="1" and the quotes confuse the code in the pci_machdep.c file).


    • The file /usr/src/sys/dev/pci/if_de.c needs a few changes to make the ethernet driver functional. In summary it was necessary to disable interrupts in the interrupt routine, rewrite the tulip setup code to do the setup synchronously (as implied in the DEC 21041 documentation) and access the virtual PCI ethernet card using I/O mapping i/o instead of memory mapped i/o. The working version of if_de.c is actually based on a snapshot from the NetBSD-current distribution
      /*      $NetBSD: if_de.c,v 1.69 1998/06/08 06:55:55 thorpej Exp $       */
      
    • Dynamically linked programs don't work very well because of the use of a self-modifying code jump table in a heavily code cached environment. In the unmodified ld.so, the code table uses a 386 CALL instruction to a binder_entry routine with an index to the required library routine. The binder looks up the library routine in the dynamic library and changes the CALL to a JMP offset, resetting the index value. Because Virtual PC caches a lot of 386 code routines, subsequent calls to the library routine often result in the CALL binder operation being re-executed, but without the right index value. The simplest approach for now is to removed the index reset code from the file /usr/src/gnu/usr.bin/ld/arch/i386/md.c. This results in unnecessary overheads in calling the binder routine, but only while this code is actually cached by Virtual PC.


    • The real time timekeeping is atrociously bad, presumably clock interrupts are being lost because MacOS is busy doing other things. To some degree you can work around this by running 'rdate -s otherhost' or by a combination of this and the NTP daemon 'xntpd'. This of course requires a network connection. If you build your own NetBSD kernel, you should modify the option RTC_OFFSET=0 to reflect reality. IE: the PC harware clock and MacOS operate in local time, the UNIX kernel uses UTC.


    • If you use the UNIX shutdown command to shutdown your NetBSD session, you will end up in the kernel debugger with the 'beep' sound running continuously. Type 'continue' and as many RETURNS as it takes to complete the shutdown process. You could alternately use sync; sync; halt.


    • The kernel causes a floating-point-exception divide-by-zero error in order to determine the method of FPU error reporting (by IRQ 13 or by exception 16). Under VirtualPC, the kernel exception routine is never called. User-level exceptions are, however, presumably this is due to FPU exceptions not working in supervisor mode. One workaround is to hardwire exception 16 as the default reporting method.


    • The emulated ATAPI CD-ROM device sets the Task File Register, Error = 0x01 as suggested by the ATAPI spec. but it also SETS the ERROR flag in the Status register. It appears that the BUSY flag is never de-asserted after an ATAPI_SOFT_RESET. This confuses the NetBSD "wd" driver. Similarly, following an ATAPI_IDENTIFY_DEVICE command, the driver never sees a drive ready status. The workarounds are to ignore the wait_for_unbusy() call after the ATAPI_SOFT_RESET command and the atapi_ready() call after the ATAPI_IDENTIFY_DEVICE command.
    The current set of source code changes are available from the source code changes directory.

    Disclaimer

    Neither the author or his employer have any affiliation with either of these packages or the respective organisations mentioned herein, except as mostly satisfied users. Virtual PC is a TradeMark of Connectix Corporation. For more information about NetBSD, contact the NetBSD Foundation, Inc.

    Enjoy!

     Created:	Thu Apr  6 19:51:46 EST 2000
     Last update:	Sun Feb  2 15:59:37 EST 2003
     Maintained by:	David Hornsby djh@cs.mu.oz.au
     Authorised by:	David Hornsby djh@cs.mu.oz.au
     Copyright:	© 1996-2003 Computer Science and Software Engineering
     		CRICOS Provider Code: 00116K