Relearning cobbler 2025
はじめに
まだ OS のインストールされていないマシンで、電源を入れただけでネットワーク越しに OS のインストールまで完了させる環境を作るのが cobbler です。
これも 2017 年当時に使ってみたものをあらためて学びなおしてみます。
cobbler についてうかつに検索すると自動生成されたような不思議なサイトにあたってしまうので、Github のリポジトリを参照してドキュメントに飛ぶのが安全だと思います。
Github
プロジェクトサイト
プロジェクト内のblog
ドキュメント
環境
Cobbler が稼働するマシンには Fedroa Server を使用します。Cobbler の最新リリースが rpm で用意されています。他のディストリビューションでも動作するようですが、systemd で各種サーバプロセスをコントロールしたり比較的大容量の ISO イメージを内包させる必要があるはずなので、WSL は使いません。
cobbler を起動する仮想マシンは二つのインターフェースに接続します。
- NAT
- ホストオンリー
テスト対象の仮想マシンのインターフェースは1つにします。
- ホストオンリー
ネットワークブートしたい仮想マシンのメモリサイズを 4GB 以上にします。VMware Workstation で仮想マシンを作成するときのデフォルト 2GB では足りません。
VMware Workstation の設定で、ホストオンリーネットワークの DHCP を停止しておきます。
ネットワークインストールを可能にする環境には以下のサーバが必要です。
- DHCP サーバ
- tftp サーバ
- http サーバ
これら流れを記載した良い記事がありましたので大いに参考にします。
また、記事中の
ではこれらサービスをまとめて go 言語で実装しているようで興味深いです。Linux環境での実行を想定しているようです。
WindowsでPXEブート環境を構築するプロジェクトもほかにあるようなので、 用途の範囲によっては cobbler にこだわる必要はないかもしれません。
cobbler のインストール
ともかく、今回は cobbler の確認を進めます。以降、すべて root ユーザで作業します。
dnf install cobbler
依存関係を確認すると、 httpd
tftp-server
が含まれていることがわかります。
dnf repoquery --depends cobbler
逆に、DHCPサーバは含まれていません。今回は cobbler に任せたいのでインストールします。既設の DHCPサービスに必要な設定を行えるのであれば不要です。
tftp サーバも有効にします。
dnf install dhcp-server
systemctl enable --now dhcpd
systemctl enable --now tftp
ブートローダ作成のために必要なモジュールを追加します。
dnf install grub2-efi-x64-modules
Cobbler 本体のサービスを起動します。
systemctl enable --now cobblerd.service
Created symlink '/etc/systemd/system/multi-user.target.wants/cobblerd.service' → '/usr/lib/systemd/system/cobblerd.service'.
起動結果を確認してください。
systemctl status cobblerd.service
● cobblerd.service - Cobbler Helper Daemon
Loaded: loaded (/usr/lib/systemd/system/cobblerd.service; enabled; preset: disabled)
SELinux を監査モードにし、 firewall を無効にします。SELinux を有効にしたまま cobbler を動作させる例を参考文献に挙げておきます。
sed -i -E "s/SELINUX=(disabled|enforcing)/SELINUX=permissive/" /etc/selinux/config
setenforce permissive
systemctl disable --now firewalld
ここまでで cobbler コマンドがエラーを返さなくなります。
cobbler
usage
=====
cobbler <distro|profile|system|repo|image|mgmtclass|package|file|menu> ...
[add|edit|copy|get-autoinstall*|list|remove|rename|report] [options|--help]
cobbler setting [edit|report]
cobbler <aclsetup|buildiso|import|list|replicate|report|reposync|sync|validate-autoinstalls|version|signature|hardlink|mkloaders> [options|--help]
設定
デフォルト root パスワードの指定
/etc/cobbler/settings.yaml
を編集します。
# Cobbler has various sample automatic installation templates stored
# in /var/lib/cobbler/templates/. This controls
# what install (root) password is set up for those
# systems that reference this variable. The factory
# default is "cobbler" and Cobbler check will warn if
# this is not changed.
# The simplest way to change the password is to run
# openssl passwd -1
# and put the output between the "" below.
default_password_crypted: "$1$mF86/UHC$WvcIcX2t6crBz2onWxyac."
指示のとおり、デフォルトのパスワードは cobbler
になっています。変更しましょう。
DHCP
cobbler を起動する仮想マシンのホストオンリーアダプタ側のIPアドレスを設定します。
nmcli connection modify ens192 ipv4.method manual ipv4.addresses 192.168.193.254/24
設定したIPアドレスに合わせて dhcpd の設定ファイルを生成するよう /etc/cobbler/settings.yaml
を設定します。
diff -u /etc/cobbler/settings.yaml.org /etc/cobbler/settings.yaml
--- /etc/cobbler/settings.yaml.org 2025-01-16 09:00:00.000000000 +0900
+++ /etc/cobbler/settings.yaml 2025-05-06 09:41:56.953152958 +0900
@@ -310,7 +310,7 @@
# set to true to enable Cobbler's DHCP management features.
# Use the "module" key in "/etc/cobbler/modules.conf" in the "dhcp" section to configure DHCP management engine
# See the docs (https://cobbler.readthedocs.io/en/latest/user-guide.html#dhcp-management) for more info
-manage_dhcp: false
+manage_dhcp: true
# set to true to enable DHCP IPv6 address configuration generation.
# This currently only works with manager.isc DHCP module (isc dhcpd6 daemon)
@@ -321,12 +321,12 @@
# set to true to enable DHCP IPv4 address configuration generation.
# This currently only works with manager.isc DHCP module
# Other dhcp modules ignore this and above settings
-manage_dhcp_v4: false
+manage_dhcp_v4: true
# if using Cobbler with manage_dhcp, put the IP address
# of the Cobbler server here so that PXE booting guests can find it
# if you do not set this correctly, this will be manifested in TFTP open timeouts.
-next_server_v4: 127.0.0.1
+next_server_v4: 192.168.193.254
# And the same if you set manage_dhcp_v6 to true.
# Set the cobbler IPv6 address here so that PXE booting guests can find it
@@ -462,7 +462,7 @@
# if you have a server that appears differently to different subnets
# (dual homed, etc), you need to read the --server-override section
# of the manpage for how that works.
-server: 127.0.0.1
+server: 192.168.193.254
# If set to true, all commands will be forced to use the localhost address
# instead of using the above value which can force commands like
/etc/cobbler/dhcp.template を編集します。DHCPサーバ用の設定ファイル、 /etc/dhcp/dhcpd.conf を生成するためのテンプレートです。テンプレートエンジンは cheetah です。 #
が単なるコメントの開始ではない場合があることを念頭においてください。
--- /etc/cobbler/dhcp.template.org 2024-11-18 06:02:02.000000000 +0900
+++ /etc/cobbler/dhcp.template 2025-05-06 09:54:16.573872292 +0900
@@ -18,11 +18,11 @@
option system-arch code 93 = unsigned integer 16;
-subnet 192.168.1.0 netmask 255.255.255.0 {
- option routers 192.168.1.5;
+subnet 192.168.193.0 netmask 255.255.255.0 {
+ option routers 192.168.193.254;
option domain-name-servers 192.168.1.1;
option subnet-mask 255.255.255.0;
- range dynamic-bootp 192.168.1.100 192.168.1.254;
+ range dynamic-bootp 192.168.193.100 192.168.193.250;
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server_v4;
ここまでの設定を反映させます。
systemctl restart cobblerd
cobbler sync
cobbler check
check の結果をみて、今後必要だと思える指摘は対応してください。初回インストールだけならここまででよいはずです。
他の仮想マシンを作成し、ネットワークインターフェースをホストオンリーにして起動します。起動中、cobbler マシンでネットワークを監視します。
ファームウェアを UEFI にした場合(セキュアブートOFF)
# tcpdump -i any -nn udp port 67 or port 68 or port 69
tcpdump: WARNING: any: That device doesn't support promiscuous mode
(Promiscuous mode not supported on the "any" device)
dropped privs to tcpdump
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on any, link-type LINUX_SLL2 (Linux cooked v2), snapshot length 262144 bytes
11:18:33.963514 ens192 B IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 00:0c:29:ee:3f:e4, length 347
11:18:33.963678 ens192 Out IP 192.168.193.254.67 > 255.255.255.255.68: BOOTP/DHCP, Reply, length 300
11:18:35.268311 ens192 B IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 00:0c:29:ee:3f:e4, length 359
11:18:35.268456 ens192 Out IP 192.168.193.254.67 > 255.255.255.255.68: BOOTP/DHCP, Reply, length 300
11:18:35.269101 ens192 In IP 192.168.193.100.1696 > 192.168.193.254.69: TFTP, length 46, RRQ "grub/grubx64.efi" octet tsize 0 blksize 1468
grub
Fedora Server の ISO イメージを仮想マシンに接続し、マウントします。
mount -o ro /dev/cdrom /mnt
イメージをインポートします。 /var/www/cobbler/distro_mirror/ にファイルがコピーされます。
cobbler import --name=fedora42 --arch=x86_64 --path=/mnt
task started: 2025-05-06_121413_Media import_92ae620965d74d84abed9fe84bea7d85
task started (id=Media import, time=Tue May 6 12:14:13 2025)
start_task(import); event_id(2025-05-06_121413_Media import_92ae620965d74d84abed9fe84bea7d85)
import_tree; ['/mnt', 'fedora42', None, None, None]
importing from a network location, running rsync to fetch the files first
running: rsync -a '/mnt/' /var/www/cobbler/distro_mirror/fedora42-x86_64 --progress
received on stdout: sending incremental file list
running: /usr/bin/file -v
received on stdout: file-5.46
No signature matched in /var/www/cobbler/distro_mirror/fedora42-x86_64
Exception occurred: <class 'cobbler.cexceptions.CX'>
Exception value: 'No signature matched in /var/www/cobbler/distro_mirror/fedora42-x86_64'
Exception Info:
!!! TASK FAILED !!!
タスクが失敗しました。ブート用ファイルの場所など、ISOイメージの構造があらかじめ設定ファイルに書いてあるものに一致しないと恩恵が受けられないようです。
似ているディストリビューションのエントリで使用しないものを上書きしてしまうことにします。
diff -u /var/lib/cobbler/distro_signatures.json.org /var/lib/cobbler/distro_signatures.json
--- /var/lib/cobbler/distro_signatures.json.org 2025-05-06 11:31:28.427731075 +0900
+++ /var/lib/cobbler/distro_signatures.json 2025-05-06 12:13:55.028281205 +0900
@@ -926,11 +926,11 @@
"boot_files": [],
"boot_loaders": {}
},
- "fedora38": {
+ "fedora42": {
"signatures": [
"Packages"
],
- "version_file": "(fedora)-release-38-(.*)\\.noarch\\.rpm",
+ "version_file": "(fedora)-release-42-(.*)\\.noarch\\.rpm",
"version_file_regex": null,
"kernel_arch": "kernel-(.*)\\.rpm",
"kernel_arch_regex": null,
cobblerd を再起動して再実行。
systemctl restart cobblerd.service
cobbler sync
cobbler import --name=fedora42 --arch=x86_64 --path=/mnt
最後に *** TASK COMPLETE ***
と出ていれば大丈夫でしょう。
ブートローダを作成します。旧来ブートローダを取得していた cobbler get-loaders
はもう存在しません。
cobbler mkloaders
task started: 2025-05-06_191517_Create bootable bootloader images_9d57a42b057e46b6817d2131235b13b1
task started (id=Create bootable bootloader images, time=Tue May 6 19:15:17 2025)
start_task(mkloaders); event_id(2025-05-06_191517_Create bootable bootloader images_9d57a42b057e46b6817d2131235b13b1)
Unable to find "shim.efi" file. Please adjust "bootloaders_shim_file" regex. Bailing out of linking the shim!
ipxe directory did not exist. Please adjust the "bootloaders_ipxe_folder". Bailing out of iPXE setup!
GRUB2 modules directory for arch "aarch64" did no exist. Skipping GRUB2 creation
GRUB2 modules directory for arch "arm" did no exist. Skipping GRUB2 creation
GRUB2 modules directory for arch "arm64-efi" did no exist. Skipping GRUB2 creation
GRUB2 modules directory for arch "i386-efi" did no exist. Skipping GRUB2 creation
Successfully built bootloader for arch "i386-pc-pxe"!
GRUB2 modules directory for arch "i686" did no exist. Skipping GRUB2 creation
GRUB2 modules directory for arch "IA64" did no exist. Skipping GRUB2 creation
GRUB2 modules directory for arch "powerpc-ieee1275" did no exist. Skipping GRUB2 creation
Successfully built bootloader for arch "x86_64-efi"!
*** TASK COMPLETE ***
TFTP への要求の様子を tcpdump で確認したときに要求しているファイルが /var/lib/tftpboot/
にあるはずです。
無い場合、必要なモジュールを dnf コマンドで追加します。
settings.yaml の bootloaders_formats
を見るとブートローダー作成には追加のモジュールが必要そうなので、 dnf コマンドで追加します(今回は最初に grub2-efi-x64-modules を追加したので大丈夫だと思います)。
cobbler mkloaders
コマンドで実際に実行される処理は以下のファイルで確認できます。
/usr/lib/python3.13/site-packages/cobbler/actions/mkloaders.py
最後に cobbler mkloaders
cobbler sync
を実行してください。
仮想マシンを再起動するとブートローダーの読み込みに成功して、インストールする OS を選択する画面が出ると思います。
kickstart
ブートローダーの処理が終わるとインストール用イメージを http で取得しに行きます。この様子は cobbler 側の /var/log/httpd/access_log で確認できます。
同時に、grub の設定ファイルに inst.ks=http://192.168.193.254/cblr/svc/...
オプションが追加され、キックスタートファイルを http で取得するようになっています。
URL /cblr/svc/...
へのリクエストは python のモジュールを呼び出します。 /etc/httpd/conf.d/cobbler.conf
で設定されています。
ここまでの設定では プロファイル fedora42-x86_64
が読み込む kickstart ファイルは sample.ks になっています。
cobbler profile report --name fedora42-x86_64
Name : fedora42-x86_64
Automatic Installation Template : sample.ks
Automatic Installation Metadata : <<inherit>>
TFTP Boot Files : <<inherit>>
Boot loaders : <<inherit>>
実体である /var/lib/cobbler/templates/sample.ks
には、最近の redhat の kickstart では使用しない指示が入っていて処理が停止します。別名でファイル fedora42.ks
を作成し編集します。
--- sample.ks 2024-11-18 06:02:02.000000000 +0900
+++ fedora42.ks 2025-05-10 16:19:36.786025046 +0900
@@ -2,7 +2,7 @@
#platform=x86, AMD64, or Intel EM64T
# System authorization information
-auth --useshadow --enablemd5
+#auth --useshadow --enablemd5
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
@@ -35,7 +35,7 @@
# System timezone
timezone America/New_York
# Install OS instead of upgrade
-install
+#install
# Clear the Master Boot Record
zerombr
# Allow anaconda to partition the system as needed
kiskstart ファイルの指定も変更します。
cobbler profile edit --name fedora42-x86_64 --autoinstall fedora42.ks
cobbler sync
これでインストールまで完了するはずです。
この後
仕組みの確認はできましたが、実際に使用するにはまだまだ考慮しなければならないことがあります。
cobbler system の使用
-
cobbler distro
ディストリビューションの ISO イメージ
-
cobbler profile
ディストリビューションのインストール設定ひな形
-
cobbler system
profile に対するインストール設定カスタマイズ、または変更
という階層になっていて、system まで定義して運用すると MACアドレス から IPアドレスとホスト名まで設定済みの状態になる仕組みのはずですが、今回試していません。
Webインターフェースの使用
Anguler を使った新しい Webインターフェース、とのことですが、試せていません。
インストール後に次の設定に移れるか
- 初期インストール時点のパーティション構造、存在していてほしいパッケージ、存在してほしいユーザ、起動してほしいサービスは何か。
- 初期インストール後にパッケージを追加・アップデートする環境をどこに作るか
- どこまで cobbler で設定して、どこから Ansible 等で設定するか
- (対象が仮想マシンではないばあい)ファームウェアのアップデートが必要ではないか。
少なくとも一度手作業でインストールして出来上がった kiskstart ファイルを確認し、テンプレートを検証する作業は必要でしょう。
ただし、あまり時間をかけていると後続のミドルウェアのインストールやアプリケーションの配置のスケジュールに間にあいません。すべてを cobbler に任せる必要はなく、電源を上げて boot メニューが開いたら kickstart ファイルの指定をホスト名ごとに定義されたものに変更して起動させる、という作戦も考えられます。これなら cobbler や テンプレートの仕組みを知らなくても最終的に使う kickstart ファイルさえ作れれば自動化の恩恵を多少は受けられます。
公式ドキュメントも充実していて必要な個別の要件にはそれぞれ解決策がありそうなのですが、一般的にこうすると8割くらいのユースケースには対応できるので初心者はここから開始するとよい、といった汎用性の高い構成を作るにはもう少し運用経験が必要だと感じました。
また、最終的にはハードウェアメーカーが指示した通りのインストール方法以外でインストールするとサポートが受けられないことへのこだわりとか、仕組みを維持してくれる SE が見当たらないとか、試用する環境がないとか、cobbler を使用せず手作業でのインストールを選択する残念な場合もあるかもしれません。
Windows への対応を考慮するか
にドキュメントがあります。仕事で使うのであれば何らかのサポート契約があることと思うので、
Windows用にはWindowsの環境を使うという選択肢もあります(試したことはありません)。
そこまでサポート範囲に含めてくれる契約にどれほどの費用が必要なのかはは知りませんが…。
参考文献
Discussion