換了新筆電,順手裝上最新的 Ubuntu 16.10,結果從舊機器搬資料過來時,發現系統裡竟然沒有 rc.local,當場傻眼。
查了一下才知道,原來 16.10 把 rc.local 服務化了。看來 systemd 獨立發展的決心很堅定。話說這個從 sysvinit 一路流傳下來的機制,生命力實在頑強,而且真的很好用。
先建立服務腳本:
sudo vi /etc/systemd/system/rc-local.service
[Unit] Description=/etc/rc.local Compatibility ConditionPathExists=/etc/rc.local [Service] Type=forking ExecStart=/etc/rc.local start TimeoutSec=0 StandardOutput=tty RemainAfterExit=yes SysVStartPriority=99 [Install] WantedBy=multi-user.target
其中 SysVStartPriority 這行可以刪掉,我在啟動日誌中看到它被忽略了。
接著讓服務生效:
sudo systemctl enable rc-local.service
然後就能照以前的格式編輯 /etc/rc.local,最後別忘了給它執行權:
chmod +x /etc/rc.local
編輯 /etc/default/grub:
GRUB_CMDLINUX="net.ifnames=0 biosdevname=0"
然後重建 grub 設定:
sudo grub-mkconfig -o /boot/grub/grub.cfg
後記:systemd 的時代已經來臨,是時候認真學一下 systemd 服務腳本的編寫了。