

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 要 VMs 从虚拟化环境中导出的配置
<a name="prepare-vm-image"></a>

在您将 VM 导入 Amazon EC2 之前，您需要从您的虚拟化环境将其导出。在将 VM 导出之前，请按照以下指南配置您的 VM。

**Topics**
+ [常规配置](#prepare-vm-image-general)
+ [Linux/Unix 配置](#prepare-vm-image-linux)
+ [Windows 配置](#prepare-vm-image-windows)

## 常规配置
<a name="prepare-vm-image-general"></a>

在将 VM 从虚拟化环境中导出之前，应在 VM 中进行以下配置。您还应该查看特定于您的操作系统的部分，以了解其他必需的配置。
+ 在您的 VM 上禁用任何反病毒软件或入侵检测软件。可在导入过程完成后重新启用上述服务。
+ 从 VMware 虚拟机中卸载 VMware 工具。
+ 断开连接任何 CD-ROM 驱动 (虚拟或实际)。
+ 源 VM 必须有一项功能 DHCP 客户端服务。确保该服务可以启动且未从管理上被禁用。在导入期间，目前分配到源 VM 的所有静态 IP 地址都被删除。当您导入的实例在 Amazon VPC 中启动时，它会收到来自子网 IPv4 地址范围的主私有 IP 地址。如果您在启动实例时未指定主私有 IP 地址，我们会为您选择子网 IPv4 范围内可用 IP 地址。有关更多信息，请参阅 [VPC 和子网大小调整](https://docs.amazonaws.cn/vpc/latest/userguide/VPC_Subnets.html#VPC_Sizing)。

## Linux/Unix 配置
<a name="prepare-vm-image-linux"></a>

在将 VM 从虚拟化环境中导出之前，应在 Linux VM 中进行以下配置。本部分假设您已经查看 [常规配置](#prepare-vm-image-general)。
+ 启用 Secure Shell（SSH）以进行远程访问。
+ 确保您的主机防火墙（例如 Linux **iptables**）允许访问 SSH。否则在导入完成后，您将无法访问您的实例。
+ 确保您已配置了一个非根用户以使用基于密钥的公共 SSH 在导入您的实例后访问它。使用基于密码的 SSH 和通过 SSH 进行根登录均可行，但不推荐使用。推荐使用公共密钥和非根用户，因为它更安全。VM Import 不会在导入过程中配置 `ec2-user` 账户。
+ 确保您的 Linux VM 将 GRUB (传统 GRUB) 或 GRUB 2 作为其启动加载程序。
+ 确保您的 Linux 虚拟机使用以下选项之一作为根文件系统： EXT2、、、Btrfs EXT3 EXT4、JFS 或 XFS。
+ 确保您的 Linux 虚拟机未使用可预测的网络接口设备名称。
+ 关闭您的 VM 并从您的虚拟化环境中将其导出。

## Windows 配置
<a name="prepare-vm-image-windows"></a>

在从虚拟化环境中导出 VM 之前，应在 Windows VM 中进行以下配置。本部分假设您已经查看 [常规配置](#prepare-vm-image-general)。
+ 启用 Remote Desktop (RDP) 以进行远程访问。
+ 如果配置了主机防火墙 (Windows 防火墙或类似防火墙)，请确保该防火墙允许访问 RDP。否则在导入完成后，您将无法访问您的实例。
+ 确保管理员账户和所有其他用户账户使用安全密码。所有账户均须有密码，否则导入过程可能失败。
+ 在虚拟机上安装 .NET Framework 4.5 或更高版本。我们根据需要在您的 VM 上安装 .NET Framework。
+ 在您的 Windows VM 上禁用 Autologon。
+ 打开 **Control Panel** > **System and Security** > **Windows Update**。在左窗格中，选择 **Change settings**。选择所需设置。请注意，如果选择 **Download updates but let me choose whether to install them**（默认值），则更新检查可能会临时占用实例上 50% 到 99% 的 CPU 资源。检查通常会在实例启动后的几分钟内执行。确保没有等待进行的 Microsoft 更新且计算机未设置成在重启时安装软件。
+ 根据需要应用以下修补程序：
  + [如果在 Windows 中启用了 RealTimeIsUniversal 注册表项，则无法更改系统时间](https://support.microsoft.com/en-us/topic/you-cannot-change-system-time-if-realtimeisuniversal-registry-entry-is-enabled-in-windows-78cf9fbe-eeca-4b06-a67a-2dacdf5189f9)
  + [Windows Server 2008、Windows 7 或 Windows Server 2008 R2 中 DST 转换期间的高 CPU 使用率](https://support.microsoft.com/en-us/topic/high-cpu-usage-during-dst-changeover-in-windows-server-2008-windows-7-or-windows-server-2008-r2-5c8a8dee-3510-cf7b-8296-05c13fd23bed)
+ 设置 RealTimeIsUniversal 注册表项。有关更多信息，请参阅《Amazon EC2 用户指南》**中的[为您的 Amazon EC2 实例设定时间](https://docs.amazonaws.cn/AWSEC2/latest/UserGuide/set-time.html)。
+ 在导入 Windows Server VM 映像之前或之后，请在其上运行 System Preparation (Sysprep)。
  + 如果您在导入 VM 之前运行 Sysprep，则导入过程将在 VM 中添加一个应答文件 (`unattend.xml`)，以自动接受最终用户许可协议 (EULA) 并将区域设置设为 EN-US。
  + 如果你在导入虚拟机后运行 Sysprep，我们建议你使用 La EC2 unch（Windows Server 2016 及更高版本）或 Confi EC2 g（通过 Windows Server 2012 R2）来运行 Sysprep。

**用您自己的应答文件替代默认应答文件 (`unattend.xml`)**

  1. 复制下面的示例文件，并将 **processorArchitecture** 参数设置为 **x86** 或 **amd64**，具体取决于您的操作系统架构：

     ```
     <?xml version='1.0' encoding='UTF-8'?>
     <unattend xmlns:wcm='https://schemas.microsoft.com/WMIConfig/2002/State' xmlns='urn:schemas-microsoft-com:unattend'>
      <settings pass='oobeSystem'>
       <component versionScope='nonSxS' processorArchitecture='x86 or amd64' name='Microsoft-Windows-International-Core' publicKeyToken='31bf3856ad364e35' language='neutral'>
        <InputLocale>en-US</InputLocale>
        <SystemLocale>en-US</SystemLocale>
        <UILanguage>en-US</UILanguage>
        <UserLocale>en-US</UserLocale>
       </component> 
       <component versionScope='nonSxS' processorArchitecture='x86 or amd64' name='Microsoft-Windows-Shell-Setup' publicKeyToken='31bf3856ad364e35' language='neutral'>
        <OOBE>
         <HideEULAPage>true</HideEULAPage>
         <SkipMachineOOBE>true</SkipMachineOOBE>
         <SkipUserOOBE>true</SkipUserOOBE>
        </OOBE>
       </component>
      </settings>
     </unattend>
     ```

  1. 使用名称 `unattend.xml` 将文件保存在 `C:\Windows\Panther` 目录中。

  1. 使用 **/oobe** 和 **/generalize** 选项运行 Sysprep。这些选项会从 Windows 安装中删除所有唯一系统信息并提示您重置管理员密码。

  1. 关闭 VM 并从您的虚拟化环境中将其导出。