ubuntu16.04.5自制圖形程式替換桌面ui
1.需求
無論是ubuntu desktop或者server版,均需要在開機啟動後執行一個圖形程式,這裡我們使用electron開發的圖形介面程式。
2.知識標籤
targets xserver xclient lightdm rc.local
3.操作-desktop
a.更改系統開機啟動到字元介面,
執行級別是以前系統的開機啟動選擇概念,在16.04.5是“targets”的概念,
檢視預設的target,執行:systemctl get-default
開機以命令模式啟動,執行:systemctl set-default multi-user.target
開機以圖形介面啟動,執行:systemctl set-default graphical.target
一般ubuntu的預設target是graphical,通過更改到命令列模式,檢視是否更改成功。
其實比如systemctl set-default multi-user.target 這個命令他是會新建一個軟連線:Created symlink from /etc/systemd/system/default.target to /lib/systemd/system/multi-user.target.
重啟之後你會發現你不會進入桌面了。理論上會預設進入tty1,這個時候你檢視執行級別,命令runlevel,也會在級別3
b.編寫一個預設的開機啟動指令碼並執行
在/etc/rc.local 執行該指令碼,給它取個名字 mystartx
且/etc/rc.local 需要新增執行許可權 即+x
#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the executio n # bits. # # By default this script does nothing. /usr/bin/mystartx exit 0 #這一行不要忘記 它涉及到另一個執行指令碼的需要,否則上面那個指令碼無法執行,或者執行也沒有用
這個指令碼也可以抄襲/usr/bin/startx,複製一個出來然後改名為mystartx,然後修改該指令碼
在這一行 xinit "$client" $clientargs -- "$server" $display $serverargs 前面新增
client=... clientargs=...
c【備註】.使用xinit命令啟動xserver和你自己編寫的介面程式
其實在這之前你可以嘗試一下在命令列介面執行自己的圖形程式,不過你首先需要關閉lightdm,命令是sudo service stop lightdm ,你只有關閉了圖形介面之後才能在xserver上執行自己的圖形介面程式,方式有其他更多種,這時候可以用xinit執行你的程式,
xinit [[client] options ] [-- [server] [display] options] 在這裡所有的程式路徑和引數路徑都需要輸入絕對路徑,類似我舉例說明:
xinit /usr/local/bin/electron /home/shaw/electron/workspace/myapp/. -- /usr/bin/Xorg :0
/usr/local/bin/electron是electron命令在的位置, /home/shaw/electron/workspace/myapp/. 是我編寫的electron在的位置,-- 是分割xserver和xclient引數的分隔符,/usr/bin/Xorg 是Xerver在ubuntu的執行命令, :0代表預設在第一塊顯示屏展示你的圖形介面程式。