Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add initramfs generation #1127

Merged
merged 14 commits into from
Apr 13, 2024
Merged
3 changes: 2 additions & 1 deletion Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ COPY --from=ghcr.io/ublue-os/bluefin-cli /usr/share/bash-prexec /usr/share/bash-
COPY --from=ghcr.io/ublue-os/akmods:${AKMODS_FLAVOR}-${FEDORA_MAJOR_VERSION} /rpms /tmp/akmods-rpms

# Build, cleanup, commit.
RUN bash -c ". /tmp/build/build-base.sh" && \
RUN rpm-ostree cliwrap install-to-root / && \
bash -c ". /tmp/build/build-base.sh" && \
rm -rf /tmp/* /var/* && \
mkdir -p /var/tmp && \
chmod -R 1777 /var/tmp && \
Expand Down
7 changes: 6 additions & 1 deletion build_files/base/branding.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

set -oue pipefail


# Branding for Bluefin/Aurora
if test "$BASE_IMAGE_NAME" = "silverblue"; then
sed -i '/^PRETTY_NAME/s/Silverblue/Bluefin/' /usr/lib/os-release
elif test "$BASE_IMAGE_NAME" = "kinoite"; then
sed -i '/^PRETTY_NAME/s/Kinoite/Aurora/' /usr/lib/os-release
sed -i 's/Bluefin/Aurora/g' /usr/etc/yafti.yml
sed -i 's/Aurora (Beta)/Aurora \- Bluefin\-KDE (Alpha)/' /usr/etc/yafti.yml
sed -i 's/Bluefin/Aurora/' /usr/libexec/ublue-flatpak-manager
fi
fi

# Watermark for Plymouth
cp /usr/share/plymouth/themes/spinner/{"$BASE_IMAGE_NAME"-,}watermark.png
3 changes: 2 additions & 1 deletion build_files/base/build-base.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/bash
# shellcheck disable=SC1091

set -oue pipefail

Expand All @@ -7,12 +8,12 @@ set -oue pipefail
. /tmp/build/install-akmods.sh
. /tmp/build/packages.sh
. /tmp/build/fetch-install.sh
rpm-ostree install ublue-update
. /tmp/build/image-info.sh
. /tmp/build/fetch-quadlets.sh
. /tmp/build/font-install.sh
. /tmp/build/install-tmp.sh
. /tmp/build/systemd.sh
. /tmp/build/aurora-changes.sh
. /tmp/build/branding.sh
. /tmp/build/initramfs.sh
. /tmp/build/cleanup.sh
4 changes: 0 additions & 4 deletions build_files/base/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

set -ouex pipefail

if [[ "${IMAGE_FLAVOR}" =~ "nvidia" ]]; then
rm /usr/lib/modprobe.d/nvidia.conf
fi

rm -f /etc/yum.repos.d/tailscale.repo
rm -f /etc/yum.repos.d/charm.repo
rm -f /etc/yum.repos.d/ublue-os-staging-fedora-"${FEDORA_MAJOR_VERSION}".repo
Expand Down
6 changes: 5 additions & 1 deletion build_files/base/fetch-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set -oue pipefail
curl -Lo /tmp/starship.tar.gz "https://github.com/starship/starship/releases/latest/download/starship-x86_64-unknown-linux-gnu.tar.gz"
tar -xzf /tmp/starship.tar.gz -C /tmp
install -c -m 0755 /tmp/starship /usr/bin
# shellcheck disable=SC2016
echo 'eval "$(starship init bash)"' >> /etc/bashrc

# Brew Install Script
Expand All @@ -17,4 +18,7 @@ mkdir -p /usr/etc/flatpak/remotes.d
wget -q https://dl.flathub.org/repo/flathub.flatpakrepo -P /usr/etc/flatpak/remotes.d

# Topgrade Install
pip install --prefix=/usr topgrade
pip install --prefix=/usr topgrade

# Install ublue-update -- breaks with packages.json
rpm-ostree install ublue-update
1 change: 1 addition & 0 deletions build_files/dx/build-dx.sh
KyleGospo marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/bash
# shellcheck disable=SC1091

set -oue pipefail

Expand Down
21 changes: 21 additions & 0 deletions build_files/shared/initramfs.sh
KyleGospo marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/bash

set -oue pipefail

# Remove nvidia specific files
if [[ "${IMAGE_FLAVOR}" =~ "nvidia" ]]; then
rm /usr/lib/modprobe.d/nvk.conf
rm /usr/lib/modprobe.d/amd-legacy.conf
else
rm /usr/lib/dracut/dracut.conf.d/95-nvidia.conf
rm /usr/lib/modprobe.d/nvidia.conf
fi

if [[ "${AKMODS_FLAVOR}" == "surface" ]]; then
KERNEL_SUFFIX="surface"
else
KERNEL_SUFFIX=""
fi

QUALIFIED_KERNEL="$(rpm -qa | grep -P 'kernel-(|'"$KERNEL_SUFFIX"'-)(\d+\.\d+\.\d+)' | sed -E 's/kernel-(|'"$KERNEL_SUFFIX"'-)//')"
/usr/libexec/rpm-ostree/wrapped/dracut --no-hostonly --kver "$QUALIFIED_KERNEL" --reproducible -v --add ostree -f "/lib/modules/$QUALIFIED_KERNEL/initramfs.img"
Copy link
Member

Choose a reason for hiding this comment

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

We should compare against uncompressed for boot time.

Nvidia likely needs to be compressed for the additional files but non-nvidia initramfs will only be about 40 MB larger.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
compress="zstd"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_dracutmodules+=" fido2 tpm2-tss pkcs11 pcsc "
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
force_drivers+=" nvidia nvidia_modeset nvidia_uvm nvidia_drm "
6 changes: 6 additions & 0 deletions system_files/shared/usr/lib/modprobe.d/amd-legacy.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Enable Legacy AMD hardware support
options amdgpu si_support=1
options amdgpu cik_support=1

options radeon si_support=0
options radeon cik_support=0
8 changes: 6 additions & 2 deletions system_files/shared/usr/lib/modprobe.d/nvidia.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# Enable GSP firmware
options nouveau config=NvGspRm=1
# Blacklist Nouveau
blacklist nouveau
options nouveau modeset=0

# Enable Nvidia Modeset
options nvidia-drm modeset=1
2 changes: 2 additions & 0 deletions system_files/shared/usr/lib/modprobe.d/nvk.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Enable GSP firmware
options nouveau config=NvGspRm=1
65 changes: 9 additions & 56 deletions system_files/shared/usr/libexec/ublue-system-setup
Original file line number Diff line number Diff line change
Expand Up @@ -16,60 +16,13 @@ KNOWN_IMAGE_FLAVOR_FILE="/etc/ublue/image_flavor"
KNOWN_IMAGE_FLAVOR=$(cat $KNOWN_IMAGE_FLAVOR_FILE)

# GLOBAL
SYS_ID="$(cat /sys/devices/virtual/dmi/id/product_name)"
GPU_ID=$(lspci -k | grep -A 3 -E "(VGA|3D)")
KARGS=$(rpm-ostree kargs)
NEEDED_KARGS=""
echo "Current kargs: $KARGS"
mkdir -p /etc/ublue

if grep -qz "Kernel driver in use: radeon" <<< $GPU_ID; then
echo "Legacy AMD hardware detected, enabling CIK and SI support in AMDGPU"
if [[ ! $KARGS =~ "radeon.si_support" ]]; then
NEEDED_KARGS="$NEEDED_KARGS --append=radeon.si_support=0"
fi

if [[ ! $KARGS =~ "radeon.cik_support" ]]; then
NEEDED_KARGS="$NEEDED_KARGS --append=radeon.cik_support=0"
fi

if [[ ! $KARGS =~ "amdgpu.si_support" ]]; then
NEEDED_KARGS="$NEEDED_KARGS --append=amdgpu.si_support=1"
fi

if [[ ! $KARGS =~ "amdgpu.cik_support" ]]; then
NEEDED_KARGS="$NEEDED_KARGS --append=amdgpu.cik_support=1"
fi
fi

if [[ $IMAGE_FLAVOR = "nvidia" ]]; then
echo "Checking for needed karg changes (Nvidia)"

if [[ ! $KARGS =~ "rd.driver.blacklist" ]]; then
NEEDED_KARGS="$NEEDED_KARGS --append=rd.driver.blacklist=nouveau"
fi

if [[ ! $KARGS =~ "modprobe.blacklist" ]]; then
NEEDED_KARGS="$NEEDED_KARGS --append=modprobe.blacklist=nouveau"
fi

if [[ ! $KARGS =~ "nvidia-drm.modeset" ]]; then
NEEDED_KARGS="$NEEDED_KARGS --append=nvidia-drm.modeset=1"
fi
else
echo "Checking for needed karg changes"

if [[ $KARGS =~ "rd.driver.blacklist=nouveau" ]]; then
NEEDED_KARGS="$NEEDED_KARGS --delete-if-present=rd.driver.blacklist=nouveau"
fi

if [[ $KARGS =~ "modprobe.blacklist=nouveau" ]]; then
NEEDED_KARGS="$NEEDED_KARGS --delete-if-present=modprobe.blacklist=nouveau"
fi

if [[ $KARGS =~ "nvidia-drm.modeset" ]]; then
NEEDED_KARGS="$NEEDED_KARGS --delete-if-present=nvidia-drm.modeset=1"
fi
if [[ "$IMAGE_FLAVOR" =~ "nvidia" && ! "$KARGS" =~ "initcall_blacklist=simpledrm_platform_driver_init" ]]; then
NEEDED_KARGS="$NEEDED_KARGS --append=initcall_blacklist=simpledrm_platform_driver_init"
fi

if [[ $KARGS =~ "nomodeset" ]]; then
Expand All @@ -84,22 +37,22 @@ fi
if [[ -n "$NEEDED_KARGS" ]]; then
echo "Found needed karg changes, applying the following: $NEEDED_KARGS"
plymouth display-message --text="Updating kargs - Please wait, this may take a while" || true
rpm-ostree kargs ${NEEDED_KARGS} --reboot || exit 1
rpm-ostree kargs "${NEEDED_KARGS}" --reboot || exit 1
else
echo "No karg changes needed"
fi

# Run script if updated
if [[ -f $HWS_VER_FILE && $HWS_VER = $HWS_VER_RAN ]]; then
if [[ -f $KNOWN_IMAGE_NAME_FILE && -f $KNOWN_IMAGE_FLAVOR_FILE ]]; then
if [[ -f "$HWS_VER_FILE" && "$HWS_VER" = "$HWS_VER_RAN" ]]; then
if [[ -f "$KNOWN_IMAGE_NAME_FILE" && -f "$KNOWN_IMAGE_FLAVOR_FILE" ]]; then
# Run script if image has been rebased
if [[ $IMAGE_NAME = $KNOWN_IMAGE_NAME && $IMAGE_FLAVOR = $KNOWN_IMAGE_FLAVOR ]]; then
if [[ "$IMAGE_NAME" = "$KNOWN_IMAGE_NAME" && "$IMAGE_FLAVOR" = "$KNOWN_IMAGE_FLAVOR" ]]; then
echo "Hardware setup has already run. Exiting..."
exit 0
fi
fi
fi

echo $HWS_VER > $HWS_VER_FILE
echo $IMAGE_NAME > $KNOWN_IMAGE_NAME_FILE
echo $IMAGE_FLAVOR > $KNOWN_IMAGE_FLAVOR_FILE
echo "$HWS_VER" > $HWS_VER_FILE
echo "$IMAGE_NAME" > $KNOWN_IMAGE_NAME_FILE
echo "$IMAGE_FLAVOR" > $KNOWN_IMAGE_FLAVOR_FILE
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading