From: Stefan Nickl Date: Wed, 27 Sep 2023 18:31:53 +0000 (+0200) Subject: Add "none" distribution X-Git-Tag: v18~15 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ee2bef6644c4b8688b67e1fd98f29e41b6a9bf99;p=thirdparty%2Fmkosi.git Add "none" distribution --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index a2175c7bb..03ec0f65a 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -39,6 +39,7 @@ from mkosi.config import ( parse_config, summary, ) +from mkosi.distributions import Distribution from mkosi.installer import clean_package_manager_metadata, package_manager_scripts from mkosi.kmod import gen_required_kernel_modules, process_kernel_modules from mkosi.log import ARG_DEBUG, complete_step, die, log_step @@ -138,6 +139,7 @@ def install_distribution(state: MkosiState) -> None: # Some distributions install EFI binaries directly to /boot/efi. Let's redirect them to /efi # instead. rmtree(state.root / "boot/efi") + (state.root / "boot").mkdir(exist_ok=True) (state.root / "boot/efi").symlink_to("../efi") if state.config.packages: @@ -176,6 +178,14 @@ def remove_packages(state: MkosiState) -> None: die(f"Removing packages is not supported for {state.config.distribution}") +def check_root_populated(state: MkosiState) -> None: + """Check that the root was populated by looking for a os-release file.""" + osrelease = state.root / "usr/lib/os-release" + if not osrelease.exists(): + die(f"{osrelease} not found.", + hint="The root must be populated by the distribution, or from base trees, skeleton trees, and prepare scripts.") + + def configure_os_release(state: MkosiState) -> None: """Write IMAGE_ID and IMAGE_VERSION to /usr/lib/os-release in the image.""" if not state.config.image_id and not state.config.image_version: @@ -969,6 +979,9 @@ def build_initrd(state: MkosiState) -> Path: if symlink.exists(): return symlink.resolve() + if state.config.distribution == Distribution.none: + die(f"Building a default initrd is not supported with distribution {state.config.distribution}") + # Default values are assigned via the parser so we go via the argument parser to construct # the config for the initrd. @@ -1945,6 +1958,7 @@ def build_image(args: MkosiArgs, config: MkosiConfig, name: str, uid: int, gid: save_cache(state) reuse_cache(state) + check_root_populated(state) run_build_scripts(state) if state.config.output_format == OutputFormat.none: diff --git a/mkosi/config.py b/mkosi/config.py index ffe4426ad..fe8780a73 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -294,7 +294,8 @@ def config_default_distribution(namespace: argparse.Namespace) -> Distribution: detected = detect_distribution()[0] if not detected: - die("Distribution of your host can't be detected or isn't a supported target. Please set Distribution= in your config.") + logging.info("Distribution of your host can't be detected or isn't a supported target. Defaulting to Distribution=none.") + return Distribution.none return detected diff --git a/mkosi/distributions/__init__.py b/mkosi/distributions/__init__.py index 02373a30b..b33334d4f 100644 --- a/mkosi/distributions/__init__.py +++ b/mkosi/distributions/__init__.py @@ -72,6 +72,7 @@ class DistributionInstaller: class Distribution(StrEnum): + none = enum.auto() fedora = enum.auto() debian = enum.auto() ubuntu = enum.auto() diff --git a/mkosi/distributions/none.py b/mkosi/distributions/none.py new file mode 100644 index 000000000..fced69ab3 --- /dev/null +++ b/mkosi/distributions/none.py @@ -0,0 +1,27 @@ +# SPDX-License-Identifier: LGPL-2.1+ + +from collections.abc import Sequence + +from mkosi.distributions import DistributionInstaller +from mkosi.log import die +from mkosi.state import MkosiState + + +class Installer(DistributionInstaller): + @classmethod + def setup(cls, state: MkosiState) -> None: + pass + + @classmethod + def install(cls, state: MkosiState) -> None: + pass + + @classmethod + def install_packages(cls, state: MkosiState, packages: Sequence[str]) -> None: + if packages: + die("Installing packages is not supported with distribution 'none'") + + @classmethod + def remove_packages(cls, state: MkosiState, packages: Sequence[str]) -> None: + if packages: + die("Removing packages is not supported with distribution 'none'") diff --git a/mkosi/resources/mkosi.md b/mkosi/resources/mkosi.md index 504f54ec3..e842399a0 100644 --- a/mkosi/resources/mkosi.md +++ b/mkosi/resources/mkosi.md @@ -395,8 +395,8 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`, : The distribution to install in the image. Takes one of the following arguments: `fedora`, `debian`, `ubuntu`, `arch`, `opensuse`, `mageia`, - `centos`, `rhel-ubi`, `openmandriva`, `rocky`, `alma`. If not - specified, defaults to the distribution of the host. + `centos`, `rhel-ubi`, `openmandriva`, `rocky`, `alma`, `none`. + If not specified, defaults to the distribution of the host. `Release=`, `--release=`, `-r` @@ -1284,6 +1284,8 @@ distributions: guarantee that it will work at all and the core maintainers will generally not fix gentoo specific issues**) +* *None* (**Requires the user to provide a pre-built rootfs**) + 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. @@ -1292,6 +1294,7 @@ any distribution that packages `apt` may be used to build *Debian* or *Ubuntu* i Any distribution that packages `dnf` may be used to build images for any of the rpm-based distributions. Any distro that packages `pacman` may be used to build *Arch Linux* images. Any distribution that packages `zypper` may be used to build *openSUSE* images. +Other distributions and build automation tools for embedded Linux systems such as Buildroot, OpenEmbedded and Yocto Project may be used by selecting the `none` distribution, and populating the rootfs via a combination of base trees, skeleton trees, and prepare scripts. Currently, *Fedora Linux* packages all relevant tools as of Fedora 28.