ラベル Preseed の投稿を表示しています。 すべての投稿を表示
ラベル Preseed の投稿を表示しています。 すべての投稿を表示

2015年3月20日金曜日

Ubuntu アーカイブミラー関連の Preseed 設定

Ubuntu アーカイブミラー関連の Preseed 設定を調べてみました。

環境

Ubuntu 14.04 (Trusty Tahr) Server

アーカイブミラーの国として日本を指定
d-i  mirror/country      string  JP
アーカイブミラーを指定
d-i  mirror/http/mirror  select  jp.archive.ubuntu.com
プロキシの設定

プロキシを設定しない場合

d-i  mirror/http/proxy   string

プロキシを設定する場合

d-i  mirror/http/proxy   string  http://ProxyServer/
  • 書式: http://[[user][:pass]@]host[:port]/

2015年3月19日木曜日

ディスクパーティション関連の Preseed 設定

ディスクパーティション関連の Preseed 設定を調べてみました。

環境

Ubuntu 14.04 (Trusty Tahr) Server
使用するディスクを指定
d-i partman-auto/disk string /dev/sda

ディスクが 1個だけの場合はデフォルトでそれが使われるのでこれ必要ないです。

複数のディスクがある場合はこれで指定します。

メソッド (lvm を使うかとか) を指定
d-i partman-auto/method string regular
  • regular: use the usual partition types for your architecture
  • lvm: use LVM to partition the disk
  • crypto: use LVM within an encrypted partition

とのことです。regular にすると手動で「Guided - use entire disk」を選んだのと同じ結果になりました。

lvm の場合は以下も指定します。
# Write the changes to disks and configure LVM?: Yes
d-i partman-lvm/confirm_nooverwrite boolean true

# Size of the selected partition: max
d-i partman-auto-lvm/guided_size string max
確認をスキップ
# Overview of your currently configured partitions and mount points:
#       Finish partitioning and write changes to disk
d-i partman/choose_partition                    select          finish

# Write the changes to disks?: Yes
d-i partman/confirm_nooverwrite                 boolean         true

参考


2014年7月24日木曜日

Ubuntu 14.04 Server 自動インストール Preseed 用 seed ファイル

Ubuntu 14.04 Server で Preseed を使って自動インストールするための seed ファイルを作ってみました。

「 KVM virt-install でネットワーク環境が全く無い場合でも DVD イメージから Preseed で自動インストール 」このあたりも参照して下さい。

環境
Ubuntu 14.04 Server

seed ファイルのコメントにも書いてますが、設定内容は以下のとおりです。

項目 設定値
IP address 192.168.122.100
Netmask 255.255.255.0
Gateway 192.168.122.1
Name server addresses 192.168.122.1
Hostname TestServer
Domain name (blank)
Full name for the new user Test full name
Username for your account testuser
Choose a password for the new user testpasswd
Re-enter password to verify testpasswd
Encrypt your home directory? No
Language English
Country, territory or area Japan
Country to base default locale settings on en_US.UTF-8
Select your time zone Tokyo
Partitioning method Guided - use entire disk and set up LVM
Write the changes to disks and configure LVM? Yes
Size of the selected partition max
Overview of your currently configured partitions and mount points Finish partitioning and write changes to disk
Write the changes to disks? Yes
HTTP proxy information (blank for none) (blank)
How do you want to manage upgrades on this system? No automatic updates
Choose software to install Basic Ubuntu server, OpenSSH server
Install the GRUB boot loader to the master boot record? Yes
Is the system clock set to UTC? Yes
Installation complete Continue

設定値は一度手動で設定してみて、以下のコマンドの出力を参考にしたりしてます。

$ sudo apt-get install debconf-utils
$ sudo debconf-get-selections --installer

Ubuntu 14.04 Server 用 seed ファイル

d-i netcfg/disable_autoconfig           boolean     true
# IP address: 192.168.122.100
d-i netcfg/get_ipaddress                string      192.168.122.100
# Netmask: 255.255.255.0
d-i netcfg/get_netmask                  string      255.255.255.0
# Gateway: 192.168.122.1
d-i netcfg/get_gateway                  string      192.168.122.1
# Name server addresses: 192.168.122.1
d-i netcfg/get_nameservers              string      192.168.122.1

# Hostname: TestServer
d-i netcfg/get_hostname                 string      TestServer
# Domain name: (blank)
d-i netcfg/get_domain                   string

# Full name for the new user: Test full name
d-i passwd/user-fullname                string      Test full name
# Username for your account: testuser
d-i passwd/username                     string      testuser
# ここにパスワードを書き込むとファイルとしてパスワードが残ってしまうので
# 以下をコメントアウトし、パスワードをコンソールから入力した方が良いです。
# Choose a password for the new user: testpasswd
d-i passwd/user-password                password    testpasswd
# Re-enter password to verify: testpasswd
d-i passwd/user-password-again          password    testpasswd
# Encrypt your home directory?: No
d-i user-setup/encrypt-home             boolean     false

# Language: English
d-i debian-installer/language           string      en
# Country, territory or area: Japan
d-i debian-installer/country            string      JP
# Country to base default locale settings on: en_US.UTF-8
d-i localechooser/preferred-locale      select      en_US.UTF-8
# Select your time zone: Tokyo
d-i time/zone                           string      Asia/Tokyo

# Partitioning method: Guided - use entire disk and set up LVM
d-i partman-auto/method                 string      lvm
# Write the changes to disks and configure LVM?: Yes
d-i partman-lvm/confirm_nooverwrite     boolean     true
# Size of the selected partition: max
d-i partman-auto-lvm/guided_size        string      max
# Overview of your currently configured partitions and mount points:
#   Finish partitioning and write changes to disk
d-i partman/choose_partition            select      finish
# Write the changes to disks?: Yes
d-i partman/confirm_nooverwrite         boolean     true

# HTTP proxy information (blank for none): (blank)
d-i mirror/http/proxy                   string
# How do you want to manage upgrades on this system?: No automatic updates
d-i pkgsel/update-policy                select      none
# Choose software to install: Basic Ubuntu server, OpenSSH server
d-i tasksel/first                       multiselect Basic Ubuntu server, OpenSSH server

# Install the GRUB boot loader to the master boot record?: Yes
d-i grub-installer/only_debian          boolean     true
# Is the system clock set to UTC?: Yes
d-i clock-setup/utc                     boolean     true

# Installation complete: Continue
d-i finish-install/reboot_in_progress   note


# 以下は有効にしなくても自動インストールできました

#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 mirror/country                     string      Japan
#d-i mirror/http/mirror                 string      jp.archive.ubuntu.com

#d-i pkgsel/install-language-support    boolean     false

# ssh コンソールでのインストール
#d-i anna/choose_modules                string      network-console
#d-i network-console/password           password    HogeHoge
#d-i network-console/password-again     password    HogeHoge

2014年2月14日金曜日

KVM virt-install でネットワーク環境が全く無い場合でも DVD イメージから Preseed で自動インストール

はじめに

KVM サーバーを構築して、ゲストマシンとして動作確認用の Ubuntu を何度もインストールするようになりました。

毎回ゲスト Ubuntu をインストールするのが大変なので、Preseed を使って自動化するんですが、「 KVM virt-install でディストリビューションツリーを指定した時に Preseed で自動設定 」 だとどうしてもネットワーク環境が必要なようです。

ネットワーク環境がなくても Preseed を使い、更に DVD メディアから全てをインストールする方法を調べてみました。インストール画面の表示も VNC コンソールではなく、virt-install を実行するターミナルに表示するようにします。

Preseed の設定ファイルをあらかじめ用意した TFTP サーバーに置く方法もあるようですが、なんとなく TFTP サーバーとか構築したくないですし、そもそもネットワーク環境が無い場合を想定しているので aufs を利用して Ubuntu インストール用 ISO イメージの中に擬似的に設定ファイルを埋め込むような方法でやってみます。

KVM サーバー環境

先日ブログに投稿した「 Kvm インストール 」でインストールした KVM です。

KVM サーバーの Ubuntu のバージョンは 12.04.3 Server です。

ISO イメージをループバックマウント

ゲスト Ubuntu も 12.04.3 Server にします。

Ubuntu のサイトから ubuntu-12.04.3-server-amd64.iso をダウンロード

マウントポイントを作成して、ダウンロードした ISO イメージをループバックマウント

$ mkdir Iso
$ sudo mount --read-only --options loop ubuntu-12.04.3-server-amd64.iso Iso/

ISO イメージの内容を擬似的に上書きするためのディレクトリ、ファイル準備

ディレクトリ作成

$ mkdir -p ForOverwrite/{isolinux,preseed}

以下の内容で ForOverwrite/isolinux/isolinux.cfg 設置

default install
label install
    kernel /install/vmlinuz
    append auto=true file=/cdrom/preseed/Custom.seed initrd=/install/initrd.gz quiet console=ttyS0 --

以下の内容で ForOverwrite/preseed/Custom.seed 設置

d-i netcfg/get_hostname                 string      TestMachine
d-i user-setup/encrypt-home             boolean     false

d-i passwd/user-fullname                string      testuser
d-i passwd/username                     string      testuser

# ここにパスワードを書き込むとファイルとしてパスワードが残ってしまうので
# 以下をコメントアウトし、パスワードをコンソールから入力した方が良いです。
d-i passwd/user-password                password    testpasswd
d-i passwd/user-password-again          password    testpasswd

d-i debian-installer/language           string      en
d-i debian-installer/country            string      JP
d-i localechooser/preferred-locale      select      en_US.UTF-8
d-i time/zone                           string      Asia/Tokyo

d-i netcfg/disable_autoconfig           boolean     true
d-i netcfg/get_ipaddress                string      192.168.122.100
d-i netcfg/get_netmask                  string      255.255.255.0
d-i netcfg/get_gateway                  string      192.168.122.1
d-i netcfg/get_nameservers              string      192.168.122.1
d-i netcfg/get_domain                   string

#d-i mirror/country                     string      Japan
#d-i mirror/http/mirror                 string      jp.archive.ubuntu.com

# ssh コンソールでのインストール
#d-i anna/choose_modules                string      network-console
#d-i network-console/password           password    HogeHoge
#d-i network-console/password-again     password    HogeHoge

#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 partman-auto/method                 string      lvm
d-i partman-lvm/confirm_nooverwrite     boolean     true
d-i partman-auto-lvm/guided_size        string      max
d-i partman/choose_partition            select      finish
d-i partman/confirm_nooverwrite         boolean     true

d-i mirror/http/proxy                   string
d-i pkgsel/update-policy                select      none
d-i pkgsel/install-language-support     boolean     false
d-i tasksel/first                       multiselect OpenSSH server

d-i grub-installer/only_debian          boolean     true
d-i clock-setup/utc                     boolean     true

d-i finish-install/reboot_in_progress   note

ゲスト Ubuntu インストール用 DVD イメージ作成

まず、現段階で ForOverwrite/、Iso/ はそれぞれ以下のようなファイル配置になってます。

ForOverwrite/
├── isolinux/
│   └── isolinux.cfg
└── preseed/
    └── Custom.seed

Iso/
├── ...
├── isolinux/
│   ├── ...
│   ├── isolinux.cfg
│   └── ...
├── preseed/
│   ├── cli.seed
│   ├── cloud.seed
│   ├── ubuntu-server-minimal.seed
│   ├── ubuntu-server-minimalvm.seed
│   └── ubuntu-server.seed
└── ...
この状態でこの2つのディレクトリを aufs で Custom/ へひとつにまとめます。
$ mkdir Custom
$ sudo mount -t aufs -o br:ForOverwrite/:Iso/ aufs Custom/

Custom/ のファイル配置はこのようになります。

Custom/
├── ...
├── isolinux/
│   ├── ...
│   ├── isolinux.cfg
│   └── ...
├── preseed/
│   ├── cli.seed
│   ├── cloud.seed
│   ├── Custom.seed
│   ├── ubuntu-server-minimal.seed
│   ├── ubuntu-server-minimalvm.seed
│   └── ubuntu-server.seed
└── ...

isolinux/isolinux.cfg は ForOverwrite/ と Iso/ のどちらにもあるので、Custom/isolinux/isolinux.cfg は mount -t aufs の引数で先に指定した ForOverwrite/isolinux/isolinux.cfg の内容となります。

最終的に、Custom/ は Iso/ の内容 (ubuntu-12.04.3-server-amd64.iso の内容) を ForOverwrite/ の内容で上書きした状態になっています。

ゲスト Ubuntu インストール用 DVD イメージ作成

$ sudo mkisofs \
-r \
-V 'Custom Ubuntu Install CD' \
-cache-inodes \
-J \
-l \
-b isolinux/isolinux.bin \
-c isolinux/boot.cat \
-no-emul-boot \
-boot-load-size 4 \
-boot-info-table \
-input-charset utf-8 \
-o Custom_ubuntu-12.04.3-server-amd64.iso \
Custom/

Custom/, Iso/ は不要になったのでマウントを解除

$ sudo umount Custom/
$ sudo umount Iso/

ゲスト Ubuntu インストール

インストールディスクイメージ作成

$ sudo qemu-img create -f qcow2 /var/lib/libvirt/images/TestMachine.qcow2 30G
ゲスト Ubuntu インストール
$ sudo virt-install \
--name TestMachine \
--ram 2048 \
--vcpus 1 \
--os-variant ubuntuprecise \
--hvm \
--virt-type kvm \
--disk /var/lib/libvirt/images/TestMachine.qcow2,format=qcow2 \
--cdrom Custom_ubuntu-12.04.3-server-amd64.iso \
--network bridge:virbr0 \
--serial pty \
--keymap ja

数秒待つとインストール画面が表示されます

インストールが終了すると最後にゲストマシンの再起動がかかり、インストールした OS で起動します。 コンソールにはゲスト OS のログインプロンプトが出てくるので ‘Ctrl + ]’ でコンソールを切断します。

再度コンソールに接続する場合
$ sudo virsh console TestMachine

コンソールから切断する場合は同様に ‘Ctrl + ]’ です。


2014年1月28日火曜日

KVM virt-install でディストリビューションツリーを指定した時に Preseed で自動設定

KVM の virt-install でのゲスト OS インストール時に --location でディストリビューションツリーを指定した場合は --initrd-inject で preseed 設定ファイルを指定することができるようなので試して見ました。

まず、preseed 設定ファイルを用意

$ ls -la /some/where/preseed.cfg
-rw-rw-r-- 1 user user 1341 Jan 23 20:49 /some/where/preseed.cfg
virt-install の --initrd-inject でこの preseed 設定ファイルを指定
$ sudo virt-install \
--name TestMachine \
--ram 2048 \
--vcpus 1 \
--os-variant ubuntuprecise \
--hvm \
--virt-type kvm \
--disk /var/lib/libvirt/images/TestMachine.qcow2,format=qcow2 \
--network bridge:virbr0 \
--keymap ja \
--location /some/where/Iso/ \
--initrd-inject /some/where/preseed.cfg  \
--serial pty \
--extra-args 'console=ttyS0 auto=true'

もともとインストーラーの Linux 環境 initrd には /preseed.cfg が存在し、デフォルトではこれに従ってインストールが進んでるようです。

で、 --initrd-inject=/some/where/preseed.cfg でカスタマイズした preseed.cfg を initrd に inject して、デフォルトの preseed.cfg を置き換えているようです。