You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Packer在vSphere构建Ubuntu 21.04桌面版时user-data无法加载问题

Ubuntu Desktop 21.04 Packer自动化构建user-data加载失败问题参考

背景说明

我此前尝试通过HCL配置在vSphere环境中自动化构建Ubuntu Desktop 21.04的Packer镜像,后续验证发现桌面版镜像的该类自动化构建仅从21.10版本开始支持,以下原始问题供其他遇到同类问题的用户参考。

核心问题描述

问题核心为boot_command中定义的seedfrom配置未生效,user-data始终无法加载,具体现象如下:

  • VM可正常启动,且boot_command中的net.ifnames=0参数已生效,网卡被正确命名为eth0
  • boot_command执行逻辑为:先按c进入grub>提示符,再输入对应启动命令
  • 查看/proc/cmdline可确认boot_command已正确应用到内核参数
  • 无任何user-data已加载的迹象,从已启动的VM中通过浏览器直接访问boot_command指定的Web服务器,可确认user-data和meta-data文件均存在且可正常访问

相关HCL配置

source "vsphere-iso" "dev_vm" {
  username            = var.vcenter_username
  password            = var.vcenter_password
  vcenter_server      = var.vcenter_server
  cluster             = var.vcenter_cluster
  datacenter          = var.vcenter_datacenter
  datastore           = var.vcenter_vm_datastore
  guest_os_type       = "ubuntu64Guest"
  insecure_connection = "true"
  iso_checksum        = "sha256:fa95fb748b34d470a7cfa5e3c1c8fa1163e2dc340cd5a60f7ece9dc963ecdf88"
  iso_urls            = ["https://releases.ubuntu.com/21.04/ubuntu-21.04-desktop-amd64.iso"]
  http_directory      = "./http"

  vm_name             = "dev_vm"
  CPUs                = 2
  RAM                 = 2048
  RAM_reserve_all     = true
  boot_wait           = "3s"
  convert_to_template = false
  boot_command        = [
    "c",
    "linux /casper/vmlinuz --- autoinstall ds='nocloud-net;seedfrom=http://{{.HTTPIP}}:{{.HTTPPort}}/' net.ifnames=0 ",
    "<enter><wait>",
    "initrd /casper/initrd<enter><wait>",
    "boot<enter>"
  ]
  network_adapters {
    network      = "xxx"
    network_card = "e1000"
  }
  storage {
    disk_size             = 40960
    disk_thin_provisioned = true
  }

  ssh_username = "xx"
  ssh_password = "xx"
  ssh_timeout  = "60m"
}

build {
  sources = [
    "source.vsphere-iso.dev_vm"
  ]
...
}

解决建议

直接升级构建使用的Ubuntu Desktop镜像版本到21.10及以上即可,21.04及更早的桌面版镜像不支持该类自动化构建方案。

内容的提问来源于stack exchange,提问作者Nathan Sowatskey

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 19:45:07