Installing Haiku OS Release 1 Alpha 4.1

Here are my notes on how to install the Haiku operating system in a virtual machine (VM) using Oracle's VirtualBox, version 4.2 (still works in 6.0.4 as of April 2019). I also leveraged that to build Haiku from source code in a virtual machine and then install it on a real hard drive (note that you need a second hard drive if you're using Windows). After much frustation, I was finally able to get it to boot Haiku for real.

Installing Haiku in VirtualBox

Install VirtualBox on your computer, assuming it has an x86 processor of recent enough vintage with virtual machine instructions, though they do say it works with older models prior to the Intel Core 2 series. I'm using a first generation Intel i5 CPU, which has that "VT-x" feature.

For better performance, turn on the virtual machine settings in the BIOS. On my motherboard they are:

[Intel Virtualization Tech]
Virtualization Feature - hardware support for running VMs faster.

[Intel VT-d]
VT-d (Directed I/O) lets a VM run a real PCI card directly. Useful for specialty hardware like video capture boards. I usually leave this BIOS setting off since it causes an IOMMU warning when booting Linux and I'm not using special hardware.

There's also the big/nested page table feature, that may have a BIOS setting too. See the VirtualBox docs for more details. And if you want to boot Haiku directly, you may want to set the SATA disk controller to run in AHCI mode, since that's the one supported best by Haiku (IDE compatibility mode is second rate). That may require a reinstall of Windows if you had installed it previously with AHCI turned off, or at least some fiddling around to get Windows booting in AHCI mode (do a web search for solutions to that problem).

Then make a new virtual machine in the VirtualBox VM Manager, with settings that look like this:

[VirtualBox Screen Shot]
VirtualBox General VM Settings

[VirtualBox Chipset]
VirtualBox Chipset Settings

In particular, you need to turn on the IOAPIC for the chipset simulation so that it can have multiple CPU cores. Even with 1 core, IOAPIC is 3% faster in a file copying test. Nested paging makes it about 10% faster. And 1 CPU core rather than 2 is unintuitively twice as fast (as of VirtualBox 5.1.14), so run with 1 CPU core for speed! PAE isn't needed unless you want to use more than 3GB of memory and are running 32 bit Haiku. You can get the other CPU settings from the general view.

For video, just pick 32MB of memory, no acceleration, no remote display. I found that my 1080p screen size didn't show up in the list of available sizes when using Haiku, but found that you can add it to the VESA screen resolution list. The magic command, run from the VirtualBox program directory, is VBoxManage setextradata "VM name" "CustomVideoMode1" "1920x1080x32". Replace "VM name" with the name you gave to your Haiku virtual machine. Note that only 32 bit works, don't even try specifying 8 bit 1080p graphics, else VirtualBox will crash.

Next up is disk and DVD storage. Make a fake DVD player to play the .iso disk image file containing Haiku R1A4, add it to the IDE controller. Haiku IDE support is getting worse (in R1A3 you had to turn DMA off, now mostly doesn't work in R1A4), but it works if it's just reading data off a DVD or CD. Download the disk image in .iso format from the Haiku web site and specify the file name here.

Add as many virtual hard disk drives as you wish, none is fine if you're just trying out the dowloaded DVD/CD of Haiku. They're best hooked up to a SATA controller, running in AHCI mode (IDE mode is broken in Haiku). For the adventurous, you can hook up a real disk drive to the VM here, more on that later.

For the network card, the main thing is to specify a certain simulated Intel card, which Haiku will know how to operate. In this case it's the "Intel PRO/1000 MT Desktop (82540EM)". Though in Haiku hrev52708 and later it interferes with host networking, causing TCP to fail due to spurriously inserted ICMP error packets (the guest Haiku works fine). In that case, the best bet is the "PCnet-PCI II (Am79C970A)". Others like virtio-net suffer from the same problem as iPro1000 or randomly crash the Haiku OS.

You should now be able to boot up the VM and run Haiku off the fake CD/DVD, optionally installing it to the fake hard drive.

Using a Real Hard Disk Drive in the Virtual Machine

It's convenient to make modifications to a real hard drive from within a VM if you want to run Haiku on the real hardware. This gives you the choice of booting up your Haiku installation in a VM or on the real hardware, as you desire. I find it useful for building the latest version of Haiku in a VM, writing the results to the real disk, and then rebooting to see if Haiku works on the real hardware.

First you need to make the hard drive accessible to VirtualBox.

On Linux this is a matter of changing permissions on a device file like /dev/sdc to give your user account access. To make them permanent, edit or create file /etc/udev/rules.d/95-disk-permissions.rules and add a line that looks like (use your own username as the owner):
SUBSYSTEM=="block", KERNEL=="sdc*", OWNER="agmsmith", GROUP="disk"

On Windows, this means using a second hard drive (they don't let programs write directly to sectors on the boot drive) and running VirtualBox in administrator mode. You also need to mark the drive as being offline to make Windows allow writes to it. I assume they require that to avoid file system corruption problems with both Windows and VirtualBox+Haiku writing to the same volume on the drive simultaneously.

To mark the drive as offline, and writeable, use the right-click "Run as Administrator" option to start a command prompt, then do these commands. Substitute the correct disk number and path names for your particular setup. Step 6 is optional if step 5 reveals that read-only is already turned off:

  1. diskpart
  2. list disk
  3. select disk 2
  4. offline disk
  5. attributes disk
  6. attributes disk clear readonly
  7. exit

Then you need to make a VirtualBox virtual disk that represents the real disk. Do this step with Administrator priviledges too (can continue typing in the command prompt used in the previous step). Remember to change the disk numbers and paths to match your system.

  1. cd C:\Program Files\Oracle\VirtualBox
  2. VBoxManage internalcommands createrawvmdk -filename "D:\agmsmith\VirtualBox VMs\Haiku Alpha 4\PhysicalDisk2.vmdk" -rawdisk \\.\PhysicalDrive2

A typical session would look like this:

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

2012-11-27 12:05:00.42 C:\Windows\system32>diskpart

Microsoft DiskPart version 6.1.7601
Copyright (C) 1999-2008 Microsoft Corporation.
On computer: ALEXW7PRO

DISKPART> list disk

  Disk ###  Status         Size     Free     Dyn  Gpt
  --------  -------------  -------  -------  ---  ---
  Disk 0    Online          931 GB      0 B
  Disk 1    Online          232 GB      0 B
  Disk 2    Online          232 GB   172 GB

DISKPART> select disk 2

Disk 2 is now the selected disk.

DISKPART> offline disk

DiskPart successfully offlined the selected disk.

DISKPART> attributes disk
Current Read-only State : No
Read-only  : No
Boot Disk  : No
Pagefile Disk  : No
Hibernation File Disk  : No
Crashdump Disk  : No
Clustered Disk  : No

DISKPART> exit

Leaving DiskPart...

2012-11-27 12:05:30.17 C:\Windows\system32>cd C:\Program Files\Oracle\VirtualBox

2012-11-27 12:05:48.39 C:\Program Files\Oracle\VirtualBox>VBoxManage internalcommands createrawvmdk -filename "D:\agmsmi
th\VirtualBox VMs\Haiku Alpha 4\PhysicalDisk2.vmdk" -rawdisk  \\.\PhysicalDrive2
RAW host disk access VMDK file D:\agmsmith\VirtualBox VMs\Haiku Alpha 4\PhysicalDisk2.vmdk created successfully.

2012-11-27 12:05:58.72 C:\Program Files\Oracle\VirtualBox>

Installing Haiku on the Real Disk

Then from within the VM manager (running VirtualBox as Administrator), add the .vmdk file to the storage controller as a hard drive, boot the VM, and run Haiku DriveSetup to format the real disk as a Haiku volume. Either format the whole disk as a volume without a partition table, or set up partitions and make one for Haiku. If it says the disk is read-only and there is an odd 128MB parition on it, then it was GPT formatted at one time and the residue is confusing the Haiku partition parser. To fix the GPT problem, boot up a live Linux CD and overwrite the first few thousand sectors of the disk with zeroes and then try partitioning again.

Once you have the new Haiku disk volume mounted, use the Haiku Installer (it's in /boot/system/apps) to install Haiku on the new volume. If you used a partition, you also need to install BootManager (also in /boot/system/apps/), otherwise it won't boot (that old stock DOS MBR boot block doesn't seem to work). It also does boot if you used the whole unpartitioned disk as a Haiku disk volume. When done, reboot the computer, set the BIOS to boot from that real disk, and off you go.

Building Haiku rather than Installing

Rather than using the Haiku installer, you can also build Haiku to a fresh disk volume, possibly on a real hard drive. After downloading the Haiku source code, change to the "haiku" directory and use a command like this. Replace TestHaiku with the name of the disk volume you want to install it on, and adjust the other options as needed. The process takes about half an hour the first time (faster on later runs) on my 4 core 2.6Ghz CPU, with 4GB of memory:

HAIKU_INSTALL_DIR=/TestHaiku jam -q -da -j4 install-haiku

You may want to try adding HAIKU_ATA_STACK=0 if you have older IDE hard drive controller hardware.

Then make the disk bootable (writes the sector number of the start of the kernel code file to the boot loader). Change to the /TestHaiku directory and type makebootable home to fix it up.

Boot up the new disk and try it out. It will be a minimal Haiku, missing things like the web browser.

If you want the web browser and other goodies, you should have a look at making a haiku/build/jam/UserBuildConfig file with the optional packages you want in addition to the bare Haiku build. Note that the WebPositive browser requires a GGC4 build or a hybrid GCC2+GCC4 build. Here's my UserBuildConfig, which is activated by using the command jam -q -da -j4 @AGMS, remember to have an empty disk volume named TestHaiku mounted before starting.

DefineBuildProfile AGMS : install : /TestHaiku ;

switch $(HAIKU_BUILD_PROFILE) {
	case "AGMS" : {
		HAIKU_IMAGE_HOST_NAME = TestHaiku ;
		AddOptionalHaikuImagePackages BeBook BePDF CARootCertificates Development Git GitDoc Man OpenSSH OpenSSL P7zip Pe SQLite Tar Vim Vision WebPositive WebPositiveBookmarks Welcome WonderBrush ;
	}
}

The hybrid build magic for making somthing like the offical build (GCC2+GCC4 so it can run both old BeOS programs and the new web browser) boils down to a few commands, first these ones for preparing the build system after you've downloaded the source code:

cd haiku
mkdir generated.x86gcc2
mkdir generated.x86gcc4

cd generated.x86gcc4
../configure --alternative-gcc-output-dir ../generated.x86gcc2 --cross-tools-prefix /boot/develop/abi/x86/gcc4/tools/current/bin/ --include-gpl-addons --include-patented-code --use-gcc-pipe

cd ../generated.x86gcc2
../configure --alternative-gcc-output-dir ../generated.x86gcc4 --cross-tools-prefix /boot/develop/abi/x86/gcc2/tools/current/bin/ --include-gpl-addons --include-patented-code --use-gcc-pipe
cd ..

Then build it (or rebuild if you have updated the source code) from within the GCC2 directory, which will do both GCC2 and GCC4 compiles and set up the system so that GCC2 is the default (which old BeOS programs need).

cd generated.x86gcc2
jam -q -da -j4 @AGMS

Copyright © 2012 by Alexander G. M. Smith.