これは資格取得の際に勉強した時の備忘録です。
Linuxのコマンドの機能の説明と自分の環境での実行結果です。
各コマンドの動作を覚えておく為に記録しました。
2.1.1
BIOS:Basic input/Output System の意
dmesgコマンド
カーネル起動中のメッセージログ
nvidia関連のものを確認する時
$ dmesg | grep nvidia
[ 9.321249] nvidia: module license 'NVIDIA' taints kernel.
[ 9.324407] nvidia: module verification failed: signature and/or required key missing - tainting kernel
[ 9.329031] nvidia-nvlink: Nvlink Core is being initialized, major device number 248
[ 9.329841] nvidia-modeset: Loading NVIDIA Kernel Mode Setting Driver for UNIX platforms 375.39 Tue Jan 31 19:41:48 PST 2017
[ 9.330121] [drm] [nvidia-drm] [GPU ID 0x00000400] Loading driver
[ 12.765407] nvidia 0000:04:00.0: irq 45 for MSI/MSI-X
[ 13.629293] nvidia-modeset: Allocated GPU:0 (GPU-01507892-4373-60ca-4bcc-5b160bb7f7b8) @ PCI:0000:04:00.0
initプロセス
カーネルが最初に起動するプロセス
/etc/inittabの設定から起動処理を行う
/etc/inittabの記載方法
ランレベル 処理
2:2345:respawn:/sbin/mingetty tty2
ID アクション指示子
アクション支持子:
-boot:システム起動時に実行さえr、プロセスの終了を待たずに次の処理を実行
bootwait:システム起動時に一度実行され、プロセスが終了するまで次の処理を行わない
ctrlaltdel:Ctrl,Alt,Deleteキーが同時に押されるSIGINTがinitに送られた場合に実行する
initdefault:デフォルトのランレベルを指定する:
once:指定したランレベルになったときに一度だけ実行され、プロセスの終了を待たずに次の処理を行う
respawn:プロセスが終了すれば再起動させる
sysinit:システム起動時にbootやbootwaitより先に実行
ランレベル
各ランレベル毎の起動スクリプトはそれぞれ/etc/rc[0-6].dに格納
ランレベル切り替え時に実行される
keigo@keigo-desktop:~/Devel$ ls /etc/rc0.d
K10unattended-upgrades K20rsync S30urandom S90halt
K20dirmngr K20speech-dispatcher S31umountnfs.sh
K20docker README S40umountfs
K20kerneloops S20sendsigs S60umountroot
keigo@keigo-desktop:~/Devel$ ls /etc/rc3.d
README S20kerneloops S20sysstat S70pppd-dns S99rc.local
S20dirmngr S20rsync S50saned S99grub-common
S20docker S20speech-dispatcher S70dns-clean S99ondemand
起動スクリプトとランレベル
/etc/rc[0-6].dの中に起動スクリプトが存在
keigo@keigo-desktop:~$ ls /etc/rc0.d
K10unattended-upgrades K20rsync S30urandom S90halt
K20dirmngr K20speech-dispatcher S31umountnfs.sh
K20docker README S40umountfs
K20kerneloops S20sendsigs S60umountroot
これらの実態は/etc/init.dディレクトリ以下のファイル
格納されているのはシンボリックリンクである
Sで始まるサービスはそのランレベルに切り替えた時に開始する
数値の小さい順にサービスは起動され
Kで始まるサービスはそのランレベルに切り替えた時に終了する
終了される時も数値が小さいものから終了する
例
keigo@keigo-desktop:~$ ls -l /etc/rc0.d/
合計 4
lrwxrwxrwx 1 root root 29 1月 9 16:30 K10unattended-upgrades -> ../init.d/unattended-upgrades
lrwxrwxrwx 1 root root 17 2月 19 11:05 K20dirmngr -> ../init.d/dirmngr
lrwxrwxrwx 1 root root 16 2月 19 12:10 K20docker -> ../init.d/docker
lrwxrwxrwx 1 root root 20 1月 9 16:30 K20kerneloops -> ../init.d/kerneloops
lrwxrwxrwx 1 root root 15 1月 9 16:30 K20rsync -> ../init.d/rsync
lrwxrwxrwx 1 root root 27 1月 9 16:30 K20speech-dispatcher -> ../init.d/speech-dispatcher
-rw-r--r-- 1 root root 353 3月 13 2014 README
lrwxrwxrwx 1 root root 18 1月 9 16:30 S20sendsigs -> ../init.d/sendsigs
lrwxrwxrwx 1 root root 17 1月 9 16:30 S30urandom -> ../init.d/urandom
lrwxrwxrwx 1 root root 22 1月 9 16:30 S31umountnfs.sh -> ../init.d/umountnfs.sh
lrwxrwxrwx 1 root root 18 1月 9 16:30 S40umountfs -> ../init.d/umountfs
lrwxrwxrwx 1 root root 20 1月 9 16:30 S60umountroot -> ../init.d/umountroot
lrwxrwxrwx 1 root root 14 1月 9 16:30 S90halt -> ../init.d/halt
[root@d9499b9f062e /]# /etc/init.d/httpd status
httpd is stopped
[root@d9499b9f062e /]# /etc/init.d/httpd condrestart
[root@d9499b9f062e /]# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.6 for ServerName
[ OK ]
[root@d9499b9f062e /]# /etc/init.d/httpd condrestart
Stopping httpd: [ OK ]
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.6 for ServerName
[ OK ]
##chkconfig コマンド
[root@d9499b9f062e /]# chkconfig --list
htcacheclean 0:off 1:off 2:off 3:off 4:off 5:off 6:off
httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
netfs 0:off 1:off 2:off 3:on 4:on 5:on 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
rdisc 0:off 1:off 2:off 3:off 4:off 5:off 6:off
restorecond 0:off 1:off 2:off 3:off 4:off 5:off 6:off
udev-post 0:off 1:on 2:on 3:on 4:on 5:on 6:off
[root@d9499b9f062e /]# chkconfig --list httpd
httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@d9499b9f062e /]# chkconfig httpd on
[root@d9499b9f062e /]# chkconfig --list httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@d9499b9f062e /]# chkconfig httpd off
[root@d9499b9f062e /]# chkconfig --list httpd
httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@d9499b9f062e /]# chkconfig --level 235 httpd on
[root@d9499b9f062e /]# chkconfig --list httpd
httpd 0:off 1:off 2:on 3:on 4:off 5:on 6:off
update-rc.d コマンド
Debian系(Ubuntuとかraspberry piのraspbianとか)
init.d配下のコマンドのシンボリックリンクを作る
起動時に起動しておくサービスの設定が出来る
keigo@keigo-desktop:~$ update-rc.d docker defaults
System start/stop links for /etc/init.d/docker already exist.
試しにdockerのシンボリックリンクを削除し作成する
update-rc.d -f docker remove
keigo@keigo-desktop:~$ sudo update-rc.d -f docker remove
[sudo] password for keigo:
Removing any system startup links for /etc/init.d/docker ...
/etc/rc0.d/K20docker
/etc/rc1.d/K20docker
/etc/rc2.d/S20docker
/etc/rc3.d/S20docker
/etc/rc4.d/S20docker
/etc/rc5.d/S20docker
/etc/rc6.d/K20docker
insservコマンド
insserv [-r] サービス名
Pr
Upstart
SysVinit系のinitでは決められた順にサービスを起動していくので
起動時に待たされるサービスが出てくる。
Upstartの方法ではイベントに応じてサービスの起動や終了を行う
Upstartの設定ファイルは/etc/initディレクトリ配下に設置されている
$ ls /etc/init
acpid.conf mountnfs.sh.conf
alsa-restore.conf mtab.sh.conf
alsa-state.conf network-interface-container.conf
alsa-store.conf network-interface-security.conf
anacron.conf network-interface.conf
apport.conf network-manager.conf
.
.
.
initctl
ジョブ制御のコマンド
Upsatrtにより制御されるものをジョブという
ジョブにはデーモンのような常駐型サービスと処理実行後に終了するタスクがある
start ジョブ:ジョブの開始
keigo@keigo-desktop:~$ initctl start indicator-printers
indicator-printers start/running, process 3220
stop ジョブ:ジョブの停止
$ initctl stop indicator-printers
indicator-printers stop/waiting
restart ジョブ:ジョブの再起動
keigo@keigo-desktop:~$ initctl restart indicator-printers
indicator-printers start/running, process 3226
reload ジョブ:ジョブにHUPシグナルを送る
status ジョブ:ジョブのステータスを表示
keigo@keigo-desktop:~$ initctl status gnome-keyring-gpg
gnome-keyring-gpg stop/waiting
list ジョブ:ジョブの一覧を表示
$ initctl list
gnome-keyring-gpg stop/waiting
indicator-application start/running, process 1975
unicast-local-avahi stop/waiting
update-notifier-crash (/var/crash/susres.2017-02-17_21:10:27.814451.crash) start/running, process 1436
update-notifier-crash (/var/crash/_usr_bin_Xorg.0.crash) start/running, process 1429
emit ジョブ:イベントを発生させる
GRUB(GRand Unified Bootloader)
Ubuntu14.04とか自分の環境でも使われているBoot Loader
version 0.9x系=GRUB Legacy
version 1.9x系=GRUB
GRUB Legacyはつぎの3 stageで構成される
1 MBR内に配置されステージ1.5または2をロードするプログラム
1.5 Stage2を見つけロードするプログラム
2 /boot/grub以下にあるGRUBの本体(/boot/brub/stage2)
GRUB Legacyの設定ファイルは/boot/grub/menu.lst
パラメーターは下記
timeout:メニューを表示している時間
default:デフォルトで起動するOSのエントリ番号
splashimage:メニューが表示されている時の背景画像
title:メニューに表示されるOSの名前
root:カーネルイメージもしくはOSが格納されているパーティションの指定
kernel
initrd:初期RAMディスクファイルの指定
makeactive:
chinloader
grubコマンド
インストールすれば対話的に /bootパーティションのディスクの指定等が出来る
終了時はquitコマンドで終わる
$ grub
Probing devices to guess BIOS drives. This may take a long time.
[ Minimal BASH-like line editing is supported. For
the first word, TAB lists possible command
completions. Anywhere else TAB lists the possible
completions of a device/filename. ]
grub>
世の中にはGRUB2もある
Ubuntuでデフォルトで設定されているのはこっちのようで
/boot/grub/grub.cfgが設定ファイルである
update-grubコマンドを実行すると
/etc/default/grubの設定に基づいて/boot/grub/grub.cfgが生成される
$ ls /boot/grub/grub.cfg
/boot/grub/grub.cfg
update-grubコマンド
設定ファイル
$ head -20 /etc/default/grub
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
# info -f grub -n 'Simple configuration'
GRUB_DEFAULT=0
#GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
#GRUB_CMDLINE_LINUX="find_preseed=/preseed.cfg auto noprompt priority=critical locale=en_US cgroup_enable=memory swapaccount=1"
GRUB_CMDLINE_LINUX=""
update-grub2コマンド
/etc/default/grubの設定パラメータから
/boot/grub/grub.cfgが生成される
※これは依存関係の問題でインストールできなかったのでupdate-grubコマンドを使った
$ sudo update-grub
Searching for GRUB installation directory ... found: /boot/grub
Searching for default file ... found: /boot/grub/default
Testing for an existing GRUB menu.lst file ... found: /boot/grub/menu.lst
Searching for splash image ... none found, skipping ...
Found kernel: /boot/vmlinuz-3.13.0-106-generic.efi.signed
Found kernel: /boot/vmlinuz-3.13.0-106-generic
Found kernel: /boot/vmlinuz-3.13.0-24-generic
Found kernel: /boot/memtest86+.bin
Updating /boot/grub/menu.lst ... done
menu.lstはなければこれで更新される
$ tail -30 /boot/grub/menu.lst
title Ubuntu 14.04.5 LTS, kernel 3.13.0-106-generic.efi.signed (recovery mode)
uuid 5a8810e6-f007-4d2b-9eaa-e6604f789020
kernel /boot/vmlinuz-3.13.0-106-generic.efi.signed root=UUID=5a8810e6-f007-4d2b-9eaa-e6604f789020 ro single