Building Managarm
This guide shows how to build a managarm distribution from source utilising the bootstrap-managarm patches and build scripts.
Building a managarm distribution from source
Build environment
To make sure that all build environments work properly, it is recommended to setup a build environment with our lightweight containerized build runtime cbuildrt (see below for instructions). It is also possible to build by installing the dependencies manually (see here), but this method is no longer recommended.
Make sure that you have at least 20 - 30 GiB of free disk space.
Preparations
- Create a directory which will be used for storing the
source and build directories. Here we use
~/managarm, but it can be any directory.mkdir ~/managarm && cd ~/managarm - Install the
xbstrapbuild system viapip3, as well as they4DSL:pip3 install xbstrap y4 - The
git,subversionandmercurialtools are required on the host (whether you build in a container or not). Install these via your package manager. - Clone this repository into a
srcdirectory and create abuilddirectory:git clone https://github.com/managarm/bootstrap-managarm.git src mkdir build
Creating a cbuildrt environment
-
Download and install the latest
cbuildrtrelease by running:xbstrap prereqs cbuildrt xbpsNote: If you choose to build
cbuildrtfrom source, make sure to place the resulting binary either in$PATHor in~/.xbstrap/bin.cbuildrtruns builds in a user namespace, which requires a range of subordinate user and group IDs for your user and thenewuidmapandnewgidmapprograms (in theuidmappackage on Debian and Ubuntu). Most distributions set up subordinate IDs when a user is created; if they are missing they can be added viausermod. -
Inside the
builddirectory, create a file namedbootstrap-site.ymlwith the following contents:auto_pull: true pkg_management: format: xbps container: runtime: cbuildrt uid: 1000 gid: 1000 src_mount: /var/lib/managarm-buildenv/src build_mount: /var/lib/managarm-buildenv/build allow_containerless: trueNote: you must keep the
src_mountandbuild_mountvalues as shown above if you want to be able to use pre-built tools from our build server. These paths refer to locations on the container, not on your host machine. Also note that these paths cannot be changed after starting the build; doing so will likely result in a broken directory tree. -
If you want this build directory to be used for building for an architecture other than the default (x86_64), you can define the
archandarch-tripleoptions. For instance, if you want to build forriscv64:define_options: arch: riscv64 arch-triple: riscv64-managarm rust-arch: riscv64gcNote: Every build directory only builds for the one architecture specified by the options. If you want to build managarm for multiple architectures, set up a build directory for each architecture desired.
Building
-
Initialize the build directory with
cd build xbstrap init ../src -
Decide which software you want to include in the image you create. There are several meta-packages available which help you decide this:
base: just enough to boot intokmsconplus some functional commands to play with (such aslessandgrep)base-devel: same asbaseplus some extra development tools (such asgccandbinutils)weston-desktop: full managarm experience with a selection of terminal and GUI software
You can install these meta-packages by doing:
xbstrap install weston-desktopThis command will download binary packages from our build servers.
-
In order to rebuild parts of the system locally (e.g., after making changes to the source code), use the
--rebuildflag:xbstrap install --rebuild managarm-system managarm-kernel mlibc mlibc-headers
Creating Images
After managarm's packages have been built, building a HDD image of the system is straightforward.
-
Create the image:
xbstrap run initialize-empty-image -
Copy the system onto it:
xbstrap run make-image # or: xbstrap run make-image-rootlessEither
make-imageormake-image-rootlessworks, with the following trade-offs:make-imagemounts the image via a loopback device. It is the fastest method, but it asks for root privileges viasudo(ordoasorsu). It runs on the host instead of in the container, so the host needsrsync,losetup,sfdisk,mkfs.vfat,mke2fs,e2fsckanddebugfs.make-image-rootlessdoes not need root privileges on the host. It mounts the image viafuse2fsinside thecbuildrtcontainer, which is slower.
-
Launch the image using QEMU:
xbstrap run qemu # Note that you can combine the last two operations: xbstrap run make-image qemu
Alternatively, you can call the necessary scripts manually (check their help messages for more information):
../src/scripts/update-image.pyfor copying the files onto the image (the mount method can be selected with the--mount-usingargument)../src/scripts/vm-util.py qemufor launching QEMU