Archive for the ‘virtual machine’ Category

Emulating minix using bochs on linux

September 17, 2007

First of all, let me provide an explanation for what minix is and why it may be useful. I remember hearing about minix a long time ago when I was reading Just For Fun: The Story of an Accidental Revolution, where Linux Torvalds and Andrew Tanenbaum, creator of Minix, argued which OS would survive. Linux originated from minix, and even though they are both derived from unix, they differ greatly how they function on the inside, with the most notable feature being the kernel. Linux is monolithic, with all the drivers running in kernel-space, meaning a bug in some driver could crash your computer easily, whereas Minix uses a client-server model for its kernel, where drivers are run in user-space. This introduces some latency, but also introduces reliability, since a driver crash will be the equivalent of a user program crashing, which is harmless to the system. The easiest way to check it out is to put it on a virtual machine and let it run. I chose bochs because it was the easiest to install (qemu wanted me to have a different compiler), and it seems to be the most suitable for testing OS code. The biggest downside is that everything is emulated, which makes it rather slow to run. For regular file editing and browsing it’s fine, but when it has to write to a disk, it can take significantly longer than running it bare on the machine. The hardest part for me was getting minix to run, so I will explain it in detail. Once you install/compile bochs on your HDD, it will look for a .bochsrc file in your user directory (/home/username or ~). You can acquire minix through downloading from their website, or you may already have a CD-ROM with minix, as in my case. In our .bochsrc file, we will first need to specify a romimage and vgaromimage that bochs can load. Bochs comes with a default one, I used it and it was fine. They’re located usually under /usr/share/bochs, but may be different depending on your system. The names of the files are BIOS-bochs-latest and VGABIOS-lgpl-latest. The first two lines, if you plan to use the default images, should be:

romimage: file=/usr/share/bochs/BIOS-bochs-latest, address=0xf0000
vgaromimage: file=/usr/share/bochs/VGABIOS-lgpl-latest

Now is the time to emulate a CD-ROM from which to boot minix. The power of bochs lies it the fact that it can very easily emulate devices, and they can be pretty much any file that you specify. So, in the case that you are booting from a CD-ROM, and the name of the device is /dev/cdrom (you may have to adjust), your line to add would be

ata0-master: type=cdrom, path=/dev/cdrom, status=inserted

In the case that you have only the minix iso file, the line to add would be

ata0-master: type=cdrom, path=/path/to/iso/file, status=inserted

For whichever type you use, at the end you will need to specify to boot from cdrom:

boot: disk

Now you should try running minix by typing “bochs” at the prompt. You will see the Main Menu of Bochs. Specify [5] (the default) to get on with the simulation. It should present you with a nice bootup screen and after the OS loads, you should be able to login with “root”. This is a live CD so you can explore the structure and all from the CD image directly. Of course, you’d want to install it to disk to be able to change minix around and save its current state. In order to do that, you will need to save the OS to disk. In order to do that, you will need to make an image file on your HDD, which acts as a partition for your virtual machine. You can use dd for that, but in order to make it easier, bximage should be used, which comes with bochs. After starting it up, you should see

Do you want to create a floppy disk image or a hard disk image?
Please type hd or fd. [hd]

Specify the default, [hd]. After that you would get

What kind of image should I create?
Please type flat, sparse or growing. [flat]

The default, [flat], should be specified again. You should now see

Enter the hard disk size in megabytes, between 1 and 129023

Minix does not need a lot of space to run, however I read somewhere that you should allocate 1 GB in order to install anything you want on there, so I specified I typed in 1024 MB, and if you have the space and plan to add packages, should too. The minix website specifies that for minimum you will need 50 MB, and if you want to have all the sources, you will need 600 MB. After you specify how much space you want to allocate, the program will give a diagnostic message of what it will do, and ask you to specify the name of the image

What should I name the image?

I chose the name “minix.img” but it’s up to you what you want to name it. After writing to the HDD, it will print out a line which you should add to your .bochsrc file

ata0-master: type=disk, path="minix.img", mode=flat, cylinders=cn, heads=hn, spt=sn

You can add that line, but you will need to change ata0-master to ata1-master, considering you still have the line where your ata0-master corresponds to your CD-ROM image, and change the boot: parameter to point to disk. This is what my final .bochsrc file looked like

romimage: file=/usr/share/bochs/BIOS-bochs-latest, address=0xf0000
vgaromimage: file=/usr/share/bochs/VGABIOS-lgpl-latest
ata0-master: type=cdrom, path=/dev/cdrom, status=inserted
ata1-master: type=disk, path="minix.img", mode=flat, cylinders=2080, heads=16, spt=63
boot: cdrom

From there, running minix and setting it up on your HDD should be a breeze. After logging in with “root”, run setup and accept all the defaults. There should be a partition that you can now install to. After a considerate amount of time of installing packages (considering you did a Full Install), you should get a screen telling you that everything succeeded. After that, exit bochs and just change the boot: parameter to point to disk and you are done. Next time you run the simulator, it should boot from the image file and you should be presented with you brand new minix installation.