태그:                                 

rc.local을 활성화하면 원하는 명령을 추가해서 부팅 시 해당 명령을 실행할 수 있다.

하지만 우분투 리눅스에는 rc.local이 활성화되어있지 않다.

rc.local을 활성화하려면 아래의 단계를 거쳐야 된다.

1. rc.local이 활성상태인지 확인하기

아래의 명령으로 rc.local이 활성화상태인지 확인할 수 있다.

$ systemctl status rc-local

위의 명령을 실행하면 아래와 같이 나오는데, 맨 끝에 보면 Active: inactive (dead)라고 비활성상태로 표시된다.

○ rc-local.service - /etc/rc.local Compatibility
Loaded: loaded (/lib/systemd/system/rc-local.service; disabled; vendor preset: enabled)
Drop-In: /usr/lib/systemd/system/rc-local.service.d
└─debian.conf
Active: inactive (dead)
Docs: man:systemd-rc-local-generator(8)

2. rc.local 파일 만들기

root 권한으로 vi나 gedit, nano 등의 에디터를 이용해서 /etc/rc.local 파일을 생성한다.

$ sudo vi /etc/rc.local

입력할 내용은 다음과 같다.

#!/bin/bash

exit 0

3. rc.local 파일에 실행 플래그 설정하기

rc.local 파일이 실행가능해야 부팅 시 실행되므로 chmod를 이용해서 실행 플래그를 설정한다.

$ sudo chmod +x /etc/rc.local

4. 서비스 등록을 위한 설정파일 편집하기

아래의 명령으로 파일이 있는지 확인한다.

$ cat /lib/systemd/system/rc-local.service

위 명령을 실행했을 때 아래와 같이 나오면 파일이 있는 것이므로 수정만 하면된다.

#  SPDX-License-Identifier: LGPL-2.1-or-later
#
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.

# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.local is executable.
[Unit]
Description=/etc/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no

이제 에디터(vi, gedit, nano 등)로 파일을 열고

$ sudo vi /lib/systemd/system/rc-local.service

아래의 내용을 추가한다.

[Install]
WantedBy=multi-user.target

추가한 후의 내용은 아래와 같으며, 이 파일이 아예 없으면 아래와 같이 전체를 추가한다.

#  SPDX-License-Identifier: LGPL-2.1-or-later
#
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.

# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.local is executable.
[Unit]
Description=/etc/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no

[Install]
WantedBy=multi-user.target

5. 서비스 등록 및 서비스 시작하기

위의 설정파일 편집까지 끝났으면 아래와 같이 해서 서비스로 등록한다.

$ sudo systemctl enable rc-local.service

처음 실행했을 때는 아래와 같은 메시지가 나오는데, 다시 실행하면 아무런 메시지도 나오지 않는게 정상이다.

Created symlink /etc/systemd/system/multi-user.target.wants/rc-local.service → /lib/systemd/system/rc-local.service.

다음으로 아래와 같이 해서 서비스를 시작한다.

$ sudo systemctl start rc-local.service

아무런 메시지도 없이 넘어가면 정상이다.

이제 다시 처음에 했던 상태를 보는 명령어인 다음과 같은 명령을 입력해보자.

$ sudo systemctl status rc-local

아래와 같이 Active: active라고 나온다.

● rc-local.service - /etc/rc.local Compatibility
Loaded: loaded (/lib/systemd/system/rc-local.service; enabled; vendor preset: enabled)
Drop-In: /usr/lib/systemd/system/rc-local.service.d
└─debian.conf
Active: active (exited) since Sat 2024-01-13 13:11:16 KST; 9min ago
Docs: man:systemd-rc-local-generator(8)
Process: 3650 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)
CPU: 7ms

6. 원하는 명령 등록하기

이제 /etc/rc.local에 원하는 명령을 넣고 재부팅하면 부팅 시 해당 명령이 실행된다.

나는 키보드 반복 지연시간 및 반복 횟수를 등록했다.

#! /bin/sh

gsettings set org.gnome.desktop.peripherals.keyboard repeat-interval 33
gsettings set org.gnome.desktop.peripherals.keyboard delay 200

exit 0

위와 같이 등록하면 키반복 지연시간이 200mS로 설정되고, 33mS(초당 30회)마다 반복입력된다.

관련글

우분투 리눅스에서 rc.local 활성화하기

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다