Skip to content

Commit

Permalink
Initial implementation for storing Agama configuration provided by ke…
Browse files Browse the repository at this point in the history
…rnel cmdline (#1866)

## Problem

As part of the linuxrc compatibilty Jira entry, we want to make sure
several boot arguments are translated to environment variables that
indeed affect the execution of Agama.

That includes the following patterns: LIBSTORAGE_*, YAST_*, Y2*,
ZYPP_FULLLOG.

Some examples (useful for verifying everything actually works):
LIBSTORAGE_MULTIPATH_AUTOSTART, LIBSTORAGE_MDPART, YAST_ACTIVATE_LUKS,
YAST_REUSE_LVM, Y2DEBUG, ZYPP_FULLLOG

- https://trello.com/c/WDefGcX1


## Solution

The configuration that is provided by the kernel cmdline will be stored
to /etc/agama.d/cmdline.conf and the agama services will use it as an
EnvironmentFile. It is an initial implementation an probably would need
some more work.

## Testing

- *Tested manually*
  • Loading branch information
teclator authored Jan 8, 2025
2 parents 83ef39c + 6bd88fc commit 1ec82fe
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 8 deletions.
6 changes: 6 additions & 0 deletions live/root/usr/lib/dracut/modules.d/99agama-cmdline/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
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.

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

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

. /lib/dracut-lib.sh

get_agama_args() {
local _i _found

for _i in $CMDLINE; do
case $_i in
LIBSTORAGE_* | YAST_* | agama* | Y2* | ZYPP_*)
_found=1
;;
esac

if [ -n "$_found" ]; then
printf "Agama variable found ($_i)"
if ! strstr "$_i" "="; then
# Set the variable as a boolean if there is no assignation
_i="${_i}=1"
fi
echo $_i >>/etc/cmdline.d/99-agama-cmdline.conf
fi
unset _found
done

return 0
}

get_agama_args
21 changes: 21 additions & 0 deletions live/root/usr/lib/dracut/modules.d/99agama-cmdline/module-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

# called by dracut
check() {
return 0
}

# called by dracut
depends() {
return 0
}

installkernel() {
return 0
}

# called by dracut
install() {
inst_hook cmdline 99 "$moddir/agama-cmdline-conf.sh"
inst_hook pre-pivot 99 "$moddir/save-agama-conf.sh"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#! /bin/sh

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

. /lib/dracut-lib.sh

if [ -e /etc/cmdline.d/99-agama-cmdline.conf ]; then
echo "Creating agama conf"
mkdir -p "$NEWROOT/etc/agama.d"
cp /etc/cmdline.d/99-agama-cmdline.conf "$NEWROOT/etc/agama.d/cmdline.conf"
fi
7 changes: 7 additions & 0 deletions live/src/agama-installer.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Wed Jan 8 12:10:39 UTC 2025 - Knut Anderssen <[email protected]>

- Make agama kernel cmdline options available in the sysroot at
/etc/agama.d/cmdline.conf and set it as a EnvironmentFile
in Agama related services (gh#agama-project/agama#1866).

-------------------------------------------------------------------
Tue Dec 10 12:46:06 UTC 2024 - Michal Filka <[email protected]>

Expand Down
16 changes: 8 additions & 8 deletions live/src/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ echo "root_disk=live:LABEL=$label" >>/etc/cmdline.d/10-liveroot.conf
# if there's a default network location, add it here
# echo "root_net=" >> /etc/cmdline.d/10-liveroot.conf
echo 'install_items+=" /etc/cmdline.d/10-liveroot.conf "' >/etc/dracut.conf.d/10-liveroot-file.conf
echo 'add_dracutmodules+=" dracut-menu "' >>/etc/dracut.conf.d/10-liveroot-file.conf
echo 'add_dracutmodules+=" dracut-menu agama-cmdline "' >>/etc/dracut.conf.d/10-liveroot-file.conf

if [ "${arch}" = "s390x" ];then
# workaround for custom bootloader setting
touch /config.bootoptions
if [ "${arch}" = "s390x" ]; then
# workaround for custom bootloader setting
touch /config.bootoptions
fi

# replace the @@LIVE_MEDIUM_LABEL@@ with the real Live partition label name from KIWI
Expand All @@ -111,7 +111,7 @@ rm /var/log/zypper.log /var/log/zypp/history
# reduce the "vim-data" content, this package is huge (37MB unpacked!), keep only
# support for JSON (for "agama config edit") and Ruby (fixing/debugging the Ruby
# service)
rpm -ql vim-data | grep -v -e '/ruby.vim$' -e '/json.vim$' -e colors | xargs rm 2> /dev/null || true
rpm -ql vim-data | grep -v -e '/ruby.vim$' -e '/json.vim$' -e colors | xargs rm 2>/dev/null || true

du -h -s /usr/{share,lib}/locale/

Expand All @@ -125,7 +125,7 @@ du -h -s /usr/{share,lib}/locale/
mkdir -p /etc/agama.d
# emulate "localectl list-locales" call, it cannot be used here because it
# insists on running systemd as PID 1 :-/
ls -1 -d /usr/lib/locale/*.utf8 | sed -e "s#/usr/lib/locale/##" -e "s#utf8#UTF-8#" > /etc/agama.d/locales
ls -1 -d /usr/lib/locale/*.utf8 | sed -e "s#/usr/lib/locale/##" -e "s#utf8#UTF-8#" >/etc/agama.d/locales

# delete translations and unusupported languages (makes ISO about 22MiB smaller)
# build list of ignore options for "ls" with supported languages like "-I cs* -I de* -I es* ..."
Expand All @@ -138,7 +138,7 @@ ls -1 "${IGNORE_OPTS[@]}" -I "en_US*" -I "C.*" /usr/lib/locale/ | xargs -I% sh -

# delete unused translations (MO files)
for t in zypper gettext-runtime p11-kit; do
rm -f /usr/share/locale/*/LC_MESSAGES/$t.mo
rm -f /usr/share/locale/*/LC_MESSAGES/$t.mo
done
du -h -s /usr/{share,lib}/locale/

Expand Down Expand Up @@ -180,7 +180,7 @@ du -h -s /lib/modules /lib/firmware

# disable the services included by dependencies
for s in purge-kernels; do
systemctl -f disable $s || true
systemctl -f disable $s || true
done

# Only used for OpenCL and X11 acceleration on vmwgfx (?), saves ~50MiB
Expand Down
1 change: 1 addition & 0 deletions rust/share/agama-web-server.service
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ After=network-online.target agama.service agama-hostname.service
BindsTo=agama.service

[Service]
EnvironmentFile=-"/etc/agama.d/cmdline.conf"
Environment="AGAMA_LOG=debug,zbus=info"
Type=notify
ExecStart=/usr/bin/agama-web-server serve --address :::80 --address2 :::443
Expand Down
1 change: 1 addition & 0 deletions service/share/agama.service
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ After=network-online.target
[Service]
Type=forking
ExecStart=/usr/bin/agamactl --daemon
EnviromentFile=-/etc/agama.d/cmdline.conf
PIDFile=/run/agama/bus.pid
User=root
TimeoutStopSec=5
Expand Down

0 comments on commit 1ec82fe

Please sign in to comment.