From: Hannes Duerr <h.duerr@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-nvidia-vgpu-helper v5 3/4] add pve-nvidia-vgpu-helper and Makefile to make dependency installation more convenient
Date: Thu, 13 Feb 2025 09:15:14 +0100 [thread overview]
Message-ID: <20250213081516.16266-4-h.duerr@proxmox.com> (raw)
In-Reply-To: <20250213081516.16266-1-h.duerr@proxmox.com>
We add the pve-nvidia-vgpu-helper script to simplify the installation of
the required Nvidia Vgpu driver dependencies.
The script performs the following tasks
- install consistent dependencies
- check the currently running kernel and install the necessary kernel
headers for the running kernel and any newer kernels installed
- blacklist the competing nouveau driver and add the opt-out flag
--no-blacklist
We also add a Makefile to help build the Debian package and install the
script
Signed-off-by: Hannes Duerr <h.duerr@proxmox.com>
---
Notes:
Changes in V5:
* Add syslog Message that mentions nouveau blacklist
Changes in V4:
* add `--help` option displaying the usage
* as suggested by @Dominik we squash the patch, to only install headers
for running kernel version and newer ones, into this one
* install `proxmox-headers-$major.$minor-pve` package so that the
headers for future updates are also installed directly
* blacklist the nouveau driver by default and add opt-out flag
`--no-blacklist`
Makefile | 54 +++++++++++++++++++++++
pve-nvidia-vgpu-helper | 99 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 153 insertions(+)
create mode 100644 Makefile
create mode 100755 pve-nvidia-vgpu-helper
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..c6e461d
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,54 @@
+include /usr/share/dpkg/default.mk
+
+PACKAGE=pve-nvidia-vgpu-helper
+
+BINDIR=/usr/bin/
+DESTDIR=
+
+GITVERSION:=$(shell git rev-parse HEAD)
+
+BUILDDIR ?= $(PACKAGE)-$(DEB_VERSION)
+DSC=$(PACKAGE)_$(DEB_VERSION).dsc
+
+DEB=$(PACKAGE)_$(DEB_VERSION_UPSTREAM_REVISION)_all.deb
+
+all:
+deb: $(DEB)
+
+$(BUILDDIR): debian
+ rm -rf $@ $@.tmp
+ rsync -a * $@.tmp/
+ echo "git clone git://git.proxmox.com/git/pve-nvidia-vgpu-helper.git\\ngit checkout $(GITVERSION)" > $@.tmp/debian/SOURCE
+ mv $@.tmp $@
+
+$(DEB): $(BUILDDIR)
+ cd $(BUILDDIR); dpkg-buildpackage -b -uc -us
+ lintian $(DEB)
+
+dsc: $(DSC)
+ $(MAKE) clean
+ $(MAKE) $(DSC)
+ lintian $(DSC)
+
+$(DSC): $(BUILDDIR)
+ cd $(BUILDDIR); dpkg-buildpackage -S -uc -us
+
+sbuild: $(DSC)
+ sbuild $(DSC)
+
+.PHONY: install
+install: pve-nvidia-vgpu-helper
+ install -d $(DESTDIR)$(BINDIR)
+ install -m 0755 pve-nvidia-vgpu-helper $(DESTDIR)$(BINDIR)
+
+.PHONY: upload
+upload: UPLOAD_DIST ?= $(DEB_DISTRIBUTION)
+upload: $(DEB)
+ tar cf - $(DEB)|ssh repoman@repo.proxmox.com -- upload --product pve --dist $(UPLOAD_DIST)
+
+.PHONY: distclean
+distclean: clean
+
+.PHONY: clean
+clean:
+ rm -rf *~ $(PACKAGE)-[0-9]*/ $(PACKAGE)*.tar.* *.deb *.dsc *.changes *.build *.buildinfo
diff --git a/pve-nvidia-vgpu-helper b/pve-nvidia-vgpu-helper
new file mode 100755
index 0000000..c162de9
--- /dev/null
+++ b/pve-nvidia-vgpu-helper
@@ -0,0 +1,99 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use PVE::Tools qw(run_command);
+use PVE::SysFSTools;
+use PVE::SafeSyslog;
+
+use AptPkg::Cache;
+use Dpkg::Version;
+use Getopt::Long;
+
+my @apt_install = qw(apt-get --no-install-recommends install --);
+my @dependencies = qw(dkms libc6-dev proxmox-default-headers);
+my @missing_packages;
+
+die "Please execute the script with root privileges\n" if $>;
+
+my $apt_cache = AptPkg::Cache->new();
+die "unable to initialize AptPkg::Cache\n" if !$apt_cache;
+
+GetOptions('no-blacklist' => \my $no_blacklist, 'help' => \my $help);
+
+if (defined($help)) {
+ print("USAGE:\tpve-nvidia-vgpu-helper [OPTIONS]\n");
+ print("\t --help\n");
+ print("\t --no-blacklist\n");
+ exit;
+}
+
+if (!defined($no_blacklist) && !-e "/etc/modprobe.d/block-nouveau.conf") {
+ run_command(["mkdir", "-p", "/etc/modprobe.d/"]);
+ PVE::SysFSTools::file_write( "/etc/modprobe.d/block-nouveau.conf",
+ "blacklist nouveau" )
+ || die "Could not create block-nouveau.conf";
+ syslog('info', "Blacklist nouveau driver");
+
+ run_command(["update-initramfs", "-u", "-k", "all"]);
+}
+
+sub package_is_installed {
+ my ($package) = @_;
+ my $p = $apt_cache->{$package};
+ if (!defined($p->{CurrentState}) || $p->{CurrentState} ne "Installed") {
+ push(@missing_packages, $package);
+ }
+}
+
+sub install_newer_headers {
+ my (%installed_versions) = @_;
+ for my $version (keys(%installed_versions)) {
+ # install header for the running kernel and newer kernel versions
+ package_is_installed("proxmox-headers-$version");
+ }
+}
+
+foreach my $dependency (@dependencies) {
+ package_is_installed($dependency);
+}
+
+
+my $running_kernel;
+run_command( ['/usr/bin/uname', '-r' ],
+ outfunc => sub { $running_kernel = shift } );
+
+if ($running_kernel =~ m/^(\d+\.\d+\.\d+-\d+)-pve$/) {
+ print "You are running the proxmox kernel `proxmox-kernel-$running_kernel`\n";
+ $running_kernel = $1;
+} else {
+ die "You are not using a proxmox-kernel, please make sure that the appropriate header package is installed.\n";
+}
+
+my %installed_versions;
+run_command(['/usr/bin/dpkg-query', '-W', 'proxmox-kernel-*-pve'],
+ outfunc => sub {
+ my $installed_kernel = shift;
+ $installed_kernel =~ m/^\s*proxmox-kernel-(\d+.\d+)(.\d+-\d+)-pve\s*$/;
+ if (Dpkg::Version::version_compare("$running_kernel", "$1$2") != 1){
+ $installed_versions{$1} = 1;
+ }
+ });
+
+install_newer_headers(%installed_versions);
+
+if (!@missing_packages){
+ print "All required packages are installed, you can continue with the Nvidia vGPU driver installation.\n";
+ exit;
+} else {
+ print "The following packages are missing:\n" . join("\n", @missing_packages) ."\n";
+ print "Would you like to install them now (y/n)?\n";
+}
+
+my $answer = <STDIN>;
+if (defined($answer) && $answer =~ m/^\s*y(?:es)?\s*$/i) {
+ if (system(@apt_install, @missing_packages) != 0) {
+ die "apt failed during the installation: ($?)\n";
+ }
+}
--
2.39.5
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev parent reply other threads:[~2025-02-13 8:16 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-13 8:15 [pve-devel] [PATCH manager/nvidia-vgpu-helper v5 0/5] reduce setup steps for nvidia vgpu drivers Hannes Duerr
2025-02-13 8:15 ` [pve-devel] [PATCH pve-nvidia-vgpu-helper v5 1/4] create a debian package to make the installation of Nvidia vGPU drivers more convenient Hannes Duerr
2025-02-13 8:15 ` [pve-devel] [PATCH pve-nvidia-vgpu-helper v5 2/4] debian/control: add dependency for helper script Hannes Duerr
2025-02-13 8:15 ` Hannes Duerr [this message]
2025-02-13 8:15 ` [pve-devel] [PATCH pve-nvidia-vgpu-helper v5 4/4] debian: add and install pve-nvidia-sriov systemd template unit file Hannes Duerr
2025-02-13 8:15 ` [pve-devel] [PATCH pve-manager v5 1/1] debian/control: add pve-nvidia-vgpu-helper as dependency Hannes Duerr
2025-02-18 13:50 ` [pve-devel] applied-series: [PATCH manager/nvidia-vgpu-helper v5 0/5] reduce setup steps for nvidia vgpu drivers Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250213081516.16266-4-h.duerr@proxmox.com \
--to=h.duerr@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal