LoginSignup
6
4

More than 3 years have passed since last update.

ランレベルのことを今更調べてみた

Posted at

勉強前イメージ

シングルユーザモードでの起動とか、GUIの起動とか表すやつ
よく見るけど、正直あんま理解してない

調査

ランレベルとは?

linuxの動作モードのこと。
0から6までモードがあって、ランレベル毎にどのサービスが起動する・しないを決定しています
/etc/rc.d/rc*.d にあるファイルによって、各ランレベルで起動するプログラムを指定しています。

  • Redhat,CentOS等

systemd target に記載した内容が結構わかりやすいのではないかなと思います。

ランレベル systemd target 内容
0 runlevel0.target, poweroff.target 停止
1 runlevel1.target, rescue.target シングルユーザーモード、ネットワーク無し。rootでのログインが出来ないときに使用します
2 runlevel2.target, multi-user.target マルチユーザーモード(NFSマウントなし)
3 runlevel3.target, multi-user.target マルチユーザーモード(コンソール)、ネットワーク有り。通常の操作で使用されます。
4 runlevel4.target, multi-user.target 未使用
5 runlevel5.target, graphical.target マルチユーザーモード(X Windows)、ネットワーク有り。GUIでのログインの際に使用されます。
6 runlevel6.target, reboot.target システム再起動

実際にランレベルを見てみよう

  • runlevelコマンド

現在のランレベルがわかります。
1つ前のランレベル 現在のランレベル という順で表示されます。
1つ前のランレベルが N : システム起動後に一度も変更されてないときに使われる
現在のランレベルが 3 : 上記の表でいうと、ネットワークが接続されておりコンソールでのログインの際に表示されるランレベル ということがわかります。

[root@localhost ~]# runlevel
N 3
  • systemctlコマンド

こちらでも、同じように現在のランレベルが見れます。
multi-user.target なので、ランレベル3で確認出来ました

[root@localhost ~]# systemctl get-default
multi-user.target
  • chkconfigコマンド

httpdとか起動してるのに見えないな...
実はsystemdの配下にしたみたいです。

[root@localhost ~]# chkconfig --list

注記: この出力に含まれるのは SysV サービスのみです。ネイティブな 
      systemd サービスは含まれません。SysV の設定データはネイティブな
        systemd 設定で上書きされる場合があります。
      systemd サービスを一覧表示する場合は 'systemctl list-unit-files' を使用します。
      特定のターゲットで有効になっているサービスを確認する場合は
      'systemctl list-dependencies [target]'を使用します。

netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off
  • systemctl list-unit-files コマンド

ここには httpd とか含まれてた。
めっちゃ出てくる

[root@localhost ~]# systemctl list-unit-files
UNIT FILE                                     STATE   
proc-sys-fs-binfmt_misc.automount             static  
dev-hugepages.mount                           static  
dev-mqueue.mount                              static  
proc-sys-fs-binfmt_misc.mount                 static  
sys-fs-fuse-connections.mount                 stati
....

[root@localhost ~]# systemctl list-unit-files | grep httpd
httpd.service                                 disabled

勉強後イメージ

実際にちゃんと気にしたことはなかったかも。。。
シングルユーザーモードで入ったりはしたことあったけど。。
3と5ってコマンドかGUIって感じだけど、2と3って難しいよね。

参考

6
4
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
6
4