第9章 システムに関するティップ

目次

9.1. The console tips
9.1.1. シェルの活動を綺麗に記録
9.1.2. screen プログラム
9.1.3. Navigating around directories
9.1.4. Readline wrapper
9.1.5. Scanning the source code tree
9.2. Vim のカスタム化
9.2.1. Customizing vim with internal features
9.2.2. Customizing vim with external packages
9.3. データーの記録と表現
9.3.1. ログデーモン
9.3.2. ログアナライザー
9.3.3. テキストデーターのカスタム化表示
9.3.4. 時間と日付のカスタム化表示
9.3.5. 着色化されたシェル出力
9.3.6. 着色化されたコマンド
9.3.7. 複雑な反復のためにエディターでの活動を記録
9.3.8. X アプリケーションの画像イメージの記録
9.3.9. 設定ファイルの変更記録
9.4. プログラム活動の監視と制御と起動
9.4.1. プロセスの時間計測
9.4.2. スケジューリングの優先度
9.4.3. ps コマンド
9.4.4. top コマンド
9.4.5. プロセスによって開かれているファイルのリスト
9.4.6. プログラム活動の追跡
9.4.7. ファイルやソケットを使っているプロセスの識別
9.4.8. 一定間隔でコマンドを反復実行
9.4.9. ファイルに関してループしながらコマンドを反復実行
9.4.10. GUI からプログラムをスタート
9.4.11. スタートするプログラムのカスタム化
9.4.12. プロセスの停止
9.4.13. タスク1回実行のスケジュール
9.4.14. タスク定期実行のスケジュール
9.4.15. Alt-SysRq キー
9.5. システム管理ティップ
9.5.1. だれがシステムを利用している?
9.5.2. 全員への警告
9.5.3. ハードウエアーの識別
9.5.4. ハードウエアー設定
9.5.5. システムとハードウエアーの時間
9.5.6. ターミナルの設定
9.5.7. 音のインフラ
9.5.8. スクリーンセーバーの無効化
9.5.9. ブザー音の無効化
9.5.10. メモリー使用状況
9.5.11. システムのセキュリティーと整合性のチェック
9.6. データー保存のティップ
9.6.1. ディスク空間の利用状況
9.6.2. ディスクパーティション設定
9.6.3. UUID を使ってパーティションをアクセス
9.6.4. LVM2
9.6.5. ファイルシステム設定
9.6.6. ファイルシステムの生成と整合性チェック
9.6.7. マウントオプションによるファイルシステムの最適化
9.6.8. スーパーブロックによるファイルシステムの最適化
9.6.9. ハードディスクの最適化
9.6.10. ソリッドステートドライブの最適化
9.6.11. SMART を用いたハードディスクの破壊の予測
9.6.12. $TMPDIR 経由で一時保存ディレクトリーを指定
9.6.13. LVM を使う使用可能なストレージ空間の拡張
9.6.14. 他パーティションをマウントする使用可能なストレージ空間の拡張
9.6.15. 他ディレクトリーをバインドマウントする使用可能なストレージ空間の拡張
9.6.16. 他ディレクトリーをオーバーレーマウントすることで使用可能なストレージ空間を拡張
9.6.17. シムリンクを使う使用可能なストレージ空間の拡張
9.7. ディスクイメージ
9.7.1. ディスクイメージの作成
9.7.2. ディスクに直接書込み
9.7.3. ディスクイメージファイルをマウント
9.7.4. ディスクイメージのクリーニング
9.7.5. 空のディスクイメージ作成
9.7.6. ISO9660 イメージファイル作成
9.7.7. CD/DVD-R/RW に直接書込み
9.7.8. ISO9660 イメージファイルをマウント
9.8. バイナリーデーター
9.8.1. バイナリーデーターの閲覧と編集
9.8.2. ディスクをマウントせずに操作
9.8.3. データーの冗長性
9.8.4. データーファイルの復元と事故の証拠解析
9.8.5. 大きなファイルを小さなファイルに分割
9.8.6. ファイル内容の消去
9.8.7. ダミーファイル
9.8.8. ハードディスクの全消去
9.8.9. ハードディスク未使用部分の全消去
9.8.10. 削除されたがまだオープン中のファイルの復活法
9.8.11. 全てのハードリンクを検索
9.8.12. 見えないディスクスペースの消費
9.9. データー暗号化ティップ
9.9.1. dm-crypt/LUKS を使ったリムーバブルディスクの暗号化
9.9.2. dm-crypt/LUKS で暗号化されたディスクのマウント
9.10. カーネル
9.10.1. カーネル変数
9.10.2. カーネルヘッダー
9.10.3. カーネルと関連モジュールのコンパイル
9.10.4. カーネルソースのコンパイル: Debian カーネルチーム推奨
9.10.5. ハードウエアードライバーとファームウエアー
9.11. 仮想化システム
9.11.1. Virtualization and emulation tools
9.11.2. 仮想化の業務フロー
9.11.3. 仮想ディスクイメージファイルをマウント。
9.11.4. Chroot システム
9.11.5. 複数のデスクトップシステム

主にコンソールからシステムを設定や管理する基本的なティップを次に記します。

There are some utility programs to help your console activities.


単に script(1) を使ってシェル活動を記録すると (「シェル活動の記録」参照下さい)、コントロール文字の入ったファイルが生成されます。このような事は次のようにして col(1) を使うことで避けられます。

$ script
Script started, file is typescript

何なりとします … そして script から脱出するために Ctrl-D を押します。

$ col -bx < typescript > cleanedfile
$ vim cleanedfile

シェルの活動を記録する他の方法もあります:

  • tee を使う (initramfs 中のブートプロセスで有用):

    $ sh -i 2>&1 | tee typescript
  • Use gnome-terminal with the extend line buffer for scrollback.

  • Use screen with "^A H" (see 「screen プログラム」) to perform recording of console.

  • Use vim with ":terminal" to enter the terminal mode. Use "Ctrl-W N" to exit from terminal mode to normal mode. Use ":w typescript" to write the buffer to a file.

  • Use emacs with "M-x shell", "M-x eshell", or "M-x term" to enter recording console. Use "C-x C-w" to write the buffer to a file.

screen(1) は複数のプロセスを1つのターミナルウィンドウでうまく動作させるのみならず、接続が中断してもリモートシェルプロセスを生き延びさせる事もできます。screen(1) の使われ方の典型的シナリオは次です。

  1. リモート機器にログインします。

  2. 単一のコンソール上で screen を起動します。

  3. ^A c ("Control-A" に続いて "c") によって作られた screen のウィンドウ中で複数のプログラムを実行します。

  4. ^A n ("Control-A" に続いて "n") によって、複数の screen のウィンドウ間を切り替えます。

  5. 突然ターミナルを離れる必要ができたけれども、接続を継続してあなたが実行中の作業を失いたくありません。

  6. 次のようないかなる方法ででも、screen のセッションをデタッチできます。

    • 暴力的にネットワーク接続を引き抜く

    • ^A d ("Control-A" に続いて "d") とタイプしてリモート接続から手動でログアウト

    • ^A DD ("Control-A" に続いて "DD") とタイプして screen をデタッチしてログアウト

  7. 同じリモート機器に (たとえ異なるターミナルからでも) 再びログインします。

  8. screen を"screen -r" として起動します。

  9. screen は全アクティブなプログラムが実行されている過去の全 screen ウィンドウを魔法のようにリアタッチします。

[ヒント] ヒント

screen を使うと、切断してもプロセスをアクティブにしておけその後で再接続した時にリアタッチできるので、ダイヤルアップやパケット接続のような計量されたネットワーク接続での接続料金の節約ができます。

screen セッションではコマンドキーストローク以外の全てのキーボード入力は現在のウィンドウに送られます。全ての screen コマンドキーストロークは ^A ("Control-A") と単一キー [プラス何らかのパラメーター] をタイプすることによって入力されます。次に覚えておくべき重要なコマンドキーストロークを記します。


詳細は screen(1) を参照下さい。

代替コマンドの機能については tmux(1) を参照下さい。

In 「Bash のカスタム化」, 2 tips to allow quick navigation around directories are described: $CDPATH and mc.

If you use fuzzy text filter program, you can do without typing the exact path. For fzf, include following in ~/.bashrc.

FZF_KEYBINDINGS_PATH=/usr/share/doc/fzf/examples/key-bindings.bash
if [ -f $FZF_KEYBINDINGS_PATH ]; then
  . $FZF_KEYBINDINGS_PATH
fi
FZF_COMPLETION_PATH=/usr/share/doc/fzf/examples/completion.bash
if [ -f $FZF_COMPLETION_PATH ]; then
  . $FZF_COMPLETION_PATH
fi

たとえば:

  • You can jump to a very deep subdirectory with minimal efforts. You first type "cd **" and press Tab. Then you will be prompted with candidate paths. Typing in partial path strings, e.g., s/d/b foo, will narrow down candidate paths. You select the path to be used by cd with cursor and return keys.

  • You can select a command from the command history more efficiently with minimal efforts. You press Ctrl-R at the command prompt. Then you will be prompted with candidate commands. Typing in partial command strings, e.g., vim d, will narrow down candidates. You select the one to be used with cursor and return keys.

After you learn basics of vim(1) through 「Using vim」, please read Bram Moolenaar's "Seven habits of effective text editing (2000)" to understand how vim should be used.

[注意] 注意

Don't try to change the default key bindings without very good reasons.

The behavior of vim can be changed significantly by enabling its internal features through the Ex-mode commands such as "set ..." to set vim options.

These Ex-mode commands can be included in user's vimrc file, traditional "~/.vimrc" or git-friendly "~/.vim/vimrc". Here is a very simple example [2]:

colorscheme murphy             " from /usr/share/vim/vim??/colors/*.vim
filetype plugin indent on      " filetype aware behavior
syntax enable                  " Syntax highlight
"set spelllang=en_us            " Spell check language as en_us
"set spell                      " Enable spell check
set autoindent                 " Copy indent from current line
set smartindent                " More than autoindent (Drop/Pop after {/})
set nosmarttab                 " <Tab>-key always inserts blanks
set backspace=indent,eol,start " Back space through everything
set laststatus=2               " Always show status line
set statusline=%<%f%m%r%h%w%=%y[U+%04B]%2l/%2L=%P,%2c%V

Simple customization to enable secure-modelines and classical IDE can be enabled by installing vim-scripts package and appending the following to user's vimrc file.

packadd! secure-modelines
packadd! winmanager
let mapleader = ' '
" Toggle paste mode with <SPACE>p
set pastetoggle=<leader>p
" IDE-like UI for files and buffers with <space>w
nnoremap <leader>w         :WMToggle<CR>
" Use safer keys <C-?> for moving to another window
nnoremap <C-H>         <C-W>h
nnoremap <C-J>         <C-W>j
nnoremap <C-K>         <C-W>k
nnoremap <C-L>         <C-W>l

In order for the above keybindings to function properly, the terminal program needs to be configured to generate "ASCII DEL" for Backspace-key and "Escape sequence" for Delete-key.

The new native Vim package system works nicely with "git" and "git submodule". One such example configuration can be found at my git repository: dot-vim. This does essentially:

  • By using "git" and "git submodule", latest external packages, such as "name", are placed into ~/.vim/pack/*/opt/name and similar.

  • By adding :packadd! name line to user's vimrc file, these packages are placed on runtimepath.

  • Vim loads these packages on runtimepath during its initialization.

  • At the end of its initialization, tags for the installed documents are updated with "helptags ALL".

For more, please start vim with "vim --startuptime vimstart.log" to check actual execution sequence and time spent for each step.

Interesting external plugin packages can be found:

It is quite confusing to see too many ways[3] to manage and load these external packages to vim. Checking the original information is the best cure.


more(1) や less(1) 等のページャーツール (「ページャー」参照下さい) や、ハイライトやフォーマット用のカスタムツール (「プレーンテキストデーターをハイライトとフォーマット」参照下さい) はテキストデーターを綺麗に表示できますが、汎用エディター (「テキストエディター」参照下さい) が最も汎用性がありカスタム化が可能です。

[ヒント] ヒント

vim(1) やそのページャーモードのエイリアス view(1) では、":set hls" とするとハイライトサーチが可能になります。

The default display format of time and date by the "ls -l" command depends on the locale (see 「タイムスタンプ」 for value). The "$LANG" variable is referred first and it can be overridden by the "$LC_TIME" or "$LC_ALL" exported environment variables.

The actual default display format for each locale depends on the version of the standard C library (the libc6 package) used. I.e., different releases of Debian had different defaults. For iso-formats, see ISO 8601.

ロケール以上にこの時間や日付の表示フォーマットをカスタム化したいと真摯に望むなら、"--time-style" 引数か "$TIME_STYLE" 値を使って時間スタイル値を設定するべきです (ls(1) と date(1) と "info coreutils 'ls invocation'" を参照下さい)。


[ヒント] ヒント

コマンドの別名を使えばコマンドライン上で長いオプションを入力しなくてもよくなります (「コマンドエイリアス」を参照下さい)。

alias ls='ls --time-style=+%d.%m.%y %H:%M'

殆どの現代的なターミナルへのシェル出力は ANSI エスケープコードを使って着色化できます ("/usr/share/doc/xterm/ctlseqs.txt.gz" を参照下さい)。

例えば、次を試してみて下さい:

$ RED=$(printf "\x1b[31m")
$ NORMAL=$(printf "\x1b[0m")
$ REVERSE=$(printf "\x1b[7m")
$ echo "${RED}RED-TEXT${NORMAL} ${REVERSE}REVERSE-TEXT${NORMAL}"

複雑な反復のためにエディターでの活動を記録できます。

Vim の場合以下のようにします。

  • "qa": 名前付きレジスタ "a" にタイプした文字の記録を開始。

  • … エディターでの活動

  • "q": タイプした文字の記録を終了。

  • "@a": レジスター "a" の内容を実行。

Emacs の場合は以下のようにします。

  • "C-x (": キーボードマクロの定義開始。

  • … エディターでの活動

  • "C-x )": キーボードマクロの定義終了。

  • "C-x e": キーボードマクロの実行。

プログラム活動は専用ツールを用いて監視と制御できます。

表9.8 プログラム活動の監視と制御のツールのリスト

パッケージ ポプコン サイズ 説明
coreutils V:908, I:999 18062 nice(1): スケジューリングの優先順位の変更してプログラムを実行
bsdutils V:610, I:999 355 renice(1): 実行中プロセスのスケジューリングの優先順位を変更
procps V:753, I:999 2091 "/proc" ファイルシステムのユーティリティー: ps(1) と top(1) と kill(1) と watch(1) 等
psmisc V:426, I:798 909 "/proc" ファイルシステムのユーティリティー: killall(1) と fuser(1) と pstree(1) と pstree(1)
time V:10, I:181 129 time(1): 時間に関するシステムリソース使用状況を報告するためにプログラムを実行
sysstat V:162, I:185 1785 sar(1)、iostat(1)、mpstat(1)、…: Linux 用のシステムパーフォーマンスツール
isag V:0, I:3 106 sysstat の対話型システムアクティビティーグラフ化ソフト
lsof V:393, I:942 482 lsof(8): "-p" オプションを使い実行中のプロセスが開いているファイルをリスト
strace V:14, I:135 2839 strace(1): システムコールやシグナルを追跡
ltrace V:0, I:18 338 ltrace(1): ライブラリーコールを追跡
xtrace V:0, I:0 353 xtrace(1): X11 のクライアントとサーバーの間の通信を追跡
powertop V:10, I:197 650 powertop(1): システムの電力消費情報
cron V:853, I:996 220 cron(8) デーモンからバックグランドでスケジュール通りプロセスを実行
anacron V:374, I:455 91 1日24時間動作でないシステム用の cron 類似のコマンドスケジューラー
at V:126, I:205 159 at(1) と batch(1) コマンド: 特定の時間や特定のロードレベル以下でジョブを実行

[ヒント] ヒント

procps パッケージはプログラム活動の監視と制御と起動の基本中の基本を提供します。このすべてを習得するべきです。

例えばグロブパターン "*.ext" へのマッチ等の何らかの条件にマッチするファイルに関してループしながらコマンドを実行する方法がいくつかあります。

for x in *.ext; do if [ -f "$x"]; then command "$x" ; fi; done
  • find(1) と xargs(1) の組み合わせ:

find . -type f -maxdepth 1 -name '*.ext' -print0 | xargs -0 -n 1 command
  • コマンド付きの "-exec" オプションを使って find(1):

find . -type f -maxdepth 1 -name '*.ext' -exec command '{}' \;
  • 短いシェルスクリプト付きの "-exec" オプションを使って find(1):

find . -type f -maxdepth 1 -name '*.ext' -exec sh -c "command '{}' && echo 'successful'" \;

上記の例はスペースを含む等の変なファイル名でも適正に処理できるように書かれています。find(1) に関する上級の使用法の詳細は「ファイル選択の慣用句」を参照下さい。

コマンドラインインターフェース (CLI) の場合、$PATH 環境変数で指定されるディレクトリー中で最初にマッチした名前のプログラムが実行されます。「"$PATH" 変数」 を参照ください。

For the graphical user interface (GUI) compliant to the freedesktop.org standards, the *.desktop files in the /usr/share/applications/ directory provide necessary attributes for the GUI menu display of each program. Each package which is compliant to Freedesktop.org's xdg menu system installs its menu data provided by "*.desktop" under "/usr/share/applications/". Modern desktop environments which are compliant to Freedesktop.org standard use these data to generate their menu using the xdg-utils package. See "/usr/share/doc/xdg-utils/README".

例えば chromium.desktop ファイルは、プログラム名の "Name" や、プログラムの実行パスと引数の "Exec" や、使用するアイコンの "Icon" 等の属性(Desktop Entry Specification 参照)を "Chromium Web Browser" に関して以下のようにして定義します:

[Desktop Entry]
Version=1.0
Name=Chromium Web Browser
GenericName=Web Browser
Comment=Access the Internet
Comment[fr]=Explorer le Web
Exec=/usr/bin/chromium %U
Terminal=false
X-MultipleArgs=false
Type=Application
Icon=chromium
Categories=Network;WebBrowser;
MimeType=text/html;text/xml;application/xhtml_xml;x-scheme-handler/http;x-scheme-handler/https;
StartupWMClass=Chromium
StartupNotify=true

これは簡略化しすぎた記述ですが、*.desktop ファイルは以下のようにしてスキャンされます。

デスクトップ環境は $XDG_DATA_HOME$XDG_DATA_DIR 環境変数を設定します。例えば GNOME 3 では:

  • $XDG_DATA_HOME が未設定。(デフォルト値の $HOME/.local/share が使われます。)

  • $XDG_DATA_DIRS/usr/share/gnome:/usr/local/share/:/usr/share/ に設定されます。

以上により、ベースディレクトリー (XDG Base Directory Specification 参照) や applications ディレクトリーは以下となります。

  • $HOME/.local/share/$HOME/.local/share/applications/

  • /usr/share/gnome//usr/share/gnome/applications/

  • /usr/local/share//usr/local/share/applications/

  • /usr/share//usr/share/applications/

*.desktop ファイルはこれらの applications ディレクトリーでこの順番でスキャンされます。

[ヒント] ヒント

ユーザーによるカスタムの GUI メニュー項目は *.desktop ファイルを $HOME/.local/share/applications/ ディレクトリーに追加することで生成できます。

[ヒント] ヒント

同様に、もしこれらのベースディレクトリーの下の autostart ディレクトリーの中に*.desktop ファイルが作成されれば、*.desktop ファイル中に指定されたプログラムがデスクトップ環境が起動された時点に自動実行されます。Desktop Application Autostart Specification を参照ください。

[ヒント] ヒント

同様に、もし$HOME/Desktop ディレクトリーの中に*.desktop ファイルが作成され、デスクトップ環境がローンチャーアイコンを表示する機能を有効としていれば、そこに指定されたプログラムがアイコンをクリックした際に実行されます。xdg-user-dirs-update(1) を参照ください。

一部のプログラムは他のプログラムを自動的にスタートします。このプロセスをカスタム化する上でのチェックポイントを次に記します。

[ヒント] ヒント

update-mime(8) は"/etc/mailcap.order" ファイルを使って "/etc/mailcap" ファイルを更新します (mailcap.order(5) 参照下さい)。

[ヒント] ヒント

debianutils パッケージは、どのエディターやページャーやウェッブブラウザーを呼び出すかに関してそれぞれ賢明な判断をする sensible-browser(1) や sensible-editor(1) や sensible-pager(1) を提供します。これらのシェルスクリプトを読む事をお薦めします。

[ヒント] ヒント

In order to run a console application such as mutt under GUI as your preferred application, you should create an GUI application as following and set "/usr/local/bin/mutt-term" as your preferred application to be started as described.

# cat /usr/local/bin/mutt-term <<EOF
#!/bin/sh
gnome-terminal -e "mutt \$@"
EOF
# chmod 755 /usr/local/bin/mutt-term
[ヒント] ヒント

GUI application can be executed easily under specific environment variables if the program for "Exec" in its corresponding *.desktop file doesn't specify the full execution path. You can enable non-English keyboard input to kitty using an input method framework ibus or fcitx5 by installing required input method packages and creating a shell script "/usr/local/bin/kitty" as follows.

# cat /usr/local/bin/kitty <<EOF
#!/bin/sh
GLFW_IM_MODULE=ibus exec /usr/bin/kitty "\$@"
EOF
# chmod 755 /usr/local/bin/kitty

This kitty script can alternatively be stored in "~/bin/" or "~/.local/bin/" directories as long as they are defined earlier than "/usr/bin/" in "$PATH".

cron(8) コマンドを実行して定期的タスクをスケジュールします。crontab(1) と crontab(5) を参照下さい。

例えば foo というノーマルユーザーとして "crontab -e" コマンドを使って "/var/spool/cron/crontabs/foo" という crontab(5) ファイルを作成することでプロセスをスケジュールして実行する事ができます。

crontab(5) ファイルの例を次に記します。

# use /bin/sh to run commands, no matter what /etc/passwd says
SHELL=/bin/sh
# mail any output to paul, no matter whose crontab this is
MAILTO=paul
# Min Hour DayOfMonth Month DayOfWeek command (Day... are OR'ed)
# run at 00:05, every day
5  0  *  * *   $HOME/bin/daily.job >> $HOME/tmp/out 2>&1
# run at 14:15 on the first of every month -- output mailed to paul
15 14 1  * *   $HOME/bin/monthly
# run at 22:00 on weekdays(1-5), annoy Joe. % for newline, last % for cc:
0 22 *   * 1-5 mail -s "It's 10pm" joe%Joe,%%Where are your kids?%.%%
23 */2 1 2 *   echo "run 23 minutes after 0am, 2am, 4am ..., on Feb 1"
5  4 *   * sun echo "run at 04:05 every Sunday"
# run at 03:40 on the first Monday of each month
40 3 1-7 * *   [ "$(date +%a)" == "Mon" ] && command -args
[ヒント] ヒント

連続的に稼働していないシステムでは、機器のアップタイム上可能な限り指定間隔に近く定期的にコマンドをスケジュールするために anacron パッケージをインストールします。anacron(8) と anacrontab(5) を参照下さい。

[ヒント] ヒント

スケジュールされたシステムメインテナンススクリプトは、そのようなスクリプトを "/etc/cron.hourly/" か "/etc/cron.daily/" か "/etc/cron.weekly/" か "/etc/cron.monthly/" 中に置くことで root アカウントからそれらを定期的に実行できます。これらのスクリプトの実行時間は "/etc/crontab" と "/etc/anacrontab" でカスタム化できます。

Systemd has low level capability to schedule programs to run without cron daemon. For example, /lib/systemd/system/apt-daily.timer and /lib/systemd/system/apt-daily.service set up daily apt download activities. See systemd.timer(5) .

Pressing Alt-SysRq (PrtScr) followed by one keys does the magic of rescuing control of the system.


See more on Linux kernel user’s and administrator’s guide » Linux Magic System Request Key Hacks

[ヒント] ヒント

SSH ターミナルなどからは、"/proc/sysrq-trigger" に書き込むことで Alt-SysRq 機能が使えます。例えば、リモートのシェルプロンプトから "echo s > /proc/sysrq-trigger; echo u > /proc/sysrq-trigger" とすると、全てのマウントされたファイルシステムを sync (同期) して umount (アンマウント) します。

The current (2021) Debian amd64 Linux kernel has /proc/sys/kernel/sysrq=438=0b110110110:

  • 2 = 0x2 - enable control of console logging level (ON)

  • 4 = 0x4 - enable control of keyboard (SAK, unraw) (ON)

  • 8 = 0x8 - enable debugging dumps of processes etc. (OFF)

  • 16 = 0x10 - enable sync command (ON)

  • 32 = 0x20 - enable remount read-only (ON)

  • 64 = 0x40 - enable signaling of processes (term, kill, oom-kill) (OFF)

  • 128 = 0x80 - allow reboot/poweroff (ON)

  • 256 = 0x100 - allow nicing of all RT tasks (ON)

GNOME や KDE のような現代的な GUI のデスクトップ環境ではほとんどのハードウエアー設定が付随する GUI 設定ツールを通じて管理できますが、それらの設定の基本的手法を知っておくのは良い事です。


上記で、ACPIAPM より新しい電力管理システムの枠組みです。

[ヒント] ヒント

最近のシステム上の CPU フリーケンシースケーリングは acpi_cpufreq のようなカーネルモジュールで管理されています。

以下はシステムとハードウエアーの時間を MM/DD hh:mm, CCYY (月/日 時:分, 年) に設定します。

# date MMDDhhmmCCYY
# hwclock --utc --systohc
# hwclock --show

Debian システムでは時間は通常地域の時間が表示されますが、ハードウエアーとシステムの時間は通常 UTC(GMT) を使います。

If the hardware time is set to UTC, change the setting to "UTC=yes" in the "/etc/default/rcS".

Debian システムが使うタイムゾーンは以下のようにして再設定できます。

# dpkg-reconfigure tzdata

ネットワーク経由でシステムの時間を更新したい場合には、ntpntpdatechrony 等のパッケージを使って NTP サービスを利用することを考えます。

[ヒント] ヒント

systemd の下では、ネットワーク時間同期には上記と代わり systemd-timesyncd を使います。詳細は systemd-timesyncd(8) を参照ください。

次を参照下さい。

[ヒント] ヒント

ntp パッケージ中の ntptrace(8) を使うと、NTP サービスの継がりを第一義的根源まで溯ることができます。

現在の Linux のためのサウンドカードのためのデバイスドライバーは Advanced Linux Sound Architecture (ALSA) で提供されています。ALSA は過去の Open Sound System (OSS) と互換性のためのエミュレーションモードを提供します。

Application softwares may be configured not only to access sound devices directly but also to access them via some standardized sound server system. Currently, PulseAudio, JACK, and PipeWire are used as sound server system. See Debian wiki page on Sound for the latest situation.

各ポピュラーなデスクトップ環境では普通共通のサウンドエンジンがあります。アプリケーションに使われるそれぞれのサウンドエンジンはそれと異なるサウンドサーバーにつなぐようにもできます。

[ヒント] ヒント

"cat /dev/urandom > /dev/audio" か speaker-test(1) を使ってスピーカをテストします。(^C で停止)

[ヒント] ヒント

音が出ない場合ですが、あなたのスピーカーが消音された出力につながっているかもしれません。現代的なサウンドシステムには多くの出力があります。alsa-utils パッケージ中の alsamixer(1) は音量や消音の設定をするのに便利です。


メモリー使用状況を確認するのに2つのリソースがあります。

  • "/var/log/dmesg" 中にあるカーネルブートメッセージには、利用可能なメモリーの正確な全サイズが書かれています。

  • free(1) や top(1) は稼働中システムのメモリーリソース情報を表示します。

以下がその例です。

# grep '\] Memory' /var/log/dmesg
[    0.004000] Memory: 990528k/1016784k available (1975k kernel code, 25868k reserved, 931k data, 296k init)
$ free -k
             total       used       free     shared    buffers     cached
Mem:        997184     976928      20256          0     129592     171932
-/+ buffers/cache:     675404     321780
Swap:      4545576          4    4545572

「dmesg は 990 MB 空いているという一方、free -k は 320 MB 空いていると言っている。 600 MB 以上行方不明だ …」 と不思議かもれません。

"Mem:" 行の "used" のサイズが大きかったり "free" のサイズが小さかったりについて悩まないでおきましょう。それらの1行下の (次の例では675404と321780) を読んで安心して下さい。

1GB=1048576k の DRAM (video システムがこのメモリーの一部を使用) が付いている私の MacBook では次のようになっています。


ダメなシステム管理をするとあなたのシステムを外界からの攻撃にさらすことになるかもしれません。

システムのセキュリティーと整合性のチェックには、次の事から始めるべきです。


次のシンプルなスクリプトを使うと、典型的な間違いの全員書込み可のファイルパーミッションをチェックできます。

# find / -perm 777 -a \! -type s -a \! -type l -a \! \( -type d -a -perm 1777 \)
[注意] 注意

debsums パッケージはローカルに保存された MD5 チェックサムを使うので、悪意ある攻撃に対抗するセキュリティー監査ツールとしては完全には信頼できません。

Linux のlive CDs とかレスキューモードで debian-installer CDs であなたのシステムをブートすることでブートデバイス上のデーターストレージの再設定が簡単にできます。

You may need to umount(8) some devices manually from the command line before operating on them if they are automatically mounted by the GUI desktop system.

ディスクのパーティションの設定に関して、fdisk(8) は標準と考えられてきていますが、parted(8) も注目に値します。"ディスクパーティションデーター" や "パーティションテーブル" や "パーティションマップ" や "ディスクラベル" は全て同意語です。

Older PCs use the classic Master Boot Record (MBR) scheme to hold disk partitioning data in the first sector, i.e., LBA sector 0 (512 bytes).

Recent PCs with Unified Extensible Firmware Interface (UEFI), including Intel-based Macs, use GUID Partition Table (GPT) scheme to hold disk partitioning data not in the first sector.

fdisk(8) はディスクパーティションツールの標準でしたが、parted(8) がそれを置き換えつつあります。


[注意] 注意

parted(8) はファイルシステムを生成やリサイズも出きるということですが、そのようなことは mkfs(8) (mkfs.msdos(8) と mkfs.ext2(8) と mkfs.ext3(8) とmkfs.ext4(8) と …) とか resize2fs(8) 等の最もよくメンテされている専用ツールを使って行う方がより安全です。

[注記] 注記

GPTMBR 間で切り替えるには、ディスクの最初数ブロックの内容を直接消去し (「ファイル内容の消去」参照下さい)、"parted /dev/sdx mklabel gpt" か "parted /dev/sdx mklabel msdos" を使ってそれを設定する必要があります。ここで "msdos" がMBR のために使われていることを覚えておきます。

LVM2 は Linux カーネル用の 論理ボリュームマネージャー です。LVM2 を使うと、ディスクパーティションを物理的ハードディスクではなく論理ボリューム上の作成できるようになります。

LVMには以下が必要です。

  • Linux カーネルによる device-mapper サポート (Debian カーネルではデフォルト)

  • ユーザースペースの device-mapper サポートライブラリー (libdevmapper* パッケージ)

  • ユーザースペースの LVM2 ツール (lvm2 パッケージ)

以下のマンページから LVM2 を学び始めましょう。

  • lvm(8): LVM2 機構の基本 (全 LVM2 コマンドのリスト)

  • lvm.conf(5): LVM2 の設定ファイル

  • lvs(8): 論理ボリュームの情報を報告します

  • vgs(8): ボリュームグループの情報を報告します

  • pvs(8): 物理ボリュームの情報を報告します

ext4 ファイルシステム用に e2fsprogs パッケージは次を提供します。

  • 新規の ext4 ファイルシステムを作成するための mkfs.ext4(8)

  • 既存の ext4 ファイルシステムをチェックと修理するための fsck.ext4(8)

  • ext4 ファイルシステムのスーパーブロックを設定するための tune2fs(8)

  • debugfs(8) を使ってext4 ファイルシステムをインタラクティブにデバグします。(削除したファイルを回復する undel コマンドがあります。)

mkfs(8) と fsck(8) コマンドは各種ファイルシステム依存プログラム (mkfs.fstypefsck.fstype) のフロントエンドとして e2fsprogs により提供されています。ext4 ファイルシステム用は、mkfs.ext4(8) と fsck.ext4(8) で、それぞれ mke2fs(8) と e2fsck(8) にシムリンクされています。

Linux によってサポートされる各ファイルシステムでも、類似コマンドが利用可能です。

表9.20 ファイルシステム管理用パッケージのリスト

パッケージ ポプコン サイズ 説明
e2fsprogs V:703, I:999 1480 ext2/ext3/ext4 ファイルシステムのためのユーティリティー
btrfs-progs V:43, I:72 4281 btrfs ファイルシステムのためのユーティリティー
reiserfsprogs V:11, I:27 1132 Reiserfs ファイルシステムのためのユーティリティー
zfsutils-linux V:27, I:29 1610 utilities for the OpenZFS filesystem
dosfstools V:149, I:504 315 FAT ファイルシステムのためのユーティリティー (Microsoft: MS-DOS, Windows)
exfatprogs V:12, I:214 281 utilities for the exFAT filesystem maintained by Samsung.
exfat-fuse V:10, I:233 75 read/write exFAT filesystem (Microsoft) driver for FUSE.
exfat-utils V:9, I:228 231 utilities for the exFAT filesystem maintained by the exfat-fuse author.
xfsprogs V:23, I:100 3444 XFS ファイルシステムのためのユーティリティー (SGI: IRIX)
ntfs-3g V:151, I:488 1469 read/write NTFS filesystem (Microsoft: Windows NT, …) driver for FUSE.
jfsutils V:0, I:10 1577 JFS ファイルシステムのためのユーティリティー (IBM: AIX, OS/2)
reiser4progs V:0, I:3 1367 Reiser4 ファイルシステムのためのユーティリティー
hfsprogs V:0, I:6 394 HFSHFS Plus ファイルシステムのためのユーティリティー (Apple: Mac OS)
zerofree V:4, I:128 25 ext2/3/4 ファイルシステムのフリーブロックをゼロにセットするプログラム

[ヒント] ヒント

Ext4 ファイルシステムは Linux システムのためのデフォルトのファイルシステムで、特定の使用しない理由がない限りこれを使用することが強く推奨されます。

Btrfs status can be found at Debian wiki on btrfs and kernel.org wiki on btrfs. It is expected to be the next default filesystem after the ext4 filesystem.

一部のツールはファイルシステムへのアクセスを Linux カーネルのサポート無しでも可能にします (「ディスクをマウントせずに操作」参照下さい)。

tune2fs(8) コマンドを用いてファイルシステムのスーパーブロックによってファイルシステムを最適化できます。

[ヒント] ヒント

tune2fs(8) は、その名前にもかかわらず、ext2 ファイルシステムに機能するだけでなく ext3 とか ext4 ファイルシステムに関しても機能します。

Solid state drive (SSD) is auto detected now.

Reduce unnecessary disk accesses to prevent disk wear out by mounting "tmpfs" on volatile data path in /etc/fstab.

smartd(8) デーモンを使うと SMART に文句を言うハードディスクの監視と記録ができます。

  1. BIOSSMART 機能を有効にします。

  2. smartmontools パッケージをインストールします。

  3. df(1) を使ってリストすることであなたのハードディスクを識別します。

    • 監視対象のハードディスクを "/dev/hda" と仮定します。

  4. SMART 機能が実際に有効となっているかを "smartctl -a /dev/hda" のアウトプットを使ってチェックします。

    • もし有効でない場合には、"smartctl -s on -a /dev/hda" として有効にします。

  5. 次のようにして smartd(8) デーモンを実行します。

    • "/etc/default/smartmontools" ファイル中の "start_smartd=yes" をアンコメントします。

    • restart the smartd(8) daemon by "sudo systemctl restart smartmontools".

[ヒント] ヒント

smartd(8) デーモンは、警告の通知の仕方を含めて /etc/smartd.conf ファイルを用いてカスタム化できます。

インストール時に論理ボリュームマネージャー (LVM) (Linux 機能) 上に作られたパーティションは、大掛かりなシステムの再設定無しに複数のストレージデバイスにまたがる LVM 上のエクステントを継ぎ足したりその上のエクステントを切り捨てることで簡単にサイズ変更が出きます。

Linux カーネル 3.18 以降 (Debian Stetch 9.0 以降) を使うと、他のパーティション中に使える空間 (例えば "/path/to/empty" と "/path/to/work") があれば、その中にディレクトリーを作成し、容量が必要な古いディレクトリー(e.g., "/path/to/old")の上に OverlayFS を使って積み重ねることができます。

$ sudo mount -t overlay overlay \
  -olowerdir=/path/to/old-dir,upperdir=/path/to/empty,workdir=/path/to/work

ここで、"/path/to/old" 上に書き込むには、読み書きが許可されたパーティション上に "/path/to/empty" と "/path/to/work" があることが必要です。

次に、ディスクイメージの操作を論じます。

例えば2番目の SCSI もしくはシリアル ATA ドライブ "/dev/sdb" 等の、アンマウントされたドライブのディスクイメージファイル "disk.img" はcp(1) か dd(1) を用いれば次のようにして作れます。

# cp /dev/sdb disk.img
# dd if=/dev/sdb of=disk.img

プライマリ IDE ディスクの最初のセクターにある伝統的 PC のマスターブートレコード (MBR) (「ディスクパーティション設定」参照下さい) のディスクイメージは、dd(1) を用いれば次のようにして作れます。

# dd if=/dev/hda of=mbr.img bs=512 count=1
# dd if=/dev/hda of=mbr-nopart.img bs=446 count=1
# dd if=/dev/hda of=mbr-part.img skip=446 bs=1 count=66
  • "mbr.img": パーティションテーブル付きの MBR

  • "mbr-nopart.img": パーティションテーブル抜きの MBR。

  • "mbr-part.img": MBR のパーティションテーブルのみ。

ブートディスクとして SCSI ドライブ もしくはシリアル ATA デバイスが使われる場合、"/dev/hda" を"/dev/sda" に置き換えて下さい。

オリジナルディスクのパーティションのイメージを作る場合には、"/dev/hda" を"/dev/hda1" 等で置き換えます。

単一パーティションイメージを含むディスクイメージ "partition.img" は次のように loop デバイスを使いマウントしアンマウントできます。

# losetup -v -f partition.img
Loop device is /dev/loop0
# mkdir -p /mnt/loop0
# mount -t auto /dev/loop0 /mnt/loop0
...hack...hack...hack
# umount /dev/loop0
# losetup -d /dev/loop0

これは以下のように簡略化出来ます。

# mkdir -p /mnt/loop0
# mount -t auto -o loop partition.img /mnt/loop0
...hack...hack...hack
# umount partition.img

複数のパーティションを含むディスクイメージ "disk.img" の各パーティションは loop デバイスを使ってマウント出来ます。loop デバイスはパーティションをデフォルトでは管理しないので、次のようにそれをリセットする必要があります。

# modinfo -p loop # verify kernel capability
max_part:Maximum number of partitions per loop device
max_loop:Maximum number of loop devices
# losetup -a # verify nothing using the loop device
# rmmod loop
# modprobe loop max_part=16

これで、loop デバイスは16パーティションまで管理出来ます。

# losetup -v -f disk.img
Loop device is /dev/loop0
# fdisk -l /dev/loop0

Disk /dev/loop0: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x452b6464

      Device Boot      Start         End      Blocks   Id  System
/dev/loop0p1               1         600     4819468+  83  Linux
/dev/loop0p2             601         652      417690   83  Linux
# mkdir -p /mnt/loop0p1
# mount -t ext4 /dev/loop0p1 /mnt/loop0p1
# mkdir -p /mnt/loop0p2
# mount -t ext4 /dev/loop0p2 /mnt/loop0p2
...hack...hack...hack
# umount /dev/loop0p1
# umount /dev/loop0p2
# losetup -d /dev/loop0

この他、同様の効果は kpartx パッケージの kpartx(8) により作られるデバイスマッパーデバイスを用いて次のようにして実現も出来ます。

# kpartx -a -v disk.img
...
# mkdir -p /mnt/loop0p2
# mount -t ext4 /dev/mapper/loop0p2 /mnt/loop0p2
...
...hack...hack...hack
# umount /dev/mapper/loop0p2
...
# kpartx -d /mnt/loop0
[注記] 注記

MBR 等をスキップするオフセットを使った loop デバイスによっても、このようなディスクイメージの単一パーティションをマウント出来ます。しかしこれは失敗しがちです。

5GiB まで成長可能な空のディスクイメージファイル "disk.img" はdd(1) と mke2fs(8) を使って次のようにして作成できます。

$ dd bs=1 count=0 if=/dev/zero of=disk.img seek=5G

Instead of using dd(1), specialized fallocate(8) may be used here.

loop デバイスを使ってこのディスクイメージ "disk.img" 上に ext4 ファイルシステムを作成できます。

# losetup -f -v disk.img
Loop device is /dev/loop1
# mkfs.ext4 /dev/loop1
...hack...hack...hack
# losetup -d /dev/loop1
$ du  --apparent-size -h disk.img
5.0G  disk.img
$ du -h disk.img
83M disk.img

"sparse" に関して、そのファイルサイズは 5.0GiB でその実ディスク使用はたったの 83MiB です。この相違は ext4スパースファイルを保持できるから可能となっています。

[ヒント] ヒント

スパースファイルによる実際のディスク使用はそこに書かれるデーターとともに成長します。

「ディスクイメージファイルをマウント」にあるように loop デバイスまたはデバイスマッパーデバイスによりデバイスに同様の操作をすることで、このディスクイメージ "disk.img" をparted(8) または fdisk(8) を使ってパーティションし mkfs.ext4(8) や mkswap(8) 等を使ってファイルシステムを作れます。

"source_directory" のソースディレクトリーツリーから作られる ISO9660 イメージファイル"cd.iso" はcdrkit が提供する genisoimage(1) を使って次のようにして作成できます。

#  genisoimage -r -J -T -V volume_id -o cd.iso source_directory

同様に、ブート可能な ISO9660 イメージファイル "cdboot.iso" は、debian-installer のような "source_directory" にあるディレクトリーツリーから次のようにして作成できます。

#  genisoimage -r -o cdboot.iso -V volume_id \
   -b isolinux/isolinux.bin -c isolinux/boot.cat \
   -no-emul-boot -boot-load-size 4 -boot-info-table source_directory

上記では、Isolinux ブートローダー (「2段目: ブートローダー」参照下さい) がブートに使われています。

次のようにすると CD-ROM デバイスから直接 md5sum 値を計算し ISO9660 イメージを作成できます。

$ isoinfo -d -i /dev/cdrom
CD-ROM is in ISO 9660 format
...
Logical block size is: 2048
Volume size is: 23150592
...
# dd if=/dev/cdrom bs=2048 count=23150592 conv=notrunc,noerror | md5sum
# dd if=/dev/cdrom bs=2048 count=23150592 conv=notrunc,noerror > cd.iso
[警告] 警告

正しい結果を得るために上記のように Linux の ISO9660 ファイルシステム先読みバグを注意深く避けなければいけません。

次に、ストレージメディア上のバイナリーデーターを直接操作することを論じます。

データーファイルの復元と事故の証拠解析のツールがあります。


[ヒント] ヒント

e2fsprogs パッケージ中の debugfs(8) の list_deleted_inodes または undel コマンドを用いると ext2 ファイルシステム上でファイルのアンデリートができます。

ハードリンクのあるファイルは "ls -li" を使って確認できます、

$ ls -li
total 0
2738405 -rw-r--r-- 1 root root 0 2008-09-15 20:21 bar
2738404 -rw-r--r-- 2 root root 0 2008-09-15 20:21 baz
2738404 -rw-r--r-- 2 root root 0 2008-09-15 20:21 foo

"baz" も "foo" もリンク数が "2" (>1) でハードリンクがある事を示しています。これらの inode 番号は共通の "2738404" です。これはこれらがハードリンクされた同じファイルということを意味します。ハードリンクされた全てのファイルを偶然うまく見つけられない場合は、それを例えば "2738404" という inode で次のようにして探せます。

# find /path/to/mount/point -xdev -inum 2738404

あなたの PC への物理的アクセスがあると、誰でも簡単に root 特権を獲得できあなたの PC の全てのファイルにアクセスできます (「root パスワードのセキュリティー確保」参照下さい)。これが意味するところは、あなたの PC が盗まれた場合にログインのパスワードではあなたのプライベートでセンシティブなデーターを守れないと言うことです。それを達成するにはデーターの暗号化技術を適用しなければいけません。GNU プライバシーガード (「データーセキュリティーのインフラ」参照下さい) はファイルを暗号化できますが、少々手間がかかります。

Dm-crypt facilitates automatic data encryption via native Linux kernel modules with minimal user efforts using device-mapper.


[注意] 注意

Data encryption costs CPU time etc. Encrypted data becomes inaccessible if its password is lost. Please weigh its benefits and costs.

[注記] 注記

debian-installer (lenny 以降) を使うと、dm-crypt/LUKS と initramfs を使って、全 Debian システムを暗号化したディスク上にインストールできます。

[ヒント] ヒント

ユーザー空間での暗号化ユーティリティーに関しては「データーセキュリティーのインフラ」を参照下さい: GNU プライバシーガード

例えば "/dev/sdx" にある USB メモリースティックのようなリムーバブルストレージデバイスの内容を dm-crypt/LUKS を使って暗号化できます。それを単に次のようにフォーマットします。

# fdisk /dev/sdx
... "n" "p" "1" "return" "return" "w"
# cryptsetup luksFormat /dev/sdx1
...
# cryptsetup open /dev/sdx1 secret
...
# ls -l /dev/mapper/
total 0
crw-rw---- 1 root root  10, 60 2021-10-04 18:44 control
lrwxrwxrwx 1 root root       7 2021-10-04 23:55 secret -> ../dm-0
# mkfs.vfat /dev/mapper/secret
...
# cryptsetup close secret

Then, it can be mounted just like normal one on to "/media/username/disk_label", except for asking password (see 「リムーバブルストレージデバイス」) under modern desktop environment using the udisks2 package. The difference is that every data written to it is encrypted. The password entry may be automated using keyring (see 「Password keyring」).

You may alternatively format media in different filesystem, e.g., ext4 with "mkfs.ext4 /dev/mapper/sdx1". If btrfs is used instead, the udisks2-btrfs package needs to be installed. For these filesystems, the file ownership and permissions may need to be configured.

Debian はモジュール化された Linux カーネルをサポートされるアーキテクチャに対してパッケージとしてディストリブートしています。

If you are reading this documentation, you probably don't need to compile Linux kernel by yourself.

多くの Linux の機能はカーネル変数を使い次のように設定されます。

See "The Linux kernel user’s and administrator’s guide » The kernel’s command-line parameters" for the detail.

Debian にはカーネルと関連モジュールをコンパイルする独自の方法があります。


「2段目: ブートローダー」 中で initrd を使う場合、initramfs-tools(8) と update-initramfs(8) と mkinitramfs(8) と initramfs.conf(5) 中の関連情報をしっかり読んで下さい。

[警告] 警告

Linux カーネルソースをコンパイルする時にソースツリー中のディレクトリー (例えば "/usr/src/linux*") から "/usr/include/linux" や "/usr/include/asm" へのシムリンクを張ってはいけません。(古くなった一部文書はまだこれをすることを提案しています。)

[注記] 注記

Debian の stable (安定版) システム上で最新の Linux カーネルをコンパイルする際には、Debian のunstable (非安定版) システムからバックポートされた最新のツールが必要かもしれません。

module-assistant(8) (or its short form m-a) helps users to build and install module package(s) easily for one or more custom kernels.

動的カーネルモジュールサポート (DKMS) は、カーネル全体を変えること無く個別カーネルモジュールをアップグレードできるようにする新しいディストリビューションに依存しない枠組みです。これはアウトオブツリーのモジュールの管理方法です。これはあなたがカーネルをアップグレードする際のモジュールの再構築を簡単にもします。

The hardware driver is the code running on the main CPUs of the target system. Most hardware drivers are available as free software now and are included in the normal Debian kernel packages in the main area.

  • GPU ドラーバー

    • Intel GPU ドラーバー (main)

    • AMD/ATI GPU ドラーバー(main)

    • NVIDIA GPU ドライバー (nouveau ドライバーは main、ベンダーにサポートされたバイナリーのみ提供のドライバーは non-free 。)

The firmware is the code or data loaded on the device attach to the target system (e.g., CPU microcode, rendering code running on GPU, or FPGA / CPLD data, …). Some firmware packages are available as free software but many firmware packages are not available as free software since they contain sourceless binary data. Installing these firmware data is essential for the device to function as expected.

  • The firmware data packages containing data loaded to the volatile memory on the target device.

    • firmware-linux-free (main)

    • firmware-linux-nonfree (non-free-firmware)

    • firmware-linux-* (non-free-firmware)

    • *-firmware (non-free-firmware)

    • intel-microcode (non-free-firmware)

    • amd64-microcode (non-free-firmware)

  • The firmware update program packages which update data on the non-volatile memory on the target device.

    • fwupd (main): Firmware update daemon which downloads firmware data from Linux Vendor Firmware Service.

    • gnome-firmware (main): GTK front end for fwupd

    • plasma-discover-backend-fwupd (main): Qt front end for fwupd

Please note that access to non-free-firmware packages are provided by the official installation media to offer functional installation experience to the user since Debian 12 Bookworm. The non-free-firmware area is described in 「Debian アーカイブの基本」.

Please also note that the firmware data downloaded by fwupd from Linux Vendor Firmware Service and loaded to the running Linux kernel may be non-free.

仮想化されたシステムを利用すると単一ハード上で同時に複数のシステムのインスタンスを実行することが加能となります。

[ヒント] ヒント

http://wiki.debian.org/SystemVirtualization を参照下さい。

There are several virtualization and emulation tool platforms.

  • Complete hardware emulation packages such as ones installed by the games-emulator metapackage

  • Mostly CPU level emulation with some I/O device emulations such as QEMU

  • Mostly CPU level virtualization with some I/O device emulations such as Kernel-based Virtual Machine (KVM)

  • OS level container virtualization with the kernel level support such as LXC (Linux Containers), Docker, ...

  • OS level filesystem access virtualization with the system library call override on the file path such as chroot

  • OS level filesystem access virtualization with the system library call override on the file ownership such as fakeroot

  • OS API emulation such as Wine

  • Interpreter level virtualization with its executable selection and run-time library overrides such as virtualenv and venv for Python

The container virtualization uses 「Linux のセキュリティ機能」 and it is the backend technology of 「サンドボックス」.

Here are some packages to help you to setup the virtualized system.

表9.27 仮想化ツールのリスト

パッケージ ポプコン サイズ 説明
schroot V:6, I:8 2508 Debian バイナリーパッケージを chroot 中で実行する専用ツール
sbuild V:1, I:4 242 Debian ソースから Debian バイナリーパッケージをビルドするツール
debootstrap V:5, I:59 279 基本的な Debian システムのブートストラップ (sh で書かれている)
cdebootstrap V:0, I:2 111 Debian システムのブートストラップ (C で書かれている)
virt-manager V:11, I:42 2296 仮想マシンマネージャー: 仮想マシンを管理するデスクトップアプリケーション
libvirt-clients V:43, I:62 1311 libvirt ライブラリー用のプログラム
games-emulator I:0 26 games-emulator: Debian's emulators for games
bochs V:0, I:1 6956 Bochs: IA-32 PC エミュレーター
qemu I:25 97 QEMU: 高速で汎用のプロセッサエミュレーター
qemu-system I:21 59 QEMU: フルシステムエミュレーションのバイナリ
qemu-user V:1, I:8 100502 QEMU: ユーザーモードエミュレーションのバイナリ
qemu-utils V:12, I:107 6875 QEMU: ユーティリティー
qemu-kvm V:2, I:19 107 KVM: ハードウエア補助仮想化を利用する x86 ハードウエア上のフル仮想化
virtualbox V:9, I:11 126370 VirtualBox: i386 と amd64 上での x86 仮想化解決策
xen-tools V:0, I:3 727 Debian XEN 仮想サーバーの管理ツール
wine V:13, I:64 134 Wine: Windows API の実装 (標準スイート)
dosbox V:2, I:16 2671 DOSBox: Tandy/Herc/CGA/EGA/VGA/SVGA グラフィクス、サウンド、DOS 付きの x86 エミュレーター
lxc V:9, I:13 25643 Linux コンテナ - ユーザースペースツール
python3-venv I:60 6 venv for creating virtual python environments (system library)
python3-virtualenv V:9, I:53 406 virtualenv for creating isolated virtual python environments
pipx V:0, I:1 887 pipx for installing python applications in isolated environments

異なるプラットフォーム仮想化策の詳細な比較は Wikipedia の記事 Comparison of platform virtual machines を参照下さい。

[注記] 注記

lenny 以降の Debian のデフォルトカーネルは KVM をサポートしています。

仮想化のための典型的な業務フローにはいくつかの段階があります。

  • 空のファイルシステムの作成 (ファイルツリーもしくはディスクイメージ)。

    • ファイルツリーは "mkdir -p /path/to/chroot" として作成できる。

    • raw ディスクイメージファイルは dd(1) を使って作れます (「ディスクイメージの作成」「空のディスクイメージ作成」参照下さい)。

    • qemu-img(1) はQEMU によりサポートされたディスクイメージの作成や変換に使えます。

    • raw と VMDK ファイルフォーマットは仮想ツール間の共通フォーマットとして使えます。

  • mount(8) を使ってディスクイメージをファイルシステムにマウントする (任意)。

  • 必要なシステムデーターを用いて対象のファイルシステムを充足。

    • debootstrapcdebootstrap のようなプログラムがこのプロセスを援助します (「Chroot システム」参照下さい)。

    • OS のインストーラーをフルシステムエミュレーション下で利用。

  • 仮想化環境下でプログラムを実行。

    • chroot は、仮想環境の中でプログラムのコンパイルやコンソールアプリケーションの実行やデーモンの実行等をするのに十分な基本的仮想環境を提供します。

    • QEMU: クロスプラットフォームの CPU エミュレーションを提供

    • KVM と共の QEMUハードウエア補助仮想化によるフルシステムエミュレーションを提供します。

    • VirtualBoxハードウエア補助仮想化の有無によらず i386 と amd64 上でのフルシステムエミュレーションを提供します。

raw ディスクイメージファイルに関しては、「ディスクイメージ」を参照下さい。

他の仮想ディスクイメージに関しては、qemu-nbd(1) を使ってネットワークブロックデバイスプロトコルを用いてそれらをエクスポートし nbd カーネルモジュールを使ってそれらをマウントできます。

qemu-nbd(1) はQEMU がサポートする次のディスクフォーマットをサポートします: raw、qcow2、qcowvmdkvdibochs、cow (user-mode Linux の copy-on-write)、parallelsdmgcloopvpc、vvfat (virtual VFAT)、host_device。

ネットワークブロックデバイスloop デバイスと同様の方法でパーティションをサポートします (「ディスクイメージファイルをマウント」参照下さい)。"image.img" の最初のパーティションは次のようにするとマウントできます。

# modprobe nbd max_part=16
# qemu-nbd -v -c /dev/nbd0 disk.img
...
# mkdir /mnt/part1
# mount /dev/nbd0p1 /mnt/part1
[ヒント] ヒント

qemu-nbd(8) に"-P 1" オプションを用いると、"disk.img" の最初のパーティションだけをエクスポートできます。

If you wish to try a new Debian environment from a terminal console, I recommend you to use chroot. This enables you to run console applications of Debian unstable and testing without usual risks associated and without rebooting. chroot(8) is the most basic way.

[注意] 注意

Examples below assumes both parent system and chroot system share the same amd64 CPU architecture.

Although you can manually create a chroot(8) environment using debootstrap(1). But this requires non-trivial efforts.

The sbuild package to build Debian packages from source uses the chroot environment managed by the schroot package. It comes with helper script sbuild-createchroot(1). Let's learn how it works by running it as follows.

$ sudo mkdir -p /srv/chroot
$ sudo sbuild-createchroot -v --include=eatmydata,ccache unstable /srv/chroot/unstable-amd64-sbuild http://deb.debian.org/debian
 ...

You see how debootstrap(8) populates system data for unstable environment under "/srv/chroot/unstable-amd64-sbuild" for a minimal build system.

You can login to this environment using schroot(1).

$ sudo schroot -v -c chroot:unstable-amd64-sbuild

You see how a system shell running under unstable environment is created.

[注記] 注記

The "/usr/sbin/policy-rc.d" file which always exits with 101 prevents daemon programs to be started automatically on the Debian system. See "/usr/share/doc/sysv-rc/README.policy-rc.d.gz".

[注記] 注記

Some programs under chroot may require access to more files from the parent system to function than sbuild-createchroot provides as above. For example, "/sys", "/etc/passwd", "/etc/group", "/var/run/utmp", "/var/log/wtmp", etc. may need to be bind-mounted or copied.

[ヒント] ヒント

The sbuild package helps to construct a chroot system and builds a package inside the chroot using schroot as its backend. It is an ideal system to check build-dependencies. See more on sbuild at Debian wiki and sbuild configuration example in "Guide for Debian Maintainers".

If you wish to try a new GUI Desktop environment of any OS, I recommend you to use QEMU or KVM on a Debian stable system to run multiple desktop systems safely using virtualization. These enable you to run any desktop applications including ones of Debian unstable and testing without usual risks associated with them and without rebooting.

Since pure QEMU is very slow, it is recommended to accelerate it with KVM when the host system supports it.

Virtual Machine Manager also known as virt-manager is a convenient GUI tool for managing KVM virtual machines via libvirt.

QEMU 用の Debian システムを含む仮想ディスクイメージ "virtdisk.qcow2" はdebian-installer: 小さな CD を使って次のように作成できます。

$ wget http://cdimage.debian.org/debian-cd/5.0.3/amd64/iso-cd/debian-503-amd64-netinst.iso
$ qemu-img create -f qcow2 virtdisk.qcow2 5G
$ qemu -hda virtdisk.qcow2 -cdrom debian-503-amd64-netinst.iso -boot d -m 256
...
[ヒント] ヒント

UbuntuFedra 等の GNU/Linux ディストリビューションを仮想化の下で実行するのは設定ティップを学ぶ非常に良い方法です。他のプロプライエタリな OS もこの GNU/Linux の仮想化の下で上手く実行できます。

See more tips at Debian wiki: SystemVirtualization.



[2] More elaborate customization examples: "Vim Galore", "sensible.vim", "#vim Recommendations" ...

[3] vim-pathogen was popular.