3

I'm currently in the progress of preseeding a Debian installation with custom setup scripts running after the actual installation to create a simple installer that will create everything that I need.

Now I found how to install additional packages and added the NetworkManager package, to simplify networking stuff. However the device has multiple ethernet interfaces and installing NetworkManager during the Debian installation creates the file /etc/NetworkManager/system-connections/Wired connection 1. However that file is configured incorrectly for the actual system. So if I remove it while NetworkManager is off and reboot, everything is working just fine. But having the file makes NetworkManager label all interfaces as "Wired connection 1" and only one interface can be active, etc. All in all, that file needs to go.

Now I first tried just removing the file during the script I invoke wiht preseed/late_command (the script runs and removes the file, I checked that). But upon booting into the system after the installation the file is back. Next I tried stopping the NetworkManager service before removing the file with in-target systemctl stop NetworkManager, but that just gives me the lovely log line in-target: Running in chroot, ignoring request. And naturally that also doesn't work.

How I can install NetworkManager during preseeding with a blank "system-connections" configuration?

In summary the relevant (and working) lines from my preseed.cfg are:

d-i pkgsel/include string ... network-manager ...
d-i preseed/late_command string sh /.../postinstall.sh

and in my postinstall.sh I tried

in-target rm /etc/NetworkManager/system-connections/*

(which actually removes the file in that moment) and

in-target systemctl stop NetworkManager
in-target rm /etc/NetworkManager/system-connections/*

Update:

As suggested I tried removing the connection with nmcli directly.
This is my script:

in-target nmcli con delete $(in-target nmcli -g uuid con)

And this is the result:

May  6 09:16:43 log-output: + in-target
May  6 09:16:43 log-output:  nmcli -g uuid con
May  6 09:16:43 log-output: dpkg-divert: warning: diverting file '/sbin/start-stop-daemon' from an Essential package with rename is dangerous, use --no-rename
May  6 09:16:43 in-target: Error: Could not create NMClient object: Could not connect: No such file or directory.
May  6 09:16:44 log-output: + in-target nmcli con delete
May  6 09:16:44 log-output: dpkg-divert: warning: diverting file '/sbin/start-stop-daemon' from an Essential package with rename is dangerous, use --no-rename
May  6 09:16:44 in-target: Error: Could not create NMClient object: Could not connect: No such file or directory.
  • Really? Since I have never reported bugs like that, where would I go? And what's at defect here? The installer? Or the NetworkManager package? And lastly, do you mean like wiping the file (> $file) and then restricting write access chmod 444 $file? (Edit: Comment I was responding to has since been removed and was suggesting to report this a bug to debian(?) and restrict write access as a temporary solution) – BrainStone May 6 at 10:56
  • i posted an answer instead it's why i deleted the comment... what look like a bug to me is that networkmanager is generating a file with a wrong config, there is indeed no-auto-default to diable that but the issue should not happen by default. bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=network-manager and debian.org/Bugs can be used to report a bug – intika May 6 at 11:15
  • This could be caused by a lack of hardware detection during the install phase. may be loading the needed network kernel module during the installation and before installing network manager could solve this – intika May 6 at 11:20
  • Yes something like > $file and then chattr +i $file but i never tested it ... it's just an idea – intika May 6 at 11:21
2
+100

Working with wired connections

By default, NetworkManager generates a connection profile for each wired ethernet connection it finds. At the point when generating the connection, it does not know whether there will be more ethernet adapters available. Hence, it calls the first wired connection "Wired connection 1". You can avoid generating this connection, by configuring no-auto-default (see man NetworkManager.conf), or by simply deleting it. Then NetworkManager will remember not to generate a connection for this interface again. You can also edit the connection (and persist it to disk) or delete it. NetworkManager will not re-generate a new connection. Then you can change the name to whatever you want. You can use something like nm-connection-editor for this task.

So, you can create NetworkManager.conf before installing network manager and set it up according to your hardware and with no-auto-default option if needed. (also check that the config file is not overwritten after the install 'should not be the case...')

An other alternative could be locking the write access to the problematic file with chmod u-w or chattr +i but this is not recommended because its not intended to work that way and may introduce other issues.

Source: arch-wiki

  • According to the man page you linked this is the exact opposite of what I want. It makes it so that any interface/connection that does not have a configuration file will not get a temporary connection. And giving every interface just a temporary connection is precisley what I want. I don't want any configured interfaces by default. – BrainStone May 6 at 11:24
  • Yes i know, but the problem you are having if i understand it right is during the install phase so you may want to use the feature during the installation and switch it back afterward – intika May 6 at 11:29
  • I currently don't have a first boot script, that could revert that change. If the clearing protecting the file solution doesn't work, I'll give that a go. – BrainStone May 6 at 12:31
  • ok, let me know otherwise as i already mentioned, its probably caused by a lack of detection of the whole network hardware during installation, you may want to unload network completely during install or make sure to load all the needed network module during installation, let me know if the above does not work i'll post how to do that. an other way is a temporary boot script that does whats needed and destroy itself afterward – intika May 6 at 14:14
  • 1
    What I ended up doing is disabling NM during postinstall, and removing the file during firstboot, then enabling and starting it. Making the file unwritable, did not work. – BrainStone May 7 at 13:30
1

I suspect that the connection file (/etc/NetworkManager/system-connections/Wired connection 1) gets created during the regular boot process. If you cannot avoid the creation of connection, one option would be to remove the connection after it is created using the nmcli command:

nmcli connection delete id <connection name>
# OR
nmcli connection delete CONNECTION_NAME
# OR
nmcli connection delete <uuid>

to get the UUID of "Wired connection 1":

nmcli con|grep 'Wired connection 1'|tr -s ' ' |cut -f2 -d' '

thus:

nmcli connection delete $(nmcli con|grep 'Wired connection 1'|tr -s ' ' |cut -f2 -d' ')
  • I tried nmcli con delete $(nmcli -g uuid con) (which does what your snippet intended to do). Though that yields me this error message: Error: Could not create NMClient object: Could not connect: No such file or directory. (see update question for full details) – BrainStone May 6 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.