Ubuntu 云镜像(Ubuntu Cloud Images,通常是 .qcow2 或 .img 格式)主要用于虚拟化/云计算环境,比如 KVM/QEMU、OpenStack、Proxmox、Docker(不常见)等。下面按最常见使用方式给你讲清楚。
官方地址:
https://cloud-images.ubuntu.com/
常见镜像:
ubuntu-22.04-server-cloudimg-amd64.imgubuntu-24.04-server-cloudimg-amd64.qcow2特点:
sudo apt update
sudo apt install qemu-kvm libvirt-daemon-system virt-manager \
cloud-image-utils genisoimage
wget https://cloud-images.ubuntu.com/22.04/current/ubuntu-22.04-server-cloudimg-amd64.img
# user-data
user: ubuntu
password: ubuntu
chpasswd:
expire: false
packages:
- qemu-guest-agent
runcmd:
- systemctl enable qemu-guest-agent
# meta-data
instance-id: ubuntu-vm
local-hostname: ubuntu-vm
cloud-localds seed.img user-data meta-data
qemu-system-x86_64 \
-m 2048 \
-smp 2 \
-hda ubuntu-22.04-server-cloudimg-amd64.img \
-hdb seed.img \
-net nic -net user,hostfwd=tcp::2222-:22 \
-nographic
登录:
ssh ubuntu@localhost -p 2222
virt-install \
--name ubuntu-cloud \
--ram 2048 \
--vcpus 2 \
--disk path=ubuntu-22.04-server-cloudimg-amd64.img \
--disk path=seed.img,device=cdrom \
--os-variant ubuntu22.04 \
--network network=default \
--graphics none \
--import
openstack image create "Ubuntu22.04" \
--file ubuntu-22.04-server-cloudimg-amd64.qcow2 \
--disk-format qcow2 \
--container-format bare \
--public
启动实例时通过 cloud-init / 密钥对 登录。
.qcow2cloud-init 驱动在 user-data 加:
ssh_pwauth: true
qemu-img resize ubuntu.img 20G
Ubuntu 云镜像 ≠ 普通 ISO
它必须通过 cloud-init 初始化后才能用
如果你告诉我:
我可以直接给你一步一步可复制的命令。