(2015-08-14: 「外部リポジトリの追加」について追記)

はじめに

少し間が空いてしまったが、Cobblerの省力化のためにプロキシと組み合わせるで、まともにローカルに全部保持するとディスクの容量を食いまくるDebianやUbuntuのリポジトリを、ローカルにキャッシュ以外を保持せずにCobblerに追加するための準備が整った。

それでは実際にDebian/UbuntuをCobblerにOSイメージとして追加し、PXEを使って自動インストールができるようにしてみる。

OSイメージの追加部分以外のCobblerの導入方法はCobblerの省力化のためにプロキシと組み合わせるCentOS 7にCobblerをインストールするを参照のこと。
DebianやUbuntuにCobblerをインストールする方法は書いていないが、手順に差分が多くて何か書く必要がありそうならそのうち書くかもしれない。

Cobblerのバージョンは2.6.9を使用している。CentOS 7にCobblerをインストールするに書いたが、Cobblerの公式サイトのドメインが変更されたため2.6.9まで上げないとcobbler get-loadersやcobbler signature updateが失敗する。

Debian, Ubuntu共通部の作業

Red Hat系ディストリビューションではOSインストール時の自動応答にkickstartを使用するがDebian系ではpreseedを使用する。
私の好みで言えばpreseedよりkickstartの方が好き(私はOSインストール後の状態を記述したいのであってインストーラがしてくる質問に対する応答を書きたいわけじゃないのだ)だし、Ubuntuはkickstartも一応使えるのだが(あまり情報は見つからなかったけどDebianでも同様に使えるんじゃないかな)、パーティション周りがまともに使えないのはあまりよろしくないので、少なくともこの資料ではpreseedを使うことにする。

というわけでpreseedファイルのCobbler用テンプレートのサンプルが /var/lib/cobbler/kickstarts/sample.seed にあるのでこれをベースに修正を加えていくのだが、これの下の方に次の2つの記述があるのが見える。

/var/lib/cobbler/kickstarts/sample.seedの一部
d-i preseed/early_command string wget -O- 
   http://$http_server/cblr/svc/op/script/$what/$name/?script=preseed_early_default | 
   /bin/sh -s
/var/lib/cobbler/kickstarts/sample.seedの一部
d-i preseed/late_command string wget -O- 
   http://$http_server/cblr/svc/op/script/$what/$name/?script=preseed_late_default | 
   chroot /target /bin/sh -s

つまりこれはパーティションを切る前に /var/lib/cobbler/scripts/preseed_early_default
の内容が、OSインストール終了後の再起動の前に /var/lib/cobbler/scripts/preseed_late_default の内容が実行されるということである。

で、これらは /var/lib/cobbler/snippets/ にあるスニペットを呼んでいる。preseed_early_defaultの方はkickstart_startスニペット、preseed_late_defaultの方はpost_install_network_config_deb, late_apt_repo_config, post_run_deb, download_config_files, kickstart_doneの各スニペットである。

これらのスニペットの中でlate_apt_repo_configはOSインストール後の /etc/apt/sources.list を作ってくれるものである。この中で次の1行はCobbler機のローカルにあるリポジトリを参照するものであるが、この資料ではリポジトリは常にCobbler機に仕掛けたプロキシを通してftp.jp.debian.orgあるいはjp.archive.ubuntu.comを参照するため、この1行を取り去る必要がある。

/var/lib/cobbler/snippets/late_apt_repo_configの一部
deb http://$http_server/cblr/links/$distro_name $os_version main

次のコマンドで取り去る。元のlate_apt_repo_configは一応 /var/lib/cobbler/snippets/late_apt_repo_config.org にしておく。

# sed -i.org '/deb http/d' /var/lib/cobbler/snippets/late_apt_repo_config

次にOSインストール中に参照するリポジトリの一覧をpreseedファイルに書き出すpreseed_apt_repo_configスニペットを修正する。
このスニペットは「d-i apt-setup/localx/repository」行を作ってくれるが、外部リポジトリではGPGキーを取り込まないとそのリポジトリからインストールする際に警告が行われる。そのため「d-i apt-setup/localx/key」行を作ってGPGキーを取り込む。
/var/lib/cobbler/snippets/preseed_apt_repo_config を以下のようにする。使い方は「外部リポジトリを追加する」の項で説明する。

/var/lib/cobbler/snippets/preseed_apt_repo_config
# Additional repositories, local[0-9] available
#set $cur=0
#set $key_cur=0
#set $repo_data = $getVar("repo_data",[])
#for $repo in $repo_data
 #for $dist in $repo.apt_dists
 #set $comps = " ".join($repo.apt_components)
d-i apt-setup/local${cur}/repository string 
 #if $repo.mirror_locally
      http://$http_server/cblr/repo_mirror/${repo.name} $dist $comps
 #else
      ${repo.mirror} $dist $comps
 #end if
 #if $repo.comment != ""
d-i apt-setup/local${cur}/comment string ${repo.comment}
 #end if
 #if $repo.breed == "src"
# Enable deb-src lines
d-i apt-setup/local${cur}/source boolean false
 #end if
 #if $repo.environment
   #for $env_key in $repo.environment.keys
     #if $env_key.startswith('gpg_key')
d-i apt-setup/local${key_cur}/key string $repo.environment[$env_key]
       #set $key_cur=$key_cur+1
     #end if
   #end for
 #end if
 #set $cur=$cur+1
 #end for
#end for

元の /var/lib/cobbler/snippets/preseed_apt_repo_config を /var/lib/cobbler/snippets/preseed_apt_repo_config.org に退避し、diff /var/lib/cobbler/snippets/preseed_apt_repo_config{.org,}した結果は次である。
patchがインストールされていればコピーしてpatch /var/lib/cobbler/snippets/preseed_apt_repo_config.org <次のdiffの内容> -o /var/lib/cobbler/snippets/preseed_apt_repo_configすれば良い。

2a3
> #set $key_cur=0
18a20,27
>  #end if
>  #if $repo.environment
>    #for $env_key in $repo.environment.keys
>      #if $env_key.startswith('gpg_key')
> d-i apt-setup/local${key_cur}/key string $repo.environment[$env_key]
>        #set $key_cur=$key_cur+1
>      #end if
>    #end for

また次は私の好みであるが、OSインストール後cobbler systemでhostnameを指定した時を除きプロファイル名の文字列から”_”を取り去ったものがhostname、「local.lan」がdomainになるが、あまりこれが好きではないので特に何もしない、というか自由に処理を追加するためのスニペットであるpost_run_debに次の1行を追加している。

echo localhost.localdomain > /etc/hostname

Debian共通部の作業

Debianを追加する場合はインポート作業用のディレクトリを作っておく。

# mkdir -p /work/import

SELinuxが有効である場合、インポート作業用のディレクトリのタイプをcobbler_var_lib_tにしておく。

# semanage fcontext -a -t cobbler_var_lib_t "/work/import(/.*)?"
# restorecon -RFv /work/import

Debian 8 (Jessie)を追加する

OSイメージの取り込み

debian-8.1.0-amd64-netinst.isoをcobbler importすれば良い……と思ったのだがOSインストール中に止まるのでnetboot.tar.gzをダウンロードしてきてちょっといじってimportしている。

インポート作業用のディレクトリにDebian 8用のディレクトリを作り、ダウンロードして解凍する。

# mkdir /work/import/jessie
# curl http://ftp.jp.debian.org/debian/dists/jessie/main/installer-amd64/current/images/netboot/netboot.tar.gz -o netboot.tar.gz
# tar xvf netboot.tar.gz -C /work/import/jessie

debian-installer/amd64/linux のままだとimportが失敗するのでvmlinuzにリネームする。

# cd /work/import/jessie
# mv debian-installer/amd64/{linux,vmlinuz}

distsディレクトリを作ってReleaseファイルとlinux-headersのdebファイルを配置する。これらもimport時に存在をチェックされるためである。
Releaseファイルの方はDebianのバージョンに応じたURLがすぐわかるからダウンロードも簡単だが、linux-headersの.debファイルの方はどれがそのバージョンで使われるものかなんて調べるのは面倒である。しかし実際のところ存在チェックしかされていないのでどれを置いても良い(もしかしたらamd64などアーキテクチャの部分はチェックされているかもしれないが未確認)。ちなみに以下のものはDebian 7用のlinux-headersの.debであってDebian 8用ではないが特に問題ない。

# mkdir dists
# curl http://ftp.jp.debian.org/debian/dists/jessie/Release -o dists/Release
# curl http://ftp.jp.debian.org/debian/pool/main/l/linux/linux-headers-3.2.0-4-amd64_3.2.65-1_amd64.deb -o dists/linux-headers-3.2.0-4-amd64_3.2.65-1_amd64.deb

ここまで来たらimport。何故かdistroの名前もprofileの名前もd8-debianer-x86_64になる。
ちなみにカレントディレクトリが /work/import/jessie だからと–pathオプションの値を”.”にしたら何故か/以下全部取り込もうとしたので注意。

# cobbler import --name d8 --path /work/import/jessie/

パッケージリポジトリの設定

OSインストール後に /etc/apt/sources.list には利用するリポジトリが「deb (リポジトリルート) (ディレクトリ) (リポジトリの種類)」の一覧の形で書かれるが、cobbler repo addのオプションとして「–mirror (リポジトリルート) –apt-dists (ディレクトリ) –apt-components (リポジトリの種類)」と指定すれば良い。

他に次のようなオプションを付ける。

  • –name (適当な名前)
  • –breed apt
  • –arch x86_64 → “amd64″ではなく”x86_64″にする
  • –mirror-locally 0 → プロキシを使う場合に必要
  • –keep-updated 0 → cobbler reposyncの対象にしない

以下はisoからDebian 8をインストールした時にできる /etc/apt/sources.list を参考に3つcobbler repo addしたものである。

# cobbler repo add --name jessie --mirror http://ftp.jp.debian.org/debian --breed apt --apt-dists jessie --apt-components main --arch x86_64 --mirror-locally 0 --keep-updated 0
# cobbler repo add --name jessie-updates --mirror http://ftp.jp.debian.org/debian --breed apt --apt-dists jessie-updates --apt-components main --arch x86_64 --mirror-locally 0 --keep-updated 0
# cobbler repo add --name jessie-security --mirror http://security.debian.org --breed apt --apt-dists jessie/updates --apt-components main --arch x86_64 --mirror-locally 0 --keep-updated 0

この後yumのリポジトリをcobbler repo addした時のようにcobbler reposyncを行う必要はないので上記のcobbler repo addではcobbler reposyncの対象にしないようしているが、cobbler import時に自動生成されたリポジトリについてもcobbler reposyncの対象にしないようにする。(cobbler repo removeで削除してしまっても良いと思う)
さもないとyumのリポジトリも管理しているなどの理由でcobbler reposyncを実行すると/usr/bin/debmirrorが見つからないと言われてエラーになる。

# cobbler repo edit --name d8-debianer-x86_64 --keep-updated 0

cobbler profileの設定変更

とりあえずsample.seedをコピーしてDebian 8用のpreseedファイルテンプレートを作り、先程cobbler repo addしたリポジトリとともにプロファイルに紐づける。

# cp /var/lib/cobbler/kickstarts/sample.seed /var/lib/cobbler/kickstarts/d8.seed
# cobbler profile edit --name d8-debianer-x86_64 --repos "jessie jessie-updates jessie-security" --kickstart /var/lib/cobbler/kickstarts/d8.seed

preseedファイルテンプレートを編集することにより、どのような内容でインストールするかを決めることができる。
編集した後、sample.seedからの変更部分をdiffしたものを次に示す。
これを使うならpatchがインストールされていればコピーしてpatch /var/lib/cobbler/kickstarts/sample.seed <次のdiffの内容> -o /var/lib/cobbler/kickstarts/d8.seedすれば良い。

10c10,11
< d-i keyboard-configuration/layoutcode string us
---
> d-i keyboard-configuration/layoutcode string jp
> d-i keyboard-configuration/xkb-keymap select jp
15d15
< #set $myhostname = $getVar('hostname',$getVar('name','cobbler')).replace("_","-")
17d16
< d-i netcfg/get_hostname string $myhostname
25c24
< d-i time/zone string US/Eastern
---
> d-i time/zone string Asia/Tokyo
28c27
< d-i clock-setup/ntp-server  string ntp.ubuntu.com
---
> d-i clock-setup/ntp-server  string ntp.nict.jp
32,40c31,33
< d-i mirror/http/hostname string $http_server
< d-i mirror/http/directory string $install_source_directory
< d-i mirror/http/proxy string
<
< #set $os_v = $getVar('os_version','')
< #if $os_v and $os_v.lower()[0] > 'p'
< # Required at least for 12.10+
< d-i live-installer/net-image string http://$http_server/cobbler/links/$distro_name/install/filesystem.squashfs
< #end if
---
> d-i mirror/http/hostname string ftp.jp.debian.org
> d-i mirror/http/directory string /debian
> d-i mirror/http/proxy string http://$http_server:8080/
72,73c65
< d-i passwd/root-login boolean true
< d-i passwd/root-password-crypted password $default_password_crypted
---
> d-i passwd/root-login boolean false
76c68,71
< d-i passwd/make-user boolean false
---
> d-i passwd/make-user boolean true
> d-i passwd/user-fullname string user
> d-i passwd/username string user
> d-i passwd/user-password-crypted password $default_password_crypted
111c106,109
< d-i pkgsel/include string ntp ssh wget
---
> tasksel tasksel/first multiselect standard, ssh-server
> d-i pkgsel/include string ntp parted
>
> grub-installer grub-installer/bootdev string /dev/sda

変更内容を説明する。

キーボードを日本語106に変更。

10c10,11
< d-i keyboard-configuration/layoutcode string us
---
> d-i keyboard-configuration/layoutcode string jp
> d-i keyboard-configuration/xkb-keymap select jp

hostnameはPXEブート時のオプションで決定され(何になるかは上記のpost_run_debスニペットに関する記述のところに書いた)、ここに指定したものは無視されるので削除。

15d15
< #set $myhostname = $getVar('hostname',$getVar('name','cobbler')).replace("_","-")
17d16
< d-i netcfg/get_hostname string $myhostname

タイムゾーンを東京に。

25c24
< d-i time/zone string US/Eastern
---
> d-i time/zone string Asia/Tokyo

OSインストール中にアクセスするNTPサーバのホスト名をntp.nict.jpに。
ここで指定したホストはOSインストール後のNTPクライアントの設定には影響しない。

28c27
< d-i clock-setup/ntp-server  string ntp.ubuntu.com
---
> d-i clock-setup/ntp-server  string ntp.nict.jp

OSインストール時に参照するリポジトリをCobbler機ではなくリモートにし、Cobbler機はプロキシに指定する。
ここでd-i mirror/http/proxyに指定したプロキシはOSインストール後も /etc/apt/apt.conf にAcquire::http::Proxyの値として設定される。

32,40c31,33
< d-i mirror/http/hostname string $http_server
< d-i mirror/http/directory string $install_source_directory
< d-i mirror/http/proxy string
---
> d-i mirror/http/hostname string ftp.jp.debian.org
> d-i mirror/http/directory string /debian
> d-i mirror/http/proxy string http://$http_server:8080/

これはUbuntuでしか使わない部分なので削除。

< #set $os_v = $getVar('os_version','')
< #if $os_v and $os_v.lower()[0] > 'p'
< # Required at least for 12.10+
< d-i live-installer/net-image string http://$http_server/cobbler/links/$distro_name/install/filesystem.squashfs
< #end if

sshd_configのデフォルト値が「PermitRootLogin without-password」なので、rootユーザのパスワードを設定せず、新しくuserユーザを作成するようにしている。

72,73c65
< d-i passwd/root-login boolean true
< d-i passwd/root-password-crypted password $default_password_crypted
---
> d-i passwd/root-login boolean false
76c68,71
< d-i passwd/make-user boolean false
---
> d-i passwd/make-user boolean true
> d-i passwd/user-fullname string user
> d-i passwd/username string user
> d-i passwd/user-password-crypted password $default_password_crypted

インストールするパッケージの選択。
大まかなところはtasksel tasksel/firstで指定して、個々のパッケージをd-i pkgsel/includeで指定している。
tasksel tasksel/firstに指定できる値はOSインストール後ならtasksel --list-tasksで取得できる。他に“standard”という値も指定できる
ここではデスクトップ環境は不要としSSHサーバとNTPクライアント、あともうfdiskを忘れつつあるのでpartedをインストールするようにした。この辺り好みで調整してほしい。

111c106,109
< d-i pkgsel/include string ntp ssh wget
---
> tasksel tasksel/first multiselect standard, ssh-server
> d-i pkgsel/include string ntp parted

Debian 7まで(あとUbuntu全般)では不要だったが、Debian 8では明示的にブートローダをインストールするデバイス名を指定する必要があるようだ。

> grub-installer grub-installer/bootdev string /dev/sda

Debian 7 (Wheezy)を追加する

やり方はDebian 8と変わらないので説明は大体省く。

# mkdir /work/import/wheezy
# curl http://ftp.jp.debian.org/debian/dists/wheezy/main/installer-amd64/current/images/netboot/netboot.tar.gz -o netboot.tar.gz
# tar xvf netboot.tar.gz -C /work/import/wheezy
# cd /work/import/wheezy
# mv debian-installer/amd64/{linux,vmlinuz}
# mkdir dists
# curl http://ftp.jp.debian.org/debian/dists/wheezy/Release -o dists/Release
# curl http://ftp.jp.debian.org/debian/pool/main/l/linux/linux-headers-3.2.0-4-amd64_3.2.65-1_amd64.deb -o dists/linux-headers-3.2.0-4-amd64_3.2.65-1_amd64.deb
# cobbler import --name d7 --path /work/import/wheezy/
# cobbler repo add --name wheezy --mirror http://ftp.jp.debian.org/debian --breed apt --apt-dists wheezy --apt-components main --arch x86_64 --mirror-locally 0 --keep-updated 0
# cobbler repo add --name wheezy-updates --mirror http://ftp.jp.debian.org/debian --breed apt --apt-dists wheezy-updates --apt-components main --arch x86_64 --mirror-locally 0 --keep-updated 0
# cobbler repo add --name wheezy-security --mirror http://security.debian.org --breed apt --apt-dists wheezy/updates --apt-components main --arch x86_64 --mirror-locally 0 --keep-updated 0
# cobbler repo edit --name d7-debianer-x86_64 --keep-updated 0
# cp /var/lib/cobbler/kickstarts/sample.seed /var/lib/cobbler/kickstarts/d7.seed
# cobbler profile edit --name d7-debianer-x86_64 --repos "wheezy wheezy-updates wheezy-security" --kickstart /var/lib/cobbler/kickstarts/d7.seed

patchでの適用に使うためにsample.seedとd7.seedのdiff。

10c10,11
< d-i keyboard-configuration/layoutcode string us
---
> d-i keyboard-configuration/layoutcode string jp
> d-i keyboard-configuration/xkb-keymap select jp
15d15
< #set $myhostname = $getVar('hostname',$getVar('name','cobbler')).replace("_","-")
17d16
< d-i netcfg/get_hostname string $myhostname
25c24
< d-i time/zone string US/Eastern
---
> d-i time/zone string Asia/Tokyo
28c27
< d-i clock-setup/ntp-server  string ntp.ubuntu.com
---
> d-i clock-setup/ntp-server  string ntp.nict.jp
32,40c31,33
< d-i mirror/http/hostname string $http_server
< d-i mirror/http/directory string $install_source_directory
< d-i mirror/http/proxy string
<
< #set $os_v = $getVar('os_version','')
< #if $os_v and $os_v.lower()[0] > 'p'
< # Required at least for 12.10+
< d-i live-installer/net-image string http://$http_server/cobbler/links/$distro_name/install/filesystem.squashfs
< #end if
---
> d-i mirror/http/hostname string ftp.jp.debian.org
> d-i mirror/http/directory string /debian
> d-i mirror/http/proxy string http://$http_server:8080/
72,73c65
< d-i passwd/root-login boolean true
< d-i passwd/root-password-crypted password $default_password_crypted
---
> d-i passwd/root-login boolean false
76c68,71
< d-i passwd/make-user boolean false
---
> d-i passwd/make-user boolean true
> d-i passwd/user-fullname string user
> d-i passwd/username string user
> d-i passwd/user-password-crypted password $default_password_crypted
111c106,107
< d-i pkgsel/include string ntp ssh wget
---
> tasksel tasksel/first multiselect standard, ssh-server
> d-i pkgsel/include string ntp parted

要はDebian 8のものとの違いはDebian 8でだけ必要になっているこれだけである。

109,110d108
< grub-installer grub-installer/bootdev string /dev/sda
<

Debian stretchを追加する

将来Debian 9になるstretchは、2015-07-06現在まだAlphaにもなっていないのでnetboot.tar.gzもないが、一応Debian 8をimportした後なら次のような方法で追加できる。

Debian 8のdistroをコピーする。

# cobbler distro copy --name d8-debianer-x86_64 --newname d9-x86_64

当然まだ /var/lib/cobbler/distro_signatures.json にstretchはないのでjessieのすぐ下に次を追加する。
(jessieのものをコピーしてjessieをstretchに修正しただけである)

/var/lib/cobbler/distro_signatures.jsonの一部
   },
   "stretch": {
    "signatures":["dists"],
    "version_file":"Release",
    "version_file_regex":"Codename: stretch",
    "kernel_arch":"linux-headers-(.*)\.deb",
    "kernel_arch_regex":null,
    "supported_arches":["i386","amd64"],
    "supported_repo_breeds":["apt"],
    "kernel_file":"vmlinuz(.*)",
    "initrd_file":"initrd(.*)\.gz",
    "isolinux_ok":false,
    "default_kickstart":"/var/lib/cobbler/kickstarts/sample.seed",
    "kernel_options":"",
    "kernel_options_post":"",
    "boot_files":[]

distro_signatures.jsonの変更を反映するためにcobblerdを再起動してからstretch用のdistroの–os-versionオプションをstretchにする。

# systemctl restart cobblerd.service
# cobbler distro edit --name d9-x86_64 --os-version stretch

パッケージリポジトリの設定。

# cobbler repo add --name stretch --mirror http://ftp.jp.debian.org/debian --breed apt --apt-dists stretch --apt-components main --arch x86_64 --mirror-locally 0 --keep-updated 0
# cobbler repo add --name stretch-updates --mirror http://ftp.jp.debian.org/debian --breed apt --apt-dists stretch-updates --apt-components main --arch x86_64 --mirror-locally 0 --keep-updated 0
# cobbler repo add --name stretch-security --mirror http://security.debian.org --breed apt --apt-dists stretch/updates --apt-components main --arch x86_64 --mirror-locally 0 --keep-updated 0

とりあえずsample.seedをコピーしてstretch用のpreseedファイルテンプレートを作り、プロファイルを作る。

# cp /var/lib/cobbler/kickstarts/sample.seed /var/lib/cobbler/kickstarts/d9.seed
# cobbler profile add --name d9-x86_64 --distro d9-x86_64 --repos "stretch stretch-updates stretch-security" --kickstart /var/lib/cobbler/kickstarts/d9.seed

stretch用のpreseedファイルテンプレートを編集する。
patchでの適用に使うために、編集後sample.seedからの変更部分をdiffしたものを次に示す。

10c10,11
< d-i keyboard-configuration/layoutcode string us
---
> d-i keyboard-configuration/layoutcode string jp
> d-i keyboard-configuration/xkb-keymap select jp
15d15
< #set $myhostname = $getVar('hostname',$getVar('name','cobbler')).replace("_","-")
17d16
< d-i netcfg/get_hostname string $myhostname
25c24
< d-i time/zone string US/Eastern
---
> d-i time/zone string Asia/Tokyo
28c27
< d-i clock-setup/ntp-server  string ntp.ubuntu.com
---
> d-i clock-setup/ntp-server  string ntp.nict.jp
32,40c31,33
< d-i mirror/http/hostname string $http_server
< d-i mirror/http/directory string $install_source_directory
< d-i mirror/http/proxy string
<
< #set $os_v = $getVar('os_version','')
< #if $os_v and $os_v.lower()[0] > 'p'
< # Required at least for 12.10+
< d-i live-installer/net-image string http://$http_server/cobbler/links/$distro_name/install/filesystem.squashfs
< #end if
---
> d-i mirror/http/hostname string ftp.jp.debian.org
> d-i mirror/http/directory string /debian
> d-i mirror/http/proxy string http://$http_server:8080/
72,73c65
< d-i passwd/root-login boolean true
< d-i passwd/root-password-crypted password $default_password_crypted
---
> d-i passwd/root-login boolean false
76c68,71
< d-i passwd/make-user boolean false
---
> d-i passwd/make-user boolean true
> d-i passwd/user-fullname string user
> d-i passwd/username string user
> d-i passwd/user-password-crypted password $default_password_crypted
111c106,109
< d-i pkgsel/include string ntp ssh wget
---
> tasksel tasksel/first multiselect standard, ssh-server
> d-i pkgsel/include string network-manager ntpdate parted
>
> grub-installer grub-installer/bootdev string /dev/sda

要はDebian 8のものとの違いはこれだけである。
NTPクライアントはsystemd-timesyncdが起動してるのでntpdateだけ。
ネットワークに繋がらないのでnetwork-managerでも入れておく。systemd-networkd使えって話なのかもしれないがもう少しだけ手間掛かるし。

107c107
< d-i pkgsel/include string ntp parted
---
> d-i pkgsel/include string network-manager ntpdate parted

Ubuntu 14.04を追加する

Ubuntuはserver.isoを取り込むことができる。desktop.isoは取り込もうとするとエラーになる。

# curl http://ftp.jaist.ac.jp/pub/Linux/ubuntu-releases/trusty/ubuntu-14.04.2-server-amd64.iso -o ubuntu-14.04.2-server-amd64.iso
# mount ubuntu-14.04.2-server-amd64.iso /mnt
# cobbler import --name u1404 --path /mnt
# umount /mnt

パッケージリポジトリの設定。

# cobbler repo add --name trusty --mirror http://jp.archive.ubuntu.com/ubuntu --breed apt --apt-dists trusty --apt-components "main restricted universe multiverse" --arch x86_64 --mirror-locally 0 --keep-updated 0
# cobbler repo add --name trusty-updates --mirror http://jp.archive.ubuntu.com/ubuntu --breed apt --apt-dists trusty-updates --apt-components "main restricted universe multiverse" --arch x86_64 --mirror-locally 0 --keep-updated 0
# cobbler repo add --name trusty-backports --mirror http://jp.archive.ubuntu.com/ubuntu --breed apt --apt-dists trusty-backports --apt-components "main restricted universe multiverse" --arch x86_64 --mirror-locally 0 --keep-updated 0
# cobbler repo add --name trusty-security --mirror http://security.ubuntu.com/ubuntu --breed apt --apt-dists trusty-security --apt-components "main restricted universe multiverse" --arch x86_64 --mirror-locally 0 --keep-updated 0

cobbler import時に自動追加されたリポジトリをcobbler reposyncの対象にしないようにする。

# cobbler repo edit --name u1404-x86_64 --keep-updated 0

とりあえずsample.seedをコピーしてUbuntu 14.04用のpreseedファイルテンプレートを作り、先程cobbler repo addしたリポジトリとともにプロファイルに紐づける。

# cp /var/lib/cobbler/kickstarts/sample.seed /var/lib/cobbler/kickstarts/u1404.seed
# cobbler profile edit --name u1404-x86_64 --repos "trusty trusty-updates trusty-backports trusty-security" --kickstart /var/lib/cobbler/kickstarts/u1404.seed

Ubuntu 14.04用のpreseedファイルテンプレートを編集する。
patchでの適用に使うために、編集後sample.seedからの変更部分をdiffしたものを次に示す。

10c10,11
< d-i keyboard-configuration/layoutcode string us
---
> d-i keyboard-configuration/layoutcode string jp
> d-i keyboard-configuration/xkb-keymap select jp
15d15
< #set $myhostname = $getVar('hostname',$getVar('name','cobbler')).replace("_","-")
17d16
< d-i netcfg/get_hostname string $myhostname
25c24
< d-i time/zone string US/Eastern
---
> d-i time/zone string Asia/Tokyo
28c27
< d-i clock-setup/ntp-server  string ntp.ubuntu.com
---
> d-i clock-setup/ntp-server  string ntp.nict.jp
32,34c31,33
< d-i mirror/http/hostname string $http_server
< d-i mirror/http/directory string $install_source_directory
< d-i mirror/http/proxy string
---
> d-i mirror/http/hostname string jp.archive.ubuntu.com
> d-i mirror/http/directory string /ubuntu
> d-i mirror/http/proxy string http://$http_server:8080/
72,73c71
< d-i passwd/root-login boolean true
< d-i passwd/root-password-crypted password $default_password_crypted
---
> d-i passwd/root-login boolean false
76c74,77
< d-i passwd/make-user boolean false
---
> d-i passwd/make-user boolean true
> d-i passwd/user-fullname string user
> d-i passwd/username string user
> d-i passwd/user-password-crypted password $default_password_crypted
111c112,113
< d-i pkgsel/include string ntp ssh wget
---
> tasksel tasksel/first multiselect server, openssh-server
> d-i pkgsel/include string ntp

Debian 8のものとの違いは以下となる。

31,32c31,32
< d-i mirror/http/hostname string ftp.jp.debian.org
< d-i mirror/http/directory string /debian
---
> d-i mirror/http/hostname string jp.archive.ubuntu.com
> d-i mirror/http/directory string /ubuntu
34a35,40
> #set $os_v = $getVar('os_version','')
> #if $os_v and $os_v.lower()[0] > 'p'
> # Required at least for 12.10+
> d-i live-installer/net-image string http://$http_server/cobbler/links/$distro_name/install/filesystem.squashfs
> #end if
>
106,109c112,113
< tasksel tasksel/first multiselect standard, ssh-server
< d-i pkgsel/include string ntp parted
<
< grub-installer grub-installer/bootdev string /dev/sda
---
> tasksel tasksel/first multiselect server, openssh-server
> d-i pkgsel/include string ntp

Debian 8との差分を説明する。

当然リポジトリの参照先がDebianとUbuntuで違う。

31,32c31,32
< d-i mirror/http/hostname string ftp.jp.debian.org
< d-i mirror/http/directory string /debian
---
> d-i mirror/http/hostname string jp.archive.ubuntu.com
> d-i mirror/http/directory string /ubuntu

この部分はubuntuだけで必要。

34a35,40
> #set $os_v = $getVar('os_version','')
> #if $os_v and $os_v.lower()[0] > 'p'
> # Required at least for 12.10+
> d-i live-installer/net-image string http://$http_server/cobbler/links/$distro_name/install/filesystem.squashfs
> #end if
>

インストールするパッケージの内容だがDebianとUbuntuではtaskselで指定できる名前や内容が違う。Ubuntuでもtasksel tasksel/firstに指定できる値はOSインストール後ならtasksel –list-tasksで取得できる。
やりたいことはほぼ一緒で、partedはUbuntuでは特に指定しなくてもインストールされていたので記述していない。

106,109c112,113
< tasksel tasksel/first multiselect standard, ssh-server
< d-i pkgsel/include string ntp parted
---
> tasksel tasksel/first multiselect server, openssh-server
> d-i pkgsel/include string ntp

この部分はDebian 8(とそれを流用して作ったstretch)でだけ必要。

< grub-installer grub-installer/bootdev string /dev/sda

Ubuntu 15.04を追加する

やり方はUbuntu 14.04と変わらないので説明は大体省く。

# curl http://ftp.jaist.ac.jp/pub/Linux/ubuntu-releases/vivid/ubuntu-15.04-server-amd64.iso -o ubuntu-15.04-server-amd64.iso
# mount ubuntu-15.04-server-amd64.iso /mnt
# cobbler import --name u1504 --path /mnt
# umount /mnt
# cobbler repo add --name vivid --mirror http://jp.archive.ubuntu.com/ubuntu --breed apt --apt-dists vivid --apt-components "main restricted universe multiverse" --arch x86_64 --mirror-locally 0 --keep-updated 0
# cobbler repo add --name vivid-updates --mirror http://jp.archive.ubuntu.com/ubuntu --breed apt --apt-dists vivid-updates --apt-components "main restricted universe multiverse" --arch x86_64 --mirror-locally 0 --keep-updated 0
# cobbler repo add --name vivid-backports --mirror http://jp.archive.ubuntu.com/ubuntu --breed apt --apt-dists vivid-backports --apt-components "main restricted universe multiverse" --arch x86_64 --mirror-locally 0 --keep-updated 0
# cobbler repo add --name vivid-security --mirror http://security.ubuntu.com/ubuntu --breed apt --apt-dists vivid-security --apt-components "main restricted universe multiverse" --arch x86_64 --mirror-locally 0 --keep-updated 0
# cobbler repo edit --name u1504-x86_64 --keep-updated 0
# cp /var/lib/cobbler/kickstarts/sample.seed /var/lib/cobbler/kickstarts/u1504.seed
# cobbler profile edit --name u1504-x86_64 --repos "vivid vivid-updates vivid-backports vivid-security" --kickstart /var/lib/cobbler/kickstarts/u1504.seed

patchでの適用に使うためにsample.seedとu1504.seedのdiff。

10c10,11
< d-i keyboard-configuration/layoutcode string us
---
> d-i keyboard-configuration/layoutcode string jp
> d-i keyboard-configuration/xkb-keymap select jp
15d15
< #set $myhostname = $getVar('hostname',$getVar('name','cobbler')).replace("_","-")
17d16
< d-i netcfg/get_hostname string $myhostname
25c24
< d-i time/zone string US/Eastern
---
> d-i time/zone string Asia/Tokyo
28c27
< d-i clock-setup/ntp-server  string ntp.ubuntu.com
---
> d-i clock-setup/ntp-server  string ntp.nict.jp
32,34c31,33
< d-i mirror/http/hostname string $http_server
< d-i mirror/http/directory string $install_source_directory
< d-i mirror/http/proxy string
---
> d-i mirror/http/hostname string jp.archive.ubuntu.com
> d-i mirror/http/directory string /ubuntu
> d-i mirror/http/proxy string http://$http_server:8080/
72,73c71
< d-i passwd/root-login boolean true
< d-i passwd/root-password-crypted password $default_password_crypted
---
> d-i passwd/root-login boolean false
76c74,77
< d-i passwd/make-user boolean false
---
> d-i passwd/make-user boolean true
> d-i passwd/user-fullname string user
> d-i passwd/username string user
> d-i passwd/user-password-crypted password $default_password_crypted
111c112,113
< d-i pkgsel/include string ntp ssh wget
---
> tasksel tasksel/first multiselect server, openssh-server
> d-i pkgsel/include string

要はUbuntu 14.04のものとの違いはこれだけである。
systemd-timesyncdが起動するしntpdateもインストールされているし、ということで追加パッケージはなしにしている。

113c113
< d-i pkgsel/include string ntp
---
> d-i pkgsel/include string

Ubuntu 15.10を追加する

2015-07-06現在、Alpha 1が出たばかりのUbuntu 15.10だがserver.isoが見つけられないのでDebian stretchと同じようにUbuntu 15.04からコピーして作る。

Ubuntu 15.04のdistroをコピーする。

# cobbler distro copy --name u1504-x86_64 --newname u1510-x86_64

/var/lib/cobbler/distro_signatures.json のvividのすぐ下に次を追加する。
(vividのものをコピーしてvividをwilyに、15.04を15.10に修正しただけである)

/var/lib/cobbler/distro_signatures.jsonの一部
   },
   "wily": {
    "signatures":["dists", ".disk"],
    "version_file":"Release|mini-info",
    "version_file_regex":"Codename: wily|Ubuntu 15.10",
    "kernel_arch":"linux-headers-(.*)\.deb",
    "kernel_arch_regex":null,
    "supported_arches":["i386","amd64"],
    "supported_repo_breeds":["apt"],
    "kernel_file":"linux(.*)",
    "initrd_file":"initrd(.*)\.gz",
    "isolinux_ok":false,
    "default_kickstart":"/var/lib/cobbler/kickstarts/sample.seed",
    "kernel_options":"",
    "kernel_options_post":"",
    "boot_files":[]

distro_signatures.jsonの変更を反映するためにcobblerdを再起動してから15.10用のdistroの–os-versionオプションをwilyにする。

# systemctl restart cobblerd.service
# cobbler distro edit --name u1510-x86_64 --os-version wily

パッケージリポジトリの設定。

# cobbler repo add --name wily --mirror http://jp.archive.ubuntu.com/ubuntu --breed apt --apt-dists wily --apt-components "main restricted universe multiverse" --arch x86_64 --mirror-locally 0 --keep-updated 0
# cobbler repo add --name wily-updates --mirror http://jp.archive.ubuntu.com/ubuntu --breed apt --apt-dists wily-updates --apt-components "main restricted universe multiverse" --arch x86_64 --mirror-locally 0 --keep-updated 0
# cobbler repo add --name wily-backports --mirror http://jp.archive.ubuntu.com/ubuntu --breed apt --apt-dists wily-backports --apt-components "main restricted universe multiverse" --arch x86_64 --mirror-locally 0 --keep-updated 0
# cobbler repo add --name wily-security --mirror http://security.ubuntu.com/ubuntu --breed apt --apt-dists wily-security --apt-components "main restricted universe multiverse" --arch x86_64 --mirror-locally 0 --keep-updated 0

とりあえずsample.seedをコピーして15.10用のpreseedファイルテンプレートを作り、プロファイルを作る。

# cp /var/lib/cobbler/kickstarts/sample.seed /var/lib/cobbler/kickstarts/u1504.seed
# cobbler profile add --name u1510-x86_64 --distro u1510-x86_64 --repos "wily wily-updates wily-backports wily-security" --kickstart /var/lib/cobbler/kickstarts/u1504.seed

15.10用のpreseedファイルテンプレートを編集する。
patchでの適用に使うために、編集後sample.seedからの変更部分をdiffしたものを次に示す。

10c10,11
< d-i keyboard-configuration/layoutcode string us
---
> d-i keyboard-configuration/layoutcode string jp
> d-i keyboard-configuration/xkb-keymap select jp
15d15
< #set $myhostname = $getVar('hostname',$getVar('name','cobbler')).replace("_","-")
17d16
< d-i netcfg/get_hostname string $myhostname
25c24
< d-i time/zone string US/Eastern
---
> d-i time/zone string Asia/Tokyo
28c27
< d-i clock-setup/ntp-server  string ntp.ubuntu.com
---
> d-i clock-setup/ntp-server  string ntp.nict.jp
32,34c31,33
< d-i mirror/http/hostname string $http_server
< d-i mirror/http/directory string $install_source_directory
< d-i mirror/http/proxy string
---
> d-i mirror/http/hostname string jp.archive.ubuntu.com
> d-i mirror/http/directory string /ubuntu
> d-i mirror/http/proxy string http://$http_server:8080/
72,73c71
< d-i passwd/root-login boolean true
< d-i passwd/root-password-crypted password $default_password_crypted
---
> d-i passwd/root-login boolean false
76c74,77
< d-i passwd/make-user boolean false
---
> d-i passwd/make-user boolean true
> d-i passwd/user-fullname string user
> d-i passwd/username string user
> d-i passwd/user-password-crypted password $default_password_crypted
111c112,113
< d-i pkgsel/include string ntp ssh wget
---
> tasksel tasksel/first multiselect server, openssh-server
> d-i pkgsel/include string network-manager

要はUbuntu 14.04のものとの違いはこれだけである。
systemd-timesyncdが起動するしntpdateもインストールされている、そしてネットワークは繋がっていないのでnetwork-managerを追加。

113c113
< d-i pkgsel/include string ntp
---
> d-i pkgsel/include string network-manager

外部リポジトリを追加する

preseed_apt_repo_configスニペットを修正したことにより、cobbler repo addの–environmentオプションにgpg_keyで始まるキーの値としてGPGキーのURLを指定してやると、そのGPGキーを取り込むようになる。
ここで取り込んだGPGキーはOSインストール後も有効である。

なお、私の現在のCobblerの立て方ではHTTPしか通らないプロキシを通すので、mirrorやGPGキーのURLのプロトコルはhttpsではなくhttpにする必要がある。

以下はDebian 8にGlusterFSのリポジトリ(注:このリンク先のGPGキーのURLには誤りがある)を追加する例である。

# cobbler repo add --name jessie-glusterfs --mirror http://download.gluster.org/pub/gluster/glusterfs/LATEST/Debian/jessie/apt --breed apt --apt-dists jessie --apt-components main --arch x86_64 --environment 'gpg_key=http://download.gluster.org/pub/gluster/glusterfs/LATEST/Debian/jessie/apt/pub.key' --mirror-locally 0 --keep-updated 0
# cobbler profile edit --name d8-debianer-x86_64 --repos "jessie jessie-updates jessie-security jessie-glusterfs"

これだけだとリポジトリを追加するだけなので、OSインストール時にインストールされるようにするためにはpreseedファイルのd-i pkgsel/includeにglusterfs-serverなどを追加する。

以下はUbuntu 15.04に日本語RemixGlusterFS 3.7のリポジトリを追加する例である。
vivid-jaでは–environmentオプションにgpg_key1とgpg_key2のGPGキーを2つ追加し、vivid-glusterfs-3.7ではPPAであるGlusterFS 3.7のリポジトリを追加している。

# cobbler repo add --name vivid-ja --mirror http://archive.ubuntulinux.jp/ubuntu --breed apt --apt-dists vivid --apt-components main --arch x86_64 --environment 'gpg_key1=http://www.ubuntulinux.jp/ubuntu-ja-archive-keyring.gpg gpg_key2=http://www.ubuntulinux.jp/ubuntu-jp-ppa-keyring.gpg' --mirror-locally 0 --keep-updated 0
# cobbler repo add --name vivid-ja-non-free --mirror http://archive.ubuntulinux.jp/ubuntu-ja-non-free --breed apt --apt-dists vivid --apt-components multiverse --arch x86_64 --mirror-locally 0 --keep-updated 0
# cobbler repo add --name vivid-glusterfs-3.7 --mirror http://ppa.launchpad.net/gluster/glusterfs-3.7/ubuntu --breed apt --apt-dists vivid --apt-components main --arch x86_64 --environment 'gpg_key=http://keyserver.ubuntu.com/pks/lookup?op=get&search=0x13E01B7B3FE869A9' --mirror-locally 0 --keep-updated 0
# cobbler profile edit --name u1504-x86_64 --repos "vivid vivid-updates vivid-backports vivid-security vivid-ja vivid-ja-non-free vivid-glusterfs-3.7"

PPAのmirrorのURLやGPGキーのURLのsearch=0xの後の値を取得するには、今のところどこかの環境にapt-add-repositoryして調べる方法しか知らない。
GlusterFS 3.7ならapt-add-repository ppa:gluster/glusterfs-3.7して /etc/apt/sources.list.d/gluster-ubuntu-glusterfs-3_7-vivid.list を見ればmirrorのURLが得られ、apt-key fingerで得られるフィンガープリントの最後の8オクテットをsearch=0xの後の値にすれば良い。
PPAのGPGキーのURLはhttp://keyserver.ubuntu.com/pks/lookup?op=get&search=0xまでは固定である。

TOP