sysctl
何するコマンド?
書き方
sysctl [オプション] [パラメータ名=値]
オプション
| オプション | 説明 | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| -a | すべての設定値を表示する Display all values currently available. | ||||||||||||||||||||||||||||||||||
| --all | すべての設定値を表示する Display all values currently available. | ||||||||||||||||||||||||||||||||||
| -A | 「-a」と同じ Alias of -a | ||||||||||||||||||||||||||||||||||
| -X | 「-a」と同じ Alias of -a | ||||||||||||||||||||||||||||||||||
| -b | 1行でずらずらっと表示する。多分、値だけが表示されている Print value without new line. | ||||||||||||||||||||||||||||||||||
| --binary | 1行でずらずらっと表示する。多分、値だけが表示されている Print value without new line. | ||||||||||||||||||||||||||||||||||
| -e | 不明なキーのエラーを無視する Use this option to ignore errors about unknown keys. | ||||||||||||||||||||||||||||||||||
| --ignore | 不明なキーのエラーを無視する Use this option to ignore errors about unknown keys. | ||||||||||||||||||||||||||||||||||
| -N | キー名だけ表示する(値を表示しない) Use this option to only print the names. It may be useful with shells that have programmable completion. | ||||||||||||||||||||||||||||||||||
| --names | キー名だけ表示する(値を表示しない) Use this option to only print the names. It may be useful with shells that have programmable completion. | ||||||||||||||||||||||||||||||||||
| -n | 値だけ表示する(キー名を表示しない) Use this option to disable printing of the key name when printing values. | ||||||||||||||||||||||||||||||||||
| --values | 値だけ表示する(キー名を表示しない) Use this option to disable printing of the key name when printing values. | ||||||||||||||||||||||||||||||||||
| -p【ファイル名】 | ファイルから読み込んだ内容をsysctlのパラメータに設定する。 Load in sysctl settings from the file specified or /etc/sysctl.conf if none given. Specifying as filename means reading da --load=【ファイル名】 | ファイルから読み込んだ内容をsysctlのパラメータに設定する。 | Load in sysctl settings from the file specified or /etc/sysctl.conf if none given. Specifying as filename means reading data from standard input. Using this option will mean arguments to sysctl are files, which are read in the order they are specified. The file argument may be specified as regular expression. -f | 「-p」と同じ | Alias of -p -r | うんちゃらかんちゃら | Only apply settings that match pattern. The pattern uses extended regular expression syntax. --pattern | うんちゃらかんちゃら | Only apply settings that match pattern. The pattern uses extended regular expression syntax. -q | 画面に表示しない? | Use this option to not display the values set to stdout. --quiet | 画面に表示しない? | Use this option to not display the values set to stdout. -w | sysctlの設定を変更したいときは、このオプションを使ってね? | Use this option when you want to change a sysctl setting. --write | sysctlの設定を変更したいときは、このオプションを使ってね? | Use this option when you want to change a sysctl setting. -o | ないよ | Does nothing, exists for BSD compatibility. -x | ないよ | Does nothing, exists for BSD compatibility. -d | 「-h」と同じ | Alias of -h --deprecated | うんちゃらかんちゃら | Include deprecated parameters to --all values listing. --system | あれやこれやの設定ファイルから読み込むよ | Load settings from all system configuration files. /run/sysctl.d/*.conf /etc/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /lib/sysctl.d/*.conf /etc/sysctl.conf -h | ヘルプを表示する | display this help and exit --help | ヘルプを表示する | display this help and exit -V | バージョン情報を表示する | output version information and exit --version | バージョン情報を表示する | output version information and exit |
補足事項
順番に見ていきましょう。
まずは予備知識として「OS」と「カーネル」について簡単に説明します。
「そんなの説明されなくても知ってるよ!」な人は適当に読み飛ばしてください。
OSは「パソコンさんの人格に相当するソフト」です。
パソコンさんは中にOSを入れることで、はじめてパソコンとしての お仕事が できます。
「これが無いとパソコンじゃねーよ」な基本ソフトです。
※「OS」という用語が世間に広まった きっかけがパソコンなので「パソコン」と書きましたが、スマホや その他のコンピュータ類でも同じです。
カーネルは「OSの中核部分として頑張っているソフトウェア」です。
OSを1つの組織と見なした場合、カーネルさんは中心人物です。
こいつがいないと始まりません。
ただし、カーネルさんだけでは組織の運営が成り立ちません。
シェルやデーモンといった、その他のソフトウェアを手足のように使うことによって、はじめて組織が回ります。
「カーネルさんは大事なやつだけど、カーネルさんだけではOSは成り立たない」と理解してください。
カーネルさんと あれやこれやのソフトウェアが組み合わさって、1つのOSが出来あがっているのです。
カーネルさんには、動かすときのパラメータが、あれやこれやとあります。
「パラメータ」と言われてもよく分からない人は設定値だと思ってください。
値を変更すると、カーネルさんの動きや状態が変わります。
以上を踏まえて
カーネルのパラメータを変更するときに使うコマンド
が「sysctl」コマンドです。
使い方は、そんなに難しくありません。
「-a」オプションを指定して
sysctl -a
を実行すると、すべてのパラメータが表示されます。
私の環境では以下の内容が表示されました。
abi.vsyscall32 = 1
crypto.fips_enabled = 0
debug.exception-trace = 1
debug.kprobes-optimization = 1
dev.cdrom.autoclose = 1
dev.cdrom.autoeject = 0
dev.cdrom.check_media = 0
dev.cdrom.debug = 0
dev.cdrom.info = CD-ROM information, Id: cdrom.c 3.20 2003/12/17
dev.cdrom.info =
(以下略)
値を設定するときは
設定項目=値
形式で設定します。
例えば
sysctl debug.exception-trace=0
を実行すると「debug.exception-trace」に「0」が表示されます。
これが「sysctl」コマンドの基本的な使い方です。
オプションについては必要に応じて情報を補完してください。
ちなみに、パラメータの設定項目と値は
/proc/sys
配下に、項目ごとにファイルが分かれて保存されています。
例えば
debug.exception-trace
は
(/proc/sys)/debug/exception-trace
です。
「.」がディレクトリの区切りになります。
例えば
sysctl debug.exception-trace
の実行結果が
debug.exception-trace = 1
だったとしましょう。
パラメータ「debug.exception-trace」の設定値は「1」です。
この状態で
more /proc/sys/debug/exception-trace
を実行すると
1
と表示されます。
この状態で
sysctl debug.exception-trace=0
を実行します。
パラメータ「debug.exception-trace」の値が「0」に変更されました。
この状態で
more /proc/sys/debug/exception-trace
を実行すると
0
と表示されます。
パラメータ「debug.exception-trace」の設定値が「/proc/sys/debug/exception-trace」に保存されていることが分かります
