NetworkManager defaults to use keyfile i.e. .nmconnnection file but
still supports reading ifcfg-* file [1]. Make use of
"nmcli connection clone --temporary" to automatically convert a ifcfg-*
file to a .nmconnection file.
[1]
https://fedoraproject.org/wiki/Changes/NetworkManager_keyfile_instead_of_...
Signed-off-by: Coiby Xu <coxu(a)redhat.com>
---
dracut-module-setup.sh | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh
index 3b6b1c3..91bebcb 100755
--- a/dracut-module-setup.sh
+++ b/dracut-module-setup.sh
@@ -348,12 +348,30 @@ kdump_setup_ifname() {
kdump_copy_nmconnection_file() {
local _dev _nmconnection_file_path _nmconnection_name _initrd_nmconnection_file_path
+ local _cloned_nmconnection_file_path _uniq_name _old_uuid _old_name _uuid
+
_dev="$1"
_nmconnection_file_path=${nmconnection_map[$_dev]}
_nmconnection_name=$(basename "$_nmconnection_file_path")
_initrd_nmconnection_file_path="/etc/NetworkManager/system-connections/$_nmconnection_name"
- inst "$_nmconnection_file_path"
"$_initrd_nmconnection_file_path"
+
+ _old_uuid=$(nmcli --get-values connection.uuid c show
"$_nmconnection_file_path")
+ _old_name=$(nmcli --get-values connection.id c show
"$_nmconnection_file_path")
+ _uniq_name=$(cat /proc/sys/kernel/random/uuid)
+
+ nmcli connection clone --temporary "$_nmconnection_file_path"
"$_uniq_name"
+ _uuid=$(nmcli --get-values connection.uuid c show "$_uniq_name")
+ # change back connection.id for the sake of readibility
+ nmcli connection modify --temporary "$_uuid" connection.id
"$_old_name"
+
+ _cloned_nmconnection_file_path=$(nmcli -g UUID,FILENAME connection show | sed -n
"s/^${_uuid}://p")
+ inst "$_cloned_nmconnection_file_path"
"$_initrd_nmconnection_file_path"
+ # change uuid back to old value in case it's refered by other connection
+ # profile e.g. connection.master could be Interface name of the master
+ # device or UUID of the master connection.
+ sed -i -r "s/(^uuid=).*$/\1${_old_uuid}/g"
"${initdir}/$_initrd_nmconnection_file_path"
+ nmcli connection del "$_uuid"
}
kdump_setup_bridge() {
--
2.34.1