[GH-ISSUE #11] Ubuntu/initramfs-tools: nvidia.ko in the initramfs binds the card before gpu_unlock loads (unlock fails with -EBUSY) #7

Open
opened 2026-10-26 16:39:04 +07:00 by bsakaguchi · 5 comments
Owner

Originally created by @daleaag2020 on GitHub (Oct 23, 2026).
Original GitHub issue: https://github.com/Zagitta/gpu-unlock/issues/11

Environment

  • Ubuntu 22.04.2 LTS, kernel 6.8.0-138-generic (HWE)
  • NVIDIA driver 595.99.02 from Ubuntu packages (nvidia-dkms-595), GA102 RTX 3090 (10de:2204)
  • gpu-unlock 1.0.0, built from source via make deb (gpu-unlock-dkms + gpu-unlock-firmware installed)
  • SecureBoot disabled, cold power-off boot, kernel cmdline gpu_unlock.targets=all

Symptom

After installing and cold-booting, the unlock fails and nvidia binds normally (no unlock):

$ journalctl -k -b | grep gpu_unlock
... kernel: Command line: ... ro gpu_unlock.targets=all
... kernel: NVRM: loading NVIDIA UNIX x86_64 Kernel Module  595.99.02 ...
... kernel: nvidia 0000:01:00.0: gpu_unlock: unlock failed (-16)

(-16 = -EBUSY, from the pdev->driver check in unlock_one().)

Root cause

Ubuntu's nvidia driver packages place nvidia.ko (and GSP firmware) inside the initramfs (usr/lib/modules/<kver>/updates/dkms/nvidia.ko). In initramfs-tools' /init, the execution order is:

run_scripts /scripts/init-top    # starts udevd and runs the coldplug trigger
...
load_modules                     # only here does /conf/modules get modprobed

run_scripts /scripts/init-top runs scripts/init-top/udev, whose coldplug trigger autoplugs the PCI device and loads nvidia immediately. /conf/modules (where /usr/share/initramfs-tools/modules.d/gpu-unlock.conf ends up) is only processed afterwards by load_modules, so gpu_unlock's init runs with the card already bound and correctly refuses with -EBUSY.

The module's own design is fine (async_synchronize_full_domain() before returning guarantees nvidia loads after it when it is loaded first); the problem is purely that on Ubuntu, modules.d entries are loaded after the init-top coldplug. This does not show up when nvidia.ko is not in the initramfs (nothing binds the card until after the root pivot, long after load_modules).

Precise timeline from the failure (journalctl -k -b -o short-precise):

02:56:30.645777 kernel: NVRM: loading NVIDIA UNIX x86_64 Kernel Module ...
02:56:30.646094 kernel: nvidia 0000:01:00.0: gpu_unlock: unlock failed (-16)

The WPR2 "card already initialised" check did not fire (the card was genuinely cold, prior boot ended with a full power-off), and the request_firmware() loads succeeded, so the only problem is the load order.

Workaround that works

An initramfs init-top hook that loads the module before the udev coldplug script; init-top scripts run in filename order, so gpu-unlock sorts before udev:

/etc/initramfs-tools/scripts/init-top/gpu-unlock (0755):

#!/bin/sh
PREREQ=""
prereqs() { echo "$PREREQ"; }
case "$1" in prereqs) prereqs; exit 0;; esac
# Must run ahead of init-top/udev: with nvidia.ko in the initramfs,
# coldplug binds the card before load_modules reaches /conf/modules.
modprobe gpu_unlock 2>/dev/null || true
exit 0

then update-initramfs -u -k all and a full power cycle. The module init blocks until the unlock completes, so nvidia binds afterwards. Verified with the same cold-boot procedure - now logs pci 0000:01:00.0: gpu_unlock: unlocked, and an FP16/BF16 GEMM on this 3090 measures ~120 TFLOPS (stock GA102 tops out around 71).

Suggestion

For the initramfs-tools path, the deb could ship this init-top script (in addition to, or instead of, the modules.d entry) so Ubuntu systems with nvidia.ko in the initramfs work out of the box - or the ordering caveat could be documented in the README. Happy to test any fix on this machine.

Originally created by @daleaag2020 on GitHub (Oct 23, 2026). Original GitHub issue: https://github.com/Zagitta/gpu-unlock/issues/11 ## Environment - Ubuntu 22.04.2 LTS, kernel 6.8.0-138-generic (HWE) - NVIDIA driver 595.99.02 from Ubuntu packages (nvidia-dkms-595), GA102 RTX 3090 (10de:2204) - gpu-unlock 1.0.0, built from source via `make deb` (gpu-unlock-dkms + gpu-unlock-firmware installed) - SecureBoot disabled, cold power-off boot, kernel cmdline `gpu_unlock.targets=all` ## Symptom After installing and cold-booting, the unlock fails and nvidia binds normally (no unlock): $ journalctl -k -b | grep gpu_unlock ... kernel: Command line: ... ro gpu_unlock.targets=all ... kernel: NVRM: loading NVIDIA UNIX x86_64 Kernel Module 595.99.02 ... ... kernel: nvidia 0000:01:00.0: gpu_unlock: unlock failed (-16) (-16 = -EBUSY, from the `pdev->driver` check in `unlock_one()`.) ## Root cause Ubuntu's nvidia driver packages place `nvidia.ko` (and GSP firmware) inside the initramfs (`usr/lib/modules/<kver>/updates/dkms/nvidia.ko`). In initramfs-tools' `/init`, the execution order is: run_scripts /scripts/init-top # starts udevd and runs the coldplug trigger ... load_modules # only here does /conf/modules get modprobed `run_scripts /scripts/init-top` runs `scripts/init-top/udev`, whose coldplug trigger autoplugs the PCI device and loads nvidia immediately. `/conf/modules` (where `/usr/share/initramfs-tools/modules.d/gpu-unlock.conf` ends up) is only processed afterwards by `load_modules`, so gpu_unlock's init runs with the card already bound and correctly refuses with -EBUSY. The module's own design is fine (`async_synchronize_full_domain()` before returning guarantees nvidia loads after it *when it is loaded first*); the problem is purely that on Ubuntu, modules.d entries are loaded *after* the init-top coldplug. This does not show up when nvidia.ko is not in the initramfs (nothing binds the card until after the root pivot, long after `load_modules`). Precise timeline from the failure (`journalctl -k -b -o short-precise`): 02:56:30.645777 kernel: NVRM: loading NVIDIA UNIX x86_64 Kernel Module ... 02:56:30.646094 kernel: nvidia 0000:01:00.0: gpu_unlock: unlock failed (-16) The WPR2 "card already initialised" check did not fire (the card was genuinely cold, prior boot ended with a full power-off), and the `request_firmware()` loads succeeded, so the only problem is the load order. ## Workaround that works An initramfs init-top hook that loads the module before the udev coldplug script; init-top scripts run in filename order, so `gpu-unlock` sorts before `udev`: `/etc/initramfs-tools/scripts/init-top/gpu-unlock` (0755): #!/bin/sh PREREQ="" prereqs() { echo "$PREREQ"; } case "$1" in prereqs) prereqs; exit 0;; esac # Must run ahead of init-top/udev: with nvidia.ko in the initramfs, # coldplug binds the card before load_modules reaches /conf/modules. modprobe gpu_unlock 2>/dev/null || true exit 0 then `update-initramfs -u -k all` and a full power cycle. The module init blocks until the unlock completes, so nvidia binds afterwards. Verified with the same cold-boot procedure - now logs `pci 0000:01:00.0: gpu_unlock: unlocked`, and an FP16/BF16 GEMM on this 3090 measures ~120 TFLOPS (stock GA102 tops out around 71). ## Suggestion For the initramfs-tools path, the deb could ship this init-top script (in addition to, or instead of, the modules.d entry) so Ubuntu systems with nvidia.ko in the initramfs work out of the box - or the ordering caveat could be documented in the README. Happy to test any fix on this machine.
Author
Owner

@yeungyim commented on GitHub (Oct 23, 2026):

A different failure shape on Ubuntu 26.04, plus a workaround that works there. Not the same root cause as this report (no -EBUSY here — nvidia is not in the initramfs at all on this host).

Environment

  • Ubuntu 26.04 LTS, kernel 7.0.0-38-generic, NVIDIA 595.91.07 (open module, Ubuntu packages), 2x GA102 RTX 3090 (0000:01:00.0, 0000:02:00.0)
  • gpu-unlock 1.0.0 via make install -> both gpu-unlock-dkms and gpu-unlock-firmware at ii
  • SecureBoot as shipped, cold power-off boot, gpu_unlock.targets=0000:01:00.0,0000:02:00.0

Symptom: the module is never placed, so nothing runs

The install itself is fine:

/lib/modules/7.0.0-38-generic/updates/dkms/gpu_unlock.ko.zst   present
modinfo gpu_unlock                                              -> version 1.0.0
/usr/share/initramfs-tools/modules.d/gpu-unlock.conf            -> contains "gpu_unlock"

sudo update-initramfs -u -k all regenerates both images, but:

$ sudo lsinitramfs /boot/initrd.img-$(uname -r) | grep -i gpu_unlock
(empty)

$ sudo lsinitramfs /boot/initrd.img-$(uname -r) | grep -c '\.ko'
0

This initramfs carries no kernel modules at all — it is a host-only image, and nvidia is not in it either (udev loads it from the root filesystem after the switch). So there is nothing for either modules.d/gpu-unlock.conf or an added line in /etc/initramfs-tools/modules to attach to: the module cannot be placed before the driver because it cannot be placed in the initramfs at all.

After a cold boot, dmesg | grep gpu_unlock shows only the kernel command line and nothing from the module — it never executed. Measured on Strata (IQ3_S, --resident-experts, 2x3090, 250 W), prefill over 4 runs: 2432.7 before, 2428.3 / 2419.3 across two attempts — no change, as expected if the unlock never happened.

Workaround that works here: softdep nvidia pre:

Since nvidia is not in the initramfs on this host, it only has to load after gpu_unlock at normal boot, and kmod can do that:

cd gpu-unlock && sudo make install
# targets still come from the kernel command line
sudo sed -i 's|^GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"|GRUB_CMDLINE_LINUX_DEFAULT="quiet splash gpu_unlock.targets=0000:01:00.0,0000:02:00.0"|' /etc/default/grub
sudo update-grub
echo "softdep nvidia pre: gpu_unlock" | sudo tee /etc/modprobe.d/gpu-unlock.conf
modprobe -n -v gpu_unlock     # resolves to the .ko.zst
sudo poweroff

After the cold boot: lsmod | grep gpu_unlock -> loaded (no holders), both cards present in nvidia-smi, and the module ran.

Measured effect on Strata (Qwen3.8-Flash-Next IQ3_S, --resident-experts, 2x3090 at 250 W, 32K cold prompt), 8 runs after vs 4 before:

before after
prefill 2403–2447 (median 2432.7) 2549–2586 (median ~2563), +5.4%
TTFT 13.49 s 12.81 s, -5.0%
decode ~137 ~139, unchanged

The two ranges do not overlap (the after-run minimum is above the before-run maximum), and two independent measurements of four runs each agree.

That is +5.4% rather than the +13-16% reported for UD-Q4_K_XL, which I would guess is the quant's different prompt kernel path plus the lower GPU share in a resident-experts split, but I have not separated those.

Why this may be worth a doc line

The README only describes the initramfs route. Where the initramfs is host-only (no .ko at all), that route cannot work no matter what goes in modules.d or /etc/initramfs-tools/modules, and the failure is silent: the package installs cleanly, update-initramfs succeeds, and the module simply never runs. Checking lsinitramfs ... | grep -c '\.ko' first tells you which route applies.

<!-- gh-comment-id:6358088102 --> @yeungyim commented on GitHub (Oct 23, 2026): A different failure shape on Ubuntu 26.04, plus a workaround that works there. Not the same root cause as this report (no `-EBUSY` here — `nvidia` is not in the initramfs at all on this host). ## Environment - Ubuntu 26.04 LTS, kernel `7.0.0-38-generic`, NVIDIA 595.91.07 (open module, Ubuntu packages), 2x GA102 RTX 3090 (`0000:01:00.0`, `0000:02:00.0`) - gpu-unlock 1.0.0 via `make install` -> both `gpu-unlock-dkms` and `gpu-unlock-firmware` at `ii` - SecureBoot as shipped, cold power-off boot, `gpu_unlock.targets=0000:01:00.0,0000:02:00.0` ## Symptom: the module is never placed, so nothing runs The install itself is fine: ``` /lib/modules/7.0.0-38-generic/updates/dkms/gpu_unlock.ko.zst present modinfo gpu_unlock -> version 1.0.0 /usr/share/initramfs-tools/modules.d/gpu-unlock.conf -> contains "gpu_unlock" ``` `sudo update-initramfs -u -k all` regenerates both images, but: ``` $ sudo lsinitramfs /boot/initrd.img-$(uname -r) | grep -i gpu_unlock (empty) $ sudo lsinitramfs /boot/initrd.img-$(uname -r) | grep -c '\.ko' 0 ``` **This initramfs carries no kernel modules at all** — it is a host-only image, and `nvidia` is not in it either (udev loads it from the root filesystem after the switch). So there is nothing for either `modules.d/gpu-unlock.conf` or an added line in `/etc/initramfs-tools/modules` to attach to: the module cannot be placed before the driver because it cannot be placed in the initramfs at all. After a cold boot, `dmesg | grep gpu_unlock` shows only the kernel command line and nothing from the module — it never executed. Measured on Strata (IQ3_S, `--resident-experts`, 2x3090, 250 W), prefill over 4 runs: 2432.7 before, 2428.3 / 2419.3 across two attempts — no change, as expected if the unlock never happened. ## Workaround that works here: `softdep nvidia pre:` Since `nvidia` is not in the initramfs on this host, it only has to load *after* `gpu_unlock` at normal boot, and kmod can do that: ```sh cd gpu-unlock && sudo make install # targets still come from the kernel command line sudo sed -i 's|^GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"|GRUB_CMDLINE_LINUX_DEFAULT="quiet splash gpu_unlock.targets=0000:01:00.0,0000:02:00.0"|' /etc/default/grub sudo update-grub echo "softdep nvidia pre: gpu_unlock" | sudo tee /etc/modprobe.d/gpu-unlock.conf modprobe -n -v gpu_unlock # resolves to the .ko.zst sudo poweroff ``` After the cold boot: `lsmod | grep gpu_unlock` -> loaded (no holders), both cards present in `nvidia-smi`, and the module ran. Measured effect on Strata (Qwen3.8-Flash-Next IQ3_S, `--resident-experts`, 2x3090 at 250 W, 32K cold prompt), 8 runs after vs 4 before: | | before | after | |---|---:|---:| | prefill | 2403–2447 (median 2432.7) | **2549–2586 (median ~2563)**, **+5.4%** | | TTFT | 13.49 s | **12.81 s**, **-5.0%** | | decode | ~137 | ~139, unchanged | The two ranges do not overlap (the after-run minimum is above the before-run maximum), and two independent measurements of four runs each agree. That is +5.4% rather than the +13-16% reported for UD-Q4_K_XL, which I would guess is the quant's different prompt kernel path plus the lower GPU share in a resident-experts split, but I have not separated those. ## Why this may be worth a doc line The README only describes the initramfs route. Where the initramfs is host-only (no `.ko` at all), that route cannot work no matter what goes in `modules.d` or `/etc/initramfs-tools/modules`, and the failure is silent: the package installs cleanly, `update-initramfs` succeeds, and the module simply never runs. Checking `lsinitramfs ... | grep -c '\.ko'` first tells you which route applies.
Author
Owner

@Zagitta commented on GitHub (Oct 23, 2026):

Hey guys, thanks for the reports and suggestions.

Could you please try out https://github.com/Zagitta/gpu-unlock/tree/fix-ubuntu-load-order and see if that works for you?

<!-- gh-comment-id:6363263660 --> @Zagitta commented on GitHub (Oct 23, 2026): Hey guys, thanks for the reports and suggestions. Could you please try out https://github.com/Zagitta/gpu-unlock/tree/fix-ubuntu-load-order and see if that works for you?
Author
Owner

@Gazoo commented on GitHub (Oct 23, 2026):

3. Hey guys, thanks for the reports and suggestions.
Could you please try out https://github.com/Zagitta/gpu-unlock/tree/fix-ubuntu-load-order and see if that works for you?

@Zagitta That branch fixed it for me on Ubuntu 26.04. Thanks!

<!-- gh-comment-id:6364611388 --> @Gazoo commented on GitHub (Oct 23, 2026): > 3\. Hey guys, thanks for the reports and suggestions. > Could you please try out https://github.com/Zagitta/gpu-unlock/tree/fix-ubuntu-load-order and see if that works for you? @Zagitta That branch fixed it for me on Ubuntu 26.04. Thanks!
Author
Owner

@isenlink commented on GitHub (Oct 24, 2026):

Same kernel here (7.0.0-38-generic, single RTX 3090, driver 615.71.09) — can confirm the host-only initramfs trap and how we routed around it:

  • Our initramfs is the full Ubuntu image (926 .ko), and nvidia.ko is not in it (only unrelated modules like hid-nvidia-shield/forcedeth). nvidia loads via udev from the rootfs after boot, so gpu_unlock from the initramfs always binds first — the standard dkms+initramfs install just works, no softdep workaround needed in this configuration.
  • Quick pre-flight check: lsinitramfs /boot/initrd.img-$(uname -r) | grep -c '\.ko' (and grep for nvidia specifically). If your initramfs is truly host-only/empty, the softdep workaround stays the right call.
  • Result here: unlock at t≈7.4 s every cold boot, vLLM prefill +33 %, 8 h+ stable. Full numbers in the new compatibility-report issue.
<!-- gh-comment-id:6378512844 --> @isenlink commented on GitHub (Oct 24, 2026): Same kernel here (7.0.0-38-generic, single RTX 3090, driver 615.71.09) — can confirm the host-only initramfs trap and how we routed around it: - Our initramfs is the **full** Ubuntu image (926 .ko), and `nvidia.ko` is **not** in it (only unrelated modules like hid-nvidia-shield/forcedeth). nvidia loads via udev from the rootfs after boot, so gpu_unlock from the initramfs always binds first — the standard dkms+initramfs install just works, no softdep workaround needed in this configuration. - Quick pre-flight check: `lsinitramfs /boot/initrd.img-$(uname -r) | grep -c '\.ko'` (and grep for nvidia specifically). If your initramfs is truly host-only/empty, the softdep workaround stays the right call. - Result here: unlock at t≈7.4 s every cold boot, vLLM prefill +33 %, 8 h+ stable. Full numbers in the new compatibility-report issue.
Author
Owner

@galvani commented on GitHub (Oct 25, 2026):

Another data point for the case where nvidia.ko IS in the initramfs, on Ubuntu 26.04.1 / 7.0.0-38 / 580.178.04 open, single RTX 3090. (I have not tried the fix-ubuntu-load-order branch; this is on main af28cbb.)

  • nvidia.ko is pulled into the image by the framebuffer-nvidia initramfs hook from nvidia-kernel-common-580 (it comes with nvidia-drm.fbdev=1), so I hit the original unlock failed (-16).
  • Listing gpu_unlock in /etc/initramfs-tools/modules (above any nvidia line) did not help. As described above, /conf/modules is processed after the init-top udev coldplug.
  • softdep nvidia pre: gpu_unlock in /etc/modprobe.d/gpu-unlock.conf was enough on its own, with no init-top script needed. initramfs-tools copies /etc/modprobe.d into the image, so the softdep also applies when udev autoloads nvidia inside the initramfs:
$ lsinitramfs /boot/initrd.img-$(uname -r) | grep -E 'nvidia\.ko|gpu_unlock|modprobe.d/gpu-unlock'
usr/lib/modules/7.0.0-38-generic/updates/dkms/gpu_unlock.ko.zst
usr/lib/modules/7.0.0-38-generic/updates/dkms/nvidia.ko.zst
etc/modprobe.d/gpu-unlock.conf

$ journalctl -k -b -o short-precise | grep -E 'gpu_unlock: unlocked|NVRM: loading'
12:27:28.513165 kernel: pci 0000:01:00.0: gpu_unlock: unlocked
12:27:28.516614 kernel: NVRM: loading NVIDIA UNIX Open Kernel Module for x86_64  580.178.04

The steps were update-initramfs -u -k all and a cold power cycle.

I know the README rules out shipping a softdep (kmod honours only the first softdep nvidia line), so this is only a local workaround for the case where nothing else declares softdep nvidia; the init-top script on fix-ubuntu-load-order looks like the right fix. Full numbers in #107.

(Diagnosis and write-up done with an AI assistant, Claude Code; the box and the boot tests are mine.)

<!-- gh-comment-id:6397649558 --> @galvani commented on GitHub (Oct 25, 2026): Another data point for the case where `nvidia.ko` IS in the initramfs, on Ubuntu 26.04.1 / 7.0.0-38 / 580.178.04 open, single RTX 3090. (I have not tried the `fix-ubuntu-load-order` branch; this is on main af28cbb.) - `nvidia.ko` is pulled into the image by the `framebuffer-nvidia` initramfs hook from `nvidia-kernel-common-580` (it comes with `nvidia-drm.fbdev=1`), so I hit the original `unlock failed (-16)`. - Listing `gpu_unlock` in `/etc/initramfs-tools/modules` (above any nvidia line) did not help. As described above, `/conf/modules` is processed after the init-top udev coldplug. - `softdep nvidia pre: gpu_unlock` in `/etc/modprobe.d/gpu-unlock.conf` was enough on its own, with no init-top script needed. initramfs-tools copies `/etc/modprobe.d` into the image, so the softdep also applies when udev autoloads nvidia inside the initramfs: ``` $ lsinitramfs /boot/initrd.img-$(uname -r) | grep -E 'nvidia\.ko|gpu_unlock|modprobe.d/gpu-unlock' usr/lib/modules/7.0.0-38-generic/updates/dkms/gpu_unlock.ko.zst usr/lib/modules/7.0.0-38-generic/updates/dkms/nvidia.ko.zst etc/modprobe.d/gpu-unlock.conf $ journalctl -k -b -o short-precise | grep -E 'gpu_unlock: unlocked|NVRM: loading' 12:27:28.513165 kernel: pci 0000:01:00.0: gpu_unlock: unlocked 12:27:28.516614 kernel: NVRM: loading NVIDIA UNIX Open Kernel Module for x86_64 580.178.04 ``` The steps were `update-initramfs -u -k all` and a cold power cycle. I know the README rules out shipping a softdep (kmod honours only the first `softdep nvidia` line), so this is only a local workaround for the case where nothing else declares `softdep nvidia`; the init-top script on `fix-ubuntu-load-order` looks like the right fix. Full numbers in #107. (Diagnosis and write-up done with an AI assistant, Claude Code; the box and the boot tests are mine.)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Zagitta/gpu-unlock#7
No description provided.