]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Drop --netdev
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 29 Mar 2023 08:50:14 +0000 (10:50 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 29 Mar 2023 09:33:38 +0000 (11:33 +0200)
Let's not configure systemd-networkd in mkosi, but leave this up
to users instead. As our SSH support now works on top of vsock, we
don't need this option anymore to make the SSH support work.

When booting, containers are started without a network device (trivial
to add one by adding --network-veth) and VMs are started with a network
device. We don't want one for containers so that they can just reuse the
network namespace of the host instead of having to start networkd to get
internet access within the container. For VMs, there's no disadvantage to
adding a network device, so we add one by default.

NEWS.md
mkosi.md
mkosi/__init__.py
mkosi/backend.py
mkosi/distributions/centos.py
mkosi/distributions/fedora.py
mkosi/distributions/openmandriva.py
mkosi/distributions/opensuse.py

diff --git a/NEWS.md b/NEWS.md
index 0127a568e63cb0bb0799c4d95bd3f98c0e885611..43075d94b997313065a907b92483260eead3a15c 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
@@ -56,6 +56,8 @@
 - Only configuration files matching `*.conf` are parsed in dropin directories now.
 - Removed `--qemu-headless`, we now start qemu in the terminal by default and configure the serial console at
   runtime. Use the new `--qemu-gui` option to start qemu in its graphical interface.
+- Removed `--netdev`. Can be replaced by manually installing systemd-networkd, putting a network file in the
+  image and enabling systemd-networkd.
 
 ## v14
 
index 7bd1e4d79b349f8f266f7fc3b87c03abff1ae304..feef292eb96e75ba1c8c5f1af7369e1251a58ba8 100644 (file)
--- a/mkosi.md
+++ b/mkosi.md
@@ -809,14 +809,6 @@ a boolean argument: either "1", "yes", or "true" to enable, or "0",
 : Space-delimited list of additional arguments to pass when invoking
   qemu.
 
-`Netdev=`, `--netdev`
-
-: When used with the boot or qemu verbs, this option creates a virtual
-  ethernet link between the host and the container/VM. The host
-  interface is automatically picked up by systemd-networkd as documented
-  in systemd-nspawn's man page:
-  https://www.freedesktop.org/software/systemd/man/systemd-nspawn.html#-n
-
 `Ephemeral=`, `--ephemeral`
 
 : When used with the `shell`, `boot`, or `qemu` verbs, this option
index 7a006ea93543912eca6192e34c7616d6c5ef5dd1..345a45a857a2eaca018c2cff97f479d6db20499b 100644 (file)
@@ -49,7 +49,6 @@ from mkosi.backend import (
     detect_distribution,
     flatten,
     format_rlimit,
-    is_centos_variant,
     is_dnf_distribution,
     patch_file,
     set_umask,
@@ -1886,19 +1885,6 @@ def create_parser() -> ArgumentParserMkosi:
         # arguments.
         help=argparse.SUPPRESS,
     )
-    group.add_argument(
-        "--network-veth",     # Compatibility option
-        dest="netdev",
-        metavar="BOOL",
-        action=BooleanAction,
-        help=argparse.SUPPRESS,
-    )
-    group.add_argument(
-        "--netdev",
-        metavar="BOOL",
-        action=BooleanAction,
-        help="Create a virtual Ethernet link between the host and the container/VM",
-    )
     group.add_argument(
         "--ephemeral",
         metavar="BOOL",
@@ -2570,9 +2556,6 @@ def load_args(args: argparse.Namespace) -> MkosiConfig:
     if args.repo_dirs:
         args.repo_dirs = [p.absolute() for p in args.repo_dirs]
 
-    if args.netdev and is_centos_variant(args.distribution) and "epel" not in args.repositories:
-        die("--netdev is only supported on EPEL centOS variants")
-
     # If we are building a sysext we don't want to add base packages to the
     # extension image, as they will already be in the base image.
     if args.base_image is not None:
@@ -2847,7 +2830,6 @@ def print_summary(config: MkosiConfig) -> None:
 
     print("        Extra search paths:", line_join_list(config.extra_search_paths))
     print("      QEMU Extra Arguments:", line_join_list(config.qemu_args))
-    print("                    Netdev:", yes_no(config.netdev))
 
 
 def make_output_dir(state: MkosiState) -> None:
@@ -2932,39 +2914,6 @@ def configure_ssh(state: MkosiState) -> None:
     presetdir.joinpath("80-mkosi-ssh.preset").write_text("enable ssh.socket")
 
 
-def configure_netdev(state: MkosiState) -> None:
-    if not state.config.netdev or state.for_cache:
-        return
-
-    with complete_step("Setting up netdev…"):
-        network_file = state.root / "etc/systemd/network/80-mkosi-netdev.network"
-        with open(network_file, "w") as f:
-            # Adapted from https://github.com/systemd/systemd/blob/v247/network/80-container-host0.network
-            f.write(
-                dedent(
-                    """\
-                    [Match]
-                    Virtualization=!container
-                    Type=ether
-                    Driver=virtio_net
-
-                    [Network]
-                    DHCP=yes
-                    LinkLocalAddressing=yes
-                    LLDP=yes
-                    EmitLLDP=customer-bridge
-
-                    [DHCP]
-                    UseTimezone=yes
-                    """
-                )
-            )
-
-        os.chmod(network_file, 0o644)
-
-        run(["systemctl", "--root", state.root, "enable", "systemd-networkd"])
-
-
 def configure_initrd(state: MkosiState) -> None:
     if state.for_cache or not state.config.output_format == OutputFormat.cpio:
         return
@@ -3180,7 +3129,6 @@ def build_image(state: MkosiState, *, manifest: Optional[Manifest] = None) -> No
         configure_root_password(state)
         configure_autologin(state)
         configure_dracut(state, cached)
-        configure_netdev(state)
         configure_initrd(state)
         run_build_script(state)
         install_build_dest(state)
@@ -3407,9 +3355,6 @@ def run_shell(config: MkosiConfig) -> None:
         if nspawn_knows_arg(console_arg):
             cmdline += [console_arg]
 
-    if config.netdev:
-        cmdline += ["--network-veth"]
-
     if config.ephemeral:
         cmdline += ["--ephemeral"]
 
@@ -3601,6 +3546,8 @@ def run_qemu(config: MkosiConfig) -> None:
         "rng-random,filename=/dev/urandom,id=rng0",
         "-device",
         "virtio-rng-pci,rng=rng0,id=rng-device0",
+        "-nic",
+        "user,model=virtio-net-pci",
     ]
 
     try:
@@ -3621,9 +3568,6 @@ def run_qemu(config: MkosiConfig) -> None:
         # -serial mon:stdio adds back the serial device removed by -nodefaults.
         cmdline += ["-nographic", "-nodefaults", "-serial", "mon:stdio"]
 
-    if config.netdev:
-        cmdline += ["-nic", "user,model=virtio-net-pci"]
-
     cmdline += ["-drive", f"if=pflash,format=raw,readonly=on,file={firmware}"]
 
     for k, v in config.credentials.items():
index 584134023a4b604367db10eb68069d6e22379231..d8355dbdf06db1b5312f1f9ac35cd4342814dec8 100644 (file)
@@ -182,14 +182,6 @@ def is_dnf_distribution(d: Distribution) -> bool:
     )
 
 
-def is_centos_variant(d: Distribution) -> bool:
-    return d in (
-        Distribution.centos,
-        Distribution.alma,
-        Distribution.rocky,
-    )
-
-
 class OutputFormat(Parseable, enum.Enum):
     directory = enum.auto()
     subvolume = enum.auto()
@@ -296,7 +288,6 @@ class MkosiConfig:
     password_is_hashed: bool
     autologin: bool
     extra_search_paths: list[Path]
-    netdev: bool
     ephemeral: bool
     ssh: bool
     credentials: dict[str, str]
index 3018a3ca9f1f165a94cb77392e986bcdfdbfeeea..f1f05eb0dccff3a87dc6d2d6013e79ee83d9c32a 100644 (file)
@@ -108,8 +108,6 @@ class CentosInstaller(DistributionInstaller):
 
         if "epel" in state.config.repositories:
             add_packages(state.config, packages, "epel-release")
-            if state.config.netdev:
-                add_packages(state.config, packages, "systemd-networkd", conditional="systemd")
 
         # Make sure we only install the minimal language files by default on CentOS Stream 8 which still
         # defaults to all langpacks.
index f0d753e7323e07a0180d139c5a03c0125c8b66a6..8e9ce633b4b3ee72cf9046be007a576337bee833 100644 (file)
@@ -104,8 +104,6 @@ def install_fedora(state: MkosiState) -> None:
         add_packages(state.config, packages, "systemd-udev", conditional="systemd")
         if not state.config.initrds:
             add_packages(state.config, packages, "dracut", "dracut-config-generic")
-    if  state.config.netdev:
-        add_packages(state.config, packages, "systemd-networkd", conditional="systemd")
     if state.config.ssh:
         add_packages(state.config, packages, "openssh-server")
 
index 4318f9c3c68a149f539d47ced11c3addc3bde8e0..91ebb2e30d3c4173176eea5025ec349682731d98 100644 (file)
@@ -70,8 +70,6 @@ def install_openmandriva(state: MkosiState) -> None:
         add_packages(state.config, packages, "kernel-release-server", "timezone")
         if not state.config.initrds:
             add_packages(state.config, packages, "dracut")
-    if state.config.netdev:
-        add_packages(state.config, packages, "systemd-networkd", conditional="systemd")
     if state.config.ssh:
         add_packages(state.config, packages, "openssh-server")
 
index 3a45f4104548448ebe94d791e0d942358f2117f3..68a760adde6b7d3e97e5df0ef6d7f475b52b01b3 100644 (file)
@@ -181,9 +181,6 @@ def install_opensuse(state: MkosiState) -> None:
             if not state.config.initrds:
                 add_packages(state.config, packages, "dracut")
 
-        if state.config.netdev:
-            add_packages(state.config, packages, "systemd-network")
-
         if state.config.ssh:
             add_packages(state.config, packages, "openssh-server")