Debian 8 -- 起動後にスクリプトを実行する

Debian 8 -- 起動後にスクリプトを実行する

起動後にパスしようとしました/etc/rc.local

/etc/rc.local

#!/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 execution
# bits.
#
# By default this script does nothing.
/home/startup.sh

exit 0

/home/startup.sh

mount -t vboxsf test /home/test

スタートアップの結果です

ここに画像の説明を入力してください。

これが出力ですsystemctl status rc-local.service

rc-local.service - /etc/rc.local Compatibility
   Loaded: loaded (/lib/systemd/system/rc-local.service; static)
   Active: failed (Result: exit-code) since Sun 2016-02-07 22:48:23 ICT; 18min ago
  Process: 432 ExecStart=/etc/rc.local start (code=exited, status=1/FAILURE)

Feb 07 22:48:23 debian rc.local[432]: /sbin/mount.vboxsf: mounting failed with the error: No such device
Feb 07 22:48:23 debian systemd[1]: rc-local.service: control process exited, code=exited status=1
Feb 07 22:48:23 debian systemd[1]: Failed to start /etc/rc.local Compatibility.
Feb 07 22:48:23 debian systemd[1]: Unit rc-local.service entered failed state.

手動で実行してみました。sudo bash /home/startup.shそしてそれは素晴らしい作品です。私もこの方法を適用しましたが、Ubuntu 14.04エラーは発生しませんでした。

今回の失敗の理由は何でしたか?どうすれば解決できますか?

ベストアンサー1

問題はrc-local.service開始前に発生したようですが、vboxadd-service.service起動後に実行する必要があります。rc.localこれはSysV(起動プロセスの最後に実行されます)であり、systemdが提供する互換性は完璧ではありません(スクリーンショットに示すように)。home-test.mount次のカスタムユニットを使用する方が良いでしょう。

[Unit]
Requires=vboxadd-service.service
After=vboxadd-service.service

[Mount]
What=test
Where=/home/test
Type=vboxsf

[Install]
WantedBy = multi-user.target

その後、通話をsystemctl enable home-test.mount削除して再開して新しい設定をテストします。/home/startup.sh/etc/rc.local

警告:私はVirtualBoxの経験がなく、インストールデバイスの経験もほとんどありません。しかし、あなたはポイントを理解しています。

おすすめ記事