【Linux】起動時に実行するコマンドを管理する

RHEL8,9では/etc/rc.d/rc.localへ起動時に実行したいコマンドを書き込むことで、Linuxのシステムが起動した際に指定のコマンドが実行されます。
/etc/rc.localは/etc/rc.d/rc.localへのシンボリックリンクです。

下記コマンドでviエディタを開きます。

vi /etc/rc.d/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local

touch /var/lock/subsys/local以下に実行したいコマンドを記載します。

また、/etc/rc.d/rc.localはchmod +x /etc/rc.d/rc.localコマンドを実行して実行権限が付与されている必要があります。再起動して動作を試す前に必ず実行権限を付与しておきます。

Linuxの再起動は下記コマンドで行います。

shutdown -r now

タイトルとURLをコピーしました