Try   HackMD

Note: 偷吃步!?Ubuntu Server安裝GUI(xfce)

基於工作上(對,又是工作)用途,需要一組具備GUI的OS環境做實驗;想想就用手上現有的版本
來搞吧,還帶自動登入呢;套件就選擇最熟悉的xfce吧!
ーー理想是這樣,結果卡在lightdm(登入顯示管理器)的設定上;時間壓力的情況下就隨便建立
一個system daemon來運行xfce;反正能動就好了!對吧(!?)

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

(對啊,牠在飛嘛)

Packages Installation

先安裝所需套件:
sudo apt update && upgrade -y
sudo apt install xfce4 -y
sudo apt install lightdm -y
sudo apt install xorg -y

Create system daemon service

使用指令建立daemon config:
vim /etc/systemd/system/startx-daemon.service

(startx是在文字界面下啟動X Window的指令,取名為startx-daemon是求一個直觀)

Details:

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

[Unit]

Description:描述daemon,直白的說明用途是啟動X Window
After:確保在網路服務啟用後啟動

[Service]

User=root:指定以root啟動
WorkingDirectory=/root:指定在/root路徑下執行
ExecStart=/usr/bin/startx:daemon主要執行的內容,啟用X Window和執行檔路徑
Restart=always:當daemon崩潰時,自動重啟
Environment=DISPLAY=:0:無超時時間,也就是systemd會等待它完成。
StandardOutput=journal:標準輸出導至日誌系統journalctl -u startx-daemon.service
StandardError=journal:標準錯誤訊息導至日誌系統journalctl -u startx-daemon.service

[Install]

WantedBy=multi-user.target:這表示當系統進入"多重使用者狀態"(可以理解為執行級別3)時會啟用此daemon

賦予權限後接著啟用daemon:
chmod a+x /etc/systemd/system/startx-daemon.service
systemctl enable startx-daemon.service

Result & check status

成果:

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

進入系統後可使用以下指令檢視運行狀態:
systemctl status startx-daemon.service

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

Ref.

about unit
about building a service
鳥哥:系統服務與開機流程