×

CentOS 安装显卡驱动 LinuxOS

牛大兵 牛大兵 发表于2023-08-20 19:40:46 浏览280 评论0

抢沙发发表评论

centos进不去图形界面可能是因为安装时没有安装图形界面。


安装centos服务器版本的时候,系统默认没安装 CentOS 的图形界面程序,解决方案如下:


1、在命令行下输入下面的命令来安装 Gnome 包

$sudo yum groupinstall "GNOME Desktop" "Graphical Administration Tools"


2、更新系统的运行级别

如果你想在系统下次启动的时候自动进入图形界面,那么我们需要更改系统的运行级别,输入下面的命令来启用图形界面。

$sudo ln -sf /lib/systemd/system/runlevel5.target /etc/systemd/system/default.target


3、重启系统


=======================================

安装Nvidia 驱动

./NVIDIA-Linux-x86_64-470.103.01.run --no-opengl-files

Nvidia驱动默认安装OpenGL与centos的GNOME桌面产生冲突,所以不能打开图形化界面。因此在安装的时候需要注意,添加参数




在安装过程中,最后会提示我们安装 xconfig,这时候果断选"no"。那么这次安装的驱动就可以正常打开了。如果已经安装的读者,可以先卸载,然后再重新安装。


Nvidia 显卡驱动的安装过程


1、禁用系统默认的nouveau显卡驱动====核显

# 查看是否开启
lsmod | grep nouveau
# 禁用nouveau显卡驱动,注意 blacklist.conf 文件名在不同主机下会有区别,这个需要自己当目录下去看
vi /etc/modprobe.d/dccp-blacklist.conf
# 添加信息如下
blacklist nouveau
options nouveau modeset=0

# 重建 initramfs image 步骤
mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak
dracut /boot/initramfs-$(uname -r).img $(uname -r)
# 查看是否禁用成功
lsmod | grep nouveau

2、安装显卡驱动

到官网去搜索与自己显卡相适应的驱动:https://www.nvidia.cn/geforce/drivers/

# 下载显卡驱动  https://cn.download.nvidia.cn/XFree86/Linux-x86_64/390.157/NVIDIA-Linux-x86_64-390.157.run
wget https://cn.download.nvidia.com/XFree86/Linux-x86_64/470.103.01/NVIDIA-Linux-x86_64-470.103.01.run

# 退出X-server图形,进入文本模式
init 3

# 添加可执行权限
chmod +x NVIDIA-Linux-x86_64-470.103.01.run
 #  Nvidia驱动默认安装OpenGL与GNOME桌面冲突,不能安装。安装xconfig时 选 "no"
./NVIDIA-Linux-x86_64-470.103.01.run --no-opengl-files

--- 安装中 ---

# 打开图形模式
init 5

# 查看驱动
nvidia-smi

# 重启电脑
reboot



这里要记得打开图形模式,否则开机会直接进入到文字模式。除了init 5,也可以采用如下设置

# 查看默认的模式:tgraphical.target-图形化界面,multi-user.target-dos界面
systemctl get-default 
systemctl set-default graphical.target



------------------------------------------------------------------------------------------------------------------------------


可能是显卡驱动没装上把。试试把显卡重置为标准显卡试试。


重启电脑进入grub,然后键入e,再 键入e,在最后输入空格 和1,回车,按b以单用户启动linux。

进入命令行,可以输入system-config-display修改显卡 改成vesa.

或者进入/etc/x11下通过vi编辑器编辑xorg.conf文件。

下面是该文件。
# Xorg configuration created by system-config-display
Section "ServerLayout"
Identifier "single head configuration"
Screen 0 "Screen0" 0 0
InputDevice "Keyboard0" "CoreKeyboard"
InputDevice "Synaptics" "CorePointer"
EndSection
Section "InputDevice"
Identifier "Keyboard0"
Driver "kbd"
Option "XkbModel" "pc105"
Option "XkbLayout" "us"
EndSection
Section "InputDevice"
Identifier "Synaptics"
Driver "synaptics"
Option "Device" "/dev/input/mice"
Option "Protocol" "auto-dev"
Option "Emulate3Buttons" "yes"
EndSection
Section "Device"
Identifier "Videocard0"
Driver "via"
EndSection
Section "Screen"
Identifier "Screen0"
Device "Videocard0"
DefaultDepth 24
SubSection "Display"
Viewport 0 0
Depth 24
EndSubSection
EndSection
修改driver对应的值为 vesa
Section "Device"
Identifier "Videocard0"
Driver "vesa"                  改这里
EndSection
重新启动计算机
这样可以保持 800*600的分辨率。然后在按照上篇文章的方法,安装驱动。



linux显卡驱动导致无法开机或无法关机的问题



屏蔽 nouveau


无法完成安装的 , 先启动安装介质, 在启动菜单出现时, 按 e , 编辑启动选项,

找到 linux开头的那一行, 在这一行末尾加上.

    modprobe.blacklist=nouveau

setparams 'Deepin 15.7'GNU/Linux'
load_video
insmod gzio
if [ x$gryb_platform = xxen ]; then insmod xzio; insmod lzopio; fi
insmod part_gpt
insmod ext2
set root='hdo,gpt2'
if [ x$feature_platform_search_hint = xy ]; then
search--no-floppy--fs-uuid --set=root --hint-bios=hdo,gpt2 --hint-efi=hdo,gpt2 --hint-aremetal=ahcio,gpt2 ee4\
54ca8-e47c-48bc-96df-439c4d94c673
else
search --no-floppy.--fs-uuid --set=root ee454ca8-e47c-48bc-96df-439c4d94c673
fi
linux
/boot/vmlinuz-4.15.0-29deepin-generic root=UUID=ee454ca8-e47c-48bc-96df-439c4d94c673 ro. splash quiet\
modprobe.blacklist=nouveau_
initrd
/boot/initrd.img-4.15.0-29deepin-generic



即可完成安装, 安装完成后, 再看下面的步骤


先完成安装, 启动系统时, 同样按上面的方法修改启动参数, 进入系统后 , 可选两种方法


使用显卡驱动管理程序切换到闭源驱动.

修改 grub.cfg , 同样是加入 modprobe.blacklist=nouveau以永久生效


Linux修改rc.local后重启无法进入系统

复现:

102服务器重启之后,一直卡在用户列表界面,但是不显示用户列表,用Alt+F2切换到黑屏终端,也无法进入终端

 

原因:

/etc/rc.d/rc.local中,在系统启动时会执行里面的任务,如果任务有问题,会导致无法进入系统

 

解决:

1、重启服务器,在选择内核时,按 “e” 进入单用户模式

2、修改,将图中的 ro 改为 rw, 删除 rhgb quiet, 并在行末加上 init=/bin/bash

insmod xfs
set root='hd0,msdos1’
if [ x$feature platform_search_hint = xy ]; then
search--no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hinv
t-efi=hd0,msdos1 --hint-baremetal=ahci0,Msdos1 --hint=’hd0,msdos1’ 4f35916b-7\
c4e-4b14-8ac1-d54802e0eb75
else
search--no-floppy --fs-uuid --set=root 4f35916b-7c4e-4b14-8ac1-d548\
02e0eb75
fi
linux16/vmlinuz-3.10.0-1127.e17.x86_64 root=/dev/mapper/rhel-root  ro\
crashkernel=auto spectre_v2=retpoline rd.lvm.lv=rehel/root rhgb quiet LANG=en_u\
S.UTF-8
  initrd16 /initramfs-3.10.0-1127.el7.x86_64.img

Press Ctrl-x to start, Ctrl-c for a command prompt or Escape to
discard edits and return to the menu. Pressing Tab lists
possible completions.

改成

insmod xfs
set root='hd0,msdos1'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hin\
t-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint=’hd0,msdos1’ 4f35916b-7\
c4e-4b14-8ac1-d54802e0eb75
else
search--no-floppy--fs-uuid --set=root 4f35916b-7c4e-4b14-8ac1-d548\
02eBeb75
fi
linux16 /vmlinuz-3.10.0-1127.e17.x86_64 root=/dev/mapper/rhel-root  rw \                                              \\ro 改成 rw
crashkernel=auto spectre v2=retpoline rd.lvm.lv=rhel/root.UTF-8 init=/bin/bash                                                \\ 并在行末加上 init=/bin/bash

initrd16 /initramfs-3.10.0-1127.el7.x86_64.img
Press Ctrl-x to start, Ctrl-c for a command prompt or Escape to
discard edits and return to the menu. Pressing Tab lists
possible completions.


3、键盘 crtl+x 启动,进入recovery模式

4、挂载根目录为可写:mount -o remount,rw /

5、修改 /etc/rc.d/rc.local,保存退出: vi /etc/rc.d/rc.local

6、重启服务器,即可进入系统

注意事项:

1、将/etc/rc.d/rc.local中的任务记录,写在统一的脚本中,待系统启动成功后,手动执行任务

2、在虚机中测试,开机自启任务是否可行,确定没问题后,在将任务添加到服务器的rc.local中

3、解决方案中的步骤2,在服务器重启后会自动还原为原始内容,已经过测试验证