Skip to content

Instantly share code, notes, and snippets.

@maur5
Created November 22, 2024 22:53
Show Gist options
  • Select an option

  • Save maur5/f2278472cdf06067d9d360bc5e6df365 to your computer and use it in GitHub Desktop.

Select an option

Save maur5/f2278472cdf06067d9d360bc5e6df365 to your computer and use it in GitHub Desktop.
Ubuntu Noble (6.8.0-48) on Proxmox 8.2.7 (6.8.12-4-pve) cloud-init i915-sriov-dkms
#!/usr/bin/bash
set -e
# References
# https://gist.github.com/scyto/e4e3de35ee23fdb4ae5d5a3b85c16ed3?permalink_comment_id=5266674#gistcomment-5266674
# https://github.com/UntouchedWagons/Ubuntu-CloudInit-Docs
# https://github.com/bbaa-bbaa/i915-sriov-dkms
# note to self: proxmox needs tools to inject things apt install --no-install-recommends --no-install-suggests guestfs-tools
# current as of now - this can probably be automated based on the image version - maybe deal with it when it's time to update
KERNEL_VERSION=6.8.0-48
KERNEL_RELEASE=${KERNEL_VERSION}-generic
VMID=8001
# Define these....
# ADMIN_USER=
# ADMIN_PASS=
# ADMIN_KEY=
# Download current Ubuntu cloud image
if [ ! -f ./noble-server-cloudimg-amd64.img ]; then
curl -OL https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img
qemu-img resize noble-server-cloudimg-amd64.img 32G
fi
# Download current i915 firmware
if [ ! -f ./i915-firmware.tar.gz ]; then
mkdir -p ./firmware/i915
wget -P ./firmware/i915 --random-wait -w 0.2 -r -nd -e robots=no -A '*.bin' --accept-regex '/plain/' https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/tree/i915/
tar -zcvf i915-firmware.tar.gz firmware
rm -rf firmware
fi
# Inject i915 firmware into ubuntu image
if [ ! -f ./noble-server-cloudimg-amd64-i915-firmware.img ]; then
cp noble-server-cloudimg-amd64.img noble-server-cloudimg-amd64-i915-firmware.img
zcat i915-firmware.tar.gz | virt-tar-in -a noble-server-cloudimg-amd64-i915-firmware.img - /lib
fi
# Clear out the old userscript
rm /var/lib/vz/snippets/ubuntu-noble-guc.yaml
# Add a new one
cat << EOF | tee /var/lib/vz/snippets/ubuntu-noble-guc.yaml
#cloud-config
runcmd:
- set -xe # Die when you fail and output commands for debugging
# Some mention of update/upgrade being required here in a FAQ somewhere. not sure if needed - it works without for me
# - apt update
# - apt upgrade -y
- apt install -y qemu-guest-agent
- systemctl start qemu-guest-agent
- apt install -y linux-headers-${KERNEL_RELEASE} linux-headers-${KERNEL_VERSION} linux-image-${KERNEL_RELEASE} linux-modules-${KERNEL_RELEASE} linux-tools-${KERNEL_RELEASE} linux-modules-extra-${KERNEL_RELEASE}
- apt-mark hold linux-headers-${KERNEL_RELEASE} linux-headers-${KERNEL_VERSION} linux-image-${KERNEL_RELEASE} linux-modules-${KERNEL_RELEASE} linux-tools-${KERNEL_RELEASE} linux-modules-extra-${KERNEL_RELEASE}
- echo "options i915 enable_guc=3" | tee -a /etc/modprobe.d/i915.conf
- apt install build-* dkms -y
# This fork has some fixes for alder lake that i need (these drivers may be more current than the parent repo)
- git clone https://github.com/bbaa-bbaa/i915-sriov-dkms.git
- dkms add ./i915-sriov-dkms
- GUCFIRMWARE_MINOR=13 dkms install -m i915-sriov-dkms -v \$(cat i915-sriov-dkms/VERSION) -k ${KERNEL_RELEASE} --force --kernelsourcedir /usr/src/linux-headers-${KERNEL_RELEASE}
- update-initramfs -u -k all
# reboot/shutdown was killing the script before it finished resulting in a supurfluous exception
# - reboot
- (sleep 5 && shutdown now) &
EOF
echo $ADMIN_KEY > ./admin-key.pub
qm create ${VMID} --name "ubuntu-noble-guc" --ostype l26 \
--memory 2048 \
--agent 1 \
--bios ovmf \
--efidisk0 local-zfs:0,pre-enrolled-keys=0 \
--machine q35,viommu=intel \
--cpu host,numa=1 --socket 1 --cores 2 \
--vga serial0 --serial0 socket \
--net0 virtio,bridge=vmbr0,queues=8
qm importdisk ${VMID} noble-server-cloudimg-amd64-i915-firmware.img local-zfs
qm set ${VMID} --scsihw virtio-scsi-single --scsi0 local-zfs:vm-${VMID}-disk-1,discard=on,iothread=1,ssd=1
qm set ${VMID} --boot order=scsi0
# qm set ${VMID} --scsi1 local-zfs:cloudinit
qm set ${VMID} --ide0 local-zfs:cloudinit
qm set ${VMID} --cicustom "vendor=local:snippets/ubuntu-noble-guc.yaml"
qm set ${VMID} --tags ubuntu,noble,intel-guc,cloudinit
qm set ${VMID} --ciuser $ADMIN_USER
qm set ${VMID} --cipassword $ADMIN_PASS
qm set ${VMID} --sshkeys ./admin-key.pub
qm set ${VMID} --ipconfig0 ip=dhcp
qm set ${VMID} --hostpci0 mapping=i915-sriov-dkms,pcie=1
# Give it a kick to compile the module - the userscript will shut down when done
qm start ${VMID}
# qm template ${VMID}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment