CentOS7.6安裝圖形界面失敗,startx執行失敗

網上關於CentOS7使用startx命令啓動圖形界面失敗的帖子很多,不過找了一天也沒解決我的問題,於是把自己掉坑過程複述一下,然後有爬出來的過程,如果有相似經歷的同學可以參考看看能不能爬出坑。

1. 先列舉一下問題:

我遇到的問題一共有兩個

一個問題是在啓動桌面程序的時候,即startx時,報:

[root@localhost vmware-tools-distrib]# startx
xauth:  file /root/.serverauth.1729 does not exist

xinit: unable to run server "/usr/bin/X": No such file or directory
Use the -- option, or make sure that /usr/bin is in your path and
that "/usr/bin/X" is a program or a link to the right type of server
for your display.  Possible server names include:

    Xorg        Common X server for most displays
    Xvfb        Virtual frame buffer
    Xfake       kdrive-based virtual frame buffer
    Xnest       X server nested in a window on another X server
    Xephyr      kdrive-based nested X server
    Xvnc        X server accessed over VNC's RFB protocol
    Xdmx        Distributed Multi-head X server

^Cxinit: giving up
xinit: unable to connect to X server: Connection refused
xinit: unexpected signal 2

這個錯在網上經過搜索後,他會告訴你安裝或者重新安裝Xorg-x11-server-Xorg,命令如下:

yum install xorg-x11-server-Xorg

安裝成功後,再次執行startx,會報下邊這個錯,也是第二個問題。
第二個問題:

[root@localhost ~]# startx
xauth:  file /root/.serverauth.1814 does not exist


X.Org X Server 1.20.1
X Protocol Version 11, Revision 0
Build Operating System:  3.10.0-957.1.3.el7.x86_64
Current Operating System: Linux localhost.localdomain 3.10.0-957.27.2.el7.x86_64 #1 SMP Mon Jul 29 17:46:05 UTC 2019 x86_64
Kernel command line: BOOT_IMAGE=/vmlinuz-3.10.0-957.27.2.el7.x86_64 root=/dev/mapper/centos-root ro crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet LANG=en_US.UTF-8
Build Date: 29 July 2019  05:38:01PM
Build ID: xorg-x11-server 1.20.1-5.6.el7_6
Current version of pixman: 0.34.0
	Before reporting problems, check http://wiki.x.org
	to make sure that you have the latest version.
Markers: (--) probed, (**) from config file, (==) default setting,
	(++) from command line, (!!) notice, (II) informational,
	(WW) warning, (EE) error, (NI) not implemented, (??) unknown.
(==) Log file: "/var/log/Xorg.0.log", Time: Sat Aug 31 06:05:16 2019
(==) Using config directory: "/etc/X11/xorg.conf.d"
(==) Using system config directory "/usr/share/X11/xorg.conf.d"
gbm: failed to open any driver (search paths /usr/lib64/dri)
gbm: Last dlopen error: /usr/lib64/dri/vmwgfx_dri.so: cannot open shared object file: No such file or directory
failed to load driver: vmwgfx
gbm: failed to open any driver (search paths /usr/lib64/dri)
gbm: Last dlopen error: /usr/lib64/dri/kms_swrast_dri.so: cannot open shared object file: No such file or directory
failed to load driver: kms_swrast
gbm: failed to open any driver (search paths /usr/lib64/dri)
gbm: Last dlopen error: /usr/lib64/dri/swrast_dri.so: cannot open shared object file: No such file or directory
failed to load swrast driver
...

這個錯網上給的答案就千奇百怪了,搜了好久都沒有解決。有的同學可能也遇到過類似的錯誤或者相同的錯誤,這個問題出現的根本原因,我也不清楚,不過我復現了一下這個錯誤,找到了我遇到這個錯誤的原因,可能這個原因也是其他人無法啓動圖形界面的原因。可以作爲一個參考

2. 我的復現過程

我是按照下邊這個過程掉坑裏的:

  • 我使用CentOS官方的Minimal鏡像做了最小化安裝,使用的就是這個版本CentOS-7-x86_64-Minimal-1810.iso
  • 然後我連上了網上的源,做了更新,用的是163的源163-centos7.6-mirror
  • 然後我想安裝圖形界面了,我在CentOS7官網下載了Everything的ISO,使用的是清華的鏡像源下載的
  • 我將iso作爲光盤掛載到了虛擬機裏面/mnt目錄下,同時使用下邊的配置引用光盤中的文件作爲源進行安裝
    [root@localhost ~]# cat /etc/yum.repos.d/bak/local.repo
    [LocalRepo]
    name=Local Repository
    baseurl=file:///mnt
    enabled=1
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
    
  • 安裝使用的命令是:
    yum groupinstall "GNOME Desktop" "Graphical Administration Tools"
    
    然後就報了一些錯,是我已經安裝的軟件包版本高於當前要安裝的軟件包版本,我也沒有在意,直接加了個參數調過了,如下:
    yum groupinstall "GNOME Desktop" "Graphical Administration Tools" --skip-broken
    
    安裝顯示需要裝的軟件包大小大約165MB,這裏和網上很多帖子提示說的是700MB不同,因爲使用的是Everything的鏡像,所以軟件包比較少。
  • 安裝完之後運行startx就無法啓動了,出現了1中描述的問題

經過覆盤分析,我覺得我安裝失敗的原因,應該就是中間做過一次update,導致軟件包的版本比鏡像中的高了很多,所以導致再次使用鏡像中的包進行安裝的時候,很多依賴的版本就沒法自動解決了。強行安裝後直接導致啓動失敗。

3. 修復實驗

在遇到這個問題並且能夠成功復現後,我進行了兩個實驗:

  1. 使用Minimal進行安裝,不做update,使用Everything進行圖形化安裝
  2. 重放復現步驟,卸載安裝的圖形軟件,進行修復

上邊兩個實驗,第一個很好做,直接就成功了。說明軟件包版本匹配的情況下,應該是可以直接啓動圖形界面的,所有運行的命令都一樣,沒有變化。

第二個實驗也很好做,重點在於如何修復。因爲這一步已經記性了update,升級的軟件很多,又不能都回退回去,所以,我想的是直接用互聯網的源進行安裝圖形界面軟件。安裝後直接運行就成功了。這次安裝的包大約需要下載700多MB,和網上帖子裏說的也比較一致。

4. 確定修復方案

通過3步驟的實驗,確定採用3步驟中的第二個實驗中的結論來進行修復。由於問題出現的環境是離線環境,所以需要採用離線方案進行軟件安裝。
離線安裝有兩種方式:

  • 將桌面安裝的包下載下來,做成鏡像源
  • 將163的源倉庫下載下來,做成鏡像源
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章