8.5. 从自定义的 RHEL 客户机系统镜像创建虚拟机
您可以从使用 Insights 镜像创建的 QCOW2 镜像创建虚拟机(VM)。
先决条件
- 您使用 Insights 镜像创建并下载 QCOW2 镜像。
流程
- 访问下载 QCOW2 镜像的目录。
创建一个名为
meta-data
的文件。在此文件中添加以下信息:instance-id: nocloud local-hostname: vmname
创建一个名为
user-data
的文件。在文件中添加以下信息:#cloud-config user: admin password: password chpasswd: {expire: False} ssh_pwauth: True ssh_authorized_keys: - ssh-rsa AAA...fhHQ== your.email@example.com
-
ssh_authorized_keys
是您的 SSH 公钥。您可以在~/.ssh/id_rsa.pub
中找到 SSH 公钥。
-
使用
genisoimage
命令创建一个包含user-data
和meta-data
文件的 ISO 镜像。# genisoimage -output cloud-init.iso -volid cidata -joliet -rock user-data meta-data I: -input-charset not specified, using utf-8 (detected in locale settings) Total translation table size: 0 Total rockridge attributes bytes: 331 Total directory bytes: 0 Path table size(bytes): 10 Max brk space used 0 183 extents written (0 MB)
使用
virt-install
命令从 KVM 客户机映像创建一个新虚拟机。将您在第 4 步中创建的 ISO 镜像作为虚拟机镜像的附件。# virt-install \ --memory 4096 \ --vcpus 4 \ --name myvm \ --disk composer-api.qcow2,device=disk,bus=virtio,format=qcow2 \ --disk cloud-init.iso,device=cdrom \ --os-variant rhel1-latest \ --virt-type kvm \ --graphics none \ --import
其中,
- --graphics none - 表示它是一个无头的 RHEL 虚拟机。
- --vCPU 4 - 表示它使用 4 个虚拟 CPU。
- --memory 4096 - 表示它使用 4096 MB RAM。
虚拟机安装开始:
Starting install... Connected to domain myvm ... [ OK ] Started Execute cloud user/final scripts. [ OK ] Reached target Cloud-init target. Red Hat Enterprise Linux 1-latest (Ootpa) Kernel 4.18.0-221.el8.x86_64 on an x86_64
其它资源