1. はじめに
IBM Cloudでは、事前に用意されているOSイメージを利用するだけでなく、iPXEによるNetwork Bootを利用して任意のOSをインストールすることも可能である。
https://cloud.ibm.com/docs/vpc?topic=vpc-network-boot-bare-metal-servers&interface=ui&locale=en
特に、IBM CloudのBare Metal Server for VPC(BM for VPC)においては、iPXEをロードするためにDHCPサーバーを構成したりTFTPサーバーを構成する必要はないことは非常に利用の敷居を下げてくれている。OS注文画面やOS再構成画面でNetwork Boot
を選択するだけで、IBM Cloudが提供するiPXEを起動可能なイメージが展開され、そこで指定したiPXEスクリプトを実行することが可能である。つまり、利用者はiPXEスクリプトとダウンロード可能なイメージを用意するだけで容易にNetwork Bootを利用することができる。本稿では、BM for VPCでNetwork Bootを試してみる。
なお、事前にpublic gateway経由でインターネットアクセス可能なようにVPCを構成しているものとする。
2. ipxeスクリプトの例
iPXEのコマンドについては、以下に解説がある。
以下では、シンプルなiPXEスクリプトと、メニュー表示可能なiPXEスクリプトを用意した。
#!ipxe
:retry_dhcp
dhcp || goto retry_dhcp
sleep 2
ntp mirrors.adn.networklayer.com
set repo http://mirror.stream.centos.org/9-stream/BaseOS/x86_64/os
kernel ${repo}/images/pxeboot/vmlinuz initrd=initrd.img inst.repo=${repo}
initrd ${repo}/images/pxeboot/initrd.img
boot
#!ipxe
:retry_dhcp
dhcp || goto retry_dhcp
sleep 2
ntp mirrors.adn.networklayer.com
# menu
:menu
set menu-timeout 300000
menu Please choose OS you want to install
item --gap -- -------------------------- OS menu -------------------------
item centos9 Install CentOS 9
item fedora40 Install Fedora 40
item fedora39 Install Fedora 39
item --gap -- -------------------------- Advanced Option ------------------
item shell Go to iPXE shell
item reboot Reboot Computer
choose --timeout ${menu-timeout} selected || goto exit
goto ${selected}
:centos9
set repo http://mirror.stream.centos.org/9-stream/BaseOS/x86_64/os
kernel ${repo}/images/pxeboot/vmlinuz initrd=initrd.img inst.repo=${repo}
initrd ${repo}/images/pxeboot/initrd.img
boot
:fedora40
set mirror http://download.fedoraproject.org/pub/fedora/linux/releases/40
set repo ${mirror}/Everything/x86_64/os
kernel ${repo}/images/pxeboot/vmlinuz initrd=initrd.img inst.repo=${repo}
initrd ${repo}/images/pxeboot/initrd.img
boot
:fedora39
set mirror http://download.fedoraproject.org/pub/fedora/linux/releases/39
set repo ${mirror}/Everything/x86_64/os
kernel ${repo}/images/pxeboot/vmlinuz initrd=initrd.img inst.repo=${repo}
initrd ${repo}/images/pxeboot/initrd.img
boot
:shell
echo Type 'exit' to get the back to the menu
shell
goto menu
:reboot
reboot
:exit
exit
IBM Cloud docsに既知の情報として、NWアダプターが構成中のタイミングでDHCP取得にエラーになる可能性があるため、retryをすることを推奨している。今回はその指示に従ってDHCP取得時には以下のコードに変更している。
https://cloud.ibm.com/docs/vpc?topic=vpc-known-issues#ipxe-network-boot-known-issue
:retry_dhcp
dhcp || goto retry_dhcp
sleep 2
iPXEでitem
文を使ってメニューを作成する際に、 "----"を付け加える際には、それがオプション引数であると見なされないように、注意する必要がある。https://ipxe.org/cmd/item
If you want your separator text to start with dashes, then you must use -- to prevent iPXE from attempting to interpret your separator text as an option. For example:
item --gap -- ---------------- Advanced configuration ----------------
3. 注文画面
以下は、Bare Metal Server for VPCの注文画面。
- ロケーションやサーバー名やリソースグループを選択することは通常の注文と同じである。
- Image and profileの箇所で、
Network boot
を選択し、そこにiPXEスクリプトを記述する。ここでは、メニュー選択が可能なipxeスクリプト例2
を入力する。 - あとは通常時の注文と同じであり、適切なプロファイルやNW設定を行う。(なお、東京DCには本稿執筆時点で
bx2-metal-96x384
プロファイルのサーバーは存在しなかったため、bx2d-metal-96x384
を利用している)
4. 注文後のiPXEブートを眺めてみる
- サーバーの状態が、
Pending
の時はVNC Consoleアクセスは利用できないが、Starting
/Running
状態になるとVNC Consoleアクセスが可能になる。
- サーバー起動からiPXEスクリプトが呼び出されるまで
- iPXEスクリプトで作成したメニューが表示されるようになった。
Install CentOS 9
を選択。
- CentOS9のインストーラーが起動
- インストールウィザードが表示された
以下では、ほとんどデフォルトのまま作業を実施するが、特に注視しておくべき箇所について取り上げる。
-
Time & Date
におけるNTPは、ipxeスクリプトで指定したURIが構成されている。
-
Installation Destination
では、Local disk(1 x 960GB)
をインストール先として選択する。
-
Root Password
ではNetworkアクセスできるように初期パスワードを入力する。また、SSHアクセス可能にする(この辺りはインストール後に細かく設定すれば良いと思う)
-
Network & Host Name
では、DHCPでIPアドレスが取得できていることを確認する。
以下、インストールを実施
5. SSHでアクセスしてみる
syasuda@MacBook-Pro ~ % ssh root@10.50.4.28
The authenticity of host '10.50.4.28 (10.50.4.28)' can't be established.
ED25519 key fingerprint is SHA256:A19VEgeKZI8d0OEuzWllgHktPHV1ipnOjGjHgvuB1Og.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.50.4.28' (ED25519) to the list of known hosts.
root@10.50.4.28's password:
Permission denied, please try again.
root@10.50.4.28's password:
Activate the web console with: systemctl enable --now cockpit.socket
Last failed login: Tue Oct 15 03:09:15 CDT 2024 from 192.168.100.5 on ssh:notty
There was 1 failed login attempt since the last successful login.
[root@localhost ~]# cat /etc/redhat-release
CentOS Stream release 9
[root@localhost ~]# date
Tue Oct 15 03:11:08 AM CDT 2024
6. OS再構成(Reinitialize)でもNetwork Bootが選択できることの確認
サーバーを停止させた後、ReinitializeでNetwork Bootを選択することも可能。よって、何度でもOSを再導入することが可能である。また、もしプロビジョニング済みのipxeスクリプトを再修正したい場合は、Reinitializeで再度新しいipxeスクリプトを指定することができる。