[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Debian GNU/Hurd on bochs



Hi guys,

many people ask how to run Debian GNU/Hurd on bochs.  Some people had
success with this, while others had less luck.  Here is what I did to
make it work.  Thanks to p2, weinholt, Jeroen and the other guys on
IRC, who helped me out here and there.

1. Setup bochs.

You need bochs 2.0.2.  Bochs 2.1.x has problems with the newest
coreutils ("cp: memory exhausted" bug and another bug, where perl
fails with "Your random is not that random" no matter what you do).
You can install bochs 2.0.2 on Debian GNU/Hurd by adding this to your
/etc/apt/sources.list:

deb http://snapshot.debian.net/archive pool bochs

And running:

# apt-get install bochs=2.0.2+20030829-1 bochs-wx=2.0.2+20030829-1 bochs-x=2.0.2+20030829-1

Then:

$ zcat /usr/share/doc/bochs/examples/bochsrc.gz > ~/.bochsrc

Edit the file.  I don't use wx but textconfig, and the "x" display
lib.  Peter warned me that wx used to be buggy (YMMV).  Choose as much
memory as you want/can spare.  I use a floppy drive image in
~/.bochs/$GUEST.fd0, and a hard drive image in ~/.bochsrc/$GUEST.hd0.
To get the actual hard drive image values (C/H/S), see below.  Floppy
is 1.44 MB.

One thing you will want (if you are serious about this) is network
access.  So, install the tun (tun.ko on Linux 2.6) module, create the
device ("cd /dev; ./MAKEDEV tun"), set the ownership so that your user
has access to /dev/net/tun (no need to run bochs as root), and add to
your bochsrc:

ne2k: ioaddr=0x280, irq=9, mac=fe:fd:00:00:00:01, ethmod=tuntap, ethdev=tun0, script=/home/marcus/gnu/bochs/start-tun

Of course, your script location will vary.  My script looks like this:

#!/bin/bash
sudo /sbin/ifconfig $1 192.168.42.1
# If you use IP masquerading, for example:
# sudo /usr/sbin/ipmasq

Make that executable.  The IP address is the one of your host then (of
the virtual ethernet bridge).  The other one will be configured in
your guest OS (GRUB and the Hurd).

This pretty much covers bochs.  But we will need the images.


2. fd0 image

First create floppy images.  This has become quite simple.  Create a
directory boot/grub in which you copy all the grub files:

$ mkdir -p boot/grub
$ cp /usr/share/grub/i386-pc/* boot/grub

Create a menu.lst file for grub and put it into boot/grub/menu.lst.
Then make a tar file out of it:

$ tar czf boot.tar.gz boot

Then create the disk image with the Grub tool mkbimage:

$ mkbimage -s ext2 -t 1.44 -f boot.gz

That's it.  Copy or link the file 1.44.image to ~/.bochs/guest.fd0

3. Optional: Grub and tftpboot

This is a fancy setup I use to test new L4 kernels etc without
changing my hd0 image.  Instead using the Debian Grub in step 2,
compile one with networking.  I got mine from Peter, it supports the
bochs network card (don't know how Peter built it).  Then put in the
following menu.lst:

ifconfig --address=192.168.42.2 --server=192.168.42.1
default 0
timeout 0
title = default
configfile (nd)/tftpboot/bochs/grub/menu.lst

Install tftpd, create directory /tftpboot/bochs/grub/, change
/etc/inetd.conf to use /tftpboot instead /boot, create the menu.lst
file in /tftpboot/bochs/grub, in which you can then refer to kernel
files in (nd)/tftpboot/ etc.  GRUB will download the menu.lst and all
kernel/module files via tftp.  Very useful.  To test a new kernel,
just copy it into the above directory and press "Reset" in the bochs
window.

4. hd0 image

Now, you have a floppy image.  Try it out if you want, by booting from
floppy: "boot: floppy" in bochsrc.  You need to do that, as the hd0
image will not be bootable, even when we created it.  Which we will do
now.

$ bximage

Select the size you want, and type "flat".  This tool will give you
the C/H/S values for the hard drive geometry, which you have to enter
into bochsrc.  You also need it to create the disk label.  Start

$ /sbin/fdisk ~/.bochsrc/guest.hd0

Then select expert mode ("x"), and set the cylinder ("c"), heads
("h"), and sectors ("s").  A 512 MB hard drive has C/H/S of
1040/16/63.  Then leave expert mode ("r") and write the MS-DOS disk
label ("o").  Supposedly you can do all this with parted, but I didn't
see how you can set the drive geometry in parted (maybe it doesn't
matter).  Then you need to create a partition ("p" etc).  I assume you
make one primary partition in slot 1, which covers the whole disk.

At this point, you may be able to boot from CD and make a CD based
install in bochs.  I didn't try that.  But if you do thaat, you are
now fine.  In fact, in this case you don't even need to setup a
partition or a disk label above.  I will continue assuming you want to
do a network install.

Once you have that, you need to create a filesystem.  That's quite a
challenge actually, if you want to do it generically, as you don't
know where the fs is in the image.  I am sure there are many ways to
do this, and probably many files to do that, too.  I like it the hard
and manual way, so this is what I did:

Create the filesystem with parted (mkfs 1 ext2).  This is however a
Linux owned filesystem, but we need the Hurd owner to be able to set
translators.  It will also have the filetype feature set, which we
don't use on the Hurd.  So I mangled it a bit:

$ dd if=~/.bochs/guest.hd0 of=/tmp/hd0 bs=512 skip=63

(63 is the start of the filesystem).  Note that this will make a copy
of the whole disk image except for the very beginning.  Well, there
are other ways to do that, but we need to get rid of the filetype
feature and this requires running (eventually) e2fsck on the
filesystem.  So, either you need lots of disk space, or defer the
e2fsck until you actually have the Hurd up and running, but then you
will have to let it clear all those filetype flags then.

$ file /tmp/hd0s1
/tmp/hd0: Linux rev 1.0 ext2 filesystem data

$ e2os.sh /tmp/hd0s1 hurd

The e2os script is in the Hurd CVS in the directory sutils/.

$ e2fsck /tmp/hd0s1

Let it clear the filetype flag.

$ dd if=/tmp/hd0s1 of=~/.bochs/guest.hd0 bs=512 seek=63

63 as above, but this time SEEK not SKIP (if you don't make a copy of
the whole image except the start, add count=SIZE to both dd
invocations and conv=notrunc to the latter to prevent truncation).

I assume you have a proper Hurdish ext2fs image on a partition on the hd now.

4. Installing the base system.

Loop-mount the image:

$ mkdir /tmp/hd0s1.mnt
$ sudo mount -o loop,offset=$((63*512)) ~/.bochs/guest.hd0 /tmp/hd0s1.mnt

The 63 is still from the above.

Now install the base system:

$ apt-get install crosshurd
$ sudo crosshurd

Crosshurd needs to run as root.  You could also use other install
methods (the older ones).

After that, boot it in bochs, using a Hurd menu entry for GRUB.  Then
run ./native-install etc as usual.

5. Note

bochs is a but buggy for me.  If I switch focus away and back to the
bochs window, the kbd state is messed up as if the ctrl key was stuck
pressed down.  Pressing both left ctrl and left shift key at the same
time fixes this for me.  Weird.

It is very slow.  Don't do this if you don't have very fast hardware.
Unpacking the base system takes about an hour on an otherwise idle P4
2.8 GHz!

Apart from the bugs noted here (bochs 2.1.x, kbd), it seems to run ok.

Thanks,
Marcus



Reply to: