それマグで!

知識はカップより、マグでゆっくり頂きます。 takuya_1stのブログ

習慣に早くから配慮した者は、 おそらく人生の実りも大きい。

preseed.cfg 設定ファイルの中身についてまとめ

前回までで、自動インストールがすんなり行くようになりました。

preseed.cfg はネットで見つけたファイルを適当に使いました。

やっぱりカスタマイズすることが出来るようになれれば楽ですよね。

参考サイト

参考サイトから寄せ集めで、preseed.cfg を作りましたが・・・

公式を見ながら読み解いておきたい。

でも、細いところには興味が無いので・・・・

ネットワーク周りやストレージ周りは、このへんからコピーしてきました。

PreseedによるUbuntuの自動インストール入門 - Qiita

公式のpreseed.cfg の構成

サンプルファイルはこのような構成になっている。

  • Contents of the preconfiguration file (for wheezy)
  • Localization
  • Network configuration
  • Network console
  • Mirror settings
  • Account setup
  • Clock and time zone setup
  • Partitioning
  • Base system installation
  • Apt setup
  • Package selection
  • Finishing up the installation
  • Preseeding other packages
  • Advanced options
  • Running custom commands during the installation

基本的には、この中の知りたい項目を一生懸命に読み解いていく。

Finishing up the installation

たとえば、インストール終了後の処理の場合、次のような選択肢がある。

と書いてある。

# debian のパッケージ調査に参加しない
#popularity-contest popularity-contest/participate boolean false

# Avoid that last message about the install being complete.
# インストール終了後に再起動メッセージ表示させない
d-i finish-install/reboot_in_progress note

# This will prevent the installer from ejecting the CD during the reboot,
# which is useful in some situations.
# インストール終了後の再起動時にCD トレイをエジェクトさせない。
#d-i cdrom-detect/eject boolean false

# This is how to make the installer shutdown when finished, but not
# reboot into the installed system.
# 終了後に再起動でなくhaltする。
#d-i debian-installer/exit/halt boolean true
# This will power off the machine instead of just halting it.
# 終了後にhalt ではなく電源オフにする。
#d-i debian-installer/exit/poweroff boolean true

こんな感じで一生懸命読んでいく。

Package selection

パッケージセレクションは tasklsel なので

#tasksel tasksel/first multiselect standard, web-server
# If the desktop task is selected, install the kde and xfce desktops
# instead of the default gnome desktop.
#tasksel tasksel/desktop multiselect kde, xfce

# Individual additional packages to install
#d-i pkgsel/include string openssh-server build-essential
# Whether to upgrade packages after debootstrap.
# Allowed values: none, safe-upgrade, full-upgrade
#d-i pkgsel/upgrade select none

このことですね。

takuya @host $ tasksel --list
i desktop   Debian デスクトップ環境
u web-server    Web サーバ
u print-server  プリンタサーバ
u database-server   SQL データベース
u dns-server    DNS サーバ
u file-server   ファイルサーバ
u mail-server   メールサーバ
i ssh-server    SSH サーバ
u laptop    ノート PC

apt setupのついては

### Apt setup
# You can choose to install non-free and contrib software.
# APT の non-free や contrib を有効にするか
#d-i apt-setup/non-free boolean true
#d-i apt-setup/contrib boolean true
# Uncomment this if you don't want to use a network mirror.
#  aptミラーを使うか
#d-i apt-setup/use_mirror boolean false
# Select which update services to use; define the mirrors to be used.
# Values shown below are the normal defaults.
# aptのミラーどこにするか、どの設定でミラーを使うか
#d-i apt-setup/services-select multiselect security, updates
#d-i apt-setup/security_host string security.debian.org

# Additional repositories, local[0-9] available
# 独自のapt サーバー参照を追加するか
#d-i apt-setup/local0/repository string \
#       http://local.server/debian stable main
#d-i apt-setup/local0/comment string local server
# Enable deb-src lines
#d-i apt-setup/local0/source boolean true
# URL to the public key of the local repository; you must provide a key or
# apt will complain about the unauthenticated repository and so the
# sources.list line will be left commented out
# 独自サーバーapt-keyはどうするか
#d-i apt-setup/local0/key string http://local.server/key

# By default the installer requires that repositories be authenticated
# using a known gpg key. This setting can be used to disable that
# authentication. Warning: Insecure, not recommended.
# gpg キーが確認出来ないときどうするか
#d-i debian-installer/allow_unauthenticated boolean true

Base system installation

# Configure APT to not install recommended packages by default. Use of this
# option can result in an incomplete system and should only be used by very
# experienced users.
# 「推奨」パッケージをインストールする依存関係から除外
# これはAPT::install-recommendですね。
#d-i base-installer/install-recommends boolean false

# The kernel image (meta) package to be installed; "none" can be used if no
# kernel is to be installed.
#d-i base-installer/kernel/image string linux-image-486

Controlling how partitions are mounted

## これはディスクマウントにUUIDを使うかどうかですね。
# The default is to mount by UUID, but you can also choose "traditional" to
# use traditional device names, or "label" to try filesystem labels before
# falling back to UUIDs.
#d-i partman/mount_style select uuid

Partitioning

パーティションの設定。

## Partitioning example
# If the system has free space you can choose to only partition that space.
# This is only honoured if partman-auto/method (below) is not set.
# とりあえず、最大限使えるだけを使うってことですね。
#d-i partman-auto/init_automatically_partition select biggest_free

# For example, to use the first SCSI/SATA hard disk:
# 自動設定するのはどのディスクにするかってことですね。
#d-i partman-auto/disk string /dev/sda
# In addition, you'll need to specify the method to use.
# The presently available methods are:
# - regular: use the usual partition types for your architecture
# - lvm:     use LVM to partition the disk
# - crypto:  use LVM within an encrypted partition
# LVMでボリューム作るってことですね
d-i partman-auto/method string lvm

細いパーティションを設定できますけど、ソコまで読んでて疲れた。

Clock and time zone setup

時刻とタイムゾーンの設定ですね。

# 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.
## 殆どの場合は Asia/Tokyo
## 選択肢は、/usr/share/zoneinfo/ のファイル名ですよっと。
d-i time/zone string US/Eastern

# Controls whether to use NTP to set the clock during the install
d-i clock-setup/ntp boolean true
# NTP server to use. The default is almost always fine here.
## NTPサーバーですね ntp.nict.jpで大丈夫
#d-i clock-setup/ntp-server string ntp.example.com

Account setup

アカウントの設定ですね。

root 作らないとsudo になるようです。ここは簡単ですね。

# Skip creation of a root account (normal user account will be able to
# use sudo).
#d-i passwd/root-login boolean false
# Alternatively, to skip creation of a normal user account.
#d-i passwd/make-user boolean false

# Root password, either in clear text
#d-i passwd/root-password password r00tme
#d-i passwd/root-password-again password r00tme
# or encrypted using an MD5 hash.
#d-i passwd/root-password-crypted password [MD5 hash]

# To create a normal user account.
#d-i passwd/user-fullname string Debian User
#d-i passwd/username string debian
# Normal user's password, either in clear text
#d-i passwd/user-password password insecure
#d-i passwd/user-password-again password insecure
# or encrypted using an MD5 hash.
#d-i passwd/user-password-crypted password [MD5 hash]
# Create the first user with the specified UID instead of the default.
#d-i passwd/user-uid string 1010

# The user account will be added to some standard initial groups. To
# override that, use this.
#d-i passwd/user-default-groups string audio cdrom video

Mirror settings

インストールパッケージは取得元のミラーサーバーの設定ですね。

FTPのほうが楽そうです。

# If you select ftp, the mirror/country string does not need to be set.
#d-i mirror/protocol string ftp
d-i mirror/country string manual
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

testing stable から選べってことでしょうね。デフォルトはstable

あとはネットワークの設定

ここは面倒だからDHCPでとりあえず、それでいいかな。

DHCPサーバー側で固定割り振りすればいいし。インスト後に書き換えられるし。

preseedファイルを既存サーバーから作る

sudo apt-get install debconf-utils

パッケージをインスト中に質問が出てきて面倒な時は、debconf-get-selections を使えば自動化出来るよって書いてある。

### Preseeding other packages
# 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

Advanced options

インスト終了後、開始前に任意のコマンドを実行するように指定できる。

たとえばメール送ったりも出来そうだけどね。

メールはOBP25とかSMTPSとか面倒だから、late_commandでHTTPサーバーにCURLでリクエストほうればいいんじゃないかと。でHTTPサーバー側でCGI経由メール送信が楽かもね

### Running custom commands during the installation
# 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
# preconfiguration file like this one. Only use preconfiguration 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 immediately before the partitioner starts. It may be
# useful to apply dynamic partitioner preseeding that depends on the state
# of the disks (which may not be visible when preseed/early_command runs).
#d-i partman/early_command \
#       string debconf-set partman-auto/disk "$(list-devices disk | head -n1)"
# This command is run just before the install finishes, but when there is
# still a usable /target directory. You can chroot to /target and use it
# directly, or use the apt-install and in-target commands to easily install
# packages and run commands in the target system.
#d-i preseed/late_command string apt-install zsh; in-target chsh -s /bin/zsh

preseedファイル作成しんどいですね。

これやっぱり適当にコピーしてきたほうが楽かもしれない。

私が作ったpreseedファイルの設定一覧はこちら。

#### Contents of the preconfiguration file (for wheezy)
### Localization
## 日本語設定
d-i debian-installer/language string ja
d-i debian-installer/country string JP
d-i debian-installer/locale string ja_JP.UTF-8
d-i localechooser/supported-locales ja_JP.UTF-8
d-i console-setup/ask_detect boolean true
d-i console-setup/layoutcode string jp
d-i console-setup/charmap select UTF-8

# キーボードレイアウトの特性の設定(日本語キーボード)
d-i console-keymaps-at/keymap select jp
d-i keyboard-configuration/layoutcode string jp
d-i keyboard-configuration/modelcode jp106


### ネットワーク周り
### DHCPサーバー
d-i netcfg/choose_interface select eth0 
d-i netcfg/disable_autoconfig boolean false
d-i netcfg/get_hostname string my_server 
d-i netcfg/get_domain string 
d-i netcfg/wireless_wep string 

## non-free なハードウェアで質問させない。
d-i hw-detect/load_firmware boolean true


### ミラーサーバーの選択
# If you select ftp, the mirror/country string does not need to be set.
d-i mirror/protocol string ftp
d-i mirror/country string manual
#d-i mirror/http/hostname string ftp.kddilabs.jp
#d-i mirror/http/directory string /pub/Linux/distributions/Debian/debian
d-i mirror/http/hostname string debian-mirror.sakura.ne.jp
d-i mirror/http/directory string /debian
### プロキシは使わない
d-i mirror/http/proxy string


### Account setup
# Skip creation of a root account (normal user account will be able to
# use sudo).
d-i passwd/root-login boolean false

# Root password, either in clear text
#d-i passwd/root-password password r00tme
#d-i passwd/root-password-again password r00tme

# To create a normal user account.
d-i passwd/user-fullname string takuya
d-i passwd/username string takuya
d-i passwd/user-password password パスワード
d-i passwd/user-password-again password パスワード
d-i user-setup/allow-password-weak boolean true

### Clock and time zone setup
# HW の時計をUTCベースにするか➝させない
d-i clock-setup/utc boolean false
# タイムゾーン
d-i time/zone string Asia/Tokyo

# インスト中に時計合わせるか 
d-i clock-setup/ntp boolean true
# ntpサーバー
d-i clock-setup/ntp-server string ntp.nict.jp

### Partitioning
d-i partman-auto/method string lvm

d-i partman-lvm/device_remove_lvm boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-lvm/confirm boolean true
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-auto/choose_recipe select atomic

# This makes partman automatically partition without confirmation.
d-i partman-md/confirm boolean true
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
d-i partman/mount_style select uuid


### Package selection
tasksel tasksel/first multiselect ssh-server
d-i pkgsel/include string openssh-server
popularity-contest popularity-contest/participate boolean false

## grub
d-i grub-installer/grub2_instead_of_grub_legacy boolean true
d-i grub-installer/only_debian boolean true
d-i grub-installer/bootdev string /dev/sda
## 最後
d-i finish-install/reboot_in_progress note

こんな感じで出来上がり。

無駄な処理省けば数分でインストール終わる。

さらに細かいオプションがあって。それは公式ドキュメントをさらに読み込む必要がある。