kata-containers/tools/osbuilder/rootfs-builder/ubuntu/rootfs_lib.sh
Jacek Tomasiak 91fb4353f6
osbuilder: ubuntu: Add REPO_COMPONENTS setting
Added variable REPO_COMPONENTS (default: "main") which sets components
used by mmdebstrap for rootfs building.
This is useful for custom image builders who want to include EXTRA_PKGS
from components other than the default "main" (e.g. "universe").

Fixes: #11278
Signed-off-by: Jacek Tomasiak <jtomasiak@arista.com>
Signed-off-by: Jacek Tomasiak <jacek.tomasiak@gmail.com>
2025-05-20 14:01:48 +02:00

42 lines
1.4 KiB
Bash

#!/usr/bin/env bash
#
# Copyright (c) 2018 Yash Jain, 2022 IBM Corp.
#
# SPDX-License-Identifier: Apache-2.0
build_rootfs() {
local rootfs_dir=$1
# This fixes the spurious error
# E: Can't find a source to download version '2021.03.26' of 'ubuntu-keyring:amd64'
apt update
# focal version of mmdebstrap only supports comma separated package lists
if [ "$OS_VERSION" = "focal" ]; then
PACKAGES=$(echo "$PACKAGES" | tr ' ' ',')
EXTRA_PKGS=$(echo "$EXTRA_PKGS" | tr ' ' ',')
fi
if ! mmdebstrap --mode auto --arch "$DEB_ARCH" --variant required \
--components="$REPO_COMPONENTS" \
--include "$PACKAGES,$EXTRA_PKGS" "$OS_VERSION" "$rootfs_dir" "$REPO_URL"; then
echo "ERROR: mmdebstrap failed, cannot proceed" && exit 1
else
echo "INFO: mmdebstrap succeeded"
fi
rm -rf "$rootfs_dir/var/run"
ln -s /run "$rootfs_dir/var/run"
cp --remove-destination /etc/resolv.conf "$rootfs_dir/etc"
local dir="$rootfs_dir/etc/ssl/certs"
mkdir -p "$dir"
cp --remove-destination /etc/ssl/certs/ca-certificates.crt "$dir"
# Reduce image size and memory footprint by removing unnecessary files and directories.
rm -rf $rootfs_dir/usr/share/{bash-completion,bug,doc,info,lintian,locale,man,menu,misc,pixmaps,terminfo,zsh}
# Minimal set of device nodes needed when AGENT_INIT=yes so that the
# kernel can properly setup stdout/stdin/stderr for us
pushd $rootfs_dir/dev
MAKEDEV -v console tty ttyS null zero fd
popd
}