This guide explains how to build the container image, set up the VM infrastructure, compile a custom kernel and modules, and run the environment using Podman.
Note: Make sure you have Podman installed and properly configured on your system before starting!
To avoid permission and ownership issues and to simplify the deployment of the entire repository, it is requireed to operate directly as the root user.
$ sudo suAfter entering this command, you'll be logged in as root. Notice that the command prompt changes from $ to #.
- Being logged in as root gives you full control over the system.
- Use root with caution: executing random commands can harm your system.
- Only the brave should operate as root; always be responsible :-)
- You may read here and there that operating as root is not recommended. This is absolutely true for production system. In our case, you are running a VM with a development environment (and it is NOT recommended to use the VM for anything else, so you should not create harm to other critical stuff).
Only after logging in as root, you can clone the repository! The cloned repository will have root as both owner and group.
- The repository was cloned using a user different from
root(e.g., the default userubuntu). - The ownership of the entire repository directory (e.g.,
/home/ubuntu/kernel-playground/) is set to that user (ubuntu). - When launching the container, the repository is mounted as a volume.
- Inside the container, the default user is
root. - The container's process attempts to initialize submodules via
git(using./setup-all.sh), which detects a mismatch in ownership.
root@test-vm:/home/ubuntu/kernel-playground/podman# ./setup-all.sh
+ set -e
+ pushd ../
/opt/kernel-playground /opt/kernel-playground/podman
+ git submodule update --init --recursive
fatal: detected dubious ownership in repository at '/opt/kernel-playground'
To add an exception for this directory, call:
git config --global --add safe.directory /opt/kernel-playgroundThis error occurs because Git detects that the directory ownership is inconsistent with the current user executing the command.
Just delete the cloned repository and clone it again after loggin in as root.
Change the ownership of the entire project directory to root. For example:
# From the parent directory of your project
sudo chown -R root:root kernel-playground/This command recursively sets the owner and group of the kernel-playground directory to root, resolving the ownership conflict and allowing Git to initialize submodules without errors.
Note: Always prefer to operate as root only when necessary and exercise caution to prevent system issues.
To install Podman on Ubuntu (20.04 or newer), run the following commands:
sudo apt update
sudo apt -y install podmanTo verify that Podman is installed correctly:
podman --versionNote: Podman is a daemonless container engine, so you don’t need to start a service like with Docker. You can use it immediately after installation.
First, build the container image that will be used to setup the environment:
# ./container-build.shThis script creates a container image containing all necessary tools for the setup process.
Once the image is built, run the following script to set up the entire environment:
# ./setup-all.shThis script automates the following steps:
-
Create the VM with root filesystem Sets up a virtual machine environment with a minimal root filesystem.
-
Configure and compile the kernel and custom module Applies kernel configuration, then compiles both the kernel and the custom modules.
-
Link the compiled kernel into the VM submodule Creates a soft link so the VM can use the freshly compiled kernel during the setup.
-
Copy the custom kernel module into shared VM folder Places the compiled kernel module into the shared folder accessible from within the VM at
/mnt/shared.
To start the container in detached mode:
# ./run-detach.shThis will run the environment in the background, allowing you to interact with it later.
To interact with the running container, execute:
podman exec -it kernel-builder bashOnce inside, navigate to the kernel playground directory:
cd /opt/kernel-playgroundNote: The
/opt/kernel-playgrounddirectory inside the container is mounted from your host machine. Any changes made within this directory inside the container are immediately reflected on your host, and vice versa. This setup facilitates seamless development and testing.
Note: Make sure you have Podman installed and properly configured on your system before starting.