Skip to content

Commit 72ae1c4

Browse files
cgwaltersharaldh
authored andcommitted
99base: Rework /etc/initrd-release to derive from real os-release
I'd like to rework CoreOS Ignition (which runs in the initramfs) to include some values from the *real* `/etc/os-release` in HTTP headers. Looking at this, it turns out dracut eats almost all of the useful information from it. I don't think `dracut` should be the `ID` here...dracut's not an OS itself, it's a way to *build* little operating systems. It'd be kind of like if Fedora's Koji injected itself into `/etc/os-release`. This code dates back a long time; not sure of all the rationale behind it. I changed it so that we keep extending the VERSION/PRETTY_NAME with the dracut version, but otherwise "pass through" the rest of the real `/etc/os-release` we were built from unchanged.
1 parent 8e9b094 commit 72ae1c4

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

modules.d/99base/module-setup.sh

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,31 +67,36 @@ install() {
6767
echo ro >> "${initdir}/etc/cmdline.d/base.conf"
6868
fi
6969

70+
[ -e "${initdir}/usr/lib" ] || mkdir -m 0755 -p ${initdir}/usr/lib
71+
7072
local VERSION=""
7173
local PRETTY_NAME=""
72-
# default values
73-
ANSI_COLOR="0;34"
74+
# Derive an os-release file from the host, if it exists
7475
if [ -e /etc/os-release ]; then
7576
. /etc/os-release
77+
grep -hE -ve '^VERSION=' -ve '^PRETTY_NAME' /etc/os-release >${initdir}/usr/lib/initrd-release
7678
[[ -n ${VERSION} ]] && VERSION+=" "
7779
[[ -n ${PRETTY_NAME} ]] && PRETTY_NAME+=" "
80+
else
81+
# Fall back to synthesizing one, since dracut is presently used
82+
# on non-systemd systems as well.
83+
{
84+
echo NAME=dracut
85+
echo ID=dracut
86+
echo VERSION_ID=\"$DRACUT_VERSION\"
87+
echo ANSI_COLOR='"0;34"'
88+
} >${initdir}/usr/lib/initrd-release
7889
fi
79-
# force-override values
80-
NAME=dracut
81-
ID=dracut
8290
VERSION+="dracut-$DRACUT_VERSION"
8391
PRETTY_NAME+="dracut-$DRACUT_VERSION (Initramfs)"
84-
VERSION_ID=$DRACUT_VERSION
85-
86-
[ -e "${initdir}/usr/lib" ] || mkdir -m 0755 -p ${initdir}/usr/lib
8792
{
88-
echo NAME=\"$NAME\"
8993
echo VERSION=\"$VERSION\"
90-
echo ID=$ID
91-
echo VERSION_ID=$VERSION_ID
9294
echo PRETTY_NAME=\"$PRETTY_NAME\"
93-
echo ANSI_COLOR=\"$ANSI_COLOR\"
94-
} > $initdir/usr/lib/initrd-release
95+
# This addition is relatively new, intended to allow software
96+
# to easily detect the dracut version if need be without
97+
# having it mixed in with the real underlying OS version.
98+
echo DRACUT_VERSION=\"${DRACUT_VERSION}\"
99+
} >> $initdir/usr/lib/initrd-release
95100
echo dracut-$DRACUT_VERSION > $initdir/lib/dracut/dracut-$DRACUT_VERSION
96101
ln -sf ../usr/lib/initrd-release $initdir/etc/initrd-release
97102
ln -sf initrd-release $initdir/usr/lib/os-release

0 commit comments

Comments
 (0)