User Tools

Site Tools


Crosscompiling MINIX with

Build compatibility

Host platform Buildable MINIX architectures
Ubuntu x86 32-bit x86 32-bit / ARMv7
Ubuntu x86 64-bit x86 32-bit / ARMv7
Arch Linux x86 32-bit x86 32-bit
Arch Linux x86 64-bit x86 32-bit / ARMv7
Mac OS X Lion x86 64-bit x86 32-bit / ARMv7
FreeBSD 10-CURRENT x86 32-bit x86 32-bit / ARMv7
FreeBSD 10-CURRENT x86 64-bit x86 32-bit / ARMv7

Building the crosscompiler

The first step to crosscompile MINIX is to obtain the sources and build the crosscompilation tools. MINIX has adopted NetBSD's script to create the crosscompiler:

$ git clone git:// minixsrc
$ cd minixsrc
$ sh -mi386 -O ../build tools

Please note that by default, the script will output the built objects to /usr/obj, so make sure it exists. Alternatively, use as above the “-O” option to redirect the output to somewhere else. When this process is completed, you'll have a ../build/tooldir.<something> directory. The <something> is roughly equivalent to

$ echo `uname -s`-`uname -r`-`uname -m`

Among the tools that are built are gcc, binutils, and gmake. The sources for these tools are not provided by us. Instead, they are downloaded on-the-fly as tarballs from the minix webserver

Note: For Cross compiling on Ubuntu , an extra library is to be installed , i.e the zlibc To install it run the following command :

$ sudo apt-get install zlibc zlib1g zlib1g-dev

Note: Also on Ubuntu, if you get an error stating that “'/lib/cpp' fails sanity check”, you need to install the GNU C++ compiler:

$ sudo apt-get install g++

Building world

The next step is to actually build MINIX:

$ sh -mi386 -O ../build -U distribution

This process will create a ../build/destdir.i386 directory that holds the built distribution of MINIX. The kernel and boot modules are stored in ../build/destdir.i386/multiboot. These files can be uploaded to an actual (virtual) machine running MINIX, or you can tell Qemu to use these to boot from instead of the files stored on the virtual hard disk. To do the latter, create a script with the following contents:

qemu -hda ~/path/to/disk/image -m 256 -kernel kernel -append rootdevname=c0d0p0s0 -initrd mod01_ds,mod02_rs,mod03_pm,mod04_sched,mod05_vfs,mod06_memory,mod07_log,mod08_tty,mod09_mfs,mod10_vm,mod11_pfs,mod12_init

As the modules are gzipped by default, you first have to unzip them before your run the script:

$ gunzip *.gz

Other useful options for qemu are -monitor telnet::4444,server,nowait (to access some interesting internal state by telnet) and -serial stdio - for convenient debug output over 'serial.'

Compiling things without

To run make in the cross-environment, i.e. to rebuild a tool (host target) or minix item (minix target), without running the full procedure all over again, use nbmake-i386, a make wrapper that sets all the right environment. First expand your $PATH to include it:

$ cd SRCDIR/tools
$ nbmake-i386 clean
$ nbmake-i386

will rebuild all the tools. After that you can e.g.

$ cd zic
$ nbmake-i386 clean
$ nbmake-i386

to just rebuild zic. As you can tell if you set MAKEVERBOSE=2, tools/zic/ will invoke cc (to run on the host platform), whereas nbmake-i386 will invoke i486–netbsdelf-gcc from your tools dir if you run it in usr.sbin/zic/, so a Minix-targeted binary is produced.

Automating the above a bit

Assuming the directory where you cloned the source tree is /HOMEDIR/minix/, make a script such as this, calling it e.g.

OBJDIR=/HOMEDIR/minix/obj.$(basename $(git symbolic-ref HEAD))
TOOLDIR=/HOMEDIR/minix/tooldir.''uname -s''-''uname -r''-''uname -m''
sh -mi386 -T $TOOLDIR -O $OBJDIR -U "$1"
echo "PATH=$PATH:$TOOLDIR/bin"

Then you can be in your source directory and invoke it like

$ sh ../ distribution

and it will print what you have to make your $PATH to get access to the commands necessary to do incremental building. This script will give you a separate objdir for every git branch, so incremental building for separate source trees is a lot smoother (if you want that). It shares the same tooldir for all branches so they're not rebuilt all the time (they needn't be).


The is tailored towards NetBSD and as such not all features make sense for MINIX. For example, we don't have a kernel configuration file. Also, you can't use for native builds on MINIX at the time of this essay writing You can consult's documentation by invoking:

$ sh

But know that not all operations and options are supported. For example, we only support the distribution build operation. You can't generate iso images with the script.

Build flags for

It is possible to tweak the build using build flags. Here are some you might find useful.

Option name Value Example Description
COPTS c flags COPTS=-g c compiler opttions

Build flags for nbmake

It is also possible to tweak when building separate components using nbmae-i386

Option name value example Description
MAKEVERBOSE [1] MAKEVERBOSE=2 Instruct make to be more verbose

Mounting a MINIX disk image on Linux

1. Load the loop kernel module, or adapt kernel commandline:

$ modprobe loop max_part=15

or add to your kernel commandline : max_part=15

2. Setup a loopback device to point to your disk image:

$ losetup /dev/loop0 minix.img

3. (Optional) list the available partitions:

$ dmesg | tail

or use

$ ls /dev/loop0*

4. Mount the desired partition somwhere

$ mount /dev/loop0p5 /mnt
releases/3.2.1/developersguide/crosscompiling.txt · Last modified: 2016/04/01 13:39 by essayltd