From: Daan De Meyer Date: Wed, 29 Mar 2023 08:50:14 +0000 (+0200) Subject: Drop --netdev X-Git-Tag: v15~272 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=96c5b9739bdfac017ba5e3250233b775303c3283;p=thirdparty%2Fmkosi.git Drop --netdev 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. --- diff --git a/NEWS.md b/NEWS.md index 0127a568e..43075d94b 100644 --- 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 diff --git a/mkosi.md b/mkosi.md index 7bd1e4d79..feef292eb 100644 --- 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 diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 7a006ea93..345a45a85 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -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(): diff --git a/mkosi/backend.py b/mkosi/backend.py index 584134023..d8355dbdf 100644 --- a/mkosi/backend.py +++ b/mkosi/backend.py @@ -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] diff --git a/mkosi/distributions/centos.py b/mkosi/distributions/centos.py index 3018a3ca9..f1f05eb0d 100644 --- a/mkosi/distributions/centos.py +++ b/mkosi/distributions/centos.py @@ -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. diff --git a/mkosi/distributions/fedora.py b/mkosi/distributions/fedora.py index f0d753e73..8e9ce633b 100644 --- a/mkosi/distributions/fedora.py +++ b/mkosi/distributions/fedora.py @@ -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") diff --git a/mkosi/distributions/openmandriva.py b/mkosi/distributions/openmandriva.py index 4318f9c3c..91ebb2e30 100644 --- a/mkosi/distributions/openmandriva.py +++ b/mkosi/distributions/openmandriva.py @@ -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") diff --git a/mkosi/distributions/opensuse.py b/mkosi/distributions/opensuse.py index 3a45f4104..68a760add 100644 --- a/mkosi/distributions/opensuse.py +++ b/mkosi/distributions/opensuse.py @@ -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")