Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions live/root/usr/lib/dracut/modules.d/99agama-cmdline/README
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,20 @@ dracut agama-cmdline module
This module writes any agama configuration given through the kernel cmdline
to its own cmdline conf file copying it to the sysroot.

It also tries to translate the linuxrc ifcfg kernel cmdline argument to the
corresponding ip one but only basic scenarios are supported.

## Supported examples

ifcfg=*=dhcp
ip=dhcp

ifcfg=eth0=dhcp
ip=eth0:dhcp

ifcfg=eth0.10=192.168.0.100/24,192.168.0.1
vlan=eth0.10:eth0 ip=192.168.0.100::192.168.0.1:24::eth0.10

ifcfg="eth0=192.168.0.33/24 10.0.0.100/24,192.168.0.1,192.168.0.1 10.0.0.1,suse.de"
ip=192.168.0.33::192.168.0.1:24::eth0 nameserver=192.168.0.1 nameserver=10.0.0.1 ip=10.0.0.100:::24::eth0

Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/bin/bash

[ -e /dracut-state.sh ] && . /dracut-state.sh

. /lib/dracut-lib.sh
. /lib/net-lib.sh

ifcfg_to_ip() {
local ip
local v="${2}",
local interface="$1"
local conf_path="/etc/cmdline.d/40-agama-network.conf"
set --
while [ -n "$v" ]; do
set -- "$@" "${v%%,*}"
v=${v#*,}
done

### See https://en.opensuse.org/SDB:Linuxrc#Network_Config
# ifcfg=<interface_spec>=[try,]dhcp*,[rfc2132,]OPTION1=value1,OPTION2=value2...
if str_starts "$1" "dhcp"; then
autoconf="$1"
if [ "$autoconf" = "dhcp4" ]; then
autoconf="dhcp"
fi
case $autoconf in
"dhcp" | "dhcp6")
if [ "$interface" = "*" ]; then
echo "ip=${1}" >>$conf_path

else
echo "ip=${interface}:${1}" >>$conf_path
fi
;;
*)
echo "No supported option ${1}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would write "Unsupported option ${1}"

;;
esac

return 0
fi

# ifcifg=<interface_spec>=ip,gateway,nameserver,domain
if strglob "$1" "*.*.*.*/*"; then
[[ -n "$2" ]] && gateway=$2
[[ -n "$3" ]] && nameserver=$3

ip="$1 "
set --
while [ -n "$ip" ]; do
set -- "$@" "${ip%% *}"
ip="${ip#* }"
done

## TODO: IP is a LIST_IP
ip="$1"
mask=${ip##*/}
ip=${ip%%/*}
shift

## Configure the first interface, the gateway must belong to the same network
echo "ip=${ip}::${gateway}:$mask::${interface}" >>$conf_path

## Configure multiple addresses for the same interface
while [[ $# -gt 0 ]]; do
ip="$1"
mask=${ip##*/}
ip=${ip%%/*}
echo "ip=${ip}:::$mask::${interface}" >>$conf_path
shift
done

## Configure nameservers
if [[ -n $nameserver ]]; then
nameserver="$nameserver "
while [ -n "$nameserver" ]; do
echo "nameserver=${nameserver%% *}" >>$conf_path
nameserver="${nameserver#* }"
done
fi
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to say that without automatic testing I would be very scared to touch this file to avoid breaking anything.

fi

return 0
}

translate_ifcfg() {
local i
local vlan
local phydevice
local conf_path="/etc/cmdline.d/40-agama-network.conf"

while read -r i; do
set --
echo "### Processing $i ###"
set -- "$@" "${i%%=*}"
options="${i#*=}"
pattern="$1"
unset vlan phydevice

if str_starts "$options" "try,"; then
options="${i#*try,*}"
fi

# The pattern Looks like a VLAN like eth0.10
if strglobin "$pattern" "*.[0-9]*"; then
phydevice=${pattern%.*}
vlan="vlan=$1:$phydevice"
echo "$vlan" >>$conf_path
fi

# Try to translate the pattern as it is, we cannot try to apply the config to check if
# it is valid because the nm-initrd-generator is called by a cmdline hook unless we call
# explicitly passing the getcmdline result
ifcfg_to_ip "$pattern" "$options"

set --
unset options pattern CMDLINE
done <<<"$(getargs ifcfg)"

return 0
}

translate_ifcfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ installkernel() {
# called by dracut
install() {
inst_hook cmdline 99 "$moddir/agama-cmdline-conf.sh"
inst_hook cmdline 99 "$moddir/agama-network-compat.sh"
inst_hook pre-pivot 99 "$moddir/save-agama-conf.sh"
}
10 changes: 10 additions & 0 deletions live/src/agama-installer.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
-------------------------------------------------------------------
Fri Jan 31 12:49:24 UTC 2025 - Knut Anderssen <kanderssen@suse.com>

- Added support for giving a file url with extra kernel cmdline
arguments (agama.info) which was known as the info file in
linuxrc.
- Added basic support for translating the ifcfg kernel cmdline arg
to its ip equivalent (gh#agama-project/agama#1896).
- Moved the kernel cmdline conf under /run/agama/cmdline.d

-------------------------------------------------------------------
Wed Jan 15 16:53:28 UTC 2025 - Eugenio Paolantonio <eugenio.paolantonio@suse.com>

Expand Down