diff --git a/live/live-root/usr/lib/dracut/modules.d/99agama-cmdline/agama-network.sh b/live/live-root/usr/lib/dracut/modules.d/99agama-cmdline/agama-network.sh new file mode 100755 index 0000000000..46712b9e3f --- /dev/null +++ b/live/live-root/usr/lib/dracut/modules.d/99agama-cmdline/agama-network.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +[ -e /dracut-state.sh ] && . /dracut-state.sh + +. /lib/dracut-lib.sh +. /lib/net-lib.sh + +if _val=$(getargs ip=); then + mkdir -p /run/agama/ + : >/run/agama/copy_network +fi diff --git a/live/live-root/usr/lib/dracut/modules.d/99agama-cmdline/module-setup.sh b/live/live-root/usr/lib/dracut/modules.d/99agama-cmdline/module-setup.sh index a25645c0f0..7e9ed2d7e4 100755 --- a/live/live-root/usr/lib/dracut/modules.d/99agama-cmdline/module-setup.sh +++ b/live/live-root/usr/lib/dracut/modules.d/99agama-cmdline/module-setup.sh @@ -18,5 +18,6 @@ installkernel() { install() { inst_hook cmdline 99 "$moddir/agama-cmdline-conf.sh" inst_hook cmdline 99 "$moddir/agama-network-compat.sh" + inst_hook cmdline 99 "$moddir/agama-network.sh" inst_hook pre-pivot 99 "$moddir/save-agama-conf.sh" } diff --git a/live/live-root/usr/lib/dracut/modules.d/99agama-cmdline/save-agama-conf.sh b/live/live-root/usr/lib/dracut/modules.d/99agama-cmdline/save-agama-conf.sh old mode 100644 new mode 100755 index 3e33f3b419..1df6d90b03 --- a/live/live-root/usr/lib/dracut/modules.d/99agama-cmdline/save-agama-conf.sh +++ b/live/live-root/usr/lib/dracut/modules.d/99agama-cmdline/save-agama-conf.sh @@ -7,3 +7,19 @@ if [ -e /etc/hostname ]; then cp /etc/hostname "$NEWROOT/etc/hostname" fi + +# If there is some explicit network configuration provided through the ip= kernel cmdline option +# then we set the config server configuration diabling the DHCP auto configuration for ethernet +# devices and also copying the configuration persistently (bsc#1241224, bsc#122486, bsc#1239777, +# bsc#1236885). +if [ -e /run/agama/copy_network ]; then + if getargbool 1 inst.copy_network; then + mkdir -p /run/NetworkManager/conf.d + echo '[main]' >/run/NetworkManager/conf.d/00-agama-server.conf + echo 'no-auto-default=*' >>/run/NetworkManager/conf.d/00-agama-server.conf + echo 'ignore-carrier=*' >>/run/NetworkManager/conf.d/00-agama-server.conf + + mkdir -p "$NEWROOT/etc/NetworkManager/system-connections/" + cp /run/NetworkManager/system-connections/* "$NEWROOT/etc/NetworkManager/system-connections/" + fi +fi diff --git a/live/src/agama-installer.changes b/live/src/agama-installer.changes index 8999eb1f65..621ffc573b 100644 --- a/live/src/agama-installer.changes +++ b/live/src/agama-installer.changes @@ -1,3 +1,15 @@ +------------------------------------------------------------------- +Thu Apr 24 16:40:41 UTC 2025 - Knut Anderssen + +- bsc#1239777, bsc#1236885 gh#agama-project/agama#2291. + - Persist the NetworkManager runtime config created by + nm-initrd-generator when given explicitlly with the 'ip=' + kernel cmdline argument. + - Allow to disable the copy of the persistent configuration with + the inst.copy_network kernel cmdline argument. + - Do not copy the NetworkManager runtime configuration to the + target system anymore. + ------------------------------------------------------------------- Thu Apr 24 15:11:35 UTC 2025 - Ladislav Slezák diff --git a/service/lib/agama/network.rb b/service/lib/agama/network.rb index fb2bdc55e7..cc736f80e5 100644 --- a/service/lib/agama/network.rb +++ b/service/lib/agama/network.rb @@ -73,6 +73,7 @@ def unlink_resolv HOSTNAME = "/etc/hostname" RESOLV = "/etc/resolv.conf" + COPY_NETWORK = "/run/agama/copy_network" RESOLV_FLAG = "/run/agama/manage_resolv" ETC_NM_DIR = "/etc/NetworkManager" RUN_NM_DIR = "/run/NetworkManager" @@ -93,13 +94,7 @@ def copy_files copy(HOSTNAME) return unless Dir.exist?(ETC_NM_DIR) - - # runtime configuration is copied first, so in case of later modification - # on same interface it gets overwriten (bsc#1210541). - copy_directory( - File.join(RUN_NM_DIR, "system-connections"), - File.join(Yast::Installation.destdir, ETC_NM_DIR, "system-connections") - ) + return unless File.exist?(COPY_NETWORK) copy_directory( File.join(ETC_NM_DIR, "system-connections"), diff --git a/service/package/rubygem-agama-yast.changes b/service/package/rubygem-agama-yast.changes index 9c2b988bb4..051331f50e 100644 --- a/service/package/rubygem-agama-yast.changes +++ b/service/package/rubygem-agama-yast.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Thu Apr 24 17:18:04 UTC 2025 - Knut Anderssen + +- Copy only the NetworkManager connnections from /etc and just + in case the copy has not been disabled + (gh#agama-project/agama#2291). + ------------------------------------------------------------------- Thu Apr 24 14:10:46 UTC 2025 - Josef Reidinger diff --git a/service/test/agama/network_test.rb b/service/test/agama/network_test.rb index be67b98ffd..79a0158d52 100644 --- a/service/test/agama/network_test.rb +++ b/service/test/agama/network_test.rb @@ -31,11 +31,15 @@ let(:targetdir) { File.join(rootdir, "mnt") } let(:fixtures) { File.join(FIXTURES_PATH, "root_dir") } let(:hostname_path) { File.join(fixtures, "etc", "hostname") } + let(:agama_dir) { File.join(rootdir, "run", "agama") } + let(:copy_network) { File.join(agama_dir, "copy_network") } before do allow(Yast::Installation).to receive(:destdir).and_return(targetdir) stub_const("Agama::Network::HOSTNAME", hostname_path) stub_const("Agama::Network::RUN_NM_DIR", File.join(rootdir, "run", "NetworkManager")) + stub_const("Agama::Network::COPY_NETWORK", copy_network) + FileUtils.mkdir_p(agama_dir) end after do @@ -48,6 +52,7 @@ let(:etcdir) do File.join(rootdir, "etc", "NetworkManager", "system-connections") end + let(:service) { instance_double(Yast2::Systemd::Service, enable: nil) } before do @@ -61,11 +66,27 @@ FileUtils.touch(File.join(etcdir, "system-connections", "wired.nmconnection")) end - it "copies the configuration files" do - network.install - expect(File).to exist( - File.join(targetdir, etcdir, "system-connections", "wired.nmconnection") - ) + context "and the /run/agama/copy_network file exists" do + around do |block| + FileUtils.mkdir_p(agama_dir) + FileUtils.touch(copy_network) + block.call + FileUtils.rm_f(copy_network) + end + + it "copies the configuration files" do + network.install + expect(File).to exist( + File.join(targetdir, etcdir, "system-connections", "wired.nmconnection") + ) + end + end + + context "and the /run/agama/copy_network file does not exist" do + it "does not try to copy any file" do + expect(FileUtils).to_not receive(:cp_r) + network.install + end end end