systemd/mkosi

Name: mkosi

Owner: systemd

Description: Build Legacy-Free OS Images

Created: 2016-07-13 10:31:19.0

Updated: 2018-05-22 20:35:44.0

Pushed: 2018-05-20 00:47:41.0

Homepage: null

Size: 452

Language: Python

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

mkosi - Create legacy-free OS images

A fancy wrapper around dnf --installroot, debootstrap, pacstrap and zypper that may generate disk images with a number of bells and whistles.

Supported output formats

The following output formats are supported:

When a GPT disk image is created, the following additional options are available:

Compatibility

Generated images are legacy-free. This means only GPT disk labels (and no MBR disk labels) are supported, and only systemd based images may be generated. Moreover, for bootable images only EFI systems are supported (not plain MBR/BIOS).

All generated GPT disk images may be booted in a local container directly with:

emd-nspawn -bi image.raw

Additionally, bootable GPT disk images (as created with the --bootable flag) work when booted directly by EFI systems, for example in KVM via:

-kvm -m 512 -smp 2 -bios /usr/share/edk2/ovmf/OVMF_CODE.fd -drive format=raw,file=image.raw

EFI bootable GPT images are larger than plain GPT images, as they additionally carry an EFI system partition containing a boot loader, as well as a kernel, kernel modules, udev and more.

All directory or btrfs subvolume images may be booted directly with:

emd-nspawn -bD image

Other features

Supported distributions

Images may be created containing installations of the following OSes.

In theory, any distribution may be used on the host for building images containing any other distribution, as long as the necessary tools are available. Specifically, any distro that packages debootstrap may be used to build Debian or Ubuntu images. Any distro that packages dnf may be used to build Fedora or Mageia images. Any distro that packages pacstrap may be used to build Arch Linux images. Any distro that packages zypper may be used to build openSUSE images. Any distro that packages yum (or the newer replacement dnf) may be used to build CentOS images.

Currently, Fedora packages all relevant tools as of Fedora 26.

Files

To make it easy to build images for development versions of your projects, mkosi can read configuration data from the local directory, under the assumption that it is invoked from a source tree. Specifically, the following files are used if they exist in the local directory:

All these files are optional.

Note that the location of all these files may also be configured during invocation via command line switches, and as settings in mkosi.default, in case the default settings are not acceptable for a project.

Examples

Create and run a raw GPT image with ext4, as image.raw:

osi
stemd-nspawn -b -i image.raw

Create and run a bootable btrfs GPT image, as foobar.raw:

osi -t raw_btrfs --bootable -o foobar.raw
stemd-nspawn -b -i foobar.raw
mu-kvm -m 512 -smp 2 -bios /usr/share/edk2/ovmf/OVMF_CODE.fd -drive format=raw,file=foobar.raw

Create and run a Fedora image into a plain directory:

osi -d fedora -t directory -o quux
stemd-nspawn -b -D quux

Create a compressed image image.raw.xz and add a checksum file, and install SSH into it:

osi -d fedora -t raw_squashfs --checksum --xz --package=openssh-clients

Inside the source directory of an automake-based project, configure mkosi so that simply invoking mkosi without any parameters builds an OS image containing a built version of the project in its current state:

t > mkosi.default <<EOF
tribution]
ribution=fedora
ase=24

put]
at=raw_btrfs
able=yes

kages]
ages=openssh-clients httpd
dPackages=make gcc libcurl-devel

t > mkosi.build <<EOF
in/sh
SRCDIR
togen.sh
nfigure --prefix=/usr
 -j `nproc`
 install

mod +x mkosi.build
osi
stemd-nspawn -bi image.raw

To create a Fedora image with hostname:

osi -d fedora --hostname image

Also you could set hostname in configuration file:

t mkosi.default

put]
name=image

Requirements

mkosi is packaged for various distributions: Debian, Ubuntu, Arch (in AUR), Fedora. It is usually easiest to use the distribution package.

The current version requires systemd 233 (or actually, systemd-nspawn of it).

When not using distribution packages make sure to install the necessary dependencies. For example, on Fedora you need:

install arch-install-scripts btrfs-progs debootstrap dosfstools edk2-ovmf e2fsprogs squashfs-tools gnupg python3 tar veritysetup xfsprogs xz zypper

On Debian/Ubuntu it might be necessary to install the ubuntu-keyring, ubuntu-archive-keyring and/or debian-archive-keyring packages explicitly, in addition to debootstrap, depending on what kind of distribution images you want to build. debootstrap on Debian only pulls in the Debian keyring on its own, and the version on Ubuntu only the one from Ubuntu.

Note that the minimum required Python version is 3.5.

If SecureBoot signing is to be used, then the “sbsign” tool needs to be installed as well, which is currently not available on Fedora, but in a COPR repository:

copr enable msekleta/sbsigntool
install sbsigntool

References


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.