准备 qcow2 文件
ls -l /data/ctyunos/ctyun-2.0.1-02.qcow2
-rw------- 1 qemu qemu 21478375424 Jan 24 19:02 /data/ctyunos/ctyun-2.0.1-02.qcow2
净化 qcow2
清除系统信息
virt-sysprep 会执行一系列操作,如清除 SSH 密钥、网络配置、日志文件等,确保映像在迁移或克隆后不会含有敏感信息。
virt-sysprep -a /data/ctyunos/ctyun-2.0.1-02.qcow2
[ 0.0] Examining the guest ...
[ 51.1] Performing "abrt-data" ...
[ 51.1] Performing "backup-files" ...
[ 52.2] Performing "bash-history" ...
[ 52.2] Performing "blkid-tab" ...
[ 52.3] Performing "crash-data" ...
[ 52.3] Performing "cron-spool" ...
[ 52.3] Performing "dhcp-client-state" ...
[ 52.3] Performing "dhcp-server-state" ...
[ 52.3] Performing "dovecot-data" ...
[ 52.3] Performing "logfiles" ...
[ 52.4] Performing "machine-id" ...
[ 52.4] Performing "mail-spool" ...
[ 52.4] Performing "net-hostname" ...
[ 52.5] Performing "net-hwaddr" ...
[ 52.5] Performing "pacct-log" ...
[ 52.5] Performing "package-manager-cache" ...
[ 52.5] Performing "pam-data" ...
[ 52.5] Performing "passwd-backups" ...
[ 52.6] Performing "puppet-data-log" ...
[ 52.6] Performing "rh-subscription-manager" ...
[ 52.6] Performing "rhn-systemid" ...
[ 52.6] Performing "rpm-db" ...
[ 52.6] Performing "samba-db-log" ...
[ 52.6] Performing "script" ...
[ 52.6] Performing "smolt-uuid" ...
[ 52.7] Performing "ssh-hostkeys" ...
[ 52.7] Performing "ssh-userdir" ...
[ 52.7] Performing "sssd-db-log" ...
[ 52.7] Performing "tmp-files" ...
[ 52.7] Performing "udev-persistent-net" ...
[ 52.7] Performing "utmp" ...
[ 52.8] Performing "yum-uuid" ...
[ 52.8] Performing "customize" ...
[ 52.8] Setting a random seed
[ 52.8] Setting the machine ID in /etc/machine-id
[ 52.8] Performing "lvm-uuids" ...
创建虚拟机
virt-install \--name ctyun-2.0.1-02 \--ram 2048 \--vcpus 2 \--virt-type kvm \--os-variant generic \--description ctyun-2.0.1-02 \--network bridge=CN1,model=virtio \--network bridge=CN2,model=virtio \--graphics vnc,listen=0.0.0.0 \--disk path=/data/ctyunos/ctyun-02_system.qcow2,format=qcow2,bus=virtio \--noautoconsole \--console pty,target_type=serial \--autostart \--boot hd
Starting install...
Domain creation completed.
查看虚拟机 ID
virsh list --all
Id Name State
--------------------------------1 ctyun-2.0.1-01 running2 ctyun-2.0.1-02 running
登录虚拟机
virsh console 2
Connected to domain ctyun-2.0.1-02
Escape character is ^] (Ctrl + ])localhost login: