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

Ubuntu 22.04 Packer自动镜像构建失败:curtin in-target报错

问题:Packer创建Ubuntu 22.04镜像时Autoinstall失败(curtin报错)

故障现象

使用Packer构建Ubuntu 22.04自动化镜像,user-data已成功传递给Autoinstaller,但安装过程失败。curtin-install.log中出现关键错误:/usr/bin/ckbcomp: Can not find file "symbols/en" in any known directory,导致setupcon --save-only命令执行失败。

关键错误日志(curtin-install.log)

Running command ['mount', '--make-private', '/target/proc'] with allowed return codes [0] (capture=False)
Running command ['umount', '/target/proc'] with allowed return codes [0] (capture=False)
Running command ['mount', '--make-private', '/target/dev'] with allowed return codes [0] (capture=False)
Running command ['umount', '/target/dev'] with allowed return codes [0] (capture=False)
finish: cmd-install/stage-curthooks/002-setupcon-save-only/cmd-in-target: FAIL: curtin command in-target
curtin: Installation failed with exception: Unexpected error while running command.
Command: ['curtin', 'in-target', '--', 'setupcon', '--save-only']
Exit code: 1
Reason: -
Stdout: start: cmd-install/stage-curthooks/002-setupcon-save-only/cmd-in-target: curtin command in-target
        Running command ['mount', '--bind', '/dev', '/target/dev'] with allowed return codes [0] (capture=False)
        Running command ['mount', '--bind', '/proc', '/target/proc'] with allowed return codes [0] (capture=False)
        Running command ['mount', '--bind', '/run', '/target/run'] with allowed return codes [0] (capture=False)
        Running command ['mount', '--bind', '/sys', '/target/sys'] with allowed return codes [0] (capture=False)
        Running command ['unshare', '--help'] with allowed return codes [0] (capture=True)
        Running command ['unshare', '--fork', '--pid', '--', 'chroot', '/target', 'setupcon', '--save-only'] with allowed return codes [0] (capture=False)
        /usr/bin/ckbcomp: Can not find file "symbols/en" in any known directory
        Running command ['udevadm', 'settle'] with allowed return codes [0] (capture=False)
        TIMED subp(['udevadm', 'settle']): 0.055
        Running command ['mount', '--make-private', '/target/sys'] with allowed return codes [0] (capture=False)
        Running command ['umount', '/target/sys'] with allowed return codes [0] (capture=False)
        Running command ['mount', '--make-private', '/target/run'] with allowed return codes [0] (capture=False)
        Running command ['umount', '/target/run'] with allowed return codes [0] (capture=False)
        Running command ['mount', '--make-private', '/target/proc'] with allowed return codes [0] (capture=False)
        Running command ['umount', '/target/proc'] with allowed return codes [0] (capture=False)
        Running command ['mount', '--make-private', '/target/dev'] with allowed return codes [0] (capture=False)
        Running command ['umount', '/target/dev'] with allowed return codes [0] (capture=False)
        finish: cmd-install/stage-curthooks/002-setupcon-save-only/cmd-in-target: FAIL: curtin command in-target

相关配置文件

ubuntu.pkr.hcl

source "hyperv-iso" "ubuntu-desktop" {
    boot_command = [
        "c",
        "set gfxpayload=keep",
        "<enter><wait>",
        "linux /casper/vmlinuz autoinstall quiet ds=\"nocloud-net;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/\"",
        "<enter><wait>",
        "initrd /casper/initrd<enter><wait>",
        "boot<enter>",
    ]
    boot_wait = "5s"
    iso_url = "ubuntu-22.04.2-live-server-amd64.iso"
    iso_checksum = "sha256:5e38b55d57d94ff029719342357325ed3bda38fa80054f9330dc789cd2d43931"
    cpus = 2
    enable_secure_boot = false
    disk_size = 128000
    memory = 4096
    mac_address = "00:15:5D:01:73:0D"
    shutdown_command = "echo 'ubuntu' | sudo -S shutdown -P now"
    ssh_password = "ubuntu"
    ssh_username = "ubuntu"
    ssh_timeout = "1h"
    ssh_host = "192.168.1.100"
    ssh_handshake_attempts = 500
    switch_name = "Hyper-V External Switch"
    vm_name = "test-desktop"
    http_directory = "http"
    http_port_max = 9987
    http_port_min = 9987
}
build {
    sources = ["source.hyperv-iso.ubuntu-desktop"]
}

user-data

#cloud-config
autoinstall:
    version: 1
#    early-commands:
#        workaround to stop ssh for packer as it thinks it timed out
#        - sudo systemctl stop ssh
    refresh-installer:
    update: yes
    locale: en_US
    keyboard:
        layout: en
    packages:
        - ubuntu-desktop
        - net-tools
        - nfs-common
        - net-tools
        - linux-virtual
        - linux-cloud-tools-virtual
        - linux-tools-virtual
    snaps:
        - name: firefox
        - name: gnome-3-38-2004
        - name: gtk-common-themes
        - name: snap-store
        - name: snapd-desktop-integration
    package_update: true
    package_upgrade: true
    storage:
        layout:
             name: direct
    early-commands:
        - echo 'linux-generic-hwe-22.04' > /run/kernel-meta-package
    identity:
        hostname: test-desktop
        username: ubuntu
        password: "$6$exDY1mhS4KUYCE/2$zmn9ToZwTKLhCw.b4/b.ZRTIZM30JZ4QrOQ2aOXJ8yk96xpcCof0kxKwuX1kqLG/ygbJ1f8wxED22bTL4F46P0"
    ssh:
        install-server: yes
        allow-pw: yes
    user-data:
        disable_root: false

故障排查与解决办法

原因分析

错误提示Can not find file "symbols/en"说明setupcon命令无法找到对应键盘布局的符号文件,核心原因是user-data中配置的键盘布局标识符不规范——en不是Ubuntu系统认可的标准键盘布局标识,正确的英文美式键盘标识应为us。

解决步骤

  1. 修正键盘布局配置
    编辑user-data,将keyboard部分的layout: en改为layout: us:

    keyboard:
        layout: us
    
  2. 提前安装键盘配置依赖(可选增强)
    若仍出现类似问题,可在early-commands中添加命令,确保键盘配置相关包提前就绪:

    early-commands:
        - echo 'linux-generic-hwe-22.04' > /run/kernel-meta-package
        - apt-get update && apt-get install -y keyboard-configuration console-setup
    
  3. 临时跳过setupcon命令(应急方案)
    若上述方法无效,可通过late-commands移除触发错误的钩子文件,但不推荐长期使用:

    late-commands:
        - curtin in-target -- rm -f /etc/init.d/setupcon-save-only
    
  4. 校验ISO镜像完整性
    确认使用的Ubuntu 22.04.2 ISO镜像未损坏,重新核对iso_checksum与官方发布值一致。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 03:17:10