mkosi
mkosi stands for Make Operating System Image, and is a tool for generating an OS tree or image that can be booted.
Installation
Install mkosi or mkosi-gitAUR. Depending on what distribution you want to build install the following packages:
Distribution | Package |
---|---|
Arch | arch-install-scripts |
Debian | debootstrap, debian-archive-keyring, dpkg, apt |
Ubuntu | debootstrap, ubuntu-keyring, dpkg, apt |
Fedora | dnf |
OpenSUSE | zypper-gitAUR |
CentOS | dnf-legacy-utilsAUR |
Basic usage
You can create an image by just running it without any arguments:
# mkosi
You can specify option as arguments or by editing files in the current folder.
Create and boot a Debian image
The following command will create a bootable image with the latest Debian version and packages openssh-client and vim installed. This command requires mtools and mkosi's optional dependency systemd-ukify:
# mkosi --distribution debian --format disk --bootable --checksum --root-password password --package systemd,udev,kmod,systemd-boot,linux-image-generic,dbus --package openssh-client,vim --output image.raw
systemd-nspawn can boot the resulting image:
# systemd-nspawn -b -i image.raw
It can also be virtualized with QEMU/KVM:
# mkosi --output image.raw --qemu-smp 2 qemu
You can also write this image to a USB drive and use it to boot your computer.
Using configuration files
The same image can be created by creating a configuration file:
mkosi.conf
[Distribution] Distribution=debian Release=stable [Output] Format=disk Output=image.raw [Content] Bootable=yes Packages=systemd,udev,kmod,systemd-boot,linux-image-generic,dbus openssh-client vim [Validation] RootPassword=password
mkosi.cache
in the current working directory, mkosi will save all downloaded packages there, so you can recreate images faster.Configuration settings
Settings can be specified as command-line arguments or, for example, in a file called mkosi.conf
in the current directory.
The most important settings are:
Command line | Configuration file | Description |
---|---|---|
--distribution
|
[Distribution] Distribution= |
Name of the distribution to install. Supported are: fedora, debian, ubuntu, arch, opensuse, mageia, centos, openmandriva, rocky, alma
|
--release
|
[Distribution] Release= |
Version of the distribution: a numeric string or a distribution version name (bookworm, … )
|
--format
|
[Output] Format= |
Format of the image to create. For example:
|
--output
|
[Output] Output= |
Name of the image file or directory |
--output-directory
|
[Output] OutputDirectory= |
Location of the image file or directory (and other generated artifacts) |
--bootable
|
[Content] Bootable= |
Enable or disable generation of a bootable image: yes, no
|
--package
|
[Content] Packages= |
List of packages to be installed into the image: line and/or comma separated list |
--root-password
|
[Validation] RootPassword= |
Initial root password |