Cross building FreeBSD
A Tale of OS Bootstrapping
What do you do when an amd64 box comes by your way but
you only have an 32-bit operating system to run on it? With
FreeBSD™, you can bootstrap your way into a 64 bit world.
Here is what you do:
-
Install FreeBSD in the usual way. When doing so, keep a spare disk partition for holding the new
amd64OS. In this example, we’ll assume that this is partition ‘d’. Mount this partition on some convenient mount point, say/1. The full FreeBSD system occupies about ~250MB these days; so make this partition a few GB in size. Don’t forget to install the sources to the FreeBSD system of course, otherwise there won’t be anything to cross-build. -
Change directory to the root of the source tree
/usr/srcand execute the following commands:# cd /usr/src # make world TARGET_ARCH=amd64 DESTDIR="/1"This step builds an
amd64userland and populates it into/1. Several interesting things happen as part of this step.- Since the host OS at this point is running in 32-bit mode it has
to build a full cross-toolchain first: tools running on the
i386architecture but manipulating libraries and executables for theamd64architecture. - It then needs to compile the whole source tree for the
amd64architecture using tools running on thei386. - Once compilation succeeds, the build process transfers the newly
built binaries into the filesystem rooted at
/1.
Other options for
TARGET_ARCHincludepowerpc,sparc64,alpha,ia64. - Since the host OS at this point is running in 32-bit mode it has
to build a full cross-toolchain first: tools running on the
-
The next step is to populate a default
/etc. This is how you do this:# make distribution TARGET_ARCH=amd64 DESTDIR=/1This step populates
/1/etcwith the default set of startup scripts. -
Now we need an
amd64kernel to boot from:# make kernel KERNCONF=GENERIC TARGET_ARCH=amd64 DESTDIR="/1"This builds a kernel following the configuration specified in the configuration file named
/usr/src/sys/amd64/conf/GENERICand installs it under/1/boot/kernel. -
Copy over
/etc/fstabto/1/etc/fstaband change the definition of the/(root) mount point to use partition ‘d’ (the default is to mount/on the ‘a’ partition). -
Copy over
/etc/rc.confto/1/etc/rc.conf, as this contains the machine’s hostname, and IP addresses of its interfaces. -
Create a file
boot.configin the ‘a’ disk partition containing the following text:0:ad(0,d)/boot/loaderThis command informs the first stage boot loader (see boot(8)) that we want to boot from partition ‘d’ instead of the usual partition ‘a’. If you’ve booted from a SCSI disk, you may need to specify the boot device as
da(0,d). -
Reboot. Viola! You boot into an
amd64kernel running anamd64userland.