您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

为 Azure 准备 Debian VHDPrepare a Debian VHD for Azure

先决条件Prerequisites

本部分假设已经将从 Debian 网站下载的 .iso 文件中的 Debian Linux 操作系统安装到虚拟硬盘。This section assumes that you have already installed a Debian Linux operating system from an .iso file downloaded from the Debian website to a virtual hard disk. 可以使用多种现有的工具来创建 .vhd 文件;Hyper-V 只是一个示例。Multiple tools exist to create .vhd files; Hyper-V is only one example. 有关 Hyper-V 的使用说明,请参阅安装 Hyper-V 角色和配置虚拟机For instructions using Hyper-V, see Install the Hyper-V Role and Configure a Virtual Machine.

安装说明Installation notes

  • 另请参阅常规 Linux 安装说明,获取更多有关如何为 Azure 准备 Linux 的提示。Please see also General Linux Installation Notes for more tips on preparing Linux for Azure.
  • Azure 不支持更新的 VHDX 格式。The newer VHDX format is not supported in Azure. 可使用 Hyper-V 管理器或 convert-vhd cmdlet 将磁盘转换为 VHD 格式。You can convert the disk to VHD format using Hyper-V Manager or the convert-vhd cmdlet.
  • 在安装 Linux 系统时,建议使用标准分区而不是 LVM(通常是许多安装的默认值)。When installing the Linux system it is recommended that you use standard partitions rather than LVM (often the default for many installations). 这会避免 LVM 与克隆 VM 发生名称冲突,特别是在 OS 磁盘需要连接到另一台 VM 以进行故障排除的情况下。This will avoid LVM name conflicts with cloned VMs, particularly if an OS disk ever needs to be attached to another VM for troubleshooting. 如果需要,可以在数据磁盘上使用 LVMRAIDLVM or RAID may be used on data disks if preferred.
  • 不要在操作系统磁盘上配置交换分区。Do not configure a swap partition on the OS disk. 可以配置 Azure Linux 代理,以在临时资源磁盘上创建交换文件。The Azure Linux agent can be configured to create a swap file on the temporary resource disk. 可以在下面的步骤中找到有关此内容的详细信息。More information about this can be found in the steps below.
  • Azure 上的所有 VHD 必须已将虚拟大小调整为 1MB。All VHDs on Azure must have a virtual size aligned to 1MB. 从原始磁盘转换为 VHD 时,必须确保在转换前原始磁盘大小是 1MB 的倍数。When converting from a raw disk to VHD you must ensure that the raw disk size is a multiple of 1MB before conversion. 有关详细信息,请参阅 Linux 安装说明See Linux Installation Notes for more information.

使用 Azure-Manage 来创建 Debian VHDUse Azure-Manage to create Debian VHDs

有工具可用于生成适用于 Azure 的 Debian VHD,如来自 credativazure-manage 脚本。There are tools available for generating Debian VHDs for Azure, such as the azure-manage scripts from credativ. 这是建议的方法,而不是从头开始创建映像。This is the recommended approach versus creating an image from scratch. 例如,要创建 Debian 8 VHD,运行以下命令来下载 azure-manage(以及依赖关系),并运行 azure_build_image 脚本:For example, to create a Debian 8 VHD run the following commands to download azure-manage (and dependencies) and run the azure_build_image script:

# sudo apt-get update
# sudo apt-get install git qemu-utils mbr kpartx debootstrap

# sudo apt-get install python3-pip python3-dateutil python3-cryptography
# sudo pip3 install azure-storage azure-servicemanagement-legacy azure-common pytest pyyaml
# git clone https://github.com/credativ/azure-manage.git
# cd azure-manage
# sudo pip3 install .

# sudo azure_build_image --option release=jessie --option image_size_gb=30 --option image_prefix=debian-jessie-azure section

手动准备 Debian VHDManually prepare a Debian VHD

  1. 在 Hyper-V 管理器中,选择虚拟机。In Hyper-V Manager, select the virtual machine.
  2. 单击“连接”打开该虚拟机的控制台窗口。Click Connect to open a console window for the virtual machine.
  3. 如果针对 ISO 文件设置了 VM,请注释掉 /etc/apt/source.list 中对应于 deb cdrom 的行。Comment out the line for deb cdrom in /etc/apt/source.list if you set up the VM against an ISO file.
  4. 编辑 /etc/default/grub 文件并按如下方式修改 GRUB_CMDLINE_LINUX 参数,包含用于 Azure 的其他内核参数。Edit the /etc/default/grub file and modify the GRUB_CMDLINE_LINUX parameter as follows to include additional kernel parameters for Azure.

     GRUB_CMDLINE_LINUX="console=tty0 console=ttyS0,115200 earlyprintk=ttyS0,115200 rootdelay=30"
    
  5. 重新生成 grub 并运行:Rebuild the grub and run:

     # sudo update-grub
    
  6. 将 Debian 的 Azure 存储库添加到 Debian 7 或 8 的 /etc/apt/sources.list 中:Add Debian's Azure repositories to /etc/apt/sources.list for either Debian 7 or 8:

    Debian 7.x "Wheezy"Debian 7.x "Wheezy"

     deb http://debian-archive.trafficmanager.net/debian wheezy-backports main
     deb-src http://debian-archive.trafficmanager.net/debian wheezy-backports main
     deb http://debian-archive.trafficmanager.net/debian-azure wheezy main
     deb-src http://debian-archive.trafficmanager.net/debian-azure wheezy main
    

    Debian 8.x "Jessie"Debian 8.x "Jessie"

     deb http://debian-archive.trafficmanager.net/debian jessie-backports main
     deb-src http://debian-archive.trafficmanager.net/debian jessie-backports main
     deb http://debian-archive.trafficmanager.net/debian-azure jessie main
     deb-src http://debian-archive.trafficmanager.net/debian-azure jessie main
    
  7. 安装 Azure Linux 代理:Install the Azure Linux Agent:

     # sudo apt-get update
     # sudo apt-get install waagent
    
  8. 对于 Debian 7,需要从 wheezy-backports 存储库运行基于 3.16 的内核。For Debian 7, it is required to run the 3.16-based kernel from the wheezy-backports repository. 首先使用以下内容创建名为 /etc/apt/preferences.d/linux.pref 的文件:First create a file called /etc/apt/preferences.d/linux.pref with the following contents:

     Package: linux-image-amd64 initramfs-tools
     Pin: release n=wheezy-backports
     Pin-Priority: 500
    

    然后运行“sudo apt-get install linux-image-amd64”,以安装新内核。Then run "sudo apt-get install linux-image-amd64" to install the new kernel.

  9. 取消对虚拟机的预配并对其进行准备,以便在 Azure 上进行预配并运行:Deprovision the virtual machine and prepare it for provisioning on Azure and run:

     # sudo waagent –force -deprovision
     # export HISTSIZE=0
     # logout
    
  10. 在 Hyper-V 管理器中单击“操作”->“关闭”。Click Action -> Shut Down in Hyper-V Manager. Linux VHD 现已准备好上传到 Azure。Your Linux VHD is now ready to be uploaded to Azure.

后续步骤Next steps

现在,可以使用 Debian 虚拟硬盘在 Azure 中创建新的 Azure 虚拟机了。You're now ready to use your Debian virtual hard disk to create new virtual machines in Azure. 如果是首次将 .vhd 文件上传到 Azure,请参阅从自定义磁盘创建 Linux VMIf this is the first time that you're uploading the .vhd file to Azure, see Create a Linux VM from a custom disk.