设置服务器

打印 上一主题 下一主题

主题 892|帖子 892|积分 2676

参考博客

1. https://blog.csdn.net/qq_31278903/article/details/83146031
2. https://blog.csdn.net/u014374826/article/details/134093409
3. https://blog.csdn.net/weixin_42728126/article/details/88887350
4. https://blog.csdn.net/Dreamhai/article/details/109764502 
5.  Ubuntu 22.04 安装 NVIDIA 显卡驱动失败笔记 - 小时百科 (wuli.wiki)
6. ubuntu20.04安装nvidia驱动真实有效 

 重装Ubuntu24.04系统

实行室有一台五年前的老机子,老师让我将它重新利用起来,于是我就来开始一顿捣鼓了。
1. 预备系统盘



  • 一个大于8G的优盘
  • 使用rufus(Index of /downloads (rufus.ie))软件制作,强推!真的非常好用!
  • 下载系统镜像文件(Get Ubuntu | Download | Ubuntu),桌面版和服务器版二则选其一即可Get Ubuntu | Download | Ubuntu
2. 更改为U盘启动

把系统盘插入电脑中,然后重启电脑,这里需要进入bios界面更改为U盘启动,差别品牌电脑进入BIOS的快捷键差别,我们实行室这台机子使用F2进入。


  • 重新启动电脑,开机时不停地按F2键进入BIOS界面
  • 更改优先启动项为U盘最高
  • 保存更改设置,然后等待提示安装系统
   BIOS是英文 "Basic Input Output System" 的缩略词,直译过来后中文名称就是 "基本输入输出系统"。其实,它是一组固化到计算机内主板上一个daoROM芯片上的步调,它保存着计算机最紧张的基本输入输出的步调、系统设置信息、开机后自检步调和系统自启动步调。 其主要功能是为计算机提供最底层的、最直接的硬件设置和控制。
  
  原文链接:https://blog.csdn.net/songyuchaoshi/article/details/109639071
   3. 安装系统

我安装的是Ubuntu2024.04桌面版,因此按默认的选项不停下一步就完事,安装乐成之后,拔出优盘,重启系统。
设置环境

1. 重置root密码

有一些下令大概应用需要用root身份安装,我想知道新装的Ubuntu系统中默认的root用户密码是多少?新装的系统的root密码是随机天生的,我们使用密码修改下令将其修改成熟悉的密码:
  1. qfchen@Tanlab-Server:~$ su passwd
复制代码
在安装系统的过程,我设置了一个用户名和密码,这个账号是具有管理员权限的,因此可以使用su下令。 
2. 格式化其他磁盘

我用 lsblk 查看系统全部的硬盘使用情况发现这台机子的旧系统放在另一个磁盘(nvme0n1)上,于是我想把nvme0n1硬盘上的信息全部格式化掉。
ubuntu--vg--1-ubuntu--lv:重新安装的系统
ubuntu--vg-ubuntu--lv:以前的老系统(需要格式化) 

然后又用 fdisk -l  下令来查看系统里面识别到的硬盘和分区的信息

这里可以用lsblk -d -o name,rota下令区分机械硬盘(hdd)和固态硬盘(ssd): 

了解到磁盘基本信息之后,我们就可以将该硬盘格式化掉啦
  1. root@server4049:~# parted /dev/nvme0n1
  2. GNU Parted 3.6
  3. Using /dev/nvme0n1
  4. Welcome to GNU Parted! Type 'help' to view a list of commands.
  5. (parted) mklabel gpt                                                      
  6. Warning: The existing disk label on /dev/nvme0n1 will be destroyed and all data on this disk will be lost. Do you want to continue?
  7. Yes/No? yes                                                               
  8. Error: Partition(s) 3 on /dev/nvme0n1 have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use.  As a
  9. result, the old partition(s) will remain in use.  You should reboot now before making further changes.
  10. Ignore/Cancel? Ignore                                                     
  11. (parted) print                                                            
  12. Model: WDS100T3X0C-00SJG0 (nvme)
  13. Disk /dev/nvme0n1: 1000GB
  14. Sector size (logical/physical): 512B/512B
  15. Partition Table: gpt
  16. Disk Flags:
  17. Number  Start  End  Size  File system  Name  Flags
  18. (parted) mkpart primary 0 1000GB
  19. Warning: The resulting partition is not properly aligned for best performance: 34s % 2048s != 0s
  20. Ignore/Cancel? Ignore                                                     
  21. Error: Partition(s) 1, 3 on /dev/nvme0n1 have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use.  As a
  22. result, the old partition(s) will remain in use.  You should reboot now before making further changes.
  23. Ignore/Cancel? Ignore                                                     
  24. (parted) print                                                            
  25. Model: WDS100T3X0C-00SJG0 (nvme)
  26. Disk /dev/nvme0n1: 1000GB
  27. Sector size (logical/physical): 512B/512B
  28. Partition Table: gpt
  29. Disk Flags:
  30. Number  Start   End     Size    File system  Name     Flags
  31. 1      17.4kB  1000GB  1000GB               primary
  32. (parted) quit                                                            
  33. Information: You may need to update /etc/fstab.
复制代码
  1. root@server4049:~# mkfs.ext4 /dev/nvme0n1
  2. mke2fs 1.47.0 (5-Feb-2023)
  3. /dev/nvme0n1 is apparently in use by the system; will not make a filesystem here!
  4. root@server4049:~# dmsetup status
  5. ubuntu--vg--1-ubuntu--lv: 0 209715200 linear
  6. ubuntu--vg-ubuntu--lv: 0 1738448896 linear
  7. ubuntu--vg-ubuntu--lv1: 0 1738448829 linear
  8. root@server4049:~# dmsetup remove_all
  9. root@server4049:~# dmsetup status
  10. ubuntu--vg--1-ubuntu--lv: 0 209715200 linear
  11. root@server4049:~# mkfs.ext4 /dev/nvme0n1p3
  12. mke2fs 1.47.0 (5-Feb-2023)
  13. /dev/nvme0n1p3 contains a LVM2_member file system
  14. Proceed anyway? (y,N) y
  15. Discarding device blocks: done                           
  16. Creating filesystem with 243521536 4k blocks and 60882944 inodes
  17. Filesystem UUID: b6e57451-0775-400b-93eb-d581a22ac075
  18. Superblock backups stored on blocks:
  19.         32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
  20.         4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
  21.         102400000, 214990848
  22. Allocating group tables: done                           
  23. Writing inode tables: done                           
  24. Creating journal (262144 blocks): done
  25. Writing superblocks and filesystem accounting information: done   
复制代码
 安装nvidia驱动的教程

首先我们需要检查一下这台机器是否有GPU,使用如下下令: lspci |grep -i nvidia
发现 lspci 下令不在Linux环境中,那我们来安装一个
  1. qfchen@Tanlab-Server:~$  lspci |grep -i nvidia
  2. Command ' lspci' not found, did you mean:
  3.   command 'lspci' from deb pciutils (1:3.10.0-2)
  4. Try: sudo apt install <deb name>
复制代码
根据提示信息, lspci 下令位于 pciutils 包中,因此需要安装这个包才气使用  lspci 下令。
  1. qfchen@Tanlab-Server:~$ sudo apt install pciutils
  2. Reading package lists... Done
  3. Building dependency tree... Done
  4. Reading state information... Done
  5. pciutils is already the newest version (1:3.10.0-2build1).
  6. pciutils set to manually installed.
  7. The following package was automatically installed and is no longer required:
  8.   libnvidia-egl-wayland1
  9. Use 'sudo apt autoremove' to remove it.
  10. 0 upgraded, 0 newly installed, 0 to remove and 33 not upgraded.
复制代码
然后我们使用  lspci 查看,发现有GPU:GeForce RTX 2080 Ti Rev. A
  1. root@server4049:/home/qfchen# lspci |grep -i nvidia
  2. 01:00.0 VGA compatible controller: NVIDIA Corporation TU102 [GeForce RTX 2080 Ti Rev. A] (rev a1)
  3. 01:00.1 Audio device: NVIDIA Corporation TU102 High Definition Audio Controller (rev a1)
  4. 01:00.2 USB controller: NVIDIA Corporation TU102 USB 3.1 Host Controller (rev a1)
  5. 01:00.3 Serial bus controller: NVIDIA Corporation TU102 USB Type-C UCSI Controller (rev a1)
复制代码
上述信息表现是有GPU,然后:


  • 第一步,打开终端,先用 nvidia-smi 查看一下,发现如下报错:
  1. NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver.
  2. Make sure that the latest NVIDIA driver is installed and running.
复制代码
报错信息大概意思是 nvidia-smi 无法与 NVIDIA 驱动步调通讯。通常情况下,这是由于 NVIDIA 驱动步调未正确安装或未加载而导致的。这个时间需要查看一下版本是否匹配,因为NVIDIA 驱动步调具有很强的版本依赖性,需要与特定的内核版本和 CUDA 版本匹配。
我们来查看是否安装完成NVIDIA 驱动步调,输入 dpkg -l | grep nvidia


  • 第二步,使用 ncvv -V检查驱动和cuda。
  1. root@server4049:/usr/src# nvcc -V
  2. Command 'nvcc' not found, but can be installed with:
  3. apt install nvidia-cuda-toolkit
复制代码
 于是根据提示安装 apt install nvidia-cuda-toolkit,乐成之后再次输入 nvcc -V表现信息如下:
  1. root@server4049:/usr/src# nvcc -V
  2. nvcc: NVIDIA (R) Cuda compiler driver
  3. Copyright (c) 2005-2023 NVIDIA Corporation
  4. Built on Fri_Jan__6_16:45:21_PST_2023
  5. Cuda compilation tools, release 12.0, V12.0.140
  6. Build cuda_12.0.r12.0/compiler.32267302_0
复制代码
表现信息表明驱动是存在的,于是举行下一步:


  • 第三步,查看已安装驱动的版本信息
  1. root@server4049:/usr/src# ls /usr/src | grep nvidia
复制代码
 没有表现任何信息,那就安装驱动呗!
首先确定 Software & Updates (桌面的Ubuntu)中的 Proprietary drivers for devices (restricted) 已经勾选
  1. sudo apt update
  2. sudo ubuntu-drivers list
复制代码
可以主动安装系统以为合适的驱动 
  1. sudo ubuntu-drivers install --gpgpu
复制代码
  1. sudo ubuntu-drivers install nvidia:535
复制代码
 完成后(可能要重启)在 Software & Updates 中可以更改想要使用的驱动。

这个教程有用,倒腾了半天,用这个教程乐成了,在root账号下操作。
1. 先把之前的nvidia驱动卸载干净:
  1. apt-get remove nvidia-*
  2. apt-get remove "*nvidia-*"
复制代码
2. 删除旧内核
  1. apt autoremove
复制代码
3. 在终端里输入下面的下令来查看可以选择哪些驱动
  1. ubuntu-drivers devices
复制代码
4. 根据表现的保举结果选一个,我选的是535版本,一样平常选择背面跟有recommend字样的版本
  1. apt install nvidia-driver-535
复制代码
5. 顺利的会直接安装乐成,然后再reboot以下即可生效驱动
6. 查看一下显卡信息,安装NVIDIA Settings控制面板,在下令行打开控制面板大概在启动器内找到控制面板图标,打开后就可以查看显卡信息啦!
  1. apt install nvidia-settings
  2. nvidia-settings
复制代码
结果如下所示: 


背面的下令就是乐成安装好 驱动之后,使用的一些基础下令查看系统信息


  •  uname下令
  1. qfchen@Tanlab-Server:~$ uname --help
  2. Usage: uname [OPTION]...
  3. Print certain system information.  With no OPTION, same as -s.
  4.   -a, --all                print all information, in the following order,
  5.                              except omit -p and -i if unknown:
  6.   -s, --kernel-name        print the kernel name
  7.   -n, --nodename           print the network node hostname
  8.   -r, --kernel-release     print the kernel release
  9.   -v, --kernel-version     print the kernel version
  10.   -m, --machine            print the machine hardware name
  11.   -p, --processor          print the processor type (non-portable)
  12.   -i, --hardware-platform  print the hardware platform (non-portable)
  13.   -o, --operating-system   print the operating system
  14.       --help        display this help and exit
  15.       --version     output version information and exit
复制代码


  • Linux查看当前使用的内核版本
  1. qfchen@Tanlab-Server:~$ uname -r
  2. 6.8.0-38-generic
复制代码


  •  Linux查看当前操作系统的内核信息
  1. qfchen@Tanlab-Server:~$ uname -a
  2. Linux Tanlab-Server 6.8.0-38-generic #38-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun  7 15:25:01 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
复制代码


  • Linux查看版本当前操作系统发行版信息
  1. qfchen@Tanlab-Server:~$ cat /etc/issue
  2. Ubuntu 24.04 LTS \n \l
复制代码


  • Linux查看cpu相关信息,包罗型号、主频、内核信息等
  1. qfchen@Tanlab-Server:~$ cat /proc/cpuinfo
复制代码


  • Ubuntu中查看主机有多少个核 
  1. qfchen@Tanlab-Server:~$ cat /proc/cpuinfo | grep processor | wc -l
  2. 20
  3. qfchen@Tanlab-Server:~$ nproc
  4. 20
复制代码


  • 查看主机名称
  1. qfchen@Tanlab-Server:~$ hostname
  2. Tanlab-Server
复制代码


  • 查看网络信息
  1. qfchen@Tanlab-Server:~$ ifconfig
  2. enp4s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
  3.         inet 10.16.27.223  netmask 255.255.128.0  broadcast 10.16.127.255
  4.         inet6 fe80::d65d:64ff:fed1:f45d  prefixlen 64  scopeid 0x20<link>
  5.         inet6 2001:da8:201d:1107::e562  prefixlen 128  scopeid 0x0<global>
  6.         ether d4:5d:64:d1:f4:5d  txqueuelen 1000  (Ethernet)
  7.         RX packets 2144728  bytes 3161595289 (3.1 GB)
  8.         RX errors 0  dropped 9198  overruns 0  frame 0
  9.         TX packets 958093  bytes 91054742 (91.0 MB)
  10.         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  11.         device memory 0xa5100000-a51fffff  
  12. lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
  13.         inet 127.0.0.1  netmask 255.0.0.0
  14.         inet6 ::1  prefixlen 128  scopeid 0x10<host>
  15.         loop  txqueuelen 1000  (Local Loopback)
  16.         RX packets 1899  bytes 414234 (414.2 KB)
  17.         RX errors 0  dropped 0  overruns 0  frame 0
  18.         TX packets 1899  bytes 414234 (414.2 KB)
  19.         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  20. wlo1: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
  21.         ether 04:33:c2:01:53:ec  txqueuelen 1000  (Ethernet)
  22.         RX packets 0  bytes 0 (0.0 B)
  23.         RX errors 0  dropped 0  overruns 0  frame 0
  24.         TX packets 0  bytes 0 (0.0 B)
  25.         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
复制代码
 环境设置着设置着发现有线网卡(enp4s0)掉了,兵来将挡水来土掩,我们来启动它,root账号操作。
  1. nmcli networking off
  2. nmcli networking on
复制代码
然后我们就会发现桌面版Ubuntu右上角的网络图标亮了,撒花撒花撒花。
接下来就是给其他小伙伴分配账号啦,大家一起愉快的玩耍。过程很曲折,结果还是算是好的,又巩固了一遍之前学的知识。
  1. adduser test
复制代码





免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

没腿的鸟

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表