LoginSignup
19
13

More than 5 years have passed since last update.

rc.localが消えたUbuntu 16.04でコマンド自動実行

Posted at

tlpの--auto-tuneをしようと思った時、いつもどおりrc.localに書こうとしたら、まさかの存在しないではないですか!?

 ~ $ ls /etc/rc.local 
ls: '/etc/rc.local' にアクセスできません: そのようなファイルやディレクトリはありません

おそらく、initからsystemd(serviceからsystemctl)にサービス関連が移行されつつあるので、それに関連してのことでしょう。

なので、起動時にコマンドを自動実行するサービスを一個追加しておきましょう。

[Unit]
Description=auto start commands in /etc/onboot.sh on boot

[Service]
Type=simple
ExecStart=/etc/onboot.sh
User=vagrant

[Install]
WantedBy=multi-user.target

私はこんな感じにしました。

そして

$ sudo touch /etc/onboot.sh

こんな感じでroot権限でファイルを作ってあげればOK。

あとはいつもどおり、

$ sudo systemctl enable onboot.service 
Created symlink /etc/systemd/system/multi-user.target.wants/onboot.service → /etc/systemd/system/onboot.service.

すれば完成。好きなコマンドを、こんどは/etc/rc.localから/etc/onboot.shに突っ込んでどうぞ!

以上!

19
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
13