debian-reference/rawxml/09_system_tips.rawxml
Osamu Aoki e097114eb9 Update mentioned packages in rawxml and po
Signed-off-by: Osamu Aoki <osamu@debian.org>
2026-01-02 23:27:42 +09:00

3315 lines
212 KiB
XML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!-- vim: set sw=2 et sts=2 ft=xml: -->
<!-- Last content review: 2024-01-21T14:32:17 UTC -->
<chapter id="_system_tips">
<title>System tips</title>
<para>Here, I describe basic tips to configure and manage systems, mostly from the console.</para>
<section id="_the_console_tips">
<title>The console tips</title>
<para>There are some utility programs to help your console activities.</para>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>List of programs to support console activities</title>
<tgroup cols="4">
<colspec colwidth="48pt" align="left"/>
<colspec colwidth="76pt" align="left"/>
<colspec colwidth="70pt" align="left"/>
<colspec colwidth="304pt" align="left"/>
<thead>
<row>
<entry> package </entry>
<entry> popcon </entry>
<entry> size </entry>
<entry> description </entry>
</row>
</thead>
<tbody>
<row>
<entry> <literal>mc</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> See <xref linkend="_midnight_commander_mc"/> </entry>
</row>
<row>
<entry> <literal>bsdutils</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> <literal>script</literal>(1) command to make a record of terminal session </entry>
</row>
<row>
<entry> <literal>screen</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> terminal multiplexer with VT100/ANSI terminal emulation </entry>
</row>
<row>
<entry> <literal>tmux</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> terminal multiplexer alternative (Use "Control-B" instead) </entry>
</row>
<row>
<entry> <literal>fzf</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> fuzzy text finder </entry>
</row>
<row>
<entry> <literal>fzy</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> fuzzy text finder </entry>
</row>
<row>
<entry> <literal>rlwrap</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> readline feature command line wrapper </entry>
</row>
<row>
<entry> <literal>ledit</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> readline feature command line wrapper </entry>
</row>
<row>
<entry> <literal>rlfe</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> readline feature command line wrapper </entry>
</row>
<row>
<entry> <literal>ripgrep</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> fast recursive string search in the source code tree with automatic filtering </entry>
</row>
</tbody>
</tgroup>
</table>
<section id="_recording_the_shell_activities_cleanly">
<title>Recording the shell activities cleanly</title>
<para>The simple use of <literal>script</literal>(1) (see <xref linkend="_recording_the_shell_activities"/>) to record shell activity produces a file with control characters. This can be avoided by using <literal>col</literal>(1) as the following.</para>
<screen>$ script
Script started, file is typescript</screen>
<para>Do whatever … and press <literal>Ctrl-D</literal> to exit <literal>script</literal>.</para>
<screen>$ col -bx &lt; typescript &gt; cleanedfile
$ vim cleanedfile</screen>
<para>There are alternative methods to record the shell activities:</para>
<itemizedlist>
<listitem>
<para> Use <literal>tee</literal> (usable during the boot process in the initramfs): </para>
<screen>$ sh -i 2&gt;&amp;1 | tee typescript</screen>
</listitem>
<listitem>
<para> Use <literal>gnome-terminal</literal> with the extend line buffer for scrollback. </para>
</listitem>
<listitem>
<para>Use <literal>screen</literal> with "<literal>^A H</literal>" (see <xref linkend="_the_screen_program"/>) to perform recording of console.</para>
</listitem>
<listitem>
<para>Use <literal>vim</literal> with "<literal>:terminal</literal>" to enter the terminal mode. Use "<literal>Ctrl-W N</literal>" to exit from terminal mode to normal mode. Use "<literal>:w typescript</literal>" to write the buffer to a file.</para>
</listitem>
<listitem>
<para>Use <literal>emacs</literal> with "<literal>M-x shell</literal>", "<literal>M-x eshell</literal>", or "<literal>M-x term</literal>" to enter recording console. Use "<literal>C-x C-w</literal>" to write the buffer to a file.</para>
</listitem>
</itemizedlist>
</section>
<section id="_the_screen_program">
<title>The screen program</title>
<para><literal>screen</literal>(1) not only allows one terminal window to work with multiple processes, but also allows <emphasis role="strong">remote shell process to survive interrupted connections</emphasis>. Here is a typical use scenario of <literal>screen</literal>(1).</para>
<orderedlist>
<listitem> <para> You login to a remote machine. </para> </listitem>
<listitem> <para> You start <literal>screen</literal> on a single console. </para> </listitem>
<listitem> <para> You execute multiple programs in <literal>screen</literal> windows created with <literal>^A c</literal> ("Control-A" followed by "c"). </para> </listitem>
<listitem> <para> You switch among the multiple <literal>screen</literal> windows by <literal>^A n</literal> ("Control-A" followed by "n"). </para> </listitem>
<listitem> <para> Suddenly you need to leave your terminal, but you don't want to lose your active work by keeping the connection. </para> </listitem>
<listitem>
<para> You may <emphasis role="strong">detach</emphasis> the <literal>screen</literal> session by any methods. </para>
<itemizedlist>
<listitem> <para> Brutally unplug your network connection </para> </listitem>
<listitem> <para> Type <literal>^A d</literal> ("Control-A" followed by "d") and manually logging out from the remote connection </para> </listitem>
<listitem> <para> Type <literal>^A DD</literal> ("Control-A" followed by "DD") to have <literal>screen</literal> detach and log you out </para> </listitem>
</itemizedlist>
</listitem>
<listitem> <para> You log in again to the same remote machine (even from a different terminal). </para> </listitem>
<listitem> <para> You start <literal>screen</literal> as "<literal>screen -r</literal>". </para> </listitem>
<listitem> <para><literal>screen</literal> magically <emphasis role="strong">reattaches</emphasis> all previous <literal>screen</literal> windows with all actively running programs. </para> </listitem>
</orderedlist>
<tip> <para>You can save connection fees with <literal>screen</literal> for metered network connections such as dial-up and packet ones, because you can leave a process active while disconnected, and then re-attach it later when you connect again.</para> </tip>
<para>In a <literal>screen</literal> session, all keyboard inputs are sent to your current window except for the command keystroke. All <literal>screen</literal> command keystrokes are entered by typing <literal>^A</literal> ("Control-A") plus a single key [plus any parameters]. Here are important ones to remember.</para>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>List of key bindings for screen</title>
<tgroup cols="2">
<colspec colwidth="65pt" align="left"/>
<colspec colwidth="271pt" align="left"/>
<thead>
<row>
<entry> key binding </entry>
<entry> meaning </entry>
</row>
</thead>
<tbody>
<row>
<entry> <literal>^A ?</literal> </entry>
<entry> show a help screen (display key bindings) </entry>
</row>
<row>
<entry> <literal>^A c</literal> </entry>
<entry> create a new window and switch to it </entry>
</row>
<row>
<entry> <literal>^A n</literal> </entry>
<entry> go to next window </entry>
</row>
<row>
<entry> <literal>^A p</literal> </entry>
<entry> go to previous window </entry>
</row>
<row>
<entry> <literal>^A 0</literal> </entry>
<entry> go to window number 0 </entry>
</row>
<row>
<entry> <literal>^A 1</literal> </entry>
<entry> go to window number 1 </entry>
</row>
<row>
<entry> <literal>^A w</literal> </entry>
<entry> show a list of windows </entry>
</row>
<row>
<entry> <literal>^A a</literal> </entry>
<entry> send a Ctrl-A to current window as keyboard input </entry>
</row>
<row>
<entry> <literal>^A h</literal> </entry>
<entry> write a hardcopy of current window to file </entry>
</row>
<row>
<entry> <literal>^A H</literal> </entry>
<entry> begin/end logging current window to file </entry>
</row>
<row>
<entry> <literal>^A ^X</literal> </entry>
<entry> lock the terminal (password protected) </entry>
</row>
<row>
<entry> <literal>^A d</literal> </entry>
<entry> detach screen session from the terminal </entry>
</row>
<row>
<entry> <literal>^A DD</literal> </entry>
<entry> detach screen session and log out </entry>
</row>
</tbody>
</tgroup>
</table>
<para>See <literal>screen</literal>(1) for details.</para>
<para>See <literal>tmux</literal>(1) for functionalities of the alternative command.</para>
</section>
<section id="_navigating_around_directories">
<title>Navigating around directories</title>
<para>In <xref linkend="_customizing_bash"/>, 2 tips to allow quick navigation around directories are described: <literal>$CDPATH</literal> and <literal>mc</literal>. </para>
<para>If you use fuzzy text filter program, you can do without typing the exact path. For <literal>fzf</literal>, include following in <literal>~/.bashrc</literal>. </para>
<screen>FZF_KEYBINDINGS_PATH=/usr/share/doc/fzf/examples/key-bindings.bash
if [ -f $FZF_KEYBINDINGS_PATH ]; then
. $FZF_KEYBINDINGS_PATH
fi</screen>
<para>For example:</para>
<itemizedlist>
<listitem> <para>You can jump to a very deep subdirectory with minimal efforts. You first type "<literal>cd **</literal>" and press <literal>Tab</literal>. Then you will be prompted with candidate paths. Typing in partial path strings, e.g., <literal>s/d/b foo</literal>, will narrow down candidate paths. You select the path to be used by <literal>cd</literal> with cursor and return keys.</para> </listitem>
<listitem> <para>You can select a command from the command history more efficiently with minimal efforts. You press <literal>Ctrl-R</literal> at the command prompt. Then you will be prompted with candidate commands. Typing in partial command strings, e.g., <literal>vim d</literal>, will narrow down candidates. You select the one to be used with cursor and return keys.</para> </listitem>
</itemizedlist>
</section>
<section id="_readline_wrapper">
<title>Readline wrapper</title>
<para>Some commands such as <literal>/usr/bin/dash</literal> which lacks command line history editing capability can add such functionality transparently by running under <literal>rlwrap</literal> or its equivalents.</para>
<screen> $ rlwrap dash -i</screen>
<para>This provides convenient platform to test subtle points for <literal>dash</literal> with friendly <literal>bash</literal>-like environment. </para>
</section>
<section id="_scanning_the_source_code_tree">
<title>Scanning the source code tree</title>
<para>The <literal>rg</literal>(1) command in the <literal>ripgrep</literal> package offers a faster alternative to the <literal>grep</literal>(1) command for scanning the source code tree for typical situation. It takes advantage of modern multi-core CPUs and automatically applies reasonable filters to skip some files. </para>
</section>
</section>
<section id="_customizing_vim">
<title>Customizing vim</title>
<para> After you learn basics of <literal>vim</literal>(1) through <xref linkend="_using_vim"/>, please read Bram Moolenaar's "<ulink url="https://www.moolenaar.net/habits.html">Seven habits of effective text editing (2000)</ulink>" to understand how <literal>vim</literal> should be used. </para>
<section id="_customizing_vim_with internal_features">
<title>Customizing vim with internal features</title>
<para>The behavior of <literal>vim</literal> can be changed significantly by enabling its internal features through the <literal>Ex</literal>-mode commands such as "<literal>set ...</literal>" to set vim options.</para>
<para>These <literal>Ex</literal>-mode commands can be included in user's vimrc file, traditional "<literal>~/.vimrc</literal>" or git-friendly "<literal>~/.vim/vimrc</literal>". Here is a very simple example
<footnote> <para>More elaborate customization examples: "<ulink url="https://github.com/mhinz/vim-galore">Vim Galore</ulink>", "<ulink url="https://github.com/tpope/vim-sensible">sensible.vim</ulink>", ... </para> </footnote>:
</para>
<!--
The following are meant to be edited by user to their taste of starting set values.
See current https://github.com/osamuaoki/dot-vim and its rationale
at https://osamuaoki.github.io/en/2023/03/05/vim-learn-7/
-->
<screen>""" Generic baseline Vim and Neovim configuration (~/.vimrc)
""" - For NeoVim, use "nvim -u ~/.vimrc [filename]"
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let mapleader = ' ' " :h mapleader
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set nocompatible " :h 'cp -- sensible (n)vim mode
syntax on " :h :syn-on
filetype plugin indent on " :h :filetype-overview
set encoding=utf-8 " :h 'enc (default: latin1) -- sensible encoding
""" current vim option value can be verified by :set encoding?
set backspace=indent,eol,start " :h 'bs (default: nobs) -- sensible BS
set statusline=%&lt;%f%m%r%h%w%=%y[U+%04B]%2l/%2L=%P,%2c%V
set listchars=eol:¶,tab:⇄\ ,extends:↦,precedes:↤,nbsp:␣
set viminfo=!,'100,&lt;5000,s100,h " :h 'vi -- bigger copy buffer etc.
""" Pick "colorscheme" from blue darkblue default delek desert elflord evening
""" habamax industry koehler lunaperche morning murphy pablo peachpuff quiet ron
""" shine slate torte zellner
colorscheme industry
""" don't pick "colorscheme" as "default" which may kill SpellUnderline settings
set scrolloff=5 " :h 'scr -- show 5 lines around cursor
set laststatus=2 " :h 'ls (default 1) k
""" boolean options can be unset by prefixing "no"
set ignorecase " :h 'ic
set smartcase " :h 'scs
set autoindent " :h 'ai
set smartindent " :h 'si
set nowrap " :h 'wrap
"set list " :h 'list (default nolist)
set noerrorbells " :h 'eb
set novisualbell " :h 'vb
set t_vb= " :h 't_vb -- termcap visual bell
set spell " :h 'spell
set spelllang=en_us,cjk " :h 'spl -- english spell, ignore CJK
set clipboard=unnamedplus " :h 'cb -- cut/copy/paste with other app
set hidden " :h 'hid
set autowrite " :h 'aw
set timeoutlen=300 " :h 'tm</screen>
<para>The keymap of <literal>vim</literal> can be changed in user's vimrc file. E.g.:</para>
<caution> <para>Don't try to change the default key bindings without very good reasons.</para> </caution>
<!--
These are taken from most popular settings
"silent!" is needed to avoid error due to difference of Vim/Nvim
I understand n and N remap may be avoided if scrolloff is big enough but I like it this way.
How to cope with remapped <C-L>
* Vim: <C-L> Clears and redraws the screen with "clear highlight"
* Nvim <C-L> Clears and redraws the screen with "clear highlight" and "diff update"
nnoremap <C-L> <Cmd>nohlsearch<Bar>diffupdate<Bar>normal! <C-L><CR>
* Lazyvim uses: map({ "i", "n" }, "<esc>", "<cmd>noh<cr><esc>", ...)
==> Remap <ESC> like Lazyvim (not exacly as Nvim <C-L> for now)
nnoremap <ESC> <CMD>noh<CR><ESC>
inoremap <ESC> <CMD>noh<CR><ESC>
ic/scs are set like LazyVim
hidden/autowrite are matched with nvim defaults
Clipboard is for console vim and nvim.
We can use shared clipboard with y/d/p (not just primary)
-->
<screen>""" Popular mappings (imitating LazyVim etc.)
""" Window moves without using CTRL-W which is dangerous in INSERT mode
nnoremap &lt;C-H&gt; &lt;C-W&gt;h
nnoremap &lt;C-J&gt; &lt;C-W&gt;j
nnoremap &lt;C-K&gt; &lt;C-W&gt;k
silent! nnoremap &lt;C-L&gt; &lt;C-W&gt;l
""" Window resize
nnoremap &lt;C-LEFT&gt; &lt;CMD&gt;vertical resize -2&lt;CR&gt;
nnoremap &lt;C-DOWN&gt; &lt;CMD&gt;resize -2&lt;CR&gt;
nnoremap &lt;C-UP&gt; &lt;CMD&gt;resize +2&lt;CR&gt;
nnoremap &lt;C-RIGHT&gt; &lt;CMD&gt;vertical resize +2&lt;CR&gt;
""" Clear hlsearch with &lt;ESC&gt; (&lt;C-L&gt; is mapped as above)
nnoremap &lt;ESC&gt; &lt;CMD&gt;noh&lt;CR&gt;&lt;ESC&gt;
inoremap &lt;ESC&gt; &lt;CMD&gt;noh&lt;CR&gt;&lt;ESC&gt;
""" center after jump next
nnoremap n nzz
nnoremap N Nzz
""" fast "jk" to get out of INSERT mode (&lt;ESC&gt;)
inoremap jk &lt;CMD&gt;noh&lt;CR&gt;&lt;ESC&gt;
""" fast "&lt;ESC&gt;&lt;ESC&gt;" to get out of TERM mode (CTRL-\ CTRL-N)
tnoremap &lt;ESC&gt;&lt;ESC&gt; &lt;C-\&gt;&lt;C-N&gt;
""" fast "jk" to get out of TERM mode (CTRL-\ CTRL-N)
tnoremap jk &lt;C-\&gt;&lt;C-N&gt;
""" previous/next trouble/quickfix item
nnoremap [q &lt;CMD&gt;cprevious&lt;CR&gt;
nnoremap ]q &lt;CMD&gt;cnext&lt;CR&gt;
""" buffers
nnoremap &lt;S-H&gt; &lt;CMD&gt;bprevious&lt;CR&gt;
nnoremap &lt;S-L&gt; &lt;CMD&gt;bnext&lt;CR&gt;
nnoremap [b &lt;CMD&gt;bprevious&lt;CR&gt;
nnoremap ]b &lt;CMD&gt;bnext&lt;CR&gt;
""" Add undo break-points
inoremap , ,&lt;C-G&gt;u
inoremap . .&lt;C-G&gt;u
inoremap ; ;&lt;C-G&gt;u
""" save file
inoremap &lt;C-S&gt; &lt;CMD&gt;w&lt;CR&gt;&lt;ESC&gt;
xnoremap &lt;C-S&gt; &lt;CMD&gt;w&lt;CR&gt;&lt;ESC&gt;
nnoremap &lt;C-S&gt; &lt;CMD&gt;w&lt;CR&gt;&lt;ESC&gt;
snoremap &lt;C-S&gt; &lt;CMD&gt;w&lt;CR&gt;&lt;ESC&gt;
""" better indenting
vnoremap &lt; &lt;gv
vnoremap &gt; &gt;gv
""" terminal (Somehow under Linux, &lt;C-/&gt; becomes &lt;C-_&gt; in Vim)
nnoremap &lt;C-_&gt; &lt;CMD&gt;terminal&lt;CR&gt;
"nnoremap &lt;C-/&gt; &lt;CMD&gt;terminal&lt;CR&gt;
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if ! has('nvim')
""" Toggle paste mode with &lt;SPACE&gt;p for Vim (no need for Nvim)
set pastetoggle=&lt;leader&gt;p
""" nvim default mappings for Vim. See :h default-mappings in nvim
""" copy to EOL (no delete) like D for d
noremap Y y$
""" sets a new undo point before deleting
inoremap &lt;C-U&gt; &lt;C-G&gt;u&lt;C-U&gt;
inoremap &lt;C-W&gt; &lt;C-G&gt;u&lt;C-W&gt;
""" &lt;C-L&gt; is re-purposed as above
""" execute the previous macro recorded with Q
nnoremap Q @@
""" repeat last substitute and *KEEP* flags
nnoremap &amp; :&amp;&amp;&lt;CR&gt;
""" search visual selected string for visual mode
xnoremap * y/\V&lt;C-R&gt;"&lt;CR&gt;
xnoremap # y?\V&lt;C-R&gt;"&lt;CR&gt;
endif</screen>
<para>In order for the above keybindings to function properly, the terminal program needs to be configured to generate "ASCII DEL" for <literal>Backspace</literal>-key and "Escape sequence" for <literal>Delete</literal>-key.</para>
<para>Other miscellaneous configuration can be changed in user's vimrc file. E.g.:</para>
<!--
I excluded ripgrep for :grep since this is non-essential
* https://www.vi-improved.org/recommendations/ to rg
For TailingWhitespaces, regex idea is from
* https://vim.fandom.com/wiki/Highlight_unwanted_spaces
This tricky regex allows to avoid red while typing
I focus on Vim8 or newer so no autocmd used for TailingWhitespaces
-->
<screen>""" Use faster 'rg' (ripgrep package) for :grep
if executable("rg")
set grepprg=rg\ --vimgrep\ --smart-case
set grepformat=%f:%l:%c:%m
endif
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""" Retain last cursor position :h '"
augroup RetainLastCursorPosition
autocmd!
autocmd BufReadPost *
\ if line("'\"") &gt; 0 &amp;&amp; line ("'\"") &lt;= line("$") |
\ exe "normal! g'\"" |
\ endif
augroup END
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""" Force to use underline for spell check results
augroup SpellUnderline
autocmd!
autocmd ColorScheme * highlight SpellBad term=Underline gui=Undercurl
autocmd ColorScheme * highlight SpellCap term=Underline gui=Undercurl
autocmd ColorScheme * highlight SpellLocal term=Underline gui=Undercurl
autocmd ColorScheme * highlight SpellRare term=Underline gui=Undercurl
augroup END
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""" highlight tailing spaces except when typing as red (set after colorscheme)
highlight TailingWhitespaces ctermbg=red guibg=red
""" \s\+ 1 or more whitespace character: &lt;Space&gt; and &lt;Tab&gt;
""" \%#\@&lt;! Matches with zero width if the cursor position does NOT match.
match TailingWhitespaces /\s\+\%#\@&lt;!$/</screen>
</section>
<section id="_customizing_vim_with_external_packages">
<title>Customizing vim with external packages</title>
<para>Interesting external plugin packages can be found:</para>
<itemizedlist>
<listitem> <para> <ulink url="https://www.vim.org/"> Vim - the ubiquitous text editor </ulink> -- The official upstream site of Vim and vim scripts </para> </listitem>
<listitem> <para> <ulink url="https://vimawesome.com/"> VimAwsome </ulink> -- The listing of Vim plugins </para> </listitem>
<listitem> <para> <ulink url="https://packages.debian.org/unstable/vim-scripts">vim-scripts</ulink> -- Debian package: a collection of vim scripts </para> </listitem>
</itemizedlist>
<para>Plugin packages in the <ulink url="https://packages.debian.org/unstable/vim-scripts">vim-scripts</ulink> package can be enabled using user's vimrc file. E.g.:</para>
<!--
I admit I don't use these now. But I need to keep these as an example.
I know "set pastetoggle" is out of place but I wanted "leader" here.
I don't want to discuss disabled secure-modeline feature in Debian's Vim package.
-->
<screen>packadd! secure-modelines
packadd! winmanager
" IDE-like UI for files and buffers with &lt;space&gt;w
nnoremap &lt;leader&gt;w :WMToggle&lt;CR&gt;</screen>
<para>The new native Vim package system works nicely with "<literal>git</literal>" and "<literal>git submodule</literal>". One such example configuration can be found at <ulink url="https://github.com/osamuaoki/dot-vim/tree/old">my git repository: dot-vim</ulink>. This does essentially:</para>
<itemizedlist>
<listitem> <para>By using "<literal>git</literal>" and "<literal>git submodule</literal>", latest external packages, such as "<literal><emphasis>name</emphasis></literal>", are placed into <literal>~/.vim/pack/*/opt/<emphasis>name</emphasis></literal> and similar.</para> </listitem>
<listitem> <para>By adding <literal>:packadd! <emphasis>name</emphasis></literal> line to user's vimrc file, these packages are placed on <literal>runtimepath</literal>.</para> </listitem>
<listitem> <para>Vim loads these packages on <literal>runtimepath</literal> during its initialization.</para> </listitem>
<listitem> <para>At the end of its initialization, tags for the installed documents are updated with "<literal>helptags ALL</literal>".</para> </listitem>
</itemizedlist>
<para>For more, please start <literal>vim</literal> with "<literal>vim --startuptime vimstart.log</literal>" to check actual execution sequence and time spent for each step.</para>
<para>It is quite confusing to see too many ways<footnote><para> <ulink url="https://packages.debian.org/unstable/vim-pathogen">vim-pathogen</ulink> was popular. </para></footnote> to manage and load these external packages to <literal>vim</literal>. Checking the original information is the best cure.</para>
<table>
<title>Information on the initialization of <literal>vim</literal></title>
<tgroup cols="2">
<colspec colwidth="100pt" align="left"/>
<colspec colwidth="500pt" align="left"/>
<thead>
<row>
<entry> key strokes </entry>
<entry> information </entry>
</row>
</thead>
<tbody>
<row>
<entry> <literal>:help package</literal> </entry>
<entry> explanation on the vim package mechanism </entry>
</row>
<row>
<entry> <literal>:help runtimepath</literal> </entry>
<entry> explanation on the <literal>runtimepath</literal> mechanism </entry>
</row>
<row>
<entry> <literal>:version</literal> </entry>
<entry> internal states including candidates for the vimrc file </entry>
</row>
<row>
<entry> <literal>:echo $VIM</literal> </entry>
<entry> the environment variable "<literal>$VIM</literal>" used to locate the vimrc file</entry>
</row>
<row>
<entry> <literal>:set runtimepath?</literal> </entry>
<entry> list of directories which will be searched for all runtime support files </entry>
</row>
<row>
<entry> <literal>:echo $VIMRUNTIME</literal> </entry>
<entry> the environment variable "<literal>$VIMRUNTIME</literal>" used to locate various system provided runtime support files </entry>
</row>
</tbody>
</tgroup>
</table>
</section>
</section>
<section id="_data_recording_and_presentation">
<title>Data recording and presentation</title>
<section id="_the_log_daemon">
<title>The log daemon</title>
<para>Many traditional programs record their activities in the text file format under the "<literal>/var/log/</literal>" directory.</para>
<para><literal>logrotate</literal>(8) is used to simplify the administration of log files on a system which generates a lot of log files.</para>
<para>Many new programs record their activities in the binary file format using <literal>systemd-journald</literal>(8) Journal service under the "<literal>/var/log/journal</literal>" directory.</para>
<para>You can log data to the <literal>systemd-journald</literal>(8) Journal from a shell script by using the <literal>systemd-cat</literal>(1) command.</para>
<para>See <xref linkend="_the_system_message"/> and <xref linkend="_the_kernel_message"/>.</para>
</section>
<section id="_log_analyzer">
<title>Log analyzer</title>
<para>Here are notable log analyzers ("<literal>~Gsecurity::log-analyzer</literal>" in <literal>aptitude</literal>(8)).</para>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>List of system log analyzers</title>
<tgroup cols="4">
<colspec colwidth="92pt" align="left"/>
<colspec colwidth="76pt" align="left"/>
<colspec colwidth="70pt" align="left"/>
<colspec colwidth="325pt" align="left"/>
<thead>
<row>
<entry> package </entry>
<entry> popcon </entry>
<entry> size </entry>
<entry> description </entry>
</row>
</thead>
<tbody>
<row>
<entry> <literal>logwatch</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> log analyzer with nice output written in Perl </entry>
</row>
<row>
<entry> <literal>fail2ban</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> ban IPs that cause multiple authentication errors </entry>
</row>
<row>
<entry> <literal>analog</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> web server log analyzer </entry>
</row>
<row>
<entry> <literal>awstats</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> powerful and featureful web server log analyzer </entry>
</row>
<row>
<entry> <literal>sarg</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> squid analysis report generator </entry>
</row>
<row>
<entry> <literal>pflogsumm</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> Postfix log entry summarizer </entry>
</row>
<row>
<entry> <literal>fwlogwatch</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> firewall log analyzer </entry>
</row>
<row>
<entry> <literal>squidview</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> monitor and analyze squid access.log files </entry>
</row>
<row>
<entry> <literal>swatch</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> log file viewer with regexp matching, highlighting, and hooks </entry>
</row>
<row>
<entry> <literal>crm114</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> Controllable Regex Mutilator and Spam Filter (CRM114) </entry>
</row>
<row>
<entry> <literal>icmpinfo</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> interpret ICMP messages </entry>
</row>
</tbody>
</tgroup>
</table>
<note> <para><ulink url="https://en.wikipedia.org/wiki/CRM114_(program)">CRM114</ulink> provides language infrastructure to write <emphasis role="strong">fuzzy</emphasis> filters with the <ulink url="https://github.com/laurikari/tre/">TRE regex library</ulink>. Its popular use is spam mail filter but it can be used as log analyzer.</para> </note>
</section>
<section id="_customized_display_of_text_data">
<title>Customized display of text data</title>
<para>Although pager tools such as <literal>more</literal>(1) and <literal>less</literal>(1) (see <xref linkend="_the_pager"/>) and custom tools for highlighting and formatting (see <xref linkend="_highlighting_and_formatting_plain_text_data"/>) can display text data nicely, general purpose editors (see <xref linkend="_the_text_editor"/>) are most versatile and customizable.</para>
<tip> <para>For <literal>vim</literal>(1) and its pager mode alias <literal>view</literal>(1), "<literal>:set hls</literal>" enables highlighted search.</para> </tip>
</section>
<section id="_customized_display_of_time_and_date">
<title>Customized display of time and date</title>
<para>The default display format of time and date by the "<literal>ls -l</literal>" command depends on the <emphasis role="strong">locale</emphasis> (see <xref linkend="_timestamps"/> for value). The "<literal>$LANG</literal>" variable is referred first and it can be overridden by the "<literal>$LC_TIME</literal>" or "<literal>$LC_ALL</literal>" exported environment variables.</para>
<para>The actual default display format for each locale depends on the version of the standard C library (the <literal>libc6</literal> package) used. I.e., different releases of Debian had different defaults. For iso-formats, see <ulink url="https://en.wikipedia.org/wiki/ISO_8601">ISO 8601</ulink>.</para>
<para>If you really wish to customize this display format of time and date beyond the <emphasis role="strong">locale</emphasis>, you should set the <emphasis role="strong">time style value</emphasis> by the "<literal>--time-style</literal>" argument or by the "<literal>$TIME_STYLE</literal>" value (see <literal>ls</literal>(1), <literal>date</literal>(1), "<literal>info coreutils 'ls invocation'</literal>").</para>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>Display examples of time and date for the "<literal>ls -l</literal>" command with the <emphasis role="strong">time style value</emphasis></title>
<tgroup cols="3">
<colspec colwidth="97pt" align="left"/>
<colspec colwidth="114pt" align="left"/>
<colspec colwidth="206pt" align="left"/>
<thead>
<row>
<entry> time style value </entry>
<entry> locale </entry>
<entry> display of time and date </entry>
</row>
</thead>
<tbody>
<row>
<entry> <literal>iso</literal> </entry>
<entry> any </entry>
<entry> <literal>01-19 00:15</literal> </entry>
</row>
<row>
<entry> <literal>long-iso</literal> </entry>
<entry> any </entry>
<entry> <literal>2009-01-19 00:15</literal> </entry>
</row>
<row>
<entry> <literal>full-iso</literal> </entry>
<entry> any </entry>
<entry> <literal>2009-01-19 00:15:16.000000000 +0900</literal> </entry>
</row>
<row>
<entry> <literal>locale</literal> </entry>
<entry> <literal>C</literal> </entry>
<entry> <literal>Jan 19 00:15</literal> </entry>
</row>
<row>
<entry> <literal>locale</literal> </entry>
<entry> <literal>en_US.UTF-8</literal> </entry>
<entry> <literal>Jan 19 00:15</literal> </entry>
</row>
<row>
<entry> <literal>locale</literal> </entry>
<entry> <literal>es_ES.UTF-8</literal> </entry>
<entry> <literal>ene 19 00:15</literal> </entry>
</row>
<row>
<entry> <literal>+%d.%m.%y %H:%M</literal> </entry>
<entry> any </entry>
<entry> <literal>19.01.09 00:15</literal> </entry>
</row>
<row>
<entry> <literal>+%d.%b.%y %H:%M</literal> </entry>
<entry> <literal>C</literal> or <literal>en_US.UTF-8</literal> </entry>
<entry> <literal>19.Jan.09 00:15</literal> </entry>
</row>
<row>
<entry> <literal>+%d.%b.%y %H:%M</literal> </entry>
<entry> <literal>es_ES.UTF-8</literal> </entry>
<entry> <literal>19.ene.09 00:15</literal> </entry>
</row>
</tbody>
</tgroup>
</table>
<tip>
<para>You can eliminate typing long option on commandline using command alias (see <xref linkend="_command_alias"/>):</para>
<screen>alias ls='ls --time-style=+%d.%m.%y %H:%M'</screen>
</tip>
</section>
<section id="_colorized_shell_echo">
<title>Colorized shell echo</title>
<para>Shell echo to most modern terminals can be colorized using <ulink url="https://en.wikipedia.org/wiki/ANSI_escape_code">ANSI escape code</ulink> (see "<literal>/usr/share/doc/xterm/ctlseqs.txt.gz</literal>").</para>
<para>For example, try the following</para>
<screen>$ RED=$(printf "\x1b[31m")
$ NORMAL=$(printf "\x1b[0m")
$ REVERSE=$(printf "\x1b[7m")
$ echo "${RED}RED-TEXT${NORMAL} ${REVERSE}REVERSE-TEXT${NORMAL}"</screen>
</section>
<section id="_colorized_commands">
<title>Colorized commands</title>
<para>Colorized commands are handy for inspecting their output in the interactive environment. I include the following in my "<literal>~/.bashrc</literal>".</para>
<screen>if [ "$TERM" != "dumb" ]; then
eval "`dircolors -b`"
alias ls='ls --color=always'
alias ll='ls --color=always -l'
alias la='ls --color=always -A'
alias less='less -R'
alias ls='ls --color=always'
alias grep='grep --color=always'
alias egrep='egrep --color=always'
alias fgrep='fgrep --color=always'
alias zgrep='zgrep --color=always'
else
alias ll='ls -l'
alias la='ls -A'
fi</screen>
<para>The use of alias limits color effects to the interactive command usage. It has advantage over exporting environment variable "<literal>export GREP_OPTIONS='--color=auto'</literal>" since color can be seen under pager programs such as <literal>less</literal>(1). If you wish to suppress color when piping to other programs, use "<literal>--color=auto</literal>" instead in the above example for "<literal>~/.bashrc</literal>".</para>
<tip> <para>You can turn off these colorizing aliases in the interactive environment by invoking shell with "<literal>TERM=dumb bash</literal>".</para> </tip>
</section>
<section id="_recording_the_editor_activities_for_complex_repeats">
<title>Recording the editor activities for complex repeats</title>
<para>You can record the editor activities for complex repeats.</para>
<para>For <ulink url="https://en.wikipedia.org/wiki/Vim_(text_editor)">Vim</ulink>, as follows.</para>
<itemizedlist>
<listitem> <para> "<literal>qa</literal>": start recording typed characters into named register "<literal>a</literal>". </para> </listitem>
<listitem> <para> … editor activities </para> </listitem>
<listitem> <para> "<literal>q</literal>": end recording typed characters. </para> </listitem>
<listitem> <para> "<literal>@a</literal>": execute the contents of register "<literal>a</literal>". </para> </listitem>
</itemizedlist>
<para>For <ulink url="https://en.wikipedia.org/wiki/Emacs">Emacs</ulink>, as follows.</para>
<itemizedlist>
<listitem> <para> "<literal>C-x (</literal>": start defining a keyboard macro. </para> </listitem>
<listitem> <para> … editor activities </para> </listitem>
<listitem> <para> "<literal>C-x )</literal>": end defining a keyboard macro. </para> </listitem>
<listitem> <para> "<literal>C-x e</literal>": execute a keyboard macro. </para> </listitem>
</itemizedlist>
</section>
<section id="_recording_the_graphic_image_of_an_x_application">
<title>Recording the graphics image of an X application</title>
<para>There are few ways to record the graphics image of an X application, including an <literal>xterm</literal> display.</para>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>List of graphics image manipulation tools</title>
<tgroup cols="4">
<colspec colwidth="86pt" align="left"/>
<colspec colwidth="76pt" align="left"/>
<colspec colwidth="70pt" align="left"/>
<colspec colwidth="65pt" align="left"/>
<thead>
<row>
<entry> package </entry>
<entry> popcon </entry>
<entry> size </entry>
<entry> screen </entry>
<entry> command </entry>
</row>
</thead>
<tbody>
<row>
<entry> <literal>gnome-screenshot</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> Wayland </entry>
<entry> screenshot application for GNOME </entry>
</row>
<row>
<entry> <literal>flameshot</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> Wayland </entry>
<entry> screenshot application on steroid </entry>
</row>
<row>
<entry> <literal>gimp</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> Wayland + X </entry>
<entry> screenshot in GUI menu </entry>
</row>
<row>
<entry> <literal>x11-apps</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> X </entry>
<entry> <literal>xwd</literal>(1) </entry>
</row>
<row>
<entry> <literal>imagemagick</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> X </entry>
<entry> <literal>import</literal>(1) </entry>
</row>
<row>
<entry> <literal>scrot</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> X </entry>
<entry> <literal>scrot</literal>(1) </entry>
</row>
</tbody>
</tgroup>
</table>
</section>
<section id="_recording_changes_in_configuration_files">
<title>Recording changes in configuration files</title>
<para>There are specialized tools to record changes in configuration files with help of DVCS and to make system snapshots on <ulink url="https://en.wikipedia.org/wiki/Btrfs">Btrfs</ulink>.</para>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>List of packages which can record configuration history</title>
<tgroup cols="4">
<colspec colwidth="76pt" align="left"/>
<colspec colwidth="76pt" align="left"/>
<colspec colwidth="70pt" align="left"/>
<colspec colwidth="526pt" align="left"/>
<thead>
<row>
<entry> package </entry>
<entry> popcon </entry>
<entry> size </entry>
<entry> description </entry>
</row>
</thead>
<tbody>
<row>
<entry> <literal>etckeeper</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> store configuration files and their metadata with <ulink url="https://en.wikipedia.org/wiki/Git_(software)">Git</ulink> (default), <ulink url="https://en.wikipedia.org/wiki/Mercurial_(software)">Mercurial</ulink>, or <ulink url="https://en.wikipedia.org/wiki/GNU_Bazaar">GNU Bazaar</ulink> </entry>
</row>
<row>
<entry> <literal>timeshift</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> system restore utility using rsync or BTRFS snapshots </entry>
</row>
<row>
<entry> <literal>snapper</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> Linux filesystem snapshot management tool </entry>
</row>
</tbody>
</tgroup>
</table>
<para>You may also think about local script <xref linkend="_backup_tips"/> approach.</para>
</section>
</section>
<section id="_monitoring_controlling_and_starting_program_activities">
<title>Monitoring, controlling, and starting program activities</title>
<para>Program activities can be monitored and controlled using specialized tools.</para>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>List of tools for monitoring and controlling program activities</title>
<tgroup cols="4">
<colspec colwidth="65pt" align="left"/>
<colspec colwidth="76pt" align="left"/>
<colspec colwidth="70pt" align="left"/>
<colspec colwidth="488pt" align="left"/>
<thead>
<row>
<entry> package </entry>
<entry> popcon </entry>
<entry> size </entry>
<entry> description </entry>
</row>
</thead>
<tbody>
<row>
<entry> <literal>coreutils</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry><literal>nice</literal>(1): run a program with modified scheduling priority </entry>
</row>
<row>
<entry> <literal>bsdutils</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry><literal>renice</literal>(1): modify the scheduling priority of a running process </entry>
</row>
<row>
<entry> <literal>procps</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> "<literal>/proc</literal>" filesystem utilities: <literal>ps</literal>(1), <literal>top</literal>(1), <literal>kill</literal>(1), <literal>watch</literal>(1), … </entry>
</row>
<row>
<entry> <literal>psmisc</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> "<literal>/proc</literal>" filesystem utilities: <literal>killall</literal>(1), <literal>fuser</literal>(1), <literal>peekfd</literal>(1), <literal>pstree</literal>(1) </entry>
</row>
<row>
<entry> <literal>time</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> <literal>time</literal>(1): run a program to report system resource usages with respect to time </entry>
</row>
<row>
<entry> <literal>sysstat</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> <literal>sar</literal>(1), <literal>iostat</literal>(1), <literal>mpstat</literal>(1), …: system performance tools for Linux </entry>
</row>
<row>
<entry> <literal>isag</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> Interactive System Activity Grapher for sysstat </entry>
</row>
<row>
<entry> <literal>lsof</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> <literal>lsof</literal>(8): list files opened by a running process using "<literal>-p</literal>" option </entry>
</row>
<row>
<entry> <literal>strace</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> <literal>strace</literal>(1): trace system calls and signals </entry>
</row>
<row>
<entry> <literal>ltrace</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> <literal>ltrace</literal>(1): trace library calls </entry>
</row>
<row>
<entry> <literal>xtrace</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> <literal>xtrace</literal>(1): trace communication between X11 client and server </entry>
</row>
<row>
<entry> <literal>powertop</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> <literal>powertop</literal>(1): information about system power use </entry>
</row>
<row>
<entry> <literal>cron</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> run processes according to a schedule in background from <literal>cron</literal>(8) daemon </entry>
</row>
<row>
<entry> <literal>anacron</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> cron-like command scheduler for systems that don't run 24 hours a day </entry>
</row>
<row>
<entry> <literal>at</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> <literal>at</literal>(1) or <literal>batch</literal>(1): run a job at a specified time or below certain load level </entry>
</row>
</tbody>
</tgroup>
</table>
<tip> <para>The <literal>procps</literal> packages provide very basics of monitoring, controlling, and starting program activities. You should learn all of them.</para> </tip>
<section id="_timing_a_process">
<title>Timing a process</title>
<para>Display time used by the process invoked by the command.</para>
<screen># time some_command &gt;/dev/null
real 0m0.035s # time on wall clock (elapsed real time)
user 0m0.000s # time in user mode
sys 0m0.020s # time in kernel mode</screen>
</section>
<section id="_the_scheduling_priority">
<title>The scheduling priority</title>
<para>A nice value is used to control the scheduling priority for the process.</para>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>List of nice values for the scheduling priority</title>
<tgroup cols="2">
<colspec colwidth="59pt" align="left"/>
<colspec colwidth="260pt" align="left"/>
<thead>
<row>
<entry> nice value </entry>
<entry> scheduling priority </entry>
</row>
</thead>
<tbody>
<row>
<entry> 19 </entry>
<entry> lowest priority process (nice) </entry>
</row>
<row>
<entry> 0 </entry>
<entry> very high priority process for user </entry>
</row>
<row>
<entry> -20 </entry>
<entry> very high priority process for root (not-nice) </entry>
</row>
</tbody>
</tgroup>
</table>
<screen># nice -19 top # very nice
# nice --20 wodim -v -eject speed=2 dev=0,0 disk.img # very fast</screen>
<para>Sometimes an extreme nice value does more harm than good to the system. Use this command carefully.</para>
</section>
<section id="_the_ps_command">
<title>The ps command</title>
<para>The <literal>ps</literal>(1) command on a Debian system support both BSD and SystemV features and helps to identify the process activity statically.</para>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>List of ps command styles</title>
<tgroup cols="3">
<colspec colwidth="48pt" align="left"/>
<colspec colwidth="86pt" align="left"/>
<colspec colwidth="97pt" align="left"/>
<thead>
<row>
<entry> style </entry>
<entry> typical command </entry>
<entry> feature </entry>
</row>
</thead>
<tbody>
<row>
<entry> BSD </entry>
<entry> <literal>ps aux</literal> </entry>
<entry> display %CPU %MEM </entry>
</row>
<row>
<entry> System V </entry>
<entry> <literal>ps -efH</literal> </entry>
<entry> display PPID </entry>
</row>
</tbody>
</tgroup>
</table>
<para>For the zombie (defunct) children process, you can kill them by the parent process ID identified in the "<literal>PPID</literal>" field.</para>
<para>The <literal>pstree</literal>(1) command display a tree of processes.</para>
</section>
<section id="_the_top_command">
<title>The top command</title>
<para><literal>top</literal>(1) on the Debian system has rich features and helps to identify what process is acting funny dynamically.</para>
<para>It is an interactive full screen program. You can get its usage help press by pressing the "h"-key and terminate it by pressing the "q"-key.</para>
</section>
<section id="_listing_files_opened_by_a_process">
<title>Listing files opened by a process</title>
<para>You can list all files opened by a process with a process ID (PID), e.g. 1, by the following.</para>
<screen>$ sudo lsof -p 1</screen>
<para>PID=1 is usually the <literal>init</literal> program.</para>
</section>
<section id="_tracing_program_activities">
<title>Tracing program activities</title>
<para>You can trace program activity with <literal>strace</literal>(1), <literal>ltrace</literal>(1), or <literal>xtrace</literal>(1) for system calls and signals, library calls, or communication between X11 client and server.</para>
<para>You can trace system calls of the <literal>ls</literal> command as the following.</para>
<screen>$ sudo strace ls</screen>
<tip> <para> Use <emphasis role="strong">strace-graph</emphasis> script found in <emphasis role="strong">/usr/share/doc/strace/examples/</emphasis> to make a nice tree view </para> </tip>
</section>
<section id="_identification_of_processes_using_files_or_sockets">
<title>Identification of processes using files or sockets</title>
<para>You can also identify processes using files by <literal>fuser</literal>(1), e.g. for "<literal>/var/log/mail.log</literal>" by the following.</para>
<screen>$ sudo fuser -v /var/log/mail.log
USER PID ACCESS COMMAND
/var/log/mail.log: root 2946 F.... rsyslogd</screen>
<para>You see that file "<literal>/var/log/mail.log</literal>" is open for writing by the <literal>rsyslogd</literal>(8) command.</para>
<para>You can also identify processes using sockets by <literal>fuser</literal>(1), e.g. for "<literal>smtp/tcp</literal>" by the following.</para>
<screen>$ sudo fuser -v smtp/tcp
USER PID ACCESS COMMAND
smtp/tcp: Debian-exim 3379 F.... exim4</screen>
<para>Now you know your system runs <literal>exim4</literal>(8) to handle <ulink url="https://en.wikipedia.org/wiki/Transmission_Control_Protocol">TCP</ulink> connections to <ulink url="https://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol">SMTP</ulink> port (25).</para>
</section>
<section id="_repeating_a_command_with_a_constant_interval">
<title>Repeating a command with a constant interval</title>
<para><literal>watch</literal>(1) executes a program repeatedly with a constant interval while showing its output in fullscreen.</para>
<screen>$ watch w</screen>
<para>This displays who is logged on to the system updated every 2 seconds.</para>
</section>
<section id="_repeating_a_command_looping_over_files">
<title>Repeating a command looping over files</title>
<para>There are several ways to repeat a command looping over files matching some condition, e.g. matching glob pattern "<literal>*.ext</literal>".</para>
<itemizedlist>
<listitem> <para> Shell for-loop method (see <xref linkend="_shell_loops"/>): </para> </listitem>
</itemizedlist>
<screen>for x in *.ext; do if [ -f "$x"]; then command "$x" ; fi; done</screen>
<itemizedlist>
<listitem> <para><literal>find</literal>(1) and <literal>xargs</literal>(1) combination: </para> </listitem>
</itemizedlist>
<screen>find . -type f -maxdepth 1 -name '*.ext' -print0 | xargs -0 -n 1 command</screen>
<itemizedlist>
<listitem> <para><literal>find</literal>(1) with "<literal>-exec</literal>" option with a command: </para> </listitem>
</itemizedlist>
<screen>find . -type f -maxdepth 1 -name '*.ext' -exec command '{}' \;</screen>
<itemizedlist>
<listitem> <para><literal>find</literal>(1) with "<literal>-exec</literal>" option with a short shell script: </para> </listitem>
</itemizedlist>
<screen>find . -type f -maxdepth 1 -name '*.ext' -exec sh -c "command '{}' &amp;&amp; echo 'successful'" \;</screen>
<para>The above examples are written to ensure proper handling of funny file names such as ones containing spaces. See <xref linkend="_idioms_for_the_selection_of_files"/> for more advance uses of <literal>find</literal>(1).</para>
</section>
<section id="_starting_a_program_from_gui">
<title>Starting a program from GUI</title>
<para>For the <ulink url="https://en.wikipedia.org/wiki/Command-line_interface">command-line interface (CLI)</ulink>, the first program with the matching name found in the directories specified in the <literal>$PATH</literal> environment variable is executed. See <xref linkend="_the_literal_path_literal_variable"/>.</para>
<para>For the <ulink url="https://en.wikipedia.org/wiki/Graphical_user_interface">graphical user interface (GUI)</ulink> compliant to the <ulink url="https://www.freedesktop.org/wiki/">freedesktop.org</ulink> standards, the <literal>*.desktop</literal> files in the <literal>/usr/share/applications/</literal> 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". </para>
<para>For example, the <literal>chromium.desktop</literal> file defines attributes for the "Chromium Web Browser" such as "Name" for the program name, "Exec" for the program execution path and arguments, "Icon" for the icon used, etc. (see the <ulink url="https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html">Desktop Entry Specification</ulink>) as follows:</para>
<screen>[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</screen>
<para>This is an oversimplified description. The <literal>*.desktop</literal> files are scanned as follows.</para>
<para>The desktop environment sets <literal>$XDG_DATA_HOME</literal> and <literal>$XDG_DATA_DIR</literal> environment variables. For example, under the GNOME 3:</para>
<itemizedlist>
<listitem> <para><literal>$XDG_DATA_HOME</literal> is unset. (The default value of <literal>$HOME/.local/share</literal> is used.) </para> </listitem>
<listitem> <para><literal>$XDG_DATA_DIRS</literal> is set to <literal>/usr/share/gnome:/usr/local/share/:/usr/share/</literal>. </para> </listitem>
</itemizedlist>
<para>So the base directories (see <ulink url="https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html">XDG Base Directory Specification</ulink>) and the <literal>applications</literal> directories are as follows.</para>
<itemizedlist>
<listitem> <para><literal>$HOME/.local/share/</literal><literal>$HOME/.local/share/applications/</literal> </para> </listitem>
<listitem> <para><literal>/usr/share/gnome/</literal><literal>/usr/share/gnome/applications/</literal> </para> </listitem>
<listitem> <para><literal>/usr/local/share/</literal><literal>/usr/local/share/applications/</literal> </para> </listitem>
<listitem> <para><literal>/usr/share/</literal><literal>/usr/share/applications/</literal> </para> </listitem>
</itemizedlist>
<para>The <literal>*.desktop</literal> files are scanned in these <literal>applications</literal> directories in this order.</para>
<tip> <para>A user custom GUI menu entry can be created by adding a <literal>*.desktop</literal> file in the <literal>$HOME/.local/share/applications/</literal> directory.</para> </tip>
<tip> <para>The "<literal>Exec=...</literal>" line isn't parsed by the shell. Use the <literal>env</literal>(1) command if environment variables need to be set.</para> </tip>
<tip> <para>Similarly, if a <literal>*.desktop</literal> file is created in the <literal>autostart</literal> directory under these base directories, the specified program in the <literal>*.desktop</literal> file is executed automatically when the desktop environment is started. See <ulink url="https://specifications.freedesktop.org/autostart-spec/autostart-spec-latest.html">Desktop Application Autostart Specification</ulink>.</para> </tip>
<tip> <para>Similarly, if a <literal>*.desktop</literal> file is created in the <literal>$HOME/Desktop</literal> directory and the Desktop environment is configured to support the desktop icon launcher feature, the specified program in it is executed upon clicking the icon. Please note that the actual name of the <literal>$HOME/Desktop</literal> directory is locale dependent. See <literal>xdg-user-dirs-update</literal>(1).</para> </tip>
</section>
<section id="_customizing_program_to_be_started">
<title>Customizing program to be started</title>
<para>Some programs start another program automatically. Here are check points for customizing this process.</para>
<itemizedlist>
<listitem>
<para> Application configuration menu: </para>
<itemizedlist>
<listitem>
<para> GNOME3 desktop: "Settings" → "System" → "Details" → "Default Applications" </para>
</listitem>
<listitem>
<para> KDE desktop: "K" → "Control Center" → "KDE Components" → "Component Chooser" </para>
</listitem>
<listitem>
<para> Iceweasel browser: "Edit" → "Preferences" → "Applications" </para>
</listitem>
<listitem>
<para><literal>mc</literal>(1): "<literal>/etc/mc/mc.ext</literal>" </para> </listitem>
</itemizedlist>
</listitem>
<listitem>
<para> Environment variables such as "<literal>$BROWSER</literal>", "<literal>$EDITOR</literal>", "<literal>$VISUAL</literal>", and "<literal>$PAGER</literal>" (see <literal>environ</literal>(7)) </para>
</listitem>
<listitem>
<para> The <literal>update-alternatives</literal>(1) system for programs such as "<literal>editor</literal>", "<literal>view</literal>", "<literal>x-www-browser</literal>", "<literal>gnome-www-browser</literal>", and "<literal>www-browser</literal>" (see <xref linkend="_setting_a_default_text_editor"/>) </para>
</listitem>
<listitem>
<para> the "<literal>~/.mailcap</literal>" and "<literal>/etc/mailcap</literal>" file contents which associate <ulink url="https://en.wikipedia.org/wiki/MIME">MIME</ulink> type with program (see <literal>mailcap</literal>(5)) </para>
</listitem>
<listitem>
<para> The "<literal>~/.mime.types</literal>" and "<literal>/etc/mime.types</literal>" file contents which associate file name extension with <ulink url="https://en.wikipedia.org/wiki/MIME">MIME</ulink> type (see <literal>run-mailcap</literal>(1)) </para>
</listitem>
</itemizedlist>
<tip> <para><literal>update-mime</literal>(8) updates the "<literal>/etc/mailcap</literal>" file using "<literal>/etc/mailcap.order</literal>" file (see <literal>mailcap.order</literal>(5)).</para> </tip>
<tip> <para>The <literal>debianutils</literal> package provides <literal>sensible-browser</literal>(1), <literal>sensible-editor</literal>(1), and <literal>sensible-pager</literal>(1) which make sensible decisions on which editor, pager, and web browser to call, respectively. I recommend you to read these shell scripts.</para> </tip>
<tip> <para>In order to run a console application such as <literal>mutt</literal> under GUI as your preferred application, you should create an GUI application as following and set "<literal>/usr/local/bin/mutt-term</literal>" as your preferred application to be started as described.</para>
<screen># cat /usr/local/bin/mutt-term &lt;&lt;EOF
#!/bin/sh
gnome-terminal -e "mutt \$@"
EOF
# chmod 755 /usr/local/bin/mutt-term</screen>
</tip>
</section >
<section id="_killing_a_process">
<title>Killing a process</title>
<para>Use <literal>kill</literal>(1) to kill (or send a signal to) a process by the process ID.</para>
<para>Use <literal>killall</literal>(1) or <literal>pkill</literal>(1) to do the same by the process command name and other attributes.</para>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>List of frequently used signals for kill command</title>
<tgroup cols="4">
<colspec colwidth="70pt" align="left"/>
<colspec colwidth="65pt" align="left"/>
<colspec colwidth="81pt" align="left"/>
<colspec colwidth="81pt" align="left"/>
<thead>
<row>
<entry> signal value </entry>
<entry> signal name </entry>
<entry> action </entry>
<entry> note </entry>
</row>
</thead>
<tbody>
<row>
<entry> 0 </entry>
<entry> --- </entry>
<entry> no signal is sent (see <literal>kill</literal>(2)) </entry>
<entry> check if process is running </entry>
</row>
<row>
<entry> 1 </entry>
<entry> <ulink url="https://en.wikipedia.org/wiki/SIGHUP">SIGHUP</ulink> </entry>
<entry> terminate the process </entry>
<entry> disconnected terminal (signal hang up) </entry>
</row>
<row>
<entry> 2 </entry>
<entry> <ulink url="https://en.wikipedia.org/wiki/Signals_intelligence">SIGINT</ulink> </entry>
<entry> terminate the process </entry>
<entry> interrupt from keyboard (<literal>CTRL-C</literal>) </entry>
</row>
<row>
<entry> 3 </entry>
<entry> <ulink url="https://en.wikipedia.org/wiki/Signal_(IPC)#SIGQUIT">SIGQUIT</ulink> </entry>
<entry> terminate the process and <ulink url="https://en.wikipedia.org/wiki/Core_dump">dump core</ulink> </entry>
<entry> quit from keyboard (<literal>CTRL-\</literal>) </entry>
</row>
<row>
<entry> 9 </entry>
<entry> <ulink url="https://en.wikipedia.org/wiki/Signal_(IPC)#SIGKILL">SIGKILL</ulink> </entry>
<entry> terminate the process </entry>
<entry> unblockable kill signal </entry>
</row>
<row>
<entry> 15 </entry>
<entry> <ulink url="https://en.wikipedia.org/wiki/Signal_(IPC)#SIGTERM">SIGTERM</ulink> </entry>
<entry> terminate the process </entry>
<entry> blockable termination signal </entry>
</row>
<!--
<row>
<entry> 18 </entry>
<entry> SIGCONT </entry>
<entry> continue the process if stopped </entry>
<entry> </entry>
</row>
<row>
<entry> 19 </entry>
<entry> SIGSTOP </entry>
<entry> stop the process </entry>
<entry> </entry>
</row>
-->
</tbody>
</tgroup>
</table>
</section>
<section id="_scheduling_tasks_once">
<title>Scheduling tasks once</title>
<para>Run the <literal>at</literal>(1) command to schedule a one-time job by the following.</para>
<screen>$ echo 'command -args'| at 3:40 monday</screen>
</section>
<section id="_scheduling_tasks_regularly">
<title>Scheduling tasks regularly</title>
<para>Use <literal>cron</literal>(8) to schedule tasks regularly. See <literal>crontab</literal>(1) and <literal>crontab</literal>(5).</para>
<para>You can schedule to run processes as a normal user, e.g. <literal>foo</literal> by creating a <literal>crontab</literal>(5) file as "<literal>/var/spool/cron/crontabs/foo</literal>" with "<literal>crontab -e</literal>" command.</para>
<para>Here is an example of a <literal>crontab</literal>(5) file.</para>
<screen># use /usr/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 &gt;&gt; $HOME/tmp/out 2&gt;&amp;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" ] &amp;&amp; command -args</screen>
<tip> <para>For the system not running continuously, install the <literal>anacron</literal> package to schedule periodic commands at the specified intervals as closely as machine-uptime permits. See <literal>anacron</literal>(8) and <literal>anacrontab</literal>(5).</para> </tip>
<tip> <para>For scheduled system maintenance scripts, you can run them periodically from root account by placing such scripts in "<literal>/etc/cron.hourly/</literal>", "<literal>/etc/cron.daily/</literal>", "<literal>/etc/cron.weekly/</literal>", or "<literal>/etc/cron.monthly/</literal>". Execution timings of these scripts can be customized by "<literal>/etc/crontab</literal>" and "<literal>/etc/anacrontab</literal>".</para> </tip>
<para> <ulink url="https://en.wikipedia.org/wiki/Systemd">Systemd</ulink> has low level capability to schedule programs to run without <literal>cron</literal> daemon. For example, <literal>/lib/systemd/system/apt-daily.timer</literal> and <literal>/lib/systemd/system/apt-daily.service</literal> set up daily apt download activities. See <literal>systemd.timer</literal>(5) .</para>
</section>
<section id="_scheduling_tasks_on_event">
<title>Scheduling tasks on event</title>
<para> <ulink url="https://en.wikipedia.org/wiki/Systemd">Systemd</ulink> can schedule program not only on the timer event but also on the mount event. See <xref linkend="_timer_event_triggered_backup" /> and <xref linkend="_mount_event_triggered_backup" /> for examples. </para>
</section>
<section id="_alt_sysrq_key">
<title>Alt-SysRq key</title>
<para>Pressing Alt-SysRq (PrtScr) followed by one keys does the magic of rescuing control of the system.</para>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>List of notable SAK command keys</title>
<tgroup cols="2">
<colspec colwidth="130pt" align="left"/>
<colspec colwidth="472pt" align="left"/>
<thead>
<row>
<entry> key following Alt-SysRq </entry>
<entry> description of action </entry>
</row>
</thead>
<tbody>
<row>
<entry> <literal>k</literal> </entry>
<entry><emphasis role="strong">k</emphasis>ill all processes on the <emphasis role="strong">current virtual console</emphasis> (<ulink url="https://en.wikipedia.org/wiki/Secure_attention_key">SAK</ulink>) </entry>
</row>
<row>
<entry> <literal>s</literal> </entry>
<entry><emphasis role="strong">s</emphasis>ync all mounted filesystems to avoid data corruption </entry>
</row>
<row>
<entry> <literal>u</literal> </entry>
<entry> remount all mounted filesystems read-only (<emphasis role="strong">u</emphasis>mount) </entry>
</row>
<row>
<entry> <literal>r</literal> </entry>
<entry> restore the keyboard from <emphasis role="strong">r</emphasis>aw mode after X crashes </entry>
</row>
</tbody>
</tgroup>
</table>
<para>See more on <ulink url="https://www.kernel.org/doc/html/latest/admin-guide/sysrq.html">Linux kernel users and administrators guide » Linux Magic System Request Key Hacks</ulink></para>
<tip> <para>From SSH terminal etc., you can use the Alt-SysRq feature by writing to the "<literal>/proc/sysrq-trigger</literal>". For example, "<literal>echo s &gt; /proc/sysrq-trigger; echo u &gt; /proc/sysrq-trigger</literal>" from the root shell prompt <emphasis role="strong">s</emphasis>yncs and <emphasis role="strong">u</emphasis>mounts all mounted filesystems.</para> </tip>
<para>The current (2021) Debian amd64 Linux kernel has <literal>/proc/sys/kernel/sysrq=438=0b110110110</literal>:</para>
<itemizedlist>
<listitem> <para>2 = 0x2 - enable control of console logging level (ON)</para> </listitem>
<listitem> <para>4 = 0x4 - enable control of keyboard (SAK, unraw) (ON)</para> </listitem>
<listitem> <para>8 = 0x8 - enable debugging dumps of processes etc. (OFF)</para> </listitem>
<listitem> <para>16 = 0x10 - enable sync command (ON)</para> </listitem>
<listitem> <para>32 = 0x20 - enable remount read-only (ON)</para> </listitem>
<listitem> <para>64 = 0x40 - enable signaling of processes (term, kill, oom-kill) (OFF)</para> </listitem>
<listitem> <para>128 = 0x80 - allow reboot/poweroff (ON)</para> </listitem>
<listitem> <para>256 = 0x100 - allow nicing of all RT tasks (ON)</para> </listitem>
</itemizedlist>
</section>
</section>
<section id="_system_maintenance_tips">
<title>System maintenance tips</title>
<section id="_who_is_on_the_system">
<title>Who is on the system?</title>
<para>You can check who is on the system by the following.</para>
<itemizedlist>
<listitem> <para><literal>who</literal>(1) shows who is logged on. </para> </listitem>
<listitem> <para><literal>w</literal>(1) shows who is logged on and what they are doing. </para> </listitem>
<listitem> <para><literal>last</literal>(1) shows listing of last logged in user. </para> </listitem>
<listitem> <para><literal>lastb</literal>(1) shows listing of last bad logged in users. </para> </listitem>
</itemizedlist>
<tip> <para>"<literal>/var/run/utmp</literal>", and "<literal>/var/log/wtmp</literal>" hold such user information. See <literal>login</literal>(1) and <literal>utmp</literal>(5).</para> </tip>
</section>
<section id="_warning_everyone">
<title>Warning everyone</title>
<para>You can send message to everyone who is logged on to the system with <literal>wall</literal>(1) by the following.</para>
<screen>$ echo "We are shutting down in 1 hour" | wall</screen>
</section>
<section id="_hardware_identification">
<title>Hardware identification</title>
<para>For the <ulink url="https://en.wikipedia.org/wiki/Peripheral_Component_Interconnect">PCI</ulink>-like devices (<ulink url="https://en.wikipedia.org/wiki/Accelerated_Graphics_Port">AGP</ulink>, <ulink url="https://en.wikipedia.org/wiki/PCI_Express">PCI-Express</ulink>, <ulink url="https://en.wikipedia.org/wiki/PC_Card#CardBus">CardBus</ulink>, <ulink url="https://en.wikipedia.org/wiki/ExpressCard">ExpressCard</ulink>, etc.), <literal>lspci</literal>(8) (probably with "<literal>-nn</literal>" option) is a good start for the hardware identification.</para>
<para>Alternatively, you can identify the hardware by reading contents of "<literal>/proc/bus/pci/devices</literal>" or browsing directory tree under "<literal>/sys/bus/pci</literal>" (see <xref linkend="_procfs_and_sysfs"/>).</para>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>List of hardware identification tools</title>
<tgroup cols="4">
<colspec colwidth="76pt" align="left"/>
<colspec colwidth="76pt" align="left"/>
<colspec colwidth="70pt" align="left"/>
<colspec colwidth="336pt" align="left"/>
<thead>
<row>
<entry> package </entry>
<entry> popcon </entry>
<entry> size </entry>
<entry> description </entry>
</row>
</thead>
<tbody>
<row>
<entry> <literal>pciutils</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> Linux PCI Utilities: <literal>lspci</literal>(8) </entry>
</row>
<row>
<entry> <literal>usbutils</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> Linux USB utilities: <literal>lsusb</literal>(8) </entry>
</row>
<row>
<entry> <literal>nvme-cli</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> NVMe utilities for Linux: <literal>nvme</literal>(1) </entry>
</row>
<row>
<entry> <literal>pcmciautils</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> PCMCIA utilities for Linux: <literal>pccardctl</literal>(8) </entry>
</row>
<row>
<entry> <literal>scsitools</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> collection of tools for SCSI hardware management: <literal>lsscsi</literal>(8) </entry>
</row>
<row>
<entry> <literal>procinfo</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> system information obtained from "<literal>/proc</literal>": <literal>lsdev</literal>(8) </entry>
</row>
<row>
<entry> <literal>lshw</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> information about hardware configuration: <literal>lshw</literal>(1) </entry>
</row>
<row>
<entry> <literal>discover</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> hardware identification system: <literal>discover</literal>(8) </entry>
</row>
</tbody>
</tgroup>
</table>
</section>
<section id="_hardware_configuration">
<title>Hardware configuration</title>
<para>Although most of the hardware configuration on modern GUI desktop systems such as GNOME and KDE can be managed through accompanying GUI configuration tools, it is a good idea to know some basics methods to configure them.</para>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>List of hardware configuration tools</title>
<tgroup cols="4">
<colspec colwidth="108pt" align="left"/>
<colspec colwidth="76pt" align="left"/>
<colspec colwidth="70pt" align="left"/>
<colspec colwidth="477pt" align="left"/>
<thead>
<row>
<entry> package </entry>
<entry> popcon </entry>
<entry> size </entry>
<entry> description </entry>
</row>
</thead>
<tbody>
<row>
<entry> <literal>console-setup</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> Linux console font and keytable utilities </entry>
</row>
<row>
<entry> <literal>x11-xserver-utils</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> X server utilities: <literal>xset</literal>(1), <literal>xmodmap</literal>(1) </entry>
</row>
<row>
<entry> <literal>acpid</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> daemon to manage events delivered by the Advanced Configuration and Power Interface (ACPI) </entry>
</row>
<row>
<entry> <literal>acpi</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> utility to display information on ACPI devices </entry>
</row>
<row>
<entry> <literal>sleepd</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> daemon to put a laptop to sleep during inactivity </entry>
</row>
<row>
<entry> <literal>hdparm</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> hard disk access optimization (see <xref linkend="_optimization_of_hard_disk"/>) </entry>
</row>
<row>
<entry> <literal>smartmontools</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> control and monitor storage systems using <ulink url="https://en.wikipedia.org/wiki/S.M.A.R.T.">S.M.A.R.T.</ulink> </entry>
</row>
<row>
<entry> <literal>setserial</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> collection of tools for serial port management </entry>
</row>
<row>
<entry> <literal>memtest86+</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> collection of tools for memory hardware management </entry>
</row>
<row>
<entry> <literal>scsitools</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> collection of tools for <ulink url="https://en.wikipedia.org/wiki/SCSI">SCSI</ulink> hardware management </entry>
</row>
<row>
<entry> <literal>setcd</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> compact disc drive access optimization </entry>
</row>
<row>
<entry> <literal>big-cursor</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> larger mouse cursors for X </entry>
</row>
</tbody>
</tgroup>
</table>
<para>Here, <ulink url="https://en.wikipedia.org/wiki/Advanced_Configuration_and_Power_Interface">ACPI</ulink> is a newer framework for the power management system than <ulink url="https://en.wikipedia.org/wiki/Advanced_Power_Management">APM</ulink>.</para>
<tip> <para>CPU frequency scaling on modern system is governed by kernel modules such as <literal>acpi_cpufreq</literal>.</para> </tip>
</section>
<section id="_system_and_hardware_time">
<title>System and hardware time</title>
<para>The following sets system and hardware time to MM/DD hh:mm, CCYY.</para>
<screen># date MMDDhhmmCCYY
# hwclock --utc --systohc
# hwclock --show</screen>
<para>Times are normally displayed in the local time on the Debian system but the hardware and system time usually use <ulink url="https://en.wikipedia.org/wiki/UTC">UTC(GMT)</ulink>.</para>
<para>If the hardware time is set to UTC, change the setting to "<literal>UTC=yes</literal>" in the "<literal>/etc/default/rcS</literal>".</para>
<para>The following reconfigure the timezone used by the Debian system.</para>
<screen># dpkg-reconfigure tzdata</screen>
<para>If you wish to update system time via network, consider to use the <ulink url="https://en.wikipedia.org/wiki/Network_Time_Protocol">NTP</ulink> service with the packages such as <literal>ntp</literal>, <literal>ntpdate</literal>, and <literal>chrony</literal>.</para>
<tip>
<para>Under <ulink url="https://en.wikipedia.org/wiki/Systemd">systemd</ulink>, use <literal>systemd-timesyncd</literal> for the network time synchronization instead. See <literal>systemd-timesyncd</literal>(8).</para>
</tip>
<para>See the following.</para>
<itemizedlist>
<listitem> <para> <ulink url="https://tldp.org/HOWTO/TimePrecision-HOWTO/index.html">Managing Accurate Date and Time HOWTO</ulink> </para> </listitem>
<listitem> <para> <ulink url="https://www.ntp.org/">NTP Public Services Project</ulink> </para> </listitem>
<listitem> <para> The <literal>ntp-doc</literal> package </para> </listitem>
</itemizedlist>
<tip> <para><literal>ntptrace</literal>(8) in the <literal>ntp</literal> package can trace a chain of NTP servers back to the primary source.</para> </tip>
</section>
<section id="_the_terminal_configuration">
<title>The terminal configuration</title>
<para>There are several components to configure character console and <literal>ncurses</literal>(3) system features.</para>
<itemizedlist>
<listitem> <para> The "<literal>/etc/terminfo/*/*</literal>" file (<literal>terminfo</literal>(5)) </para> </listitem>
<listitem> <para> The "<literal>$TERM</literal>" environment variable (<literal>term</literal>(7)) </para> </listitem>
<listitem> <para><literal>setterm</literal>(1), <literal>stty</literal>(1), <literal>tic</literal>(1), and <literal>toe</literal>(1) </para> </listitem>
</itemizedlist>
<para>If the <literal>terminfo</literal> entry for <literal>xterm</literal> doesn't work with a non-Debian <literal>xterm</literal>, change your terminal type, "<literal>$TERM</literal>", from "<literal>xterm</literal>" to one of the feature-limited versions such as "<literal>xterm-r6</literal>" when you log in to a Debian system remotely. See "<literal>/usr/share/doc/libncurses5/FAQ</literal>" for more. "<literal>dumb</literal>" is the lowest common denominator for "<literal>$TERM</literal>".</para>
</section>
<section id="_the_sound_infrastructure">
<title>The sound infrastructure</title>
<para>Device drivers for sound cards for current Linux are provided by <ulink url="https://en.wikipedia.org/wiki/Advanced_Linux_Sound_Architecture">Advanced Linux Sound Architecture (ALSA)</ulink>. ALSA provides emulation mode for previous <ulink url="https://en.wikipedia.org/wiki/Open_Sound_System">Open Sound System (OSS)</ulink> for compatibility.</para>
<para>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 <ulink url="https://wiki.debian.org/Sound">Debian wiki page on Sound</ulink> for the latest situation.</para>
<para>There is usually a common sound engine for each popular desktop environment. Each sound engine used by the application can choose to connect to different sound servers.</para>
<tip> <para>Use "<literal>cat /dev/urandom &gt; /dev/audio</literal>" or <literal>speaker-test</literal>(1) to test speaker (^C to stop).</para> </tip>
<tip> <para>If you can not get sound, your speaker may be connected to a muted output. Modern sound system has many outputs. <literal>alsamixer</literal>(1) in the <literal>alsa-utils</literal> package is useful to configure volume and mute settings.</para> </tip>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>List of sound packages</title>
<tgroup cols="4">
<colspec colwidth="114pt" align="left"/>
<colspec colwidth="76pt" align="left"/>
<colspec colwidth="70pt" align="left"/>
<colspec colwidth="488pt" align="left"/>
<thead>
<row>
<entry> package </entry>
<entry> popcon </entry>
<entry> size </entry>
<entry> description </entry>
</row>
</thead>
<tbody>
<row>
<entry> <literal>alsa-utils</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> utilities for configuring and using ALSA </entry>
</row>
<row>
<entry> <literal>oss-compat</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> OSS compatibility under ALSA preventing "<literal>/dev/dsp not found</literal>" errors </entry>
</row>
<row>
<entry> <literal>pipewire</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry><ulink url="https://en.wikipedia.org/wiki/PipeWire">audio and video processing engine multimedia server</ulink> - metapackage </entry>
</row>
<row>
<entry> <literal>pipewire-bin</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry><ulink url="https://en.wikipedia.org/wiki/PipeWire">audio and video processing engine multimedia server</ulink> - audio server and CLI programs </entry>
</row>
<row>
<entry> <literal>pipewire-alsa</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry><ulink url="https://en.wikipedia.org/wiki/PipeWire">audio and video processing engine multimedia server</ulink> - audio server to replace ALSA </entry>
</row>
<row>
<entry> <literal>pipewire-pulse</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry><ulink url="https://en.wikipedia.org/wiki/PipeWire">audio and video processing engine multimedia server</ulink> - audio server to replace PulseAudio </entry>
</row>
<row>
<entry> <literal>pulseaudio</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry><ulink url="https://en.wikipedia.org/wiki/PulseAudio">PulseAudio</ulink> server </entry>
</row>
<row>
<entry> <literal>libpulse0</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry><ulink url="https://en.wikipedia.org/wiki/PulseAudio">PulseAudio</ulink> client library </entry>
</row>
<row>
<entry> <literal>jackd</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry><ulink url="https://en.wikipedia.org/wiki/JACK_Audio_Connection_Kit">JACK Audio Connection Kit. (JACK)</ulink> server (low latency) </entry>
</row>
<row>
<entry> <literal>libjack0</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry><ulink url="https://en.wikipedia.org/wiki/JACK_Audio_Connection_Kit">JACK Audio Connection Kit. (JACK)</ulink> library (low latency) </entry>
</row>
<row>
<entry> <literal>libgstreamer1.0-0</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry><ulink url="https://en.wikipedia.org/wiki/GStreamer">GStreamer</ulink>: GNOME sound engine </entry>
</row>
<row>
<entry> <literal>libphonon4qt5-4</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry><ulink url="https://en.wikipedia.org/wiki/Phonon_(KDE)">Phonon</ulink>: KDE sound engine </entry>
</row>
</tbody>
</tgroup>
</table>
</section>
<section id="_disabling_the_screen_saver">
<title>Disabling the screen saver</title>
<para>For disabling the screen saver, use following commands.</para>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>List of commands for disabling the screen saver</title>
<tgroup cols="2">
<colspec colwidth="271pt" align="left"/>
<colspec colwidth="162pt" align="left"/>
<thead>
<row>
<entry> environment </entry>
<entry> command </entry>
</row>
</thead>
<tbody>
<row>
<entry> The Linux console </entry>
<entry> <literal>setterm -powersave off</literal> </entry>
</row>
<row>
<entry> The X Window (turning off screensaver) </entry>
<entry> <literal>xset s off</literal> </entry>
</row>
<row>
<entry> The X Window (disabling dpms) </entry>
<entry> <literal>xset -dpms</literal> </entry>
</row>
<row>
<entry> The X Window (GUI configuration of screen saver) </entry>
<entry> <literal>xscreensaver-command -prefs</literal> </entry>
</row>
</tbody>
</tgroup>
</table>
</section>
<section id="_disabling_beep_sounds">
<title>Disabling beep sounds</title>
<para>One can always unplug the PC speaker to disable beep sounds. Removing <literal>pcspkr</literal> kernel module does this for you.</para>
<para>The following prevents the <literal>readline</literal>(3) program used by <literal>bash</literal>(1) to beep when encountering an alert character (ASCII=7).</para>
<screen>$ echo "set bell-style none"&gt;&gt; ~/.inputrc</screen>
</section>
<section id="_memory_usage">
<title>Memory usage</title>
<para>There are 2 resources available for you to get the memory usage situation.</para>
<itemizedlist>
<listitem> <para> The kernel boot message in the "<literal>/var/log/dmesg</literal>" contains the total exact size of available memory. </para> </listitem>
<listitem> <para><literal>free</literal>(1) and <literal>top</literal>(1) display information on memory resources on the running system. </para> </listitem>
</itemizedlist>
<para>Here is an example.</para>
<screen># 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</screen>
<para>You may be wondering "dmesg tells me a free of 990 MB, and free -k says 320 MB is free. More than 600 MB missing …".</para>
<para>Do not worry about the large size of "<literal>used</literal>" and the small size of "<literal>free</literal>" in the "<literal>Mem:</literal>" line, but read the one under them (675404 and 321780 in the example above) and relax.</para>
<para>For my MacBook with 1GB=1048576k DRAM (video system steals some of this), I see the following.</para>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>List of memory sizes reported</title>
<tgroup cols="2">
<colspec colwidth="108pt" align="left"/>
<colspec colwidth="130pt" align="left"/>
<thead>
<row>
<entry> report </entry>
<entry> size </entry>
</row>
</thead>
<tbody>
<row>
<entry> Total size in dmesg </entry>
<entry> 1016784k = 1GB - 31792k </entry>
</row>
<row>
<entry> Free in dmesg </entry>
<entry> 990528k </entry>
</row>
<row>
<entry> Total under shell </entry>
<entry> 997184k </entry>
</row>
<row>
<entry> Free under shell </entry>
<entry> 20256k (but effectively 321780k) </entry>
</row>
</tbody>
</tgroup>
</table>
</section>
<section id="_system_security_and_integrity_check">
<title>System security and integrity check</title>
<para>Poor system maintenance may expose your system to external exploitation.</para>
<para>For system security and integrity check, you should start with the following.</para>
<itemizedlist>
<listitem> <para> The <literal>debsums</literal> package, see <literal>debsums</literal>(1) and <xref linkend="_top_level_release_file_and_authenticity"/>. </para> </listitem>
<listitem> <para> The <literal>chkrootkit</literal> package, see <literal>chkrootkit</literal>(1). </para> </listitem>
<listitem> <para> The <literal>clamav</literal> package family, see <literal>clamscan</literal>(1) and <literal>freshclam</literal>(1). </para> </listitem>
<listitem> <para><ulink url="https://www.debian.org/security/faq">Debian security FAQ</ulink>. </para> </listitem>
<listitem> <para><ulink url="https://www.debian.org/doc/manuals/securing-debian-manual/">Securing Debian Manual</ulink>. </para> </listitem>
</itemizedlist>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>List of tools for system security and integrity check</title>
<tgroup cols="4">
<colspec colwidth="70pt" align="left"/>
<colspec colwidth="76pt" align="left"/>
<colspec colwidth="70pt" align="left"/>
<colspec colwidth="352pt" align="left"/>
<thead>
<row>
<entry> package </entry>
<entry> popcon </entry>
<entry> size </entry>
<entry> description </entry>
</row>
</thead>
<tbody>
<row>
<entry> <literal>logcheck</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> daemon to mail anomalies in the system logfiles to the administrator </entry>
</row>
<row>
<entry> <literal>debsums</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> utility to verify installed package files against MD5 checksums </entry>
</row>
<row>
<entry> <literal>chkrootkit</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry><ulink url="https://en.wikipedia.org/wiki/Rootkit">rootkit</ulink> detector </entry>
</row>
<row>
<entry> <literal>clamav</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> anti-virus utility for Unix - command-line interface </entry>
</row>
<row>
<entry> <literal>tiger</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> report system security vulnerabilities </entry>
</row>
<row>
<entry> <literal>tripwire</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> file and directory integrity checker </entry>
</row>
<row>
<entry> <literal>john</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> active password cracking tool </entry>
</row>
<row>
<entry> <literal>aide</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> Advanced Intrusion Detection Environment - static binary </entry>
</row>
<row>
<entry> <literal>integrit</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> file integrity verification program </entry>
</row>
<row>
<entry> <literal>crack</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> password guessing program </entry>
</row>
</tbody>
</tgroup>
</table>
<para>Here is a simple script to check for typical world writable incorrect file permissions.</para>
<screen># find / -perm 777 -a \! -type s -a \! -type l -a \! \( -type d -a -perm 1777 \)</screen>
<caution> <para>Since the <literal>debsums</literal> package uses <ulink url="https://en.wikipedia.org/wiki/MD5">MD5</ulink> checksums stored locally, it can not be fully trusted as the system security audit tool against malicious attacks.</para> </caution>
</section>
</section>
<section id="_data_storage_tips">
<title>Data storage tips</title>
<para>Booting your system with Linux <ulink url="https://en.wikipedia.org/wiki/Live_CD">live CDs</ulink> or <ulink url="https://www.debian.org/releases/stable/debian-installer/">debian-installer CDs</ulink> in rescue mode makes it easy for you to reconfigure data storage on your boot device.</para>
<para>You may need to <literal>umount</literal>(8) some devices manually from the command line before operating on them if they are automatically mounted by the GUI desktop system.</para>
<section id="_disk_space_usage">
<title>Disk space usage</title>
<para>The disk space usage can be evaluated by programs provided by the <literal>mount</literal>, <literal>coreutils</literal>, and <literal>xdu</literal> packages:</para>
<itemizedlist>
<listitem> <para><literal>mount</literal>(8) reports all mounted filesystems (= disks). </para> </listitem>
<listitem> <para><literal>df</literal>(1) reports the disk space usage for the file system. </para> </listitem>
<listitem> <para><literal>du</literal>(1) reports the disk space usage for the directory tree. </para> </listitem>
</itemizedlist>
<tip> <para>You can feed the output of <literal>du</literal>(8) to <literal>xdu</literal>(1x) to produce its graphical and interactive presentation with "<literal>du -k . |xdu</literal>", "<literal>sudo du -k -x / |xdu</literal>", etc.</para> </tip>
</section>
<section id="_disk_partition_configuration">
<title>Disk partition configuration</title>
<para>For <ulink url="https://en.wikipedia.org/wiki/Disk_partitioning">disk partition</ulink> configuration, although <literal>fdisk</literal>(8) has been considered standard, <literal>parted</literal>(8) deserves some attention. "Disk partitioning data", "partition table", "partition map", and "disk label" are all synonyms.</para>
<para>Older PCs use the classic <ulink url="https://en.wikipedia.org/wiki/Master_boot_record">Master Boot Record (MBR)</ulink> scheme to hold <ulink url="https://en.wikipedia.org/wiki/Disk_partitioning">disk partitioning</ulink> data in the first sector, i.e., <ulink url="https://en.wikipedia.org/wiki/Logical_block_addressing">LBA</ulink> sector 0 (512 bytes).</para>
<para>Recent PCs with <ulink url="https://en.wikipedia.org/wiki/Unified_Extensible_Firmware_Interface">Unified Extensible Firmware Interface (UEFI)</ulink>, including Intel-based Macs, use <ulink url="https://en.wikipedia.org/wiki/GUID_Partition_Table">GUID Partition Table (GPT)</ulink> scheme to hold <ulink url="https://en.wikipedia.org/wiki/Disk_partitioning">disk partitioning</ulink> data not in the first sector.</para>
<para>Although <literal>fdisk</literal>(8) has been standard for the disk partitioning tool, <literal>parted</literal>(8) is replacing it.</para>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>List of disk partition management packages</title>
<tgroup cols="4">
<colspec colwidth="70pt" align="left"/>
<colspec colwidth="76pt" align="left"/>
<colspec colwidth="70pt" align="left"/>
<colspec colwidth="369pt" align="left"/>
<thead>
<row>
<entry> package </entry>
<entry> popcon </entry>
<entry> size </entry>
<entry> description </entry>
</row>
</thead>
<tbody>
<row>
<entry> <literal>util-linux</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> miscellaneous system utilities including <literal>fdisk</literal>(8) and <literal>cfdisk</literal>(8) </entry>
</row>
<row>
<entry> <literal>parted</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> GNU Parted disk partition resizing program </entry>
</row>
<row>
<entry> <literal>gparted</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> GNOME partition editor based on <literal>libparted</literal> </entry>
</row>
<row>
<entry> <literal>gdisk</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> partition editor for the GPT/MBR hybrid disk </entry>
</row>
<row>
<entry> <literal>kpartx</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> program to create device mappings for partitions </entry>
</row>
</tbody>
</tgroup>
</table>
<caution> <para>Although <literal>parted</literal>(8) claims to create and to resize filesystem too, it is safer to do such things using best maintained specialized tools such as <literal>mkfs</literal>(8) (<literal>mkfs.msdos</literal>(8), <literal>mkfs.ext2</literal>(8), <literal>mkfs.ext3</literal>(8), <literal>mkfs.ext4</literal>(8), …) and <literal>resize2fs</literal>(8).</para> </caution>
<note> <para>In order to switch between <ulink url="https://en.wikipedia.org/wiki/GUID_Partition_Table">GPT</ulink> and <ulink url="https://en.wikipedia.org/wiki/Master_boot_record">MBR</ulink>, you need to erase first few blocks of disk contents directly (see <xref linkend="_clearing_file_contents"/>) and use "<literal>parted /dev/sdx mklabel gpt</literal>" or "<literal>parted /dev/sdx mklabel msdos</literal>" to set it. Please note "<literal>msdos</literal>" is use here for <ulink url="https://en.wikipedia.org/wiki/Master_boot_record">MBR</ulink>.</para> </note>
</section>
<section id="_accessing_partition_using_uuid">
<title>Accessing partition using UUID</title>
<para>Although reconfiguration of your partition or activation order of removable storage media may yield different names for partitions, you can access them consistently. This is also helpful if you have multiple disks and your BIOS/UEFI doesn't give them consistent device names.</para>
<itemizedlist>
<listitem> <para><literal>mount</literal>(8) with "<literal>-U</literal>" option can mount a block device using <ulink url="https://en.wikipedia.org/wiki/Universally_Unique_Identifier">UUID</ulink>, instead of using its file name such as "<literal>/dev/sda3</literal>". </para> </listitem>
<listitem> <para> "<literal>/etc/fstab</literal>" (see <literal>fstab</literal>(5)) can use <ulink url="https://en.wikipedia.org/wiki/Universally_Unique_Identifier">UUID</ulink>. </para> </listitem>
<listitem> <para> Boot loaders (<xref linkend="_stage_2_the_boot_loader"/>) may use <ulink url="https://en.wikipedia.org/wiki/Universally_Unique_Identifier">UUID</ulink> too. </para> </listitem>
</itemizedlist>
<tip>
<para>You can probe <ulink url="https://en.wikipedia.org/wiki/Universally_Unique_Identifier">UUID</ulink> of a block special device with <literal>blkid</literal>(8).</para>
<para>You can also probe UUID and other information with "<literal>lsblk -f</literal>".</para>
</tip>
</section>
<section id="_lvm2">
<title>LVM2</title>
<para>LVM2 is a <ulink url="https://en.wikipedia.org/wiki/Logical_Volume_Manager_(Linux)">logical volume manager</ulink> for the Linux kernel. With LVM2, disk partitions can be created on logical volumes instead of the physical harddisks.</para>
<para>LVM requires the following.</para>
<itemizedlist>
<listitem> <para> device-mapper support in the Linux kernel (default for Debian kernels) </para> </listitem>
<listitem> <para> the userspace device-mapper support library (<literal>libdevmapper*</literal> package) </para> </listitem>
<listitem> <para> the userspace LVM2 tools (<literal>lvm2</literal> package) </para> </listitem>
</itemizedlist>
<para>Please start learning LVM2 from the following manpages.</para>
<itemizedlist>
<listitem> <para><literal>lvm</literal>(8): Basics of LVM2 mechanism (list of all LVM2 commands) </para> </listitem>
<listitem> <para><literal>lvm.conf</literal>(5): Configuration file for LVM2 </para> </listitem>
<listitem> <para><literal>lvs</literal>(8): Report information about logical volumes </para> </listitem>
<listitem> <para><literal>vgs</literal>(8): Report information about volume groups </para> </listitem>
<listitem> <para><literal>pvs</literal>(8): Report information about physical volumes </para> </listitem>
</itemizedlist>
</section>
<section id="_filesystem_configuration">
<title>Filesystem configuration</title>
<para>For <ulink url="https://en.wikipedia.org/wiki/Ext4">ext4</ulink> filesystem, the <literal>e2fsprogs</literal> package provides the following.</para>
<itemizedlist>
<listitem> <para><literal>mkfs.ext4</literal>(8) to create new <ulink url="https://en.wikipedia.org/wiki/Ext4">ext4</ulink> filesystem </para> </listitem>
<listitem> <para><literal>fsck.ext4</literal>(8) to check and to repair existing <ulink url="https://en.wikipedia.org/wiki/Ext4">ext4</ulink> filesystem </para> </listitem>
<listitem> <para><literal>tune2fs</literal>(8) to configure superblock of <ulink url="https://en.wikipedia.org/wiki/Ext4">ext4</ulink> filesystem </para> </listitem>
<listitem> <para><literal>debugfs</literal>(8) to debug <ulink url="https://en.wikipedia.org/wiki/Ext4">ext4</ulink> filesystem interactively. (It has <literal>undel</literal> command to recover deleted files.) </para> </listitem>
</itemizedlist>
<para>The <literal>mkfs</literal>(8) and <literal>fsck</literal>(8) commands are provided by the <literal>e2fsprogs</literal> package as front-ends to various filesystem dependent programs (<literal>mkfs.fstype</literal> and <literal>fsck.fstype</literal>). For <ulink url="https://en.wikipedia.org/wiki/Ext4">ext4</ulink> filesystem, they are <literal>mkfs.ext4</literal>(8) and <literal>fsck.ext4</literal>(8) (they are symlinked to <literal>mke2fs</literal>(8) and <literal>e2fsck</literal>(8)).</para>
<para>Similar commands are available for each filesystem supported by Linux.</para>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>List of filesystem management packages</title>
<tgroup cols="4">
<colspec colwidth="86pt" align="left"/>
<colspec colwidth="76pt" align="left"/>
<colspec colwidth="70pt" align="left"/>
<colspec colwidth="515pt" align="left"/>
<thead>
<row>
<entry> package </entry>
<entry> popcon </entry>
<entry> size </entry>
<entry> description </entry>
</row>
</thead>
<tbody>
<row>
<entry> <literal>e2fsprogs</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> utilities for the <ulink url="https://en.wikipedia.org/wiki/Ext2">ext2</ulink>/<ulink url="https://en.wikipedia.org/wiki/Ext3">ext3</ulink>/<ulink url="https://en.wikipedia.org/wiki/Ext4">ext4</ulink> filesystems </entry>
</row>
<row>
<entry> <literal>btrfs-progs</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> utilities for the <ulink url="https://en.wikipedia.org/wiki/Btrfs">Btrfs</ulink> filesystem </entry>
</row>
<row>
<entry> <literal>reiserfsprogs</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> utilities for the <ulink url="https://en.wikipedia.org/wiki/Reiserfs">Reiserfs</ulink> filesystem </entry>
</row>
<row>
<entry> <literal>zfsutils-linux</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> utilities for the <ulink url="https://en.wikipedia.org/wiki/OpenZFS">OpenZFS</ulink> filesystem </entry>
</row>
<row>
<entry> <literal>dosfstools</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> utilities for the <ulink url="https://en.wikipedia.org/wiki/File_Allocation_Table">FAT</ulink> filesystem. (Microsoft: MS-DOS, Windows) </entry>
</row>
<row>
<entry> <literal>exfatprogs</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> utilities for the <ulink url="https://en.wikipedia.org/wiki/ExFAT">exFAT</ulink> filesystem maintained by Samsung. </entry>
</row>
<row>
<entry> <literal>exfat-fuse</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> read/write <ulink url="https://en.wikipedia.org/wiki/ExFAT">exFAT</ulink> filesystem (Microsoft) driver for FUSE. </entry>
</row>
<!--
<row>
<entry> <literal>exfat-utils</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> utilities for the <ulink url="https://en.wikipedia.org/wiki/ExFAT">exFAT</ulink> filesystem maintained by the exfat-fuse author. </entry>
</row>
-->
<row>
<entry> <literal>xfsprogs</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> utilities for the <ulink url="https://en.wikipedia.org/wiki/XFS">XFS</ulink> filesystem. (SGI: IRIX) </entry>
</row>
<row>
<entry> <literal>ntfs-3g</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> read/write <ulink url="https://en.wikipedia.org/wiki/NTFS">NTFS</ulink> filesystem (Microsoft: Windows NT, …) driver for FUSE. </entry>
</row>
<row>
<entry> <literal>jfsutils</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> utilities for the <ulink url="https://en.wikipedia.org/wiki/JFS_(file_system)">JFS</ulink> filesystem. (IBM: AIX, OS/2) </entry>
</row>
<row>
<entry> <literal>reiser4progs</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> utilities for the <ulink url="https://en.wikipedia.org/wiki/Reiser4">Reiser4</ulink> filesystem </entry>
</row>
<row>
<entry> <literal>hfsprogs</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> utilities for <ulink url="https://en.wikipedia.org/wiki/Hierarchical_File_System">HFS</ulink> and <ulink url="https://en.wikipedia.org/wiki/HFS_Plus">HFS Plus</ulink> filesystem. (Apple: Mac OS) </entry>
</row>
<row>
<entry> <literal>zerofree</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> program to zero free blocks from ext2/3/4 filesystems </entry>
</row>
</tbody>
</tgroup>
</table>
<tip>
<para><ulink url="https://en.wikipedia.org/wiki/Ext4">Ext4</ulink> filesystem is the default filesystem for the Linux system and strongly recommended to use it unless you have some specific reasons not to.</para>
<para><ulink url="https://en.wikipedia.org/wiki/Btrfs">Btrfs</ulink> status can be found at <ulink url="https://wiki.debian.org/Btrfs">Debian wiki on btrfs</ulink> and <ulink url="https://btrfs.wiki.kernel.org/index.php/Status">kernel.org wiki on btrfs</ulink>. It is expected to be the next default filesystem after the ext4 filesystem.</para>
<para>Some tools allow access to filesystem without Linux kernel support (see <xref linkend="_manipulating_files_without_mounting_disk"/>).</para>
</tip>
</section>
<section id="_filesystem_creation_and_integrity_check">
<title>Filesystem creation and integrity check</title>
<para>The <literal>mkfs</literal>(8) command creates the filesystem on a Linux system. The <literal>fsck</literal>(8) command provides the filesystem integrity check and repair on a Linux system.</para>
<para>Debian now defaults to no periodic <literal>fsck</literal> after filesystem creation.</para>
<caution> <para>It is generally not safe to run <literal>fsck</literal> on <emphasis role="strong">mounted filesystems</emphasis>.</para> </caution>
<tip>
<para>You can run the <literal>fsck</literal>(8) command safely on all filesystems including root filesystem on reboot by setting "<literal>enable_periodic_fsck</literal>" in "<literal>/etc/mke2fs.conf</literal>" and the max mount count to 0 using "<literal>tune2fs -c0 /dev/<emphasis>partition_name</emphasis></literal>". See <literal>mke2fs.conf</literal>(5) and <literal>tune2fs</literal>(8).</para>
<para>Check files in "<literal>/var/log/fsck/</literal>" for the result of the <literal>fsck</literal>(8) command run from the boot script.</para>
</tip>
</section>
<section id="_optimization_of_filesystem_by_mount_options">
<title>Optimization of filesystem by mount options</title>
<para>The basic static filesystem configuration is given by "<literal>/etc/fstab</literal>". For example,</para>
<screen>«file system» «mount point» «type» «options» «dump» «pass»
proc /proc proc defaults 0 0
UUID=709cbe4c-80c1-56db-8ab1-dbce3146d2f7 / ext4 errors=remount-ro 0 1
UUID=817bae6b-45d2-5aca-4d2a-1267ab46ac23 none swap sw 0 0
/dev/scd0 /media/cdrom0 udf,iso9660 user,noauto 0 0</screen>
<tip> <para><ulink url="https://en.wikipedia.org/wiki/Universally_Unique_Identifier">UUID</ulink> (see <xref linkend="_accessing_partition_using_uuid"/>) may be used to identify a block device instead of normal block device names such as "<literal>/dev/sda1</literal>", "<literal>/dev/sda2</literal>", …</para> </tip>
<para>Since Linux 2.6.30, the kernel defaults to the behavior provided by "<literal>relatime</literal>" option. </para>
<para>See <literal>fstab</literal>(5) and <literal>mount</literal>(8).</para>
</section>
<section id="_optimization_of_filesystem_via_superblock">
<title>Optimization of filesystem via superblock</title>
<para>Characteristics of a filesystem can be optimized via its superblock using the <literal>tune2fs</literal>(8) command.</para>
<itemizedlist>
<listitem> <para> Execution of "<literal>sudo tune2fs -l /dev/hda1</literal>" displays the contents of the filesystem superblock on "<literal>/dev/hda1</literal>". </para> </listitem>
<listitem> <para> Execution of "<literal>sudo tune2fs -c 50 /dev/hda1</literal>" changes frequency of filesystem checks (<literal>fsck</literal> execution during boot-up) to every 50 boots on "<literal>/dev/hda1</literal>". </para> </listitem>
<listitem> <para> Execution of "<literal>sudo tune2fs -j /dev/hda1</literal>" adds journaling capability to the filesystem, i.e. filesystem conversion from <ulink url="https://en.wikipedia.org/wiki/Ext2">ext2</ulink> to <ulink url="https://en.wikipedia.org/wiki/Ext3">ext3</ulink> on "<literal>/dev/hda1</literal>". (Do this on the unmounted filesystem.) </para> </listitem>
<listitem> <para> Execution of "<literal>sudo tune2fs -O extents,uninit_bg,dir_index /dev/hda1 &amp;&amp; fsck -pf /dev/hda1</literal>" converts it from <ulink url="https://en.wikipedia.org/wiki/Ext3">ext3</ulink> to <ulink url="https://en.wikipedia.org/wiki/Ext4">ext4</ulink> on "<literal>/dev/hda1</literal>". (Do this on the unmounted filesystem.) </para> </listitem>
</itemizedlist>
<tip> <para>Despite its name, <literal>tune2fs</literal>(8) works not only on the <ulink url="https://en.wikipedia.org/wiki/Ext2">ext2</ulink> filesystem but also on the <ulink url="https://en.wikipedia.org/wiki/Ext3">ext3</ulink> and <ulink url="https://en.wikipedia.org/wiki/Ext4">ext4</ulink> filesystems.</para> </tip>
</section>
<section id="_optimization_of_hard_disk">
<title>Optimization of hard disk</title>
<warning> <para>Please check your hardware and read manpage of <literal>hdparm</literal>(8) before playing with hard disk configuration because this may be quite dangerous for the data integrity.</para> </warning>
<para>You can test disk access speed of a hard disk, e.g. "<literal>/dev/hda</literal>", by "<literal>hdparm -tT /dev/hda</literal>". For some hard disk connected with (E)IDE, you can speed it up with "<literal>hdparm -q -c3 -d1 -u1 -m16 /dev/hda</literal>" by enabling the "(E)IDE 32-bit I/O support", enabling the "using_dma flag", setting "interrupt-unmask flag", and setting the "multiple 16 sector I/O" (dangerous!).</para>
<para>You can test write cache feature of a hard disk, e.g. "<literal>/dev/sda</literal>", by "<literal>hdparm -W /dev/sda</literal>". You can disable its write cache feature with "<literal>hdparm -W 0 /dev/sda</literal>".</para>
<para>You may be able to read badly pressed CDROMs on modern high speed CD-ROM drive by slowing it down with "<literal>setcd -x 2</literal>".</para>
</section>
<section id="_optimization_of_solid_state_drive">
<title>Optimization of solid state drive</title>
<para><ulink url="https://en.wikipedia.org/wiki/Solid-state_drive">Solid state drive (SSD)</ulink> is auto detected now.</para>
<para>Reduce unnecessary disk accesses to prevent disk wear out by mounting "<literal>tmpfs</literal>" on volatile data path in <literal>/etc/fstab</literal>. </para>
</section>
<section id="_using_smart_to_predict_hard_disk_failure">
<title>Using SMART to predict hard disk failure</title>
<para>You can monitor and log your hard disk which is compliant to <ulink url="https://en.wikipedia.org/wiki/S.M.A.R.T.">SMART</ulink> with the <literal>smartd</literal>(8) daemon.</para>
<orderedlist>
<listitem> <para> Enable <ulink url="https://en.wikipedia.org/wiki/S.M.A.R.T.">SMART</ulink> feature in <ulink url="https://en.wikipedia.org/wiki/BIOS">BIOS</ulink>. </para> </listitem>
<listitem> <para> Install the <literal>smartmontools</literal> package. </para> </listitem>
<listitem>
<para> Identify your hard disk drives by listing them with <literal>df</literal>(1). </para>
<itemizedlist>
<listitem> <para> Let's assume a hard disk drive to be monitored as "<literal>/dev/hda</literal>". </para> </listitem>
</itemizedlist>
</listitem>
<listitem>
<para> Check the output of "<literal>smartctl -a /dev/hda</literal>" to see if <ulink url="https://en.wikipedia.org/wiki/S.M.A.R.T.">SMART</ulink> feature is actually enabled. </para>
<itemizedlist>
<listitem> <para> If not, enable it by "<literal>smartctl -s on -a /dev/hda</literal>". </para> </listitem>
</itemizedlist>
</listitem>
<listitem>
<para> Enable <literal>smartd</literal>(8) daemon to run by the following. </para>
<itemizedlist>
<listitem> <para> uncomment "<literal>start_smartd=yes</literal>" in the "<literal>/etc/default/smartmontools</literal>" file. </para> </listitem>
<listitem> <para> restart the <literal>smartd</literal>(8) daemon by "<literal>sudo systemctl restart smartmontools</literal>". </para> </listitem>
</itemizedlist>
</listitem>
</orderedlist>
<tip> <para>The <literal>smartd</literal>(8) daemon can be customized with the <literal>/etc/smartd.conf</literal> file including how to be notified of warnings.</para> </tip>
</section>
<section id="_specify_temporary_storage_directory_via_tmpdir">
<title>Specify temporary storage directory via $TMPDIR</title>
<para>Applications create temporary files normally under the temporary storage directory "<literal>/tmp</literal>". If "<literal>/tmp</literal>" does not provide enough space, you can specify such temporary storage directory via the <literal>$TMPDIR</literal> variable for well-behaving programs.</para>
</section>
<section id="_expansion_of_usable_storage_space_via_lvm">
<title>Expansion of usable storage space via LVM</title>
<para>For partitions created on <ulink url="https://en.wikipedia.org/wiki/Logical_Volume_Manager_(Linux)">Logical Volume Manager (LVM)</ulink> (Linux feature) at install time, they can be resized easily by concatenating extents onto them or truncating extents from them over multiple storage devices without major system reconfiguration.</para>
</section>
<section id="_expansion_of_usable_storage_space_by_mounting_another_partition">
<title>Expansion of usable storage space by mounting another partition</title>
<para>If you have an empty partition (e.g., "<literal>/dev/sdx</literal>"), you can format it with <literal>mkfs.ext4</literal>(1) and <literal>mount</literal>(8) it to a directory where you need more space. (You need to copy original data contents.)</para>
<screen>$ sudo mv work-dir old-dir
$ sudo mkfs.ext4 /dev/sdx
$ sudo mount -t ext4 /dev/sdx work-dir
$ sudo cp -a old-dir/* work-dir
$ sudo rm -rf old-dir</screen>
<tip> <para>You may alternatively mount an empty disk image file (see <xref linkend="_making_the_empty_disk_image_file"/>) as a loop device (see <xref linkend="_mounting_the_disk_image_file"/>). The actual disk usage grows with the actual data stored.</para> </tip>
</section>
<section id="_expansion_of_usable_storage_space_by_bind_mounting_another_directory">
<title>Expansion of usable storage space by bind-mounting another directory</title>
<para>If you have an empty directory (e.g., "<literal>/path/to/emp-dir</literal>") on another partition with usable space, you can mount(8) it with "<literal>--bind</literal>" option to a directory (e.g., "<literal>work-dir</literal>") where you need more space.</para>
<screen>$ sudo mount --bind /path/to/emp-dir work-dir</screen>
</section>
<section id="_expansion_of_usable_storage_space_by_overlay_mounting_another_directory">
<title>Expansion of usable storage space by overlay-mounting another directory</title>
<para>If you have usable space in another partition (e.g., "<literal>/path/to/empty</literal>" and "<literal>/path/to/work</literal>"), you can create a directory in it and stack that on to an old directory (e.g., "<literal>/path/to/old</literal>") where you need space using the <ulink url="https://en.wikipedia.org/wiki/OverlayFS">OverlayFS</ulink> for Linux kernel 3.18 or newer (Debian Stretch 9.0 or newer).</para>
<screen>$ sudo mount -t overlay overlay \
-olowerdir=/path/to/old-dir,upperdir=/path/to/empty,workdir=/path/to/work</screen>
<para>Here, "<literal>/path/to/empty</literal>" and "<literal>/path/to/work</literal>" should be on the RW-enabled partition to write on "<literal>/path/to/old</literal>".</para>
</section>
<section id="_expansion_of_usable_storage_space_using_symlink">
<title>Expansion of usable storage space using symlink</title>
<caution> <para>This is a deprecated method. Some software may not function well with "symlink to a directory". Instead, use the "mounting" approaches described in the above.</para> </caution>
<para>If you have an empty directory (e.g., "<literal>/path/to/emp-dir</literal>") in another partition with usable space, you can create a symlink to the directory with <literal>ln</literal>(8).</para>
<screen>$ sudo mv work-dir old-dir
$ sudo mkdir -p /path/to/emp-dir
$ sudo ln -sf /path/to/emp-dir work-dir
$ sudo cp -a old-dir/* work-dir
$ sudo rm -rf old-dir</screen>
<warning> <para>Do not use "symlink to a directory" for directories managed by the system such as "<literal>/opt</literal>". Such a symlink may be overwritten when the system is upgraded.</para> </warning>
</section>
</section>
<section id="_the_disk_image">
<title>The disk image</title>
<para>Here, we discuss manipulations of the disk image.</para>
<section id="_making_the_disk_image_file">
<title>Making the disk image file</title>
<para>The disk image file, "<literal>disk.img</literal>", of an unmounted device, e.g., the second SCSI or serial ATA drive "<literal>/dev/sdb</literal>", can be made using <literal>cp</literal>(1) or <literal>dd</literal>(1) by the following.</para>
<screen># cp /dev/sdb disk.img
# dd if=/dev/sdb of=disk.img</screen>
<para>The disk image of the traditional PC's <ulink url="https://en.wikipedia.org/wiki/Master_boot_record">master boot record (MBR)</ulink> (see <xref linkend="_disk_partition_configuration"/>) which reside on the first sector on the primary IDE disk can be made by using <literal>dd</literal>(1) by the following.</para>
<screen># 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</screen>
<itemizedlist>
<listitem> <para> "<literal>mbr.img</literal>": The MBR with the partition table </para> </listitem>
<listitem> <para> "<literal>mbr-nopart.img</literal>": The MBR without the partition table </para> </listitem>
<listitem> <para> "<literal>mbr-part.img</literal>": The partition table of the MBR only </para> </listitem>
</itemizedlist>
<para>If you have an SCSI or serial ATA device as the boot disk, substitute "<literal>/dev/hda</literal>" with "<literal>/dev/sda</literal>".</para>
<para>If you are making an image of a disk partition of the original disk, substitute "<literal>/dev/hda</literal>" with "<literal>/dev/hda1</literal>" etc.</para>
</section>
<section id="_writing_directly_to_the_disk">
<title>Writing directly to the disk</title>
<para>The disk image file, "<literal>disk.img</literal>" can be written to an unmounted device, e.g., the second SCSI drive "<literal>/dev/sdb</literal>" with matching size, by the following.</para>
<screen># dd if=disk.img of=/dev/sdb</screen>
<para>Similarly, the disk partition image file, "<literal>partition.img</literal>" can be written to an unmounted partition, e.g., the first partition of the second SCSI drive "<literal>/dev/sdb1</literal>" with matching size, by the following.</para>
<screen># dd if=partition.img of=/dev/sdb1</screen>
</section>
<section id="_mounting_the_disk_image_file">
<title>Mounting the disk image file</title>
<para>The disk image "<literal>partition.img</literal>" containing a single partition image can be mounted and unmounted by using the <ulink url="https://en.wikipedia.org/wiki/Loop_device">loop device</ulink> as follows.</para>
<screen># losetup --show -f partition.img
/dev/loop0
# mkdir -p /mnt/loop0
# mount -t auto /dev/loop0 /mnt/loop0
...hack...hack...hack
# umount /dev/loop0
# losetup -d /dev/loop0</screen>
<para>This can be simplified as follows.</para>
<screen># mkdir -p /mnt/loop0
# mount -t auto -o loop partition.img /mnt/loop0
...hack...hack...hack
# umount partition.img</screen>
<!--
Post kernel version 3.2+ and util-linux 2.21+ support mounting multiple partitions. (After 2012-01).
losetup and kpartx has changed behavior. So script outputs are updated in 2024-04-03.
Disk image used below is the official cloud Debian image from https://cloud.debian.org/images/cloud/
-->
<para>Each partition of the disk image "<literal>disk.img</literal>" containing multiple partitions can be mounted by using the <ulink url="https://en.wikipedia.org/wiki/Loop_device">loop device</ulink>.</para>
<screen># losetup --show -f -P disk.img
/dev/loop0
# ls -l /dev/loop0*
brw-rw---- 1 root disk 7, 0 Apr 2 22:51 /dev/loop0
brw-rw---- 1 root disk 259, 12 Apr 2 22:51 /dev/loop0p1
brw-rw---- 1 root disk 259, 13 Apr 2 22:51 /dev/loop0p14
brw-rw---- 1 root disk 259, 14 Apr 2 22:51 /dev/loop0p15
# fdisk -l /dev/loop0
Disk /dev/loop0: 2 GiB, 2147483648 bytes, 4194304 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 6A1D9E28-C48C-2144-91F7-968B3CBC9BD1
Device Start End Sectors Size Type
/dev/loop0p1 262144 4192255 3930112 1.9G Linux root (x86-64)
/dev/loop0p14 2048 8191 6144 3M BIOS boot
/dev/loop0p15 8192 262143 253952 124M EFI System
Partition table entries are not in disk order.
# mkdir -p /mnt/loop0p1
# mkdir -p /mnt/loop0p15
# mount -t auto /dev/loop0p1 /mnt/loop0p1
# mount -t auto /dev/loop0p15 /mnt/loop0p15
# mount |grep loop
/dev/loop0p1 on /mnt/loop0p1 type ext4 (rw,relatime)
/dev/loop0p15 on /mnt/loop0p15 type vfat (rw,relatime,fmask=0002,dmask=0002,allow_utime=0020,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro)
...hack...hack...hack
# umount /dev/loop0p1
# umount /dev/loop0p15
# losetup -d /dev/loop0</screen>
<para>Alternatively, similar effects can be done by using the <ulink url="https://en.wikipedia.org/wiki/Device_mapper">device mapper</ulink> devices created by <literal>kpartx</literal>(8) from the <literal>kpartx</literal> package as follows.</para>
<screen># kpartx -a -v disk.img
add map loop0p1 (253:0): 0 3930112 linear 7:0 262144
add map loop0p14 (253:1): 0 6144 linear 7:0 2048
add map loop0p15 (253:2): 0 253952 linear 7:0 8192
# fdisk -l /dev/loop0
Disk /dev/loop0: 2 GiB, 2147483648 bytes, 4194304 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 6A1D9E28-C48C-2144-91F7-968B3CBC9BD1
Device Start End Sectors Size Type
/dev/loop0p1 262144 4192255 3930112 1.9G Linux root (x86-64)
/dev/loop0p14 2048 8191 6144 3M BIOS boot
/dev/loop0p15 8192 262143 253952 124M EFI System
Partition table entries are not in disk order.
# ls -l /dev/mapper/
total 0
crw------- 1 root root 10, 236 Apr 2 22:45 control
lrwxrwxrwx 1 root root 7 Apr 2 23:19 loop0p1 -> ../dm-0
lrwxrwxrwx 1 root root 7 Apr 2 23:19 loop0p14 -> ../dm-1
lrwxrwxrwx 1 root root 7 Apr 2 23:19 loop0p15 -> ../dm-2
# mkdir -p /mnt/loop0p1
# mkdir -p /mnt/loop0p15
# mount -t auto /dev/mapper/loop0p1 /mnt/loop0p1
# mount -t auto /dev/mapper/loop0p15 /mnt/loop0p15
# mount |grep loop
/dev/loop0p1 on /mnt/loop0p1 type ext4 (rw,relatime)
/dev/loop0p15 on /mnt/loop0p15 type vfat (rw,relatime,fmask=0002,dmask=0002,allow_utime=0020,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro)
...hack...hack...hack
# umount /dev/mapper/loop0p1
# umount /dev/mapper/loop0p15
# kpartx -d disk.img</screen>
</section>
<section id="_cleaning_a_disk_image_file">
<title>Cleaning a disk image file</title>
<para>A disk image file, "<literal>disk.img</literal>" can be cleaned of all removed files into clean sparse image "<literal>new.img</literal>" by the following.</para>
<screen># mkdir old; mkdir new
# mount -t auto -o loop disk.img old
# dd bs=1 count=0 if=/dev/zero of=new.img seek=5G
# mount -t auto -o loop new.img new
# cd old
# cp -a --sparse=always ./ ../new/
# cd ..
# umount new.img
# umount disk.img</screen>
<para>If "<literal>disk.img</literal>" is in ext2, ext3 or ext4, you can also use <literal>zerofree</literal>(8) from the <literal>zerofree</literal> package as follows.</para>
<screen># losetup --show -f disk.img
/dev/loop0
# zerofree /dev/loop0
# cp --sparse=always disk.img new.img
# losetup -d /dev/loop0</screen>
</section>
<section id="_making_the_empty_disk_image_file">
<title>Making the empty disk image file</title>
<para>The empty disk image "<literal>disk.img</literal>" which can grow up to 5GiB can be made using <literal>dd</literal>(1) as follows.</para>
<screen>$ dd bs=1 count=0 if=/dev/zero of=disk.img seek=5G</screen>
<para>Instead of using <literal>dd</literal>(1), specialized <literal>fallocate</literal>(8) may be used here.</para>
<para>You can create an ext4 filesystem on this disk image "<literal>disk.img</literal>" using the <ulink url="https://en.wikipedia.org/wiki/Loop_device">loop device</ulink> as follows.</para>
<screen># losetup --show -f disk.img
/dev/loop0
# mkfs.ext4 /dev/loop0
...hack...hack...hack
# losetup -d /dev/loop0
$ du --apparent-size -h disk.img
5.0G disk.img
$ du -h disk.img
83M disk.img</screen>
<para>For "<literal>disk.img</literal>", its file size is 5.0 GiB and its actual disk usage is mere 83MiB. This discrepancy is possible since <ulink url="https://en.wikipedia.org/wiki/Ext4">ext4</ulink> can hold <ulink url="https://en.wikipedia.org/wiki/Sparse_file">sparse file</ulink>.</para>
<tip> <para>The actual disk usage of <ulink url="https://en.wikipedia.org/wiki/Sparse_file">sparse file</ulink> grows with data which are written to it.</para> </tip>
<para>Using similar operation on devices created by the <ulink url="https://en.wikipedia.org/wiki/Loop_device">loop device</ulink> or the <ulink url="https://en.wikipedia.org/wiki/Device_mapper">device mapper</ulink> devices as <xref linkend="_mounting_the_disk_image_file"/>, you can partition this disk image "<literal>disk.img</literal>" using <literal>parted</literal>(8) or <literal>fdisk</literal>(8), and can create filesystem on it using <literal>mkfs.ext4</literal>(8), <literal>mkswap</literal>(8), etc.</para>
</section>
<section id="_making_the_iso9660_image_file">
<title>Making the ISO9660 image file</title>
<para>The <ulink url="https://en.wikipedia.org/wiki/ISO_9660">ISO9660</ulink> image file, "<literal>cd.iso</literal>", from the source directory tree at "<literal>source_directory</literal>" can be made using <literal>genisoimage</literal>(1) provided by <ulink url="https://en.wikipedia.org/wiki/Cdrkit">cdrkit</ulink> by the following.</para>
<screen># genisoimage -r -J -T -V volume_id -o cd.iso source_directory</screen>
<para>Similarly, the bootable ISO9660 image file, "<literal>cdboot.iso</literal>", can be made from <literal>debian-installer</literal> like directory tree at "<literal>source_directory</literal>" by the following.</para>
<screen># 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</screen>
<para>Here <ulink url="https://en.wikipedia.org/wiki/SYSLINUX">Isolinux boot loader</ulink> (see <xref linkend="_stage_2_the_boot_loader"/>) is used for booting.</para>
<para>You can calculate the md5sum value and make the ISO9660 image directly from the CD-ROM device as follows.</para>
<screen>$ 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 &gt; cd.iso</screen>
<warning> <para>You must carefully avoid ISO9660 filesystem read ahead bug of Linux as above to get the right result.</para> </warning>
</section>
<section id="_writing_directly_to_the_cd_dvd_r_rw">
<title>Writing directly to the CD/DVD-R/RW</title>
<tip> <para>DVD is only a large CD to <literal>wodim</literal>(1) provided by <ulink url="https://en.wikipedia.org/wiki/Cdrkit">cdrkit</ulink>.</para> </tip>
<para>You can find a usable device by the following.</para>
<screen># wodim --devices</screen>
<para>Then the blank CD-R is inserted to the CD drive, and the ISO9660 image file, "<literal>cd.iso</literal>" is written to this device, e.g., "<literal>/dev/hda</literal>", using <literal>wodim</literal>(1) by the following.</para>
<screen># wodim -v -eject dev=/dev/hda cd.iso</screen>
<para>If CD-RW is used instead of CD-R, do this instead by the following.</para>
<screen># wodim -v -eject blank=fast dev=/dev/hda cd.iso</screen>
<tip> <para>If your desktop system mounts CDs automatically, unmount it by "<literal>sudo umount /dev/hda</literal>" from console before using <literal>wodim</literal>(1).</para> </tip>
</section>
<section id="_mounting_the_iso9660_image_file">
<title>Mounting the ISO9660 image file</title>
<para>If "<literal>cd.iso</literal>" contains an ISO9660 image, then the following manually mounts it to "<literal>/cdrom</literal>".</para>
<screen># mount -t iso9660 -o ro,loop cd.iso /cdrom</screen>
<tip> <para>Modern desktop system may mount removable media such as ISO9660 formatted CD automatically (see <xref linkend="_removable_storage_device"/>).</para> </tip>
</section>
</section>
<section id="_the_binary_data">
<title>The binary data</title>
<para>Here, we discuss direct manipulations of the binary data on storage media.</para>
<section id="_viewing_and_editing_binary_data">
<title>Viewing and editing binary data</title>
<para>The most basic viewing method of binary data is to use "<literal>od -t x1</literal>" command.</para>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>List of packages which view and edit binary data</title>
<tgroup cols="4">
<colspec colwidth="97pt" align="left"/>
<colspec colwidth="76pt" align="left"/>
<colspec colwidth="70pt" align="left"/>
<colspec colwidth="504pt" align="left"/>
<thead>
<row>
<entry> package </entry>
<entry> popcon </entry>
<entry> size </entry>
<entry> description </entry>
</row>
</thead>
<tbody>
<row>
<entry> <literal>coreutils</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> basic package which has <literal>od</literal>(1) to dump files (HEX, ASCII, OCTAL, …) </entry>
</row>
<row>
<entry> <literal>bsdmainutils</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> utility package which has <literal>hd</literal>(1) to dump files (HEX, ASCII, OCTAL, …) </entry>
</row>
<row>
<entry> <literal>hexedit</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> binary editor and viewer (HEX, ASCII) </entry>
</row>
<row>
<entry> <literal>bless</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> full featured hexadecimal editor (GNOME) </entry>
</row>
<row>
<entry> <literal>okteta</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> full featured hexadecimal editor (KDE4) </entry>
</row>
<row>
<entry> <literal>ncurses-hexedit</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> binary editor and viewer (HEX, ASCII, EBCDIC) </entry>
</row>
<row>
<entry> <literal>beav</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> binary editor and viewer (HEX, ASCII, EBCDIC, OCTAL, …) </entry>
</row>
</tbody>
</tgroup>
</table>
<tip> <para>HEX is used as an acronym for <ulink url="https://en.wikipedia.org/wiki/Hexadecimal">hexadecimal</ulink> format with <ulink url="https://en.wikipedia.org/wiki/Radix">radix</ulink> 16. OCTAL is for <ulink url="https://en.wikipedia.org/wiki/Octal">octal</ulink> format with <ulink url="https://en.wikipedia.org/wiki/Radix">radix</ulink> 8. ASCII is for <ulink url="https://en.wikipedia.org/wiki/ASCII">American Standard Code for Information Interchange</ulink>, i.e., normal English text code. EBCDIC is for <ulink url="https://en.wikipedia.org/wiki/Extended_Binary_Coded_Decimal_Interchange_Code">Extended Binary Coded Decimal Interchange Code</ulink> used on <ulink url="https://en.wikipedia.org/wiki/IBM_mainframe">IBM mainframe</ulink> operating systems.</para> </tip>
</section>
<section id="_manipulating_files_without_mounting_disk">
<title>Manipulating files without mounting disk</title>
<para>There are tools to read and write files without mounting disk.</para>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>List of packages to manipulate files without mounting disk</title>
<tgroup cols="4">
<colspec colwidth="59pt" align="left"/>
<colspec colwidth="76pt" align="left"/>
<colspec colwidth="70pt" align="left"/>
<colspec colwidth="304pt" align="left"/>
<thead>
<row>
<entry> package </entry>
<entry> popcon </entry>
<entry> size </entry>
<entry> description </entry>
</row>
</thead>
<tbody>
<row>
<entry> <literal>mtools</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> utilities for MSDOS files without mounting them </entry>
</row>
<row>
<entry> <literal>hfsutils</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> utilities for HFS and HFS+ files without mounting them </entry>
</row>
</tbody>
</tgroup>
</table>
</section>
<section id="_data_redundancy">
<title>Data redundancy</title>
<para>Software <ulink url="https://en.wikipedia.org/wiki/RAID">RAID</ulink> systems offered by the Linux kernel provide data redundancy in the kernel filesystem level to achieve high levels of storage reliability.</para>
<para>There are tools to add data redundancy to files in application program level to achieve high levels of storage reliability, too.</para>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>List of tools to add data redundancy to files</title>
<tgroup cols="4">
<colspec colwidth="70pt" align="left"/>
<colspec colwidth="76pt" align="left"/>
<colspec colwidth="70pt" align="left"/>
<colspec colwidth="347pt" align="left"/>
<thead>
<row>
<entry> package </entry>
<entry> popcon </entry>
<entry> size </entry>
<entry> description </entry>
</row>
</thead>
<tbody>
<row>
<entry> <literal>par2</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> Parity Archive Volume Set, for checking and repair of files </entry>
</row>
<row>
<entry> <literal>dvdisaster</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> data loss/scratch/aging protection for CD/DVD media </entry>
</row>
<row>
<entry> <literal>dvbackup</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> backup tool using MiniDV camcorders (providing <literal>rsbep</literal>(1)) </entry>
</row>
<!--
<row>
<entry> <literal>vdmfec</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> recover lost blocks using Forward Error Correction </entry>
</row>
-->
</tbody>
</tgroup>
</table>
</section>
<section id="_data_file_recovery_and_forensic_analysis">
<title>Data file recovery and forensic analysis</title>
<para>There are tools for data file recovery and forensic analysis.</para>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>List of packages for data file recovery and forensic analysis</title>
<tgroup cols="4">
<colspec colwidth="86pt" align="left"/>
<colspec colwidth="76pt" align="left"/>
<colspec colwidth="70pt" align="left"/>
<colspec colwidth="304pt" align="left"/>
<thead>
<row>
<entry> package </entry>
<entry> popcon </entry>
<entry> size </entry>
<entry> description </entry>
</row>
</thead>
<tbody>
<row>
<entry> <literal>testdisk</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> utilities for partition scan and disk recovery </entry>
</row>
<row>
<entry> <literal>magicrescue</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> utility to recover files by looking for magic bytes </entry>
</row>
<row>
<entry> <literal>scalpel</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> frugal, high performance file carver </entry>
</row>
<row>
<entry> <literal>myrescue</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> rescue data from damaged harddisks </entry>
</row>
<row>
<entry> <literal>extundelete</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> utility to undelete files on the ext3/4 filesystem </entry>
</row>
<row>
<entry> <literal>ext4magic</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> utility to undelete files on the ext3/4 filesystem </entry>
</row>
<row>
<entry> <literal>ext3grep</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> tool to help recover deleted files on the ext3 filesystem </entry>
</row>
<row>
<entry> <literal>scrounge-ntfs</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> data recovery program for NTFS filesystems </entry>
</row>
<row>
<entry> <literal>gzrt</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> gzip recovery toolkit </entry>
</row>
<row>
<entry> <literal>sleuthkit</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> tools for forensics analysis. (Sleuthkit) </entry>
</row>
<row>
<entry> <literal>autopsy</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> graphical interface to SleuthKit </entry>
</row>
<row>
<entry> <literal>foremost</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> forensics application to recover data </entry>
</row>
<row>
<entry> <literal>guymager</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> forensic imaging tool based on Qt </entry>
</row>
<row>
<entry> <literal>dcfldd</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> enhanced version of <literal>dd</literal> for forensics and security </entry>
</row>
</tbody>
</tgroup>
</table>
<tip> <para>You can undelete files on the ext2 filesystem using <literal>list_deleted_inodes</literal> and <literal>undel</literal> commands of <literal>debugfs</literal>(8) in the <literal>e2fsprogs</literal> package.</para> </tip>
</section>
<section id="_splitting_a_large_file_into_small_files">
<title>Splitting a large file into small files</title>
<para>When a data is too big to backup as a single file, you can backup its content after splitting it into, e.g. 2000MiB chunks and merge those chunks back into the original file later.</para>
<screen>$ split -b 2000m large_file
$ cat x* &gt;large_file</screen>
<caution> <para>Please make sure you do not have any files starting with "<literal>x</literal>" to avoid name crashes.</para> </caution>
</section>
<section id="_clearing_file_contents">
<title>Clearing file contents</title>
<para>In order to clear the contents of a file such as a log file, do not use <literal>rm</literal>(1) to delete the file and then create a new empty file, because the file may still be accessed in the interval between commands. The following is the safe way to clear the contents of the file.</para>
<screen>$ :&gt;file_to_be_cleared</screen>
</section>
<section id="_dummy_files">
<title>Dummy files</title>
<para>The following commands create dummy or empty files.</para>
<screen>$ dd if=/dev/zero of=5kb.file bs=1k count=5
$ dd if=/dev/urandom of=7mb.file bs=1M count=7
$ touch zero.file
$ : &gt; alwayszero.file</screen>
<para>You should find following files.</para>
<itemizedlist>
<listitem> <para> "<literal>5kb.file</literal>" is 5KB of zeros. </para> </listitem>
<listitem> <para> "<literal>7mb.file</literal>" is 7MB of random data. </para> </listitem>
<listitem> <para> "<literal>zero.file</literal>" may be a 0 byte file. If it existed, its <literal>mtime</literal> is updated while its content and its length are kept. </para> </listitem>
<listitem> <para> "<literal>alwayszero.file</literal>" is always a 0 byte file. If it existed, its <literal>mtime</literal> is updated and its content is reset. </para> </listitem>
</itemizedlist>
</section>
<section id="_erasing_an_entire_hard_disk">
<title>Erasing an entire hard disk</title>
<para>There are several ways to completely erase data from an entire hard disk like device, e.g., USB memory stick at "<literal>/dev/sda</literal>".</para>
<caution> <para>Check your USB memory stick location with <literal>mount</literal>(8) first before executing commands here. The device pointed by "<literal>/dev/sda</literal>" may be SCSI hard disk or serial-ATA hard disk where your entire system resides.</para> </caution>
<para>Erase all the disk content by resetting data to 0 with the following.</para>
<screen># dd if=/dev/zero of=/dev/sda</screen>
<para>Erase everything by overwriting with random data as follows.</para>
<screen># dd if=/dev/urandom of=/dev/sda</screen>
<para>Erase everything by overwriting with random data very efficiently as follows.</para>
<screen># shred -v -n 1 /dev/sda</screen>
<para>You may alternatively use <literal>badblocks</literal>(8) with <literal>-t random</literal> option.</para>
<para>Since <literal>dd</literal>(1) is available from the shell of many bootable Linux CDs such as Debian installer CD, you can erase your installed system completely by running an erase command from such media on the system hard disk, e.g., "<literal>/dev/hda</literal>", "<literal>/dev/sda</literal>", etc.</para>
</section>
<section id="_erasing_unused_area_of_an_hard_disk">
<title>Erasing unused area of an hard disk</title>
<para>Unused area on an hard disk (or USB memory stick), e.g. "<literal>/dev/sdb1</literal>" may still contain erased data themselves since they are only unlinked from the filesystem. These can be cleaned by overwriting them.</para>
<screen># mount -t auto /dev/sdb1 /mnt/foo
# cd /mnt/foo
# dd if=/dev/zero of=junk
dd: writing to `junk': No space left on device
...
# sync
# umount /dev/sdb1</screen>
<warning>
<para>This is usually good enough for your USB memory stick. But this is not perfect. Most parts of erased filenames and their attributes may be hidden and remain in the filesystem.</para>
</warning>
</section>
<section id="_undeleting_deleted_but_still_open_files">
<title>Undeleting deleted but still open files</title>
<para>Even if you have accidentally deleted a file, as long as that file is still being used by some application (read or write mode), it is possible to recover such a file.</para>
<para>For example, try the following</para>
<screen>$ echo foo &gt; bar
$ less bar
$ ps aux | grep ' less[ ]'
bozo 4775 0.0 0.0 92200 884 pts/8 S+ 00:18 0:00 less bar
$ rm bar
$ ls -l /proc/4775/fd | grep bar
lr-x------ 1 bozo bozo 64 2008-05-09 00:19 4 -&gt; /home/bozo/bar (deleted)
$ cat /proc/4775/fd/4 &gt;bar
$ ls -l
-rw-r--r-- 1 bozo bozo 4 2008-05-09 00:25 bar
$ cat bar
foo</screen>
<para>Execute on another terminal (when you have the <literal>lsof</literal> package installed) as follows.</para>
<screen>$ ls -li bar
2228329 -rw-r--r-- 1 bozo bozo 4 2008-05-11 11:02 bar
$ lsof |grep bar|grep less
less 4775 bozo 4r REG 8,3 4 2228329 /home/bozo/bar
$ rm bar
$ lsof |grep bar|grep less
less 4775 bozo 4r REG 8,3 4 2228329 /home/bozo/bar (deleted)
$ cat /proc/4775/fd/4 &gt;bar
$ ls -li bar
2228302 -rw-r--r-- 1 bozo bozo 4 2008-05-11 11:05 bar
$ cat bar
foo</screen>
</section>
<section id="_searching_all_hardlinks">
<title>Searching all hardlinks</title>
<para>Files with hardlinks can be identified by "<literal>ls -li</literal>".</para>
<screen>$ 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</screen>
<para>Both "<literal>baz</literal>" and "<literal>foo</literal>" have link counts of "2" (&gt;1) showing them to have hardlinks. Their <ulink url="https://en.wikipedia.org/wiki/Inode">inode</ulink> numbers are common "2738404". This means they are the same hardlinked file. If you do not happen to find all hardlinked files by chance, you can search it by the <ulink url="https://en.wikipedia.org/wiki/Inode">inode</ulink>, e.g., "2738404" as the following.</para>
<screen># find /path/to/mount/point -xdev -inum 2738404</screen>
</section>
<section id="_invisible_disk_space_consumption">
<title>Invisible disk space consumption</title>
<para>All deleted but open files consume disk space although they are not visible from normal <literal>du</literal>(1). They can be listed with their size by the following.</para>
<screen># lsof -s -X / |grep deleted</screen>
</section>
</section>
<section id="_data_encryption_tips">
<title>Data encryption tips</title>
<para>With physical access to your PC, anyone can easily gain root privilege and access all the files on your PC (see <xref linkend="_securing_the_root_password"/>). This means that login password system can not secure your private and sensitive data against possible theft of your PC. You must deploy data encryption technology to do it. Although <ulink url="https://en.wikipedia.org/wiki/GNU_Privacy_Guard">GNU privacy guard</ulink> (see <xref linkend="_data_security_infrastructure"/>) can encrypt files, it takes some user efforts.</para>
<para><ulink url="https://en.wikipedia.org/wiki/Dm-crypt">Dm-crypt</ulink> facilitates automatic data encryption via native Linux kernel modules with minimal user efforts using <ulink url="https://en.wikipedia.org/wiki/Device_mapper">device-mapper</ulink>.</para>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>List of data encryption utilities</title>
<tgroup cols="4">
<colspec colwidth="92pt" align="left"/>
<colspec colwidth="76pt" align="left"/>
<colspec colwidth="70pt" align="left"/>
<colspec colwidth="510pt" align="left"/>
<thead>
<row>
<entry> package </entry>
<entry> popcon </entry>
<entry> size </entry>
<entry> description </entry>
</row>
</thead>
<tbody>
<row>
<entry> <literal>cryptsetup</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> utilities for encrypted block device (<ulink url="https://en.wikipedia.org/wiki/Dm-crypt">dm-crypt</ulink> / <ulink url="https://en.wikipedia.org/wiki/Linux_Unified_Key_Setup">LUKS</ulink>) </entry>
</row>
<row>
<entry> <literal>cryptmount</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> utilities for encrypted block device (<ulink url="https://en.wikipedia.org/wiki/Dm-crypt">dm-crypt</ulink> / <ulink url="https://en.wikipedia.org/wiki/Linux_Unified_Key_Setup">LUKS</ulink>) with focus on mount/unmount by normal users </entry>
</row>
<row>
<entry> <literal>fscrypt</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> utilities for Linux filesystem encryption (<ulink url="https://www.kernel.org/doc/html/latest/filesystems/fscrypt.html">fscrypt</ulink>) </entry>
</row>
<row>
<entry> <literal>libpam-fscrypt</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> PAM module for Linux filesystem encryption (<ulink url="https://www.kernel.org/doc/html/latest/filesystems/fscrypt.html">fscrypt</ulink>) </entry>
</row>
</tbody>
</tgroup>
</table>
<caution> <para>Data encryption costs CPU time etc. Encrypted data becomes inaccessible if its password is lost. Please weigh its benefits and costs.</para> </caution>
<note> <para>Entire Debian system can be installed on a encrypted disk by the <ulink url="https://www.debian.org/devel/debian-installer/">debian-installer</ulink> (lenny or newer) using <ulink url="https://en.wikipedia.org/wiki/Dm-crypt">dm-crypt</ulink>/<ulink url="https://en.wikipedia.org/wiki/Linux_Unified_Key_Setup">LUKS</ulink> and initramfs.</para> </note>
<tip> <para>See <xref linkend="_data_security_infrastructure"/> for user space encryption utility: <ulink url="https://en.wikipedia.org/wiki/GNU_Privacy_Guard">GNU Privacy Guard</ulink>.</para> </tip>
<section id="_removable_disk_encryption_with_dm_crypt_luks">
<title>Removable disk encryption with dm-crypt/LUKS</title>
<para>You can encrypt contents of removable mass devices, e.g. USB memory stick on "<literal>/dev/sdx</literal>", using <ulink url="https://en.wikipedia.org/wiki/Dm-crypt">dm-crypt</ulink>/<ulink url="https://en.wikipedia.org/wiki/Linux_Unified_Key_Setup">LUKS</ulink>. You simply format it as the following.</para>
<screen># 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</screen>
<para>Then, it can be mounted just like normal one on to "<literal>/media/<emphasis>username/disk_label</emphasis></literal>", except for asking password (see <xref linkend="_removable_storage_device"/>) under modern desktop environment using the <literal>udisks2</literal> package. The difference is that every data written to it is encrypted. The password entry may be automated using keyring (see <xref linkend="_password_keyring"/>).</para>
<para>You may alternatively format media in different filesystem, e.g., ext4 with "<literal>mkfs.ext4 /dev/mapper/sdx1</literal>". If btrfs is used instead, the <literal>udisks2-btrfs</literal> package needs to be installed. For these filesystems, the file ownership and permissions may need to be configured.</para>
</section>
<section id="_mounting_encrypted_disk_with_dm_crypt_luks">
<title>Mounting encrypted disk with dm-crypt/LUKS</title>
<para>For example, an encrypted disk partition created with dm-crypt/LUKS on "<literal>/dev/sdc5</literal>" by Debian Installer can be mounted onto "<literal>/mnt</literal>" as follows:</para>
<screen>$ sudo cryptsetup open /dev/sdc5 ninja --type luks
Enter passphrase for /dev/sdc5: ****
$ sudo lvm
lvm&gt; lvscan
inactive '/dev/ninja-vg/root' [13.52 GiB] inherit
inactive '/dev/ninja-vg/swap_1' [640.00 MiB] inherit
ACTIVE '/dev/goofy/root' [180.00 GiB] inherit
ACTIVE '/dev/goofy/swap' [9.70 GiB] inherit
lvm&gt; lvchange -a y /dev/ninja-vg/root
lvm&gt; exit
Exiting.
$ sudo mount /dev/ninja-vg/root /mnt</screen>
</section>
</section>
<section id="_the_kernel">
<title>The kernel</title>
<para>Debian distributes modularized <ulink url="https://en.wikipedia.org/wiki/Linux_kernel">Linux kernel</ulink> as packages for supported architectures.</para>
<para>If you are reading this documentation, you probably don't need to compile Linux kernel by yourself.</para>
<section id="_kernel_parameters">
<title>Kernel parameters</title>
<para>Many Linux features are configurable via kernel parameters as follows.</para>
<itemizedlist>
<listitem> <para> Kernel parameters initialized by the bootloader (see <xref linkend="_stage_2_the_boot_loader"/>) </para> </listitem>
<listitem> <para> Kernel parameters changed by <literal>sysctl</literal>(8) at runtime for ones accessible via sysfs (see <xref linkend="_procfs_and_sysfs"/>) </para> </listitem>
<listitem> <para> Module parameters set by arguments of <literal>modprobe</literal>(8) when a module is activated (see <xref linkend="_mounting_the_disk_image_file"/>) </para> </listitem>
</itemizedlist>
<para>See "<ulink url="https://www.kernel.org/doc/html/latest/admin-guide/index.html">The Linux kernel users and administrators guide</ulink> » <ulink url="https://www.kernel.org/doc/html/latest/admin-guide/kernel-parameters.html">The kernels command-line parameters</ulink>" for the detail.</para>
</section>
<section id="_kernel_headers">
<title>Kernel headers</title>
<para>Most <emphasis role="strong">normal programs</emphasis> don't need kernel headers and in fact may break if you use them directly for compiling. They should be compiled against the headers in "<literal>/usr/include/linux</literal>" and "<literal>/usr/include/asm</literal>" provided by the <literal>libc6-dev</literal> package (created from the <literal>glibc</literal> source package) on the Debian system.</para>
<note> <para>For compiling some kernel-specific programs such as the kernel modules from the external source and the automounter daemon (<literal>amd</literal>), you must include path to the corresponding kernel headers, e.g. "<literal>-I/usr/src/linux-particular-version/include/</literal>", to your command line. </para> </note>
</section>
<section id="_compiling_the_kernel_and_related_modules">
<title>Compiling the kernel and related modules</title>
<para>Debian has its own method of compiling the kernel and related modules.</para>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>List of key packages to be installed for the kernel recompilation on the Debian system</title>
<tgroup cols="4">
<colspec colwidth="108pt" align="left"/>
<colspec colwidth="76pt" align="left"/>
<colspec colwidth="70pt" align="left"/>
<colspec colwidth="418pt" align="left"/>
<thead>
<row>
<entry> package </entry>
<entry> popcon </entry>
<entry> size </entry>
<entry> description </entry>
</row>
</thead>
<tbody>
<row>
<entry> <literal>build-essential</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> essential packages for building Debian packages: <literal>make</literal>, <literal>gcc</literal>, … </entry>
</row>
<row>
<entry> <literal>bzip2</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> compress and decompress utilities for bz2 files </entry>
</row>
<row>
<entry> <literal>libncurses5-dev</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> developer's libraries and docs for ncurses </entry>
</row>
<row>
<entry> <literal>git</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> git: distributed revision control system used by the Linux kernel </entry>
</row>
<row>
<entry> <literal>fakeroot</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> provide fakeroot environment for building package as non-root </entry>
</row>
<row>
<entry> <literal>initramfs-tools</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> tool to build an initramfs (Debian specific) </entry>
</row>
<row>
<entry> <literal>dkms</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> <ulink url="https://en.wikipedia.org/wiki/Dynamic_Kernel_Module_Support">dynamic kernel module support (DKMS)</ulink> (generic) </entry>
</row>
<row>
<entry> <literal>module-assistant</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> helper tool to make module package (Debian specific) </entry>
</row>
<row>
<entry> <literal>devscripts</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> helper scripts for a Debian Package maintainer (Debian specific) </entry>
</row>
</tbody>
</tgroup>
</table>
<para>If you use <literal>initrd</literal> in <xref linkend="_stage_2_the_boot_loader"/>, make sure to read the related information in <literal>initramfs-tools</literal>(8), <literal>update-initramfs</literal>(8), <literal>mkinitramfs</literal>(8) and <literal>initramfs.conf</literal>(5).</para>
<warning> <para>Do not put symlinks to the directories in the source tree (e.g. "<literal>/usr/src/linux*</literal>") from "<literal>/usr/include/linux</literal>" and "<literal>/usr/include/asm</literal>" when compiling the Linux kernel source. (Some outdated documents suggest this.)</para> </warning>
<note>
<para>When compiling the latest Linux kernel on the Debian <literal>stable</literal> system, the use of backported latest tools from the Debian <literal>unstable</literal> may be needed.</para>
<para> <literal>module-assistant</literal>(8) (or its short form <literal>m-a</literal>) helps users to build and install module package(s) easily for one or more custom kernels.</para>
<para>The <ulink url="https://en.wikipedia.org/wiki/Dynamic_Kernel_Module_Support">dynamic kernel module support (DKMS)</ulink> is a new distribution independent framework designed to allow individual kernel modules to be upgraded without changing the whole kernel. This is used for the maintenance of out-of-tree modules. This also makes it very easy to rebuild modules as you upgrade kernels.</para>
</note>
</section>
<section id="_compiling_the_kernel_source_debian_kernel_team_recommendation">
<title>Compiling the kernel source: Debian Kernel Team recommendation</title>
<para>For building custom kernel binary packages from the upstream kernel source, you should use the "<literal>deb-pkg</literal>" target provided by it.</para>
<screen>$ sudo apt-get build-dep linux
$ cd /usr/src
$ wget https://mirrors.edge.kernel.org/pub/linux/kernel/v6.x/linux-<emphasis>version</emphasis>.tar.xz
$ tar --xz -xvf linux-<emphasis>version</emphasis>.tar.xz
$ cd linux-<emphasis>version</emphasis>
$ cp /boot/config-<emphasis>version</emphasis> .config
$ make menuconfig
...
$ make deb-pkg</screen>
<tip> <para>The linux-source-<emphasis>version</emphasis> package provides the Linux kernel source with Debian patches as "<literal>/usr/src/linux-<emphasis>version</emphasis>.tar.bz2</literal>".</para> </tip>
<para>For building specific binary packages from the Debian kernel source package, you should use the "<literal>binary-arch_<emphasis>architecture</emphasis>_<emphasis>featureset</emphasis>_<emphasis>flavour</emphasis></literal>" targets in "<literal>debian/rules.gen</literal>".</para>
<screen>$ sudo apt-get build-dep linux
$ apt-get source linux
$ cd linux-3.*
$ fakeroot make -f debian/rules.gen binary-arch_i386_none_686</screen>
<para>See further information:</para>
<itemizedlist>
<listitem> <para> Debian Wiki: <ulink url="https://wiki.debian.org/KernelFAQ">KernelFAQ</ulink> </para> </listitem>
<listitem> <para> Debian Wiki: <ulink url="https://wiki.debian.org/DebianKernel">DebianKernel</ulink> </para> </listitem>
<listitem> <para> Debian Linux Kernel Handbook: <ulink url="https://kernel-team.pages.debian.net/kernel-handbook/">https://kernel-handbook.debian.net</ulink> </para> </listitem>
</itemizedlist>
</section>
<section id="_hardware_drivers_and_firmware">
<title>Hardware drivers and firmware</title>
<para>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 <literal>main</literal> area.</para>
<itemizedlist>
<listitem>
<para><ulink url="https://en.wikipedia.org/wiki/Graphics_processing_unit">GPU</ulink> driver </para>
<itemizedlist>
<listitem> <para> Intel GPU driver (<literal>main</literal>) </para> </listitem>
<listitem> <para> AMD/ATI GPU driver (<literal>main</literal>) </para> </listitem>
<listitem> <para> NVIDIA GPU driver (<literal>main</literal> for <ulink url="https://en.wikipedia.org/wiki/Nouveau_(software)">nouveau</ulink> driver, and <literal>non-free</literal> for binary-only drivers supported by the vendor.) </para>
</listitem>
</itemizedlist>
</listitem>
</itemizedlist>
<para>The firmware is the code or data loaded on the device attach to the target system (e.g., CPU <ulink url="https://en.wikipedia.org/wiki/Microcode">microcode</ulink>, rendering code running on GPU, or <ulink url="https://en.wikipedia.org/wiki/FPGA">FPGA</ulink> / <ulink url="https://en.wikipedia.org/wiki/Complex_programmable_logic_device">CPLD</ulink> 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.</para>
<itemizedlist>
<listitem>
<para>The firmware data packages containing data loaded to the volatile memory on the target device.</para>
<itemizedlist>
<listitem> <para> firmware-linux-free (<literal>main</literal>) </para> </listitem>
<listitem> <para> firmware-linux-nonfree (<literal>non-free-firmware</literal>) </para> </listitem>
<listitem> <para> firmware-linux-* (<literal>non-free-firmware</literal>) </para> </listitem>
<listitem> <para> *-firmware (<literal>non-free-firmware</literal>) </para> </listitem>
<listitem> <para> intel-microcode (<literal>non-free-firmware</literal>) </para> </listitem>
<listitem> <para> amd64-microcode (<literal>non-free-firmware</literal>) </para> </listitem>
</itemizedlist>
</listitem>
<listitem>
<para>The firmware update program packages which update data on the non-volatile memory on the target device.</para>
<itemizedlist>
<listitem> <para> <ulink url="https://en.wikipedia.org/wiki/Fwupd">fwupd</ulink> (<literal>main</literal>): Firmware update daemon which downloads firmware data from <ulink url="https://fwupd.org/">Linux Vendor Firmware Service</ulink>.</para> </listitem>
<listitem> <para> gnome-firmware (<literal>main</literal>): GTK front end for fwupd </para> </listitem>
<listitem> <para> plasma-discover-backend-fwupd (<literal>main</literal>): Qt front end for fwupd </para> </listitem>
</itemizedlist>
</listitem>
</itemizedlist>
<para>Please note that access to <literal>non-free-firmware</literal> packages are provided by the official installation media to offer functional installation experience to the user since Debian 12 Bookworm. The <literal>non-free-firmware</literal> area is described in <xref linkend="_debian_archive_basics"/>.</para>
<para>Please also note that the firmware data downloaded by <ulink url="https://en.wikipedia.org/wiki/Fwupd">fwupd</ulink> from <ulink url="https://fwupd.org/">Linux Vendor Firmware Service</ulink> and loaded to the running Linux kernel may be <literal>non-free</literal>.</para>
</section>
</section>
<section id="_virtualized_system">
<title>Virtualized system</title>
<para>Use of virtualized system enables us to run multiple instances of system simultaneously on a single hardware.</para>
<tip> <para>See <ulink url="https://wiki.debian.org/SystemVirtualization">Debian wiki on SystemVirtualization</ulink>.</para> </tip>
<section id="_virtualization_tools">
<title>Virtualization and emulation tools</title>
<para>There are several <ulink url="https://en.wikipedia.org/wiki/Virtualization">virtualization</ulink> and emulation tool platforms.</para>
<itemizedlist>
<listitem> <para> Complete <ulink url="https://en.wikipedia.org/wiki/Hardware_emulation">hardware emulation</ulink> packages such as ones installed by the <ulink url="https://packages.debian.org/sid/games-emulator">games-emulator</ulink> metapackage</para> </listitem>
<listitem> <para> Mostly CPU level emulation with some I/O device emulations such as <ulink url="https://en.wikipedia.org/wiki/QEMU">QEMU</ulink> </para> </listitem>
<listitem> <para> Mostly CPU level virtualization with some I/O device emulations such as <ulink url="https://en.wikipedia.org/wiki/Kernel-based_Virtual_Machine">Kernel-based Virtual Machine (KVM)</ulink> </para> </listitem>
<listitem> <para> OS level container virtualization with the kernel level support such as <ulink url="https://en.wikipedia.org/wiki/LXC">LXC (Linux Containers)</ulink>, <ulink url="https://en.wikipedia.org/wiki/Docker_(software)">Docker</ulink>, <literal>systemd-nspawn</literal>(1), ... </para> </listitem>
<listitem> <para> OS level filesystem access virtualization with the system library call override on the file path such as <ulink url="https://en.wikipedia.org/wiki/Chroot">chroot</ulink> </para> </listitem>
<listitem> <para> OS level filesystem access virtualization with the system library call override on the file ownership such as <ulink url="https://en.wikipedia.org/wiki/">fakeroot</ulink> </para> </listitem>
<listitem> <para> OS API emulation such as <ulink url="https://en.wikipedia.org/wiki/Wine_(software)">Wine</ulink> </para> </listitem>
<listitem> <para> Interpreter level virtualization with its executable selection and run-time library overrides such as <ulink url="https://virtualenv.pypa.io/">virtualenv</ulink> and <ulink url="https://docs.python.org/3/library/venv.html">venv</ulink> for Python </para> </listitem>
</itemizedlist>
<para>The container virtualization uses <xref linkend="_linux_security_features"/> and is the backend technology of <xref linkend="_sandbox"/>.</para>
<para>Here are some packages to help you to setup the virtualized system.</para>
<table pgwide="0" frame="topbot" rowsep="1" colsep="1">
<title>List of virtualization tools</title>
<tgroup cols="4">
<colspec colwidth="97pt" align="left"/>
<colspec colwidth="76pt" align="left"/>
<colspec colwidth="70pt" align="left"/>
<colspec colwidth="504pt" align="left"/>
<thead>
<row>
<entry> package </entry>
<entry> popcon </entry>
<entry> size </entry>
<entry> description </entry>
</row>
</thead>
<tbody>
<row>
<entry> <literal>coreutils</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> GNU core utilities which contain <literal>chroot</literal>(8) </entry>
</row>
<row>
<entry> <literal>systemd-container</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> systemd container/nspawn tools which contain <literal>systemd-nspawn</literal>(1) </entry>
</row>
<row>
<entry> <literal>schroot</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> specialized tool for executing Debian binary packages in chroot </entry>
</row>
<row>
<entry> <literal>sbuild</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> tool for building Debian binary packages from Debian sources </entry>
</row>
<!--
<row>
<entry> <literal>pbuilder</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> personal package builder for Debian packages </entry>
</row>
-->
<row>
<entry> <literal>debootstrap</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> bootstrap a basic Debian system (written in sh) </entry>
</row>
<row>
<entry> <literal>cdebootstrap</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> bootstrap a Debian system (written in C) </entry>
</row>
<row>
<entry> <literal>cloud-image-utils</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> cloud image management utilities </entry>
</row>
<row>
<entry> <literal>cloud-guest-utils</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> cloud guest utilities </entry>
</row>
<row>
<entry> <literal>virt-manager</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> <ulink url="https://en.wikipedia.org/wiki/Virt-manager">Virtual Machine Manager</ulink>: desktop application for managing virtual machines </entry>
</row>
<row>
<entry> <literal>libvirt-clients</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> programs for the <ulink url="https://en.wikipedia.org/wiki/Libvirt">libvirt</ulink> library </entry>
</row>
<row>
<entry> <literal>incus</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> <ulink url="https://wiki.debian.org/Incus">Incus</ulink>: system container and virtual machine manager (for Debian 13 "Trixie") </entry>
</row>
<row>
<entry> <literal>lxd</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> <ulink url="https://wiki.debian.org/LXD">LXD</ulink>: system container and virtual machine manager (for Debian 12 "Bookworm") </entry>
</row>
<row>
<entry> <literal>podman</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> <ulink url="https://podman.io/">podman</ulink>: engine to run OCI-based containers in Pods </entry>
</row>
<row>
<entry> <literal>podman-docker</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> engine to run OCI-based containers in Pods - wrapper for docker </entry>
</row>
<row>
<entry> <literal>docker.io</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> <ulink url="https://en.wikipedia.org/wiki/Docker_(software)">docker</ulink>: Linux container runtime </entry>
</row>
<row>
<entry> <literal>games-emulator</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> <ulink url="https://packages.debian.org/sid/games-emulator">games-emulator</ulink>: Debian's emulators for games </entry>
</row>
<row>
<entry> <literal>bochs</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry><ulink url="https://en.wikipedia.org/wiki/Bochs">Bochs</ulink>: IA-32 PC emulator </entry>
</row>
<!--
<row>
<entry> <literal>qemu</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> <ulink url="https://en.wikipedia.org/wiki/QEMU">QEMU</ulink>: fast generic processor emulator </entry>
</row>
-->
<row>
<entry> <literal>qemu-system</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> <ulink url="https://en.wikipedia.org/wiki/QEMU">QEMU</ulink>: full system emulation binaries </entry>
</row>
<row>
<entry> <literal>qemu-user</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> <ulink url="https://en.wikipedia.org/wiki/QEMU">QEMU</ulink>: user mode emulation binaries </entry>
</row>
<row>
<entry> <literal>qemu-utils</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> <ulink url="https://en.wikipedia.org/wiki/QEMU">QEMU</ulink>: utilities </entry>
</row>
<row>
<entry> <literal>qemu-system-x86</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> <ulink url="https://en.wikipedia.org/wiki/Kernel-based_Virtual_Machine">KVM</ulink>: full virtualization on x86 hardware with the <ulink url="https://en.wikipedia.org/wiki/Hardware-assisted_virtualization">hardware-assisted virtualization</ulink> </entry>
</row>
<row>
<entry> <literal>virtualbox</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> <ulink url="https://en.wikipedia.org/wiki/VirtualBox">VirtualBox</ulink>: x86 virtualization solution on i386 and amd64 </entry>
</row>
<row>
<entry> <literal>gnome-boxes</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> <ulink url="https://wiki.gnome.org/Apps/Boxes">Boxes</ulink>: Simple GNOME app to access virtual systems </entry>
</row>
<row>
<entry> <literal>xen-tools</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> tools to manage debian <ulink url="https://en.wikipedia.org/wiki/Xen">XEN</ulink> virtual server </entry>
</row>
<row>
<entry> <literal>wine</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> <ulink url="https://en.wikipedia.org/wiki/Wine_(software)">Wine</ulink>: Windows API Implementation (standard suite) </entry>
</row>
<row>
<entry> <literal>dosbox</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> <ulink url="https://en.wikipedia.org/wiki/DOSBox">DOSBox</ulink>: x86 emulator with Tandy/Herc/CGA/EGA/VGA/SVGA graphics, sound and DOS </entry>
</row>
<!--
<row>
<entry> <literal></literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> </entry>
</row>
<row>
<entry> <literal>dosemu</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> <ulink url="https://en.wikipedia.org/wiki/DOSEMU">DOSEMU</ulink>: The Linux DOS Emulator </entry>
</row>
<row>
<entry> <literal>vzctl</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry><ulink url="https://en.wikipedia.org/wiki/OpenVZ">OpenVZ</ulink> server virtualization solution - control tools </entry>
</row>
<row>
<entry> <literal>vzquota</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry><ulink url="https://en.wikipedia.org/wiki/OpenVZ">OpenVZ</ulink> server virtualization solution - quota tools </entry>
</row>
-->
<row>
<entry> <literal>lxc</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> <ulink url="https://en.wikipedia.org/wiki/LXC">Linux containers user space tools</ulink> </entry>
</row>
<row>
<entry> <literal>python3-venv</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> <ulink url="https://docs.python.org/3/library/venv.html">venv</ulink> for creating virtual python environments (system library) </entry>
</row>
<row>
<entry> <literal>python3-virtualenv</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> <ulink url="https://virtualenv.pypa.io/">virtualenv</ulink> for creating isolated virtual python environments </entry>
</row>
<row>
<entry> <literal>pipx</literal> </entry>
<entry> @-@popcon1@-@ </entry>
<entry> @-@psize1@-@ </entry>
<entry> <ulink url="https://pipx.pypa.io/">pipx</ulink> for installing python applications in isolated environments </entry>
</row>
</tbody>
</tgroup>
</table>
<para>See Wikipedia article <ulink url="https://en.wikipedia.org/wiki/Comparison_of_platform_virtual_machines">Comparison of platform virtual machines</ulink> for detail comparison of different platform virtualization solutions.</para>
</section>
<section id="_virtualization_work_flow">
<title>Virtualization work flow</title>
<note> <para>Default Debian kernels support <ulink url="https://en.wikipedia.org/wiki/Kernel-based_Virtual_Machine">KVM</ulink> since <literal>lenny</literal>.</para> </note>
<para>Typical work flow for <ulink url="https://en.wikipedia.org/wiki/Virtualization">virtualization</ulink> involves several steps.</para>
<itemizedlist>
<listitem>
<para> Create an empty filesystem (a file tree or a disk image). </para>
<itemizedlist>
<listitem> <para> The file tree can be created by "<literal>mkdir -p /path/to/chroot</literal>". </para> </listitem>
<listitem> <para> The raw disk image file can be created with <literal>dd</literal>(1) (see <xref linkend="_making_the_disk_image_file"/> and <xref linkend="_making_the_empty_disk_image_file"/>). </para> </listitem>
<listitem> <para><literal>qemu-img</literal>(1) can be used to create and convert disk image files supported by <ulink url="https://en.wikipedia.org/wiki/QEMU">QEMU</ulink>. </para> </listitem>
<listitem> <para> The raw and <ulink url="https://en.wikipedia.org/wiki/VMDK">VMDK</ulink> file format can be used as common format among virtualization tools. </para> </listitem>
</itemizedlist>
</listitem>
<listitem>
<para> Mount the disk image with <literal>mount</literal>(8) to the filesystem (optional). </para>
<itemizedlist>
<listitem> <para> For the raw disk image file, mount it as <ulink url="https://en.wikipedia.org/wiki/Loop_device">loop device</ulink> or <ulink url="https://en.wikipedia.org/wiki/Device_mapper">device mapper</ulink> devices (see <xref linkend="_mounting_the_disk_image_file"/>). </para> </listitem>
<listitem> <para> For disk images supported by <ulink url="https://en.wikipedia.org/wiki/QEMU">QEMU</ulink>, mount them as <ulink url="https://en.wikipedia.org/wiki/Network_block_device">network block device</ulink> (see <xref linkend="_mounting_the_virtual_disk_image_file"/>). </para> </listitem>
</itemizedlist>
</listitem>
<listitem>
<para> Populate the target filesystem with required system data. </para>
<itemizedlist>
<listitem> <para> The use of programs such as <literal>debootstrap</literal> and <literal>cdebootstrap</literal> helps with this process (see <xref linkend="_chroot_system"/>). </para> </listitem>
<listitem> <para> Use installers of OSs under the full system emulation. </para> </listitem>
</itemizedlist>
</listitem>
<listitem>
<para> Run a program under a virtualized environment. </para>
<itemizedlist>
<listitem> <para><ulink url="https://en.wikipedia.org/wiki/Chroot">chroot</ulink> provides basic virtualized environment enough to compile programs, run console applications, and run daemons in it. </para> </listitem>
<listitem> <para><ulink url="https://en.wikipedia.org/wiki/QEMU">QEMU</ulink> provides cross-platform CPU emulation. </para> </listitem>
<listitem> <para><ulink url="https://en.wikipedia.org/wiki/QEMU">QEMU</ulink> with <ulink url="https://en.wikipedia.org/wiki/Kernel-based_Virtual_Machine">KVM</ulink> provides full system emulation by the <ulink url="https://en.wikipedia.org/wiki/Hardware-assisted_virtualization">hardware-assisted virtualization</ulink>. </para> </listitem>
<listitem> <para><ulink url="https://en.wikipedia.org/wiki/VirtualBox">VirtualBox</ulink> provides full system emulation on i386 and amd64 with or without the <ulink url="https://en.wikipedia.org/wiki/Hardware-assisted_virtualization">hardware-assisted virtualization</ulink>. </para> </listitem>
</itemizedlist>
</listitem>
</itemizedlist>
</section>
<section id="_mounting_the_virtual_disk_image_file">
<title>Mounting the virtual disk image file</title>
<para>For the raw disk image file, see <xref linkend="_the_disk_image"/>.</para>
<para>For other virtual disk image files, you can use <literal>qemu-nbd</literal>(8) to export them using <ulink url="https://en.wikipedia.org/wiki/Network_block_device">network block device</ulink> protocol and mount them using the <literal>nbd</literal> kernel module.</para>
<para><literal>qemu-nbd</literal>(8) supports disk formats supported by <ulink url="https://en.wikipedia.org/wiki/QEMU">QEMU</ulink>: raw, <ulink url="https://en.wikipedia.org/wiki/Qcow">qcow2, qcow</ulink>, <ulink url="https://en.wikipedia.org/wiki/VMDK">vmdk</ulink>, <ulink url="https://en.wikipedia.org/wiki/VirtualBox#Virtual_Desktop_Image">vdi</ulink>, <ulink url="https://en.wikipedia.org/wiki/Bochs">bochs</ulink>, cow (user-mode Linux copy-on-write), <ulink url="https://en.wikipedia.org/wiki/Parallels_Workstation">parallels</ulink>, <ulink url="https://en.wikipedia.org/wiki/Apple_Disk_Image">dmg</ulink>, <ulink url="https://en.wikipedia.org/wiki/Cloop">cloop</ulink>, <ulink url="https://en.wikipedia.org/wiki/VHD_(file_format)">vpc</ulink>, vvfat (virtual VFAT), and host_device.</para>
<para>The <ulink url="https://en.wikipedia.org/wiki/Network_block_device">network block device</ulink> can support partitions in the same way as the <ulink url="https://en.wikipedia.org/wiki/Loop_device">loop device</ulink> (see <xref linkend="_mounting_the_disk_image_file"/>). You can mount the first partition of "<literal>disk.img</literal>" as follows.</para>
<screen># modprobe nbd max_part=16
# qemu-nbd -v -c /dev/nbd0 disk.img
...
# mkdir /mnt/part1
# mount /dev/nbd0p1 /mnt/part1</screen>
<tip> <para>You may export only the first partition of "<literal>disk.img</literal>" using "<literal>-P 1</literal>" option to <literal>qemu-nbd</literal>(8).</para> </tip>
</section>
<section id="_chroot_system">
<title>Chroot system</title>
<para>If you wish to try a new Debian environment from a terminal console, I recommend you to use <ulink url="https://en.wikipedia.org/wiki/Chroot">chroot</ulink>. This enables you to run console applications of Debian <literal>unstable</literal> and <literal>testing</literal> without usual risks associated and without rebooting. <literal>chroot</literal>(8) is the most basic way.</para>
<caution> <para>Examples below assumes both parent system and chroot system share the same <literal>amd64</literal> CPU architecture.</para> </caution>
<para>Although you can manually create a <literal>chroot</literal>(8) environment using <literal>debootstrap</literal>(1), this requires non-trivial efforts.</para>
<para>The <ulink url="https://packages.debian.org/search?keywords=sbuild">sbuild</ulink> package to build Debian packages from source uses the chroot environment managed by the <ulink url="https://packages.debian.org/search?keywords=schroot">schroot</ulink> package. It comes with helper script <literal>sbuild-createchroot</literal>(1). Let's learn how it works by running it as follows.</para>
<screen>$ sudo mkdir -p /srv/chroot
$ sudo sbuild-createchroot -v --include=eatmydata,ccache unstable /srv/chroot/unstable-amd64-sbuild http://deb.debian.org/debian
...</screen>
<para>You see how <literal>debootstrap</literal>(8) populates system data for <literal>unstable</literal> environment under "<literal>/srv/chroot/unstable-amd64-sbuild</literal>" for a minimal build system.</para>
<para>You can login to this environment using <literal>schroot</literal>(1).</para>
<screen>$ sudo schroot -v -c chroot:unstable-amd64-sbuild</screen>
<para>You see how a system shell running under <literal>unstable</literal> environment is created.</para>
<note> <para>The "<literal>/usr/sbin/policy-rc.d</literal>" file which always exits with 101 prevents daemon programs to be started automatically on the Debian system. See "<literal>/usr/share/doc/init-system-helpers/README.policy-rc.d.gz</literal>".</para> </note>
<note> <para>Some programs under chroot may require access to more files from the parent system to function than <literal>sbuild-createchroot</literal> provides as above. For example, "<literal>/sys</literal>", "<literal>/etc/passwd</literal>", "<literal>/etc/group</literal>", "<literal>/var/run/utmp</literal>", "<literal>/var/log/wtmp</literal>", etc. may need to be bind-mounted or copied.</para> </note>
<tip> <para>The <literal>sbuild</literal> package helps to construct a chroot system and builds a package inside the chroot using <literal>schroot</literal> as its backend. It is an ideal system to check build-dependencies. See more on <ulink url="https://wiki.debian.org/sbuild">sbuild at Debian wiki</ulink> and <ulink url="https://www.debian.org/doc/manuals/debmake-doc/ch03.en.html#sbuild-setup">sbuild configuration example in "Guide for Debian Maintainers"</ulink>. </para> </tip>
<tip> <para>The <literal>systemd-nspawn</literal>(1) command helps to run a command or OS in a light-weight container in similar ways to <literal>chroot</literal>. It is more powerful since it uses namespaces to fully virtualize the the process tree, IPC, hostname, domain name and, optionally, networking and user databases. See <ulink url="https://wiki.debian.org/nspawn">systemd-nspawn</ulink>. </para> </tip>
</section>
<!--
OCI
- Docker
- Podman
Cliché: https://osamuaoki.github.io/en/2024/02/14/podman-1/#typical-clich%C3%A9-for-dockerpodman
- Kubertner
-->
<!--
Incus (LXD replacement)
- with Linux Container
- with Vm (KVM, qemu)
-->
<!--
Virt-manager/Gnome Box
- with Vm (KVM, qemu)
-->
<section id="_multiple_desktop_systems">
<title>Multiple desktop systems</title>
<para>If you wish to try a new GUI Desktop environment of any OS, I recommend you to use <ulink url="https://en.wikipedia.org/wiki/QEMU">QEMU</ulink> or <ulink url="https://en.wikipedia.org/wiki/Kernel-based_Virtual_Machine">KVM</ulink> on a Debian <literal>stable</literal> system to run multiple desktop systems safely using <ulink url="https://en.wikipedia.org/wiki/Virtualization">virtualization</ulink>. These enable you to run any desktop applications including ones of Debian <literal>unstable</literal> and <literal>testing</literal> without usual risks associated with them and without rebooting.</para>
<para>Since pure <ulink url="https://en.wikipedia.org/wiki/QEMU">QEMU</ulink> is very slow, it is recommended to accelerate it with <ulink url="https://en.wikipedia.org/wiki/Kernel-based_Virtual_Machine">KVM</ulink> when the host system supports it.</para>
<para><ulink url="https://en.wikipedia.org/wiki/Virt-manager">Virtual Machine Manager</ulink> also known as <literal>virt-manager</literal> is a convenient GUI tool for managing KVM virtual machines via <ulink url="https://en.wikipedia.org/wiki/Libvirt">libvirt</ulink>.</para>
<para>The virtual disk image "<literal>virtdisk.qcow2</literal>" containing a Debian system for <ulink url="https://en.wikipedia.org/wiki/QEMU">QEMU</ulink> can be created using <ulink url="https://www.debian.org/distrib/netinst">debian-installer: Small CDs</ulink> as follows.</para>
<screen>$ wget https://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
...</screen>
<tip> <para>Running other GNU/Linux distributions such as <ulink url="https://www.ubuntu.com/">Ubuntu</ulink> and <ulink url="https://fedoraproject.org/">Fedora</ulink> under <ulink url="https://en.wikipedia.org/wiki/Virtualization">virtualization</ulink> is a great way to learn configuration tips. Other proprietary OSs may be run nicely under this GNU/Linux <ulink url="https://en.wikipedia.org/wiki/Virtualization">virtualization</ulink>, too.</para> </tip>
<para>See more tips at <ulink url="https://wiki.debian.org/SystemVirtualization">Debian wiki: SystemVirtualization</ulink>.</para>
</section>
</section>
</chapter>