preseed を利用したインストールの自動化 本付録は preseed の説明を行い、 インストールの自動化に関する &d-i; の質問への回答です。 本付録で使用した設定の断片は、 &urlset-example-preseed; にあるサンプル preseed ファイルでも利用できます。 はじめに preseed は、インストールの実行中に手動で回答を入力せずに、 質問の答えを設定する方法を提供します。 これにより、ほとんどの方法のインストールを自動化し、 さらに通常のインストールでは利用できない特徴もあります。 preseed を使用して、インストールの第 1 段階 (新しいシステムで再起動する前まで) と第 2 段階の両方で行われる質問に、回答を与えることができます。 preseed の方法 preseed を利用するには、3 種類方法があります。 initrd, ファイル, ネットワーク です。 initrd preseed は、いずれのインストール方法でも動作し、 より多くの preseed をサポートしますが、大量の準備が必要です。 ファイル preseed やネットワーク preseed は、 それぞれインストール方法が異なる場合に使用されます。 ファイル preseed やネットワーク preseed では、 preseed 設定ファイルが読み込まれる前にいくつか質問されてしまうため、 その質問を preseed に含めることができません。 以下の表では、各インストール方法で使用できる preseed 方法を示します。 インストール方法initrd ファイルネットワーク CD/DVD yes yes no netboot yes no yes hd-media (USB スティック含む) yes yes no フロッピーベース (CD ドライバ) yes yes no フロッピーベース (ネットドライバ) yes no yes generic/tape yes no yes preseed 方法の重要な違いは、preseed 設定ファイルを読込・処理するポイントです。 initrd preseed では、インストールの始め (最初の質問が行われる前) で読み込まれます。 ファイル preseed では、CD や CD イメージが読み込まれた後です。 ネットワーク preseed では、ネットワークの設定の後でないと読み込まれません。 実際の話をすると、ファイル preseed やネットワーク preseed では、 言語、国、キーボードの選択について質問は、既にされてしまっています。 ネットワーク preseed では、そこにネットワークの設定についても加えてください。 その他、優先度が「中」や「低」でしか表示されない質問 (はじめのハードウェア検出など) は、既に処理されてしまっています。 言うまでもなく、preseed 設定ファイルが読み込まれる前に処理される質問は、 preseed できません。 では、 そういった質問が出ないようにする方法を提供しています。 制限 &d-i; で行われる質問のほとんどはこの方法で preseed できますが、 いくつか注目すべき例外があります。 ディスク全体を (再度) パーティション分割をするか、 ディスクの空き領域を利用しなければなりません。 つまり既存のパーティションを利用できないと言うことです。 また現在、RAID や LVM のセットアップに preseed を利用できません。 インストール中でのカスタムコマンドの実行 preseed ツールで提供される、とても強力で柔軟なオプションに、 インストールの決まった場所でコマンドやスクリプトを実行する機能があります。 詳細は をご覧ください。 preseed/early_command: は、 preseed 設定ファイルが読み込まれるとすぐに実行します。 preseed/late_command: は、 インストールの第 1 段階が終わって再起動する直前、 /target ファイルシステムをアンマウントする前に実行します。 base-config/early_command: は、 インストールの第 2 段階の始め、 base-config を実行し始めるときに実行します。 base-config/late_command: は、 base-config の最後、 ログインプロンプトを出す直前に実行します。 デフォルト値の変更に関する preseed の利用 訊かれる質問に対するデフォルトの回答を変更するのに preseed を利用できます。 これには、テンプレートに値を設定した後で、 seen フラグを false に設定しなければなりません。 d-i foo/bar string value d-i foo/bar seen false preseed の利用 もちろん最初に preseed ファイルを作成し、使用したい場所に配置する必要があります。 preseed ファイルの作成は本付録で後ほど扱います。 ネットワーク preseed の場合や、 ファイルをフロッピーや USB スティックから読み込みたい場合、 正しい位置に preseed ファイルを配置するのは簡単です。 CD や DVD にファイルを含めたければ、 ISO イメージを再度マスタリングする必要があります。 initrd に含まれている preseed ファイルを取り出すのは、この文書では扱いません。 &d-i; の開発者向け文書を当たってください。 preseed ファイルの基礎にできる preseed ファイルのサンプルは、 &urlset-example-preseed; から取得できます。 このファイルは、この付録にある設定片を元にしています。 preseed ファイルの読み込み initrd preseed を使用する場合、preseed.cfg というファイルがinitrd のルートディレクトリに確実にある必要があります。 インストーラは、このファイルがあるか自動的にチェックし、読み込みます。 他の preseed 方法では、ブート時にどのファイルを読み込むか、 インストーラに指定する必要があります。 カーネルのブートパラメータで渡して行います。 これは起動時に手動で与えるか、 ブートローダ設定ファイル (例: syslinux.cfg) を編集し、 カーネルへのappend行の最後にパラメータを追加して与えます。 ブートローダの設定で preseed ファイルを指定するなら、 設定を変更すれば、インストーラの起動時に ENTER を押す必要はありません。 syslinux ではこの設定をするのに、 syslinux.cfg でタイムアウトを 1 にします。 インストーラが確実に正しい preseed ファイルを取得するには、 このファイルのチェックサムを指定することができます。 現在、これには md5sum が必要です。 また、指定した物と preseed ファイル一致しなければなりません。 そうでなければインストーラはこのファイルを使用しません。 ブートパラメータの設定: - netboot の場合: preseed/url=http://host/path/to/preseed.cfg preseed/url/checksum=5da499872becccfeda2c4872f9171c3d - リマスタリングした CD で起動する場合: preseed/file=/cdrom/preseed.cfg preseed/file/checksum=5da499872becccfeda2c4872f9171c3d - USB メディアで起動する場合 (preseed ファイルを USB スティックの トップレベルディレクトリにおくこと) toplevel directory of the USB stick): preseed/file=/hd-media/preseed.cfg preseed/file/checksum=5da499872becccfeda2c4872f9171c3d 実行するにあたり、ブートパラメータに debconf/priority=critical を追加したいかもしれません。 preseed でいくつか以下の設定を漏らしても、 ほとんどの質問が表示されなくなります。 preseed を補足するブートパラメータの利用 インストールプロセスのいくつかの部分は、 preseed ファイルが読み込まれる前に質問が起きるので、 自動で行うことができません。 例えば、preseed ファイルをネットワークからダウンロードする場合、 まずネットワークの設定が完了していなければなりません。 initrd preseed を使用する理由のひとつに、 これがインストールプロセスの初めから preseed できると言うことがあります。 preseed ファイルを preseed に使用できないステップがあっても、 コマンドラインから preseed の値をカーネルに渡せますので、 まだ完全に自動化できます。 path/to/var=value というように、 サンプルにある preseed 変数を渡してください。 カーネル 2.4 では最大 (インストーラがデフォルトで指定するオプションを含め) コマンドラインオプションを 8 つ、環境オプションを 8 つ受け取れます。 この数を超えると、カーネル 2.4 では超過したオプションを取りこぼしてしまい、 カーネル 2.6 ではパニックしてしまいます。 カーネル 2.6.9 以降では、コマンドラインオプションを 32、 環境オプションを 32 受け取れます。 ほとんどのインストールでは、ブートローダ設定ファイルにある ('vga=normal' のような) デフォルトオプションを安全に削除できるかもしれません。 これにより preseed 用にもっとオプションを追加できます。 ブートパラメータに空白を含んだ値を設定するのは、 引用符で区切ったとしてもいつもうまくいくとは限りません。 preseed ファイルの作成 事前設定ファイルは、debconf-set-selections コマンドで使用されるフォーマットです。 ファイルフォーマット テンプレートの型と値の間には空白がひとつだけ有効 /var/lib/(c)debconf/templates との関連 テンプレートの型と値の提供方法 ほとんどの値は英語かコード 手動インストールを基礎として使用する。 有効な値の検索 preseed ファイルのフォーマットがインストールを実行する前に有効か調べるには、 debconf-set-selections -c preseed.cfg を使用できます。 インストール第 1 段階の preseed 本付録で使用する設定片は、 &urlset-example-preseed; のサンプル preseed ファイルでも利用できます。 本サンプルは、 Intel x86 アーキテクチャ用インストールを元にしていることに注意してください。 他のアーキテクチャにインストールする場合、 いくつかのサンプル (キーボードの選択やブートローダの選択など) は関連がないかもしれませんし、 そのアーキテクチャ用に適切な debconf 設定で置き換える必要があるでしょう。 地域化 地域化の設定値は initrd preseed を利用しているときのみ動作します。 他のすべての方法では、 この質問をされた後にでしか preseed ファイルを読み込めません。 ロケールは言語と国を両方指定します。 ブートパラメータでロケールを指定するには、 debian-installer/locale=en_US としてください。 # Locale sets language and country. d-i debian-installer/locale string en_US キーボード設定は、 キーボードアーキテクチャとキーマップを選択することから成っています。 ほとんどの場合、正しいキーボードアーキテクチャはデフォルトで選択されています。 そのため、通常 preseed する必要はありません。 キーマップは選択したキーボードアーキテクチャで、有効でなくてはなりません。 # Keyboard selection. #d-i console-tools/archs select at d-i console-keymaps-at/keymap select us # Example for a different keyboard architecture #d-i console-keymaps-usb/keymap select mac-usb-us キーボード設定をスキップするには、 console-tools/archsskip-config と preseed してください。 これにより、カーネルのキーマップが有効になったままとなります。 カーネル 2.6 では入力レイヤが変更され、 キーボードアーキテクチャは事実上時代遅れです。 カーネル 2.6 では通常、PC (at) キーマップが既に選択されています。 ネットワーク設定 もちろん、ネットワークから preseed ファイルを読み込むなら、 preseed のネットワーク設定は動作しません。 しかし、CD や USB スティックから起動するときには重要です。 ネットワークから preseed ファイルを読み込む場合、 ネットワーク設定パラメータを、カーネルブートパラメータで渡せます。 # netcfg will choose an interface that has link if possible. This makes it # skip displaying a list if there is more than one interface. d-i netcfg/choose_interface select auto # If you have a slow dhcp server and the installer times out waiting for # it, this might be useful. #d-i netcfg/dhcp_timeout string 60 # If you prefer to configure the network manually, here's how: #d-i netcfg/disable_dhcp boolean true #d-i netcfg/get_nameservers string 192.168.1.1 #d-i netcfg/get_ipaddress string 192.168.1.42 #d-i netcfg/get_netmask string 255.255.255.0 #d-i netcfg/get_gateway string 192.168.1.1 #d-i netcfg/confirm_static boolean true # Any hostname and domain names assigned from dhcp take precedence over # values set here. However, setting the values still prevents the questions # from being shown, even if values come from dhcp. d-i netcfg/get_hostname string unassigned-hostname d-i netcfg/get_domain string unassigned-domain # Disable that annoying WEP key dialog. d-i netcfg/wireless_wep string # The wacky dhcp hostname that some ISPs use as a password of sorts. #d-i netcfg/dhcp_hostname string radish ミラー設定 使用するインストール方法に依存しますが、 インストーラの追加コンポーネントのダウンロードや、基本システム、 インストールしたシステムの /etc/apt/sources.list の セットアップにミラーを使用できます。 mirror/suite パラメータでは、 インストールするシステム用の組を設定します。 mirror/udeb/suite パラメータでは、 インストーラの追加コンポーネントの組を設定します。 実際にコンポーネントをネットワークでダウンロードする場合に役立つだけです。 また、インストールで使用するインストール方法のための initrd を生成するには、 この組が一致していなければなりません。 mirror/udeb/suite のデフォルト値は、 mirror/suite と同じです。 d-i mirror/country string enter information manually d-i mirror/http/hostname string http.us.debian.org d-i mirror/http/directory string /debian d-i mirror/http/proxy string # Suite to install. #d-i mirror/suite string testing # Suite to use for loading installer components (optional). #d-i mirror/udeb/suite string testing パーティション分割 ハードディスクのパーティション分割に preseed を使用するのは、 partman-auto でサポートしている機能に限定されています。 パーティションはディスクに既存の空き領域とディスク全体のどちらかから選べます。 ディスクレイアウトは、あらかじめ定義したレシピ、 レシピファイルによるカスタムレシピ、 preseed ファイルに書いたレシピから選択できます。 現在、パーティションに preseed を用いて複数のディスクを割り当てられませんし、 RAID や LVM の設定もできません。 ディスクの識別は、ドライバの読み込み順に依存します。 複数のディスクがシステムにある場合、 preseed を使用する前に確実に正しい物を選択するようにしなければなりません。 # If the system has free space you can choose to only partition that space. #d-i partman-auto/init_automatically_partition \ # select Use the largest continuous free space # Alternatively, you can specify a disk to partition. The device name can # be given in either devfs or traditional non-devfs format. # For example, to use the first disk devfs knows of: d-i partman-auto/disk string /dev/discs/disc0/disc # You can choose from any of the predefined partitioning recipes: d-i partman-auto/choose_recipe \ select All files in one partition (recommended for new users) #d-i partman-auto/choose_recipe \ # select Separate /home partition #d-i partman-auto/choose_recipe \ # select Separate /home, /usr, /var, and /tmp partitions # Or provide a recipe of your own... # The recipe format is documented in the file devel/partman-auto-recipe.txt. # If you have a way to get a recipe file into the d-i environment, you can # just point at it. #d-i partman-auto/expert_recipe_file string /hd-media/recipe # If not, you can put an entire recipe the preseed file in one (logical) # line. This example creates a small /boot partition, suitable swap, and # uses the rest of the space for the root partition: #d-i partman-auto/expert_recipe string \ # boot-root :: \ # 40 50 100 ext3 \ # $primary{ } $bootable{ } \ # method{ format } format{ } \ # use_filesystem{ } filesystem{ ext3 } \ # mountpoint{ /boot } \ # . \ # 500 10000 1000000000 ext3 \ # method{ format } format{ } \ # use_filesystem{ } filesystem{ ext3 } \ # mountpoint{ / } \ # . \ # 64 512 300% linux-swap \ # method{ swap } format{ } \ # . # This makes partman automatically partition without confirmation. d-i partman/confirm_write_new_label boolean true d-i partman/choose_partition \ select Finish partitioning and write changes to disk d-i partman/confirm boolean true 時計・タイムゾーン設定 # Controls whether or not the hardware clock is set to UTC. d-i clock-setup/utc boolean true # You may set this to any valid setting for $TZ; see the contents of # /usr/share/zoneinfo/ for valid values. d-i time/zone string US/Eastern Apt 設定 /etc/apt/sources.list のセットアップと基本設定オプションは、 インストール方法と初期の質問への回答から、完全に自動的に行われます。 preseed に関連する変数は 2 つしかありません。 # You can choose to install non-free and contrib software. #d-i apt-setup/non-free boolean true #d-i apt-setup/contrib boolean true アカウント設定 root アカウント用のパスワードや、 最初のユーザアカウントの名前・パスワードは preseed できます。 パスワードには、クリアテキストか MD5 ハッシュのどちらかを 使用できます。 preseed のパスワードは、 パスワードを知っている preseed ファイルが誰でもアクセスできるために、 完全に安全でないことを知っておいてください。 MD5 ハッシュを使えば、セキュリティ的には多少ましと言えますが、 MD5 ハッシュは総当たり攻撃にかけられることを考えると、 誤った感覚を与えるかもしれません。 # Root password, either in clear text #passwd passwd/root-password password r00tme #passwd passwd/root-password-again password r00tme # or encrypted using an MD5 hash. #passwd passwd/root-password-crypted password [MD5 hash] # Skip creation of a normal user account. #passwd passwd/make-user boolean false # Alternatively, create a normal user account. #passwd passwd/user-fullname string Debian User #passwd passwd/username string debian # Normal user's password, either in clear text #passwd passwd/user-password password insecure #passwd passwd/user-password-again password insecure # or encrypted using an MD5 hash. #passwd passwd/user-password-crypted password [MD5 hash] passwd/root-password-crypted 変数や passwd/user-password-crypted 変数では、 preseed で ! という値を取れます。 この場合、そのアカウントは無効となります。 もちろん管理権限での実行や root ログインを許可する代替手段 (例えば SSH キー認証や sudo) を用意しておいた上で、 root アカウントに設定すると便利です。 パスワードの MD5 ハッシュは以下のコマンドで生成できます。 $ echo "r00tme" | mkpasswd -s -H MD5 ブートローダのインストール # Grub is the default boot loader (for x86). If you want lilo installed # instead, uncomment this: #d-i grub-installer/skip boolean true # This is fairly safe to set, it makes grub install automatically to the MBR # if no other operating system is detected on the machine. d-i grub-installer/only_debian boolean true # This one makes grub-installer install to the MBR if if finds some other OS # too, which is less safe as it might not be able to boot that other OS. d-i grub-installer/with_other_os boolean true # Alternatively, if you want to install to a location other than the mbr, # uncomment and edit these lines: #d-i grub-installer/bootdev string (hd0,0) #d-i grub-installer/only_debian boolean false #d-i grub-installer/with_other_os boolean false インストール第 1 段階の仕上 # Avoid that last message about the install being complete. d-i prebaseconfig/reboot_in_progress note # This will prevent the installer from ejecting the CD during the reboot, # which is useful in some situations. #d-i cdrom-detect/eject boolean false インストール第 2 段階の preseed Base config # Avoid the introductory message. base-config base-config/intro note # Avoid the final message. base-config base-config/login note # If you installed a display manager, but don't want to start it immediately # after base-config finishes. #base-config base-config/start-display-manager boolean false # Some versions of the installer can report back on what you've installed. # The default is not to report back, but sending reports helps the project # determine what software is most popular and include it on CDs. #popularity-contest popularity-contest/participate boolean false パッケージ選択 有効なタスクを組み合わせてインストールするものを選ぶことができます。 有効なタスクを以下に書き出します。 Standard system (標準システム) Desktop environment (デスクトップ環境) Web server (Web サーバ) Print server (印刷サーバ) DNS server (DNS サーバ) File server (ファイルサーバ) Mail server (メールサーバ) SQL database (SQL サーバ) Laptop (ラップトップ) manual package selection (マニュアルパッケージ集) この後に aptitude を実行します。 タスクをインストールしないこともできますし、 他の方法でパッケージのセットが強制的にインストールされることもあります。 Standard system タスクは常に含めるのをお奨めします。 tasksel tasksel/first multiselect Standard system, Desktop environment #tasksel tasksel/first multiselect Standard system, Web server メール設定 通常のインストールでは、exim は少々質問しますが、 さらにこれを避ける方法もあります。 もっと複雑な preseed も可能です。 exim4-config exim4/dc_eximconfig_configtype \ select no configuration at this time exim4-config exim4/no_config boolean true exim4-config exim4/no_config boolean true exim4-config exim4/dc_postmaster string X 設定 Debian の X 設定を preseed が可能です。 しかし、マシンのビデオハードウェアについて、 詳細を知っている必要があるかもしれません。 Debian の X コンフィグレータはすべてを自動設定するわけには行かないのです。 # X can detect the right driver for some cards, but if you're preseeding, # you override whatever it chooses. Still, vesa will work most places. #xserver-xfree86 xserver-xfree86/config/device/driver select vesa # A caveat with mouse autodetection is that if it fails, X will retry it # over and over. So if it's preseeded to be done, there is a possibility of # an infinite loop if the mouse is not autodetected. #xserver-xfree86 xserver-xfree86/autodetect_mouse boolean true # Monitor autodetection is recommended. xserver-xfree86 xserver-xfree86/autodetect_monitor boolean true # Uncomment if you have an LCD display. #xserver-xfree86 xserver-xfree86/config/monitor/lcd boolean true # X has three configuration paths for the monitor. Here's how to preseed # the "medium" path, which is always available. The "simple" path may not # be available, and the "advanced" path asks too many questions. xserver-xfree86 xserver-xfree86/config/monitor/selection-method \ select medium xserver-xfree86 xserver-xfree86/config/monitor/mode-list \ select 1024x768 @ 60 Hz 他パッケージの preseed # Depending on what software you choose to install, or if things go wrong # during the installation process, it's possible that other questions may # be asked. You can preseed those too, of course. To get a list of every # possible question that could be asked during an install, do an # installation, and then run these commands: # debconf-get-selections --installer > file # debconf-get-selections >> file 高度なオプション シェルコマンド # d-i preseeding is inherently not secure. Nothing in the installer checks # for attempts at buffer overflows or other exploits of the values of a # preseed file like this one. Only use preseed files from trusted # locations! To drive that home, and because it's generally useful, here's # a way to run any shell command you'd like inside the installer, # automatically. # This first command is run as early as possible, just after # preseeding is read. #d-i preseed/early_command string anna-install some-udeb # This command is run just before the install finishes, but when there is # still a usable /target directory. #d-i preseed/late_command string echo foo > /target/etc/bar # This command is run just as base-config is starting up. #base-config base-config/early_command string echo hi mom # This command is run after base-config is done, just before the login: # prompt. This is a good way to install a set of packages you want, or to # tweak the configuration of the system. #base-config base-config/late_command \ # string apt-get install zsh; chsh -s /bin/zsh preseed ファイルの連鎖読み込み preseed ファイルから他の preseed ファイルを読み込めます。 前に読み込まれたファイルの既存設定を、 後から読み込まれたいずれの設定でも上書きします。 これは例えば、あるファイルに一般的なネットワークの設定を書いておき、 他のファイルでより確かな設定を指定するという使い方ができます。 # More that one file can be listed, separated by spaces; all will be # loaded. The included files can have preseed/include directives of their # own as well. Note that if the filenames are relative, they are taken from # the same directory as the preseed file that includes them. #d-i preseed/include string x.cfg # The installer can optionally verify checksums of preseed files before # using them. Currently only md5sums are supported, list the md5sums # in the same order as the list of files to include. #d-i preseed/include/checksum string 5da499872becccfeda2c4872f9171c3d # More flexibly, this runs a shell command and if it outputs the names of # preseed files, includes those files. #d-i preseed/include_command \ # string echo if [ "`hostname`" = bob ]; then echo bob.cfg; fi