ubuntu2204配置anacondacuda4090nvidia驱动

news2025/2/25 9:24:03

背景

某个机房的几台机器前段时间通过dnat暴露至公网后被入侵挖矿,为避免一些安全隐患将这几台机器执行重装系统操作;

这里主要记录配置nvidia驱动及cuda&anaconda。

步骤

大概分为几个步骤

  1. 禁用nouveau
  2. 配置grub显示菜单
  3. install nvidia-driver
  4. install cuda
  5. install anaconda
  6. 测试

执行

system info

root@xxx:~# cat /etc/os-release 
PRETTY_NAME="Ubuntu 22.04.3 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.3 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
root@xxx:~# uname -a 
Linux exai-121 6.5.0-41-generic #41~22.04.2-Ubuntu SMP PREEMPT_DYNAMIC Mon Jun  3 11:32:55 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

禁用nouveau

echo -e "blacklist nouveau\noptions nouveau modeset=0" > /etc/modprobe.d/blacklist-nouveau.conf
update-initramfs -u

配置grub显示菜单

    sed -i 's/^GRUB_TIMEOUT=.*$/GRUB_TIMEOUT=10/' /etc/default/grub
    sed -i 's/^GRUB_TIMEOUT_STYLE=hidden/#&/' /etc/default/grub
    # 验证
    grep -E "GRUB_TIMEOUT" /etc/default/grub
    # 更新grub
    update-grub

install nvidia-driver

两种安装驱动的方法

  1. 添加ppa源的方式用apt安装
  2. 官网下载指定版本的离线安全包安装

方法一

使用ubuntu带的硬件扫描配合ppa源安装

# 扫描硬件
ubuntu-drivers devices

== /sys/devices/pci0000:00/0000:00:01.1/0000:01:00.0 ==
modalias : pci:v000010DEd00002684sv000010DEsd0000167Cbc03sc00i00
vendor   : NVIDIA Corporation
manual_install: True
driver   : nvidia-driver-535-server-open - distro non-free
driver   : nvidia-driver-535 - distro non-free recommended
driver   : nvidia-driver-545-open - distro non-free
driver   : nvidia-driver-535-server - distro non-free
driver   : nvidia-driver-545 - distro non-free
driver   : nvidia-driver-535-open - distro non-free
driver   : nvidia-driver-530 - third-party non-free
driver   : xserver-xorg-video-nouveau - distro free builtin
# apt安装需要的驱动版本即可 例如
apt install nvidia-driver-535 -y

方法二

编译器下载

apt update && apt install gcc make -y

官网下载535.183.01版本对应的离线安装run包
这里直接使用curl+proxy下载了

chmod +x NVIDIA-Linux-x86_64-535.183.01.run 
 ./NVIDIA-Linux-x86_64-535.183.01.run

过程中遇到的选项根据提示选择即可

root@xxx:~# nvidia-smi 
Thu Jul 14 09:xx:01 2024       
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.183.01             Driver Version: 535.183.01   CUDA Version: 12.2     |
|-----------------------------------------+----------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|=========================================+======================+======================|
|   0  NVIDIA GeForce RTX 4090        Off | 00000000:01:00.0 Off |                  Off |
| 32%   62C    P2             224W / 450W |  19736MiB / 24564MiB |     96%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+
|   1  NVIDIA GeForce RTX 4090        Off | 00000000:81:00.0 Off |                  Off |
| 31%   49C    P2             144W / 450W |  11430MiB / 24564MiB |     38%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+
|   2  NVIDIA GeForce RTX 4090        Off | 00000000:C1:00.0 Off |                  Off |
| 37%   63C    P2             140W / 450W |  11430MiB / 24564MiB |     39%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+
|   3  NVIDIA GeForce RTX 4090        Off | 00000000:C2:00.0 Off |                  Off |
| 32%   58C    P2             136W / 450W |  11430MiB / 24564MiB |     40%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+

其他常用命令
更详细的卸载请参考https://blog.csdn.net/qq_43652666/article/details/134705794

# 卸载nvidia驱动
nvidia-uninstall

如果系统没有nvidia-uninstall可以使用dpkg包管理器列出系统中的nvidia关键字的包进行卸载

dpkg -l |grep nvidia*
apt remove --purge '^nvidia-.*'

install cuda

https://developer.nvidia.com/cuda-toolkit-archive这里选择要下载的版本
下载对应的离线run包
在这里插入图片描述
执行安装的时候要取消自带安装的530版本驱动,因为本地已经有驱动了。
注意这里cuda后缀标识代表会安装530.30.02版本的驱动,而我们本地已经安装了535的驱动,cuda版本是向下兼容的。

root@xxx:~# chmod +x cuda_12.1.1_530.30.02_linux.run 
# 安装完成
root@exai-121:~# sh cuda_12.1.1_530.30.02_linux.run
===========
= Summary =
===========

Driver:   Not Selected
Toolkit:  Installed in /usr/local/cuda-12.1/

Please make sure that
 -   PATH includes /usr/local/cuda-12.1/bin
 -   LD_LIBRARY_PATH includes /usr/local/cuda-12.1/lib64, or, add /usr/local/cuda-12.1/lib64 to /etc/ld.so.conf and run ldconfig as root

To uninstall the CUDA Toolkit, run cuda-uninstaller in /usr/local/cuda-12.1/bin
***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 530.00 is required for CUDA 12.1 functionality to work.
To install the driver using this installer, run the following command, replacing <CudaInstaller> with the name of this run file:
    sudo <CudaInstaller>.run --silent --driver

Logfile is /var/log/cuda-installer.log

# 验证
root@xxx:~# /usr/local/cuda-12.1/bin/nvcc --version 
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2023 NVIDIA Corporation
Built on Mon_Apr__3_17:16:06_PDT_2023
Cuda compilation tools, release 12.1, V12.1.105
Build cuda_12.1.r12.1/compiler.32688072_0

ubuntu2204上不推荐使用530版本的驱动,安装会有一些依赖和GCC问题,尝试解决无果。推荐使用高版本驱动来向下兼容cuda版本。

问题:
make: *** [Makefile:82: modules] Error 2
-> Checking to see whether the nvidia kernel module was successfully built
executing: ‘cd ./kernel; /usr/bin/make -k -j32 NV_EXCLUDE_KERNEL_MODULES=“” SYSSRC=“/lib/modules/6.5.0-41-generic/build” SYSOUT=“/lib/modules/6.5.0-41-generic/build” NV_KERNEL_MODULES=“nvidia”’…
make[1]: Entering directory ‘/usr/src/linux-headers-6.5.0-41-generic’
warning: the compiler differs from the one used to build the kernel
The kernel was built by: x86_64-linux-gnu-gcc-12 (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0
You are using: cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0

Warning: Compiler version check failed:

The major and minor number of the compiler used to
compile the kernel:

x86_64-linux-gnu-gcc-12 (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0, GNU ld (GNU Binutils for Ubuntu) 2.38

does not match the compiler used here:

cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Copyright © 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

It is recommended to set the CC environment variable
to the compiler that was used to compile the kernel.

To skip the test and silence this warning message, set
the IGNORE_CC_MISMATCH environment variable to “1”.
However, mixing compiler versions between the kernel
and kernel modules can result in subtle bugs that are
difficult to diagnose.
Failed CC version check.

The kernel was built by: x86_64-linux-gnu-gcc-12 (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0 You are using: cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
make[3]: *** [scripts/Makefile.build:251: /tmp/selfgz2901/NVIDIA-Linux-x86_64-530.30.02/kernel/nvidia/i2c_nvswitch.o] Error 1
make[3]: Target ‘/tmp/selfgz2901/NVIDIA-Linux-x86_64-530.30.02/kernel/’ not remade because of errors.
make[2]: *** [/usr/src/linux-headers-6.5.0-41-generic/Makefile:2039: /tmp/selfgz2901/NVIDIA-Linux-x86_64-530.30.02/kernel] Error 2
make[2]: Target ‘modules’ not remade because of errors.
make[1]: *** [Makefile:234: __sub-make] Error 2
make[1]: Target ‘modules’ not remade because of errors.
make[1]: Leaving directory ‘/usr/src/linux-headers-6.5.0-41-generic’
make: *** [Makefile:82: modules] Error 2
ERROR: The nvidia kernel module was not created.
ERROR: Installation has failed. Please see the file ‘/var/log/nvidia-installer.log’ for details. You may find suggestions on fixing installation problems in the README available on the Linux driver download page at www.nvidia.com.
/tmp/selfgz2901/NVIDIA-Linux-x86_64-530.30.02/kernel/common/inc/nv-mm.h:88:60: warning: passing argument 4 of ‘get_user_pages’ makes pointer from integer without a cast [-Wint-conversion]
/tmp/selfgz2901/NVIDIA-Linux-x86_64-530.30.02/kernel/nvidia/nv-mmap.c:673:23: error: assignment of read-only member ‘vm_flags’

尝试通过更换gcc版本解决:

update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 11
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 12
update-alternatives --config gcc
# 弹出来的选项中选择12版本

这是离线安装驱动方案下的问题,使用apt安装530版本未测试过,不确定包管理器是否会自动解决编译依赖问题

后续

使用sudo定制权限管理
https://blog.51cto.com/154773488/2449180
https://blog.csdn.net/Field_Yang/article/details/51547804

参考

https://www.cnblogs.com/tarsss/p/17433419.html
https://blog.csdn.net/jiexijihe945/article/details/131517630
cuda下载地址
https://developer.nvidia.com/cuda-toolkit-archive

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1935832.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Linux——远程连接服务器

sshd服务端 ssh客户端 ssh 服务配置 #ssh 服务安装包 openssh-server [rootserver1 ~] # vim /etc/ssh/sshd_config 17 . #Port 22 # 监听端口&#xff0c;默认监听 22 端口 【默认可修改】 18 . #AddressFamily any #IPV4 和 IPV6 协议家族用哪个&#xff0c; any 表示二者…

Python莫兰生死抑制放大进化图

&#x1f3af;要点 &#x1f3af;种群离散时间莫兰生死动态图解 | &#x1f3af;良好混合种群的固定概率 | &#x1f3af;数值求解生成埃尔多斯-雷尼图 | &#x1f3af;计算马尔可夫链的转移矩阵概率 | &#x1f3af;出生死亡动态和死亡出生动态概率无向随机图和有向随机图&am…

【数据结构】树和二叉树——Lesson1

Hi~&#xff01;这里是奋斗的小羊&#xff0c;很荣幸您能阅读我的文章&#xff0c;诚请评论指点&#xff0c;欢迎欢迎 ~~ &#x1f4a5;&#x1f4a5;个人主页&#xff1a;奋斗的小羊 &#x1f4a5;&#x1f4a5;所属专栏&#xff1a;C语言 &#x1f680;本系列文章为个人学习…

一个小问题导致,AI大模型集体翻车?

9.11大还是9.9大&#xff1f; 这两天大家都在说ChatGPT大模型翻车了 &#xff01; 这到底是怎么个事儿呢&#xff1f; 原来是最近有人想ChatGPT等大模型提了一个简单的问题&#xff1a; 9.11 大还是 9.9 大&#xff1f; 答案显而易见&#xff0c;然而众多大模型却给出了错误…

基于JAVA+SpringBoot+Vue的oa系统

✌全网粉丝20W,csdn特邀作者、博客专家、CSDN新星计划导师、java领域优质创作者,博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和毕业项目实战✌ 技术范围&#xff1a;SpringBoot、Vue、SSM、HLMT、Jsp、SpringCloud、Layui、Echarts图表、Nodejs、爬…

【高性能服务器】poll模型

&#x1f525;博客主页&#xff1a; 我要成为C领域大神&#x1f3a5;系列专栏&#xff1a;【C核心编程】 【计算机网络】 【Linux编程】 【操作系统】 ❤️感谢大家点赞&#x1f44d;收藏⭐评论✍️ 本博客致力于知识分享&#xff0c;与更多的人进行学习交流 poll模型 关于sel…

算法-计数质数

题目&#xff1a; 给定整数 n &#xff0c;返回 所有小于非负整数 n 的质数的数量 。 思路&#xff1a; 使用埃式筛法 当n大于等于2时&#xff0c;如果当前遍历的数 i 是质数&#xff0c;那么从 i*i 开始&#xff0c;直到 n 为止&#xff0c;把 i 的倍数都标记为合数 代码&a…

一个关于STM32的DAC输出的遗忘点

众所周知熟练使用HAL库可以帮你解决不少stm32的开发难题&#xff0c;但是是谁让你陷入了这些难题&#xff0c;别问。 如上图所示&#xff0c;正常初始化这个模块后生成代码如下图所示&#xff1b; * DAC init function */ void MX_DAC_Init(void) {/* USER CODE BEGIN DAC_Ini…

【LabVIEW作业篇 - 3】:数组相加、for循环创建二位数组、数组练习(求最大最小值、平均值、中位数、提取范围内的数据、排序)

文章目录 数组相加for循环实现直接使用加函数 for循环创建二位数组数组练习 数组相加 要求&#xff1a;用两种方法实现两个数组相加 for循环实现 在前面板中分别创建两个数值类型的一维数组&#xff0c;并设置相应的值&#xff0c;然后在程序框图中创建一个for循环&#xff…

数据结构(Java):力扣牛客 二叉树面试OJ题(一)

&#x1f449; ​​​​​​目录 &#x1f448; 1、题一&#xff1a;检查两棵树是否相同 1.1 思路分析 1.2 代码 2、题二&#xff1a;另一棵树的子树 2.1 思路分析 2.2 代码 3、题三&#xff1a;翻转二叉树 3.1 思路分析 3.2 代码 4、题四&#xff1a;判断树是否对称 …

小模型大突破!神经网络透视空间异质性,准确描述复杂地理现象

为推进 AI4S 的普适化&#xff0c;降低学术机构科研成果的传播壁垒&#xff0c;为更多行业学者、科技爱好者及产业单位提供交流平台&#xff0c;HyperAI超神经策划了「Meet AI4S」系列直播栏目&#xff0c; 邀请深耕 AI for Science 领域的科研人员或相关单位&#xff0c;以视频…

新时代多目标优化【数学建模】领域的极致探索——数学规划模型

目录 例1 1.问题重述 2.基本模型 变量定义&#xff1a; 目标函数&#xff1a; 约束条件&#xff1a; 3.模型分析与假设 4.模型求解 5.LINGO代码实现 6.结果解释 ​编辑 7.敏感性分析 8.结果解释 例2 奶制品的销售计划 1.问题重述 ​编辑 2.基本模型 3.模…

北京邮电大学,中央空调的分户计费系统

北京邮电大学 中央空调如何公平、公正、合理的收取费用&#xff0c;一直都是各建筑管理者的首要问题。北京邮电大学也面临着能源分配不公&#xff0c;学校管理者空调收费管理困难等问题。根据学校的具体情况&#xff0c;拓森为其制定了一套中央空调管理运营方案—无线中央空调…

jupyter学习笔记

简介 Jupyter Notebook是一个Web应用程序&#xff0c;它可以在网页页面中直接编写代码和运行代码&#xff0c;代码的运行结果也会直接在代码块下显示。 安装使用 前提&#xff1a;必须安装python 先升级pip至最新版本 pip3 install --upgrade pip安装jupyter notebook pi…

springboot的简单应用

Mvc与三层架构 创建Spring项目 勾选web和mabais框架 配置yml文件&#xff0c;这里创建spring项目默认生成的是propertise文件&#xff0c;但是properties文件的格式看起来没有yml文件一目了然。yml文件配置数据库还有映射mapper层的xml文件以及设置日志级别&#xff0c;比如map…

刚起步的家庭海外仓:涉及到的全部业务优化流程

对于家庭海外仓来说&#xff0c;最难的阶段应该就是刚起步的时候。对业务流程不熟悉&#xff0c;也没有客户积累&#xff0c;本身的预算又十分有限。 在这个情况下应该注意什么&#xff0c;怎样才能顺利的开展业务&#xff1f;今天我们就针对这个问题详细的梳理了一下家庭海外…

尚品汇-(二十一)

目录&#xff1a; &#xff08;1&#xff09;使用redis实现分布式锁 &#xff08;2&#xff09;优化之设置锁的过期时间 &#xff08;3.&#xff09;优化之UUID防误删 &#xff08;4&#xff09;优化之LUA脚本保证删除的原子性 &#xff08;1&#xff09;使用redis实现分布…

go语言编程 小试牛刀 goroutine和reflect知识点

&#xff08;一&#xff09;goroutine package _caseimport "fmt"// sum 函数计算整数切片 values 的总和&#xff0c;并将结果发送到 resultChan 通道中 func sum(values []int, resultChan chan int) {sum : 0for _, value : range values {sum value}resultChan…

HarmonyOS NEXT学习——@Styles、@Extend、stateStyles

Styles装饰器 定义组件重用样式 仅支持通用属性和通用事件不支持参数可以定义全局和组件内使用&#xff0c;全局使用需要加function // 全局 Styles function functionName() { ... }// 在组件内 Component struct FancyUse {Styles fancy() {.height(100)} }组件内Styles的优…

智能一体式闸门在灌区中的应用

在现代化的农业灌溉领域&#xff0c;智能一体式闸门作为一种集自动化、智能化、高效能于一体的先进设备&#xff0c;正逐渐在灌区管理中发挥着重要作用。 灌区是农业生产的重要基地&#xff0c;其水资源的管理和利用直接关系到农作物的生长和产量。然而&#xff0c;传统的闸门管…