Skip to content
Merged
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
28 changes: 16 additions & 12 deletions modules/initramfs/initramfs.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#!/usr/bin/env bash
#!/bin/sh

set -euo pipefail
set -eu

if ! command -v rpm-ostree &> /dev/null || ! command -v bootc &> /dev/null; then
if ! command -v rpm-ostree >/dev/null 2>&1 || ! command -v bootc >/dev/null 2>&1; then
echo "This module is only compatible with Fedora Atomic images"
exit 1
fi

if [[ "${OS_VERSION}" -le 40 ]]; then
if [ "${OS_VERSION}" -le 40 ]; then
echo "This module is only compatible with Fedora 41+ images."
exit 1
fi

# If images already installed cliwrap, use it. Only used in transition period, so it should be removed when base images like Ublue remove cliwrap
if [[ -f "/usr/libexec/rpm-ostree/wrapped/dracut" ]]; then
if [ -f "/usr/libexec/rpm-ostree/wrapped/dracut" ]; then
DRACUT="/usr/libexec/rpm-ostree/wrapped/dracut"
else
DRACUT="/usr/bin/dracut"
Expand All @@ -25,10 +25,12 @@ fi
# Refactor the module to support UKIs once they are starting to be used, if possible.
# That won't be soon, so this module should work for good period of time

KERNEL_MODULES_PATH="/usr/lib/modules"
readarray -t QUALIFIED_KERNEL < <(find "${KERNEL_MODULES_PATH}" -mindepth 1 -maxdepth 1 -type d -printf "%f\n")
kernel_count=0
for kernel_path in /usr/lib/modules/*/; do
kernel_count=$(( kernel_count + 1 ))
done

if [[ "${#QUALIFIED_KERNEL[@]}" -gt 1 ]]; then
if [ "${kernel_count}" -gt 1 ]; then
echo "NOTE: There are several versions of kernel's initramfs."
echo " There is a possibility that you have multiple kernels installed in the image."
echo " It is most ideal to have only 1 kernel, to make initramfs regeneration faster."
Expand All @@ -45,17 +47,19 @@ kmsgloglvl=0
fileloglvl=0
EOF

for qual_kernel in "${QUALIFIED_KERNEL[@]}"; do
INITRAMFS_IMAGE="${KERNEL_MODULES_PATH}/${qual_kernel}/initramfs.img"
for kernel_path in /usr/lib/modules/*/; do
kernel_path="${kernel_path%/}"
initramfs_image="${kernel_path}/initramfs.img"
qual_kernel=${kernel_path##*/}
echo "Starting initramfs regeneration for kernel version: ${qual_kernel}"
"${DRACUT}" \
--kver "${qual_kernel}" \
--force \
--add 'ostree' \
--no-hostonly \
--reproducible \
"${INITRAMFS_IMAGE}"
chmod 0600 "${INITRAMFS_IMAGE}"
"${initramfs_image}"
chmod 0600 "${initramfs_image}"
done

rm -- "${temp_conf_file}"
Loading