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 rebuilding with support for user defined initramfs args #586

Merged
merged 7 commits into from
Nov 27, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Anything commented out with # on a new line will be ignored
# These files follow the "rpm-ostree initramfs" syntax, please consult
# "rpm-ostree initramfs --help" for more information
#
# You can do 1 initramfs argument per line or do them all in 1 line.
# If you need to just add drivers to dracut, you should instead just add
# config files for dracut into /etc/dracut.conf.d/ and trigger an initramfs
# rebuild using "sudo touch /etc/bazzite/initramfs/rebuild" which
# will rebuild the initramfs on next boot using bazzite-hardware-setup.
#
# Multiline Example:
#--arg="--add-drivers"
#--arg="vfio vfio_iommu_type1 vfio-pci"
#
# Single Line Example:
#--arg="--add-drivers" --arg="vfio vfio_iommu_type1 vfio-pci
56 changes: 46 additions & 10 deletions system_files/desktop/shared/usr/bin/bazzite-hardware-setup
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ BASE_IMAGE_NAME=$(jq -r '."base-image-name"' < $IMAGE_INFO)
FEDORA_VERSION=$(jq -r '."fedora-version"' < $IMAGE_INFO)

# SCRIPT VERSION
HWS_VER=15
HWS_VER=16
HWS_VER_FILE="/etc/bazzite/hws_version"
HWS_VER_RAN=$(cat $HWS_VER_FILE)

Expand All @@ -19,17 +19,42 @@ KNOWN_IMAGE_FLAVOR=$(cat $KNOWN_IMAGE_FLAVOR_FILE)
KNOWN_FEDORA_VERSION_FILE="/etc/bazzite/fedora_version"
KNOWN_FEDORA_VERSION=$(cat $KNOWN_FEDORA_VERSION_FILE)

# RUN REMAINDER OF SCRIPT ONLY 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 $KNOWN_FEDORA_VERSION_FILE && -f $KNOWN_FEDORA_VERSION_FILE ]]; then
# Run script if image has been rebased
if [[ $IMAGE_NAME = $KNOWN_IMAGE_NAME && $IMAGE_FLAVOR = $KNOWN_IMAGE_FLAVOR && $FEDORA_VERSION = $KNOWN_FEDORA_VERSION ]]; then
echo "Hardware setup has already run. Exiting..."
exit 0
# INITRAMFS CONFIG
INITRAMFS_DIR="/etc/bazzite/initramfs"
INITRAMFS_REBUILD_TRIGGER="$INITRAMFS_DIR/rebuild"
INITRAMFS_BAZZITE_ARG_FILE="$INITRAMFS_DIR/hardware-setup.args"
INITRAMFS_BAZZITE_ARGS=$(cat $INITRAMFS_BAZZITE_ARG_FILE)
INITRAMFS_CUSTOM_ARGS_DIR="$INITRAMFS_DIR/args.d"
INITRAMFS_CUSTOM_ARGS=""

# If the /etc/bazzite/initramfs/args.d dir exists
if [[ -d "$INITRAMFS_CUSTOM_ARGS_DIR" ]]; then
# Grab all the content of the files (minus comments) and join them together with spaces
INITRAMFS_CUSTOM_ARGS=$(grep -RvP "^(#|$)" $INITRAMFS_CUSTOM_ARGS_DIR/ | sort | perl -pe 's/(^$INITRAMFS_CUSTOM_ARGS_DIR\/.+:|\\\n$)//g' | tr '\n' ' ')
fi

# If no rebuild is requested
if [[ ! -f $INITRAMFS_REBUILD_TRIGGER ]]; then
# RUN REMAINDER OF SCRIPT ONLY 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 $KNOWN_FEDORA_VERSION_FILE && -f $KNOWN_FEDORA_VERSION_FILE ]]; then
# Run script if image has been rebased
if [[ $IMAGE_NAME = $KNOWN_IMAGE_NAME && $IMAGE_FLAVOR = $KNOWN_IMAGE_FLAVOR && $FEDORA_VERSION = $KNOWN_FEDORA_VERSION ]]; then
echo "Hardware setup has already run. Exiting..."
exit 0
fi
fi
fi
fi
else
# REMOVE REBUILD TRIGGER TO AVOID INFINITE BOOT LOOP!
rm $INITRAMFS_REBUILD_TRIGGER
# Rebuild current initramfs (this will add any new configs added to /etc/dracut.conf.d/) then reboot
echo "Initramfs rebuild triggered, using: $INITRAMFS_BAZZITE_ARGS $INITRAMFS_CUSTOM_ARGS"
plymouth display-message --text="Updating initramfs - Please wait, this may take a while" || true
rpm-ostree initramfs --enable "$INITRAMFS_BAZZITE_ARGS" "$INITRAMFS_CUSTOM_ARGS" --reboot
exit 0
fi

# GLOBAL
Expand Down Expand Up @@ -62,10 +87,21 @@ for INITRAMFS_ARG in ${NEEDED_INITRAMFS[@]}; do
fi
done

# If there is nothing in INITRAMFS_BAZZITE_ARGS
if [[ ! $INITRAMFS_BAZZITE_ARGS ]]; then
# Make sure we will have /etc/bazzite/initramfs/bazzite.args for the future
mkdir -p /etc/bazzite/initramfs/args.d
echo "--arg=\"-I ${NEEDED_INITRAMFS[*]}\"" > $INITRAMFS_BAZZITE_ARG_FILE
INITRAMFS_BAZZITE_ARGS=$(cat $INITRAMFS_BAZZITE_ARG_FILE)
fi

if $NEEDS_INITRAMFS_APPLICATION; then
echo "Found needed initramfs changes, applying the following: ${NEEDED_INITRAMFS[*]}"
echo "--arg=\"-I ${NEEDED_INITRAMFS[*]}\"" > $INITRAMFS_BAZZITE_ARG_FILE
INITRAMFS_BAZZITE_ARGS=$(cat $INITRAMFS_BAZZITE_ARG_FILE)
echo "Building initramfs with following custom args: $INITRAMFS_CUSTOM_ARGS"
plymouth display-message --text="Updating initramfs - Please wait, this may take a while" || true
rpm-ostree initramfs --enable --arg="-I ${NEEDED_INITRAMFS[*]}"
rpm-ostree initramfs --enable "$INITRAMFS_BAZZITE_ARGS" "$INITRAMFS_CUSTOM_ARGS"
else
echo "No initramfs changes needed"
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,8 @@ enable-vfio:
CPU_VENDOR=$(grep "vendor_id" "/proc/cpuinfo" | uniq | awk -F": " '{ print $2 }')
VENDOR_KARG="unset"
if [[ ${VIRT_TEST} == *kvm.report_ignored_msrs* ]]; then
rpm-ostree initramfs \
--enable \
--arg="--add-drivers" \
--arg="vfio vfio_iommu_type1 vfio-pci"
echo 'add_drivers+=" vfio vfio_iommu_type1 vfio-pci "' | sudo tee /etc/dracut.conf.d/vfio.conf
sudo touch /etc/bazzite/initramfs/rebuild
if [[ ${CPU_VENDOR} == "AuthenticAMD" ]]; then
VENDOR_KARG="amd_iommu=on"
elif [[ ${CPU_VENDOR} == "GenuineIntel" ]]; then
Expand All @@ -266,7 +264,7 @@ enable-vfio:
--append-if-missing="iommu=pt" \
--append-if-missing="rd.driver.pre=vfio_pci" \
--append-if-missing="vfio_pci.disable_vga=1"
echo "VFIO enabled, make sure you enable IOMMU, VT-d or AMD-v in your BIOS!"
echo "VFIO will be enabled on next boot, make sure you enable IOMMU, VT-d or AMD-v in your BIOS!"
echo "Please understand that since this is such a niche use case, support will be very limited!"
echo "To add your unused/second GPU device ids to the vfio driver by running"
echo 'rpm-ostree kargs --append-if-missing="vfio-pci.ids=xxxx:yyyy,xxxx:yyzz"'
Expand Down
Loading