# 使用 iPXE 部署自定义镜像

[**iPXE**](https://ipxe.org/) 是一个免费的开源网络启动固件，提供了一个灵活且可扩展的框架，用于通过网络启动操作系统。它提供了一个完整的 PXE 实现，并增强了额外的功能。

**您有一个有效的公网 URL 存储您的 iPXE 脚本。**

您可以使用 iPXE 脚本来部署您的自定义镜像。一个 iPXE 脚本本质上是一组用于指定启动过程和配置网络参数的指令。iPXE 脚本可以包括获取 IP 地址、配置网络设置、加载特定启动镜像等任务的命令。

以下是一个 iPXE 脚本的示例：

```
#!ipxe

# Download Ubuntu 20.04 ISO image
kernel http://path/to/ubuntu-20.04-netboot/vmlinuz
initrd http://path/to/ubuntu-20.04-netboot/initrd
boot

:install
set base-url http://path/to/ubuntu-20.04-netboot/

# Launch Ubuntu setup
kernel ${base-url}linux auto=true hostname=${hostname} domain=${domain} url=${preseed/url} locale=${locale} console-setup/layoutcode=us keyboard-configuration/layoutcode=us file=/cdrom/preseed/ubuntu-server.seed initrd=initrd.gz quiet ---
initrd ${base-url}initrd.gz
boot
```

**您暂时没有公网 URL。**

您可以参考 [**netboot.xyz**](https://netboot.xyz/docs/) 来完成操作系统安装。[**netboot.xyz**](https://netboot.xyz/) 提供了一个用户友好的菜单，让您轻松选择所需的操作系统及其特定版本或可启动标志。

## 操作步骤

### 部署自定义镜像

请参阅 [**创建裸机实例**](/welcome/cn/bare-metal/get-started/create-a-bare-metal-instance.md) 以获取创建实例的详细步骤，并在选择操作系统时选择 **自定义操作系统**。

* 通过 iPXE URL 安装：输入存储您的 iPXE 脚本的公网 URL。
* 通过 netboot.xyz 安装：您不需要准备 iPXE 脚本。

按照其他步骤完成实例创建。

{% hint style="info" %} <mark style="color:blue;">**注意**</mark>

<mark style="color:blue;">使用自定义操作系统部署后，</mark>

* <mark style="color:blue;">您无法创建分区或标注主机名。</mark>
* <mark style="color:blue;">您只能使用自定义的密码。请记住您的密码，以便稍后登录 IPMI 控制台。</mark>
* <mark style="color:blue;">您的实例状态将从</mark> <mark style="color:blue;">**创建中**</mark> <mark style="color:blue;">变为</mark> <mark style="color:blue;">**安装中**</mark> <mark style="color:blue;">，再变为</mark> <mark style="color:blue;">**已启动**</mark> <mark style="color:blue;">。这并不意味着您的镜像已安装完成。您需要远程访问实例以在系统上进行配置。</mark>
  {% endhint %}

### 下一步操作

1. 转到实例 **详情 > 操作系统 & IPMI > 登录 IPMI 控制台**。
2. 使用公网用户名 (`operator`) 和您的密码登录 IPMI 控制台。
3. 选择您需要的配置，并按照向导完成操作系统的安装。
4. 返回控制台并转到实例 **详情** 页面，点击 **重置 IP**。
5. 完成 IP 重置后，重新启动您的实例。

{% hint style="info" %} <mark style="color:blue;">**注意**</mark>

<mark style="color:blue;">IP 重置可能会失败。请重试。如果 IP 成功重置，您还需要在服务器上检查您的操作是否生效。</mark>
{% endhint %}

### 其他网络操作

由于您使用 iPXE 安装了操作系统，所有网络相关操作（除 IP 重置外）都需要在实例系统上手动配置才能生效。

以下以添加弹性 IP 为例：

1. 转到实例 **详情 > 网络** 页面并点击 **添加弹性 IP**。
2. 选择您希望分配的弹性 IP (`23.90.160.73`)。

   <figure><img src="/files/kgKbELi8Ib93vdFo3wHq" alt=""><figcaption></figcaption></figure>
3. 单击 **IP 封堵**。
4. 远程访问您的实例并执行以下命令。

```bash
sudo ip addr add 23.90.160.73/32 dev wan0
```

{% hint style="info" %} <mark style="color:blue;">**注意**</mark>

<mark style="color:blue;">您必须</mark> <mark style="color:blue;">**首先**</mark> <mark style="color:blue;">在控制台</mark> <mark style="color:blue;">**执行 IP 封堵**</mark> <mark style="color:blue;">，然后在服务器上进行配置，才能使您的操作真正生效。</mark>
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.console.zenlayer.com/welcome/cn/bare-metal/get-started/create-a-bare-metal-instance/deploy-a-custom-image-using-ipxe.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
