2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

IBM Cloud: Bare Metal Server for VPCでNetwork Boot(iPXEブート)を試してみた

Last updated at Posted at 2024-10-16

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スクリプト例1: CentOS9の導入
#!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スクリプト例2: メニュー選択が可能
#!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.png
  • Image and profileの箇所で、Network bootを選択し、そこにiPXEスクリプトを記述する。ここでは、メニュー選択が可能なipxeスクリプト例2を入力する。image.png
  • あとは通常時の注文と同じであり、適切なプロファイルやNW設定を行う。(なお、東京DCには本稿執筆時点でbx2-metal-96x384プロファイルのサーバーは存在しなかったため、bx2d-metal-96x384を利用している)
    image.png
    image.png

4. 注文後のiPXEブートを眺めてみる

  • サーバーの状態が、Pendingの時はVNC Consoleアクセスは利用できないが、Starting/Running状態になるとVNC Consoleアクセスが可能になる。
    image.png
  • サーバー起動からiPXEスクリプトが呼び出されるまで
    image.png
    image.png
    image.png
  • iPXEスクリプトで作成したメニューが表示されるようになった。Install CentOS 9を選択。
    image.png
  • CentOS9のインストーラーが起動
    image.png
    image.png
  • インストールウィザードが表示された
    image.png
    image.png

以下では、ほとんどデフォルトのまま作業を実施するが、特に注視しておくべき箇所について取り上げる。

  • Time & DateにおけるNTPは、ipxeスクリプトで指定したURIが構成されている。
    image.png
  • Installation Destinationでは、Local disk(1 x 960GB)をインストール先として選択する。
    image.png
  • Root PasswordではNetworkアクセスできるように初期パスワードを入力する。また、SSHアクセス可能にする(この辺りはインストール後に細かく設定すれば良いと思う)
    image.png
  • Network & Host Nameでは、DHCPでIPアドレスが取得できていることを確認する。
    image.png

以下、インストールを実施

  • Begin Installation
    image.png
    image.png
  • Rebootを実施
    image.png
    image.png
  • インストールの完了
    image.png

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スクリプトを指定することができる。

  • サーバーを停止した後、Reinitializeを選択
    image.png
  • Network Bootを選択。image.png
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?