Genesis a CLI project written in Python. It can build Ubuntu images from scratch.
The tool is named genesis (because you start from nothing). And is available as a python package: https://github.com/gjolly/genesis (it’s also packaged as a deb in a PPA.
A basic example
We are going to create a very minimal image of Ubuntu 23.04 (Lunar Lobster) and try to boot from it using qemu.
Creating a base image
First you want to start by bootstrapping a basic filesystem:
Then, with this filesystem, you can create a disk-image:
Once this is done, you need to update your system (debootstrap only uses the release pocket). While doing this stage, you can install some extra packages. Here we are going to build a very minimalist image of Ubuntu using only
We still need to install a boot loader and this operation requires its own command:
| |
Final customizations
The image is almost ready but we can (and here we need) customize it by adding extra files directly on the filesystem. This is done with the copy-files command.
Configuring networking
Because we did not install cloud-init in our image, we need to pre-configure it with everything it needs. Here we assume that this image will be run with qemu and a virtual network card attached. We configure netplan accordingly:
with netplan.yaml being the following:
Configuring the sources
We want to define the Debian packages source. For now there is just a default source file pointing to http://archive.ubuntu.com in the image. Maybe, since I live in France, I want my image to be configured with a local mirror:
deb https://fr.archive.ubuntu.com/ubuntu lunar main universe restricted
deb https://fr.archive.ubuntu.com/ubuntu lunar-updates main universe restricted
deb https://fr.archive.ubuntu.com/ubuntu lunar-security main universe restricted
This is what my sources.list would look like and I can now install it on the live image:
User config
Finally, I need to configure a user. Here I create a user with create-user and I copy my public ssh key in .ssh/authorized_keys directory for this user.
Note that if .ssh does not exist under /home/ubuntu, it will be automatically created by copy-files.
Running the image
Now let’s try to run this image that we have just created. For that we need a bit of qemu black magic:
| |
If you don’t understand what is going on, this is not very important. But, assuming you have all the right dependencies installed, this should start a virtual machine and boot on the disk we’ve just created.
Then you should be able to ssh (by opening another terminal):
| |
And we can check the boot time:
| |
Because the image is so minimal, the system boots in less than a second.
Is it usable for building production-ready images of Ubuntu?
No