创建 win7 images
需要linux7__ KVM 环境,提前搭建完成,准备镜像:win7.iso 和virtio启动.iso,下载地址如下:
https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso
创建磁盘
[root@localhost mnt]# qemu-img create -f qcow2 /mnt/win7_x64_170621.qcow2 20G
Formatting '/mnt/win7_x64_170621.qcow2', fmt=qcow2 size=21474836480 encryption=off cluster_size=65536 lazy_refcounts=off
启动虚机
[root@localhost mnt]# virt-install --virt-type kvm --name win7_x64 --memory 2048 --vcpus 2 --network bridge=br0,model=virtio --graphics vnc,listen=0.0.0.0 --noautoconsole --disk /mnt/win7_x64_170621.qcow2,device=disk,bus=virtio --cdrom /mnt/virtio-win.iso --disk /mnt/windows7_sp1x64.iso,device=cdrom --os-type windows --os-variant win7
virt-install --name win7_x64 --memory 2048 --vcpus 2 --network network=default,model=virtio --graphics vnc,listen=0.0.0.0 --noautoconsole --disk /mnt/win7_x64_170622.qcow2,device=disk,bus=virtio --cdrom /mnt/virtio-win.iso --disk /mnt/windows7_sp1x64.iso,device=cdrom --os-type windows --os-variant win7
Starting install...
Creating domain... | 0 B 00:00:00
Domain installation still in progress. You can reconnect to
the console to complete the installation process.
[root@localhost mnt]#
登录界面virtual-manager





磁盘virtio 已经有了

开始安装系统,不在叙述
系统安装后,没有网卡驱动,









安装cloudbase-init
目的:
cloudbase-init 的一项功能是自动扩展 windows 的 C 盘。比如 windows 镜像是 20G,在部署 instance 时选择的 flavor 磁盘定义是 40G,那么 instance 部署时 cloudbase-init 会自动将 C 盘扩到 40G。
cloudbase-init 自动扩盘这个操作是我们需要的,但它有个副作用。 在 windows 中,我们可以将硬盘划分成多个逻辑盘 C:,D: 等,比如对于 40G 的空间,用户可以给 C 盘 20G,D 盘 20G,但这对于安装了 cloudbase-init 的系统就会有问题。* 系统每次启动时 cloudbase-init 都会把 C 盘 和 D 盘合并为一个 C 盘。
解决这个问题的方法很简单:卸载掉 cloudbase-init,这样就是一个普通 windwos 虚拟机了。不过如果后面在 OpenStack 中对 instance 做了 resize 操作就只能手工扩盘了。 推荐的方式为:系统盘只作 C 盘,如果需要 D 盘、E 盘,通过添加 cinder volume 实现。
https://cloudbase.it/cloudbase-init/#download
https://cloudbase.it/downloads/CloudbaseInitSetup_0_9_11_x64.msi

全部默认其他选项全部默认
最后勾选一下安装,完成安装

虚机会重启,就做好了
对虚机关机,进行如下操作
下面的操作不支持用于soc7 镜像的操作
清除硬件信息
[root@localhost mnt]# virt-sysprep -d win7_x64
[ 0.0] Examining the guest ...
[ 30.7] Performing "abrt-data" ...
[ 30.7] Performing "bash-history" ...
[ 30.7] Performing "blkid-tab" ...
[ 30.7] Performing "crash-data" ...
[ 30.7] Performing "cron-spool" ...
[ 30.7] Performing "dhcp-client-state" ...
[ 30.7] Performing "dhcp-server-state" ...
[ 30.7] Performing "dovecot-data" ...
[ 30.7] Performing "logfiles" ...
[ 30.7] Performing "machine-id" ...
[ 30.7] Performing "mail-spool" ...
[ 30.7] Performing "net-hostname" ...
[ 30.7] Performing "net-hwaddr" ...
[ 30.7] Performing "pacct-log" ...
[ 30.7] Performing "package-manager-cache" ...
[ 30.7] Performing "pam-data" ...
[ 30.7] Performing "puppet-data-log" ...
[ 30.7] Performing "rh-subscription-manager" ...
[ 30.7] Performing "rhn-systemid" ...
[ 30.7] Performing "rpm-db" ...
[ 30.7] Performing "samba-db-log" ...
[ 30.7] Performing "script" ...
[ 30.7] Performing "smolt-uuid" ...
[ 30.7] Performing "ssh-hostkeys" ...
[ 30.7] Performing "ssh-userdir" ...
[ 30.7] Performing "sssd-db-log" ...
[ 30.7] Performing "tmp-files" ...
[ 30.7] Performing "udev-persistent-net" ...
[ 30.7] Performing "utmp" ...
[ 30.7] Performing "yum-uuid" ...
[ 30.7] Performing "customize" ...
[ 30.7] Setting a random seed
virt-sysprep: warning: random seed could not be set for this type of guest
[ 30.8] Performing "lvm-uuids" ...
压缩镜像
[root@localhost mnt]# virt-sparsify --compress win7_x64_170621
win7_x64_170621_noinstall_cloudinit.qcow2 win7_x64_170621.qcow2
[root@localhost mnt]# virt-sparsify --compress win7_x64_170621.qcow2 ../win7_x64_170621.qcow2
[ 0.2] Create overlay file in /tmp to protect source disk
[ 0.3] Examine source disk
[ 2.1] Fill free space in /dev/sda1 with zero
[ 3.3] Fill free space in /dev/sda2 with zero
$<2>◑ 1% ⟦▒▒═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════⟧ --$<2>◒ 1% ⟦▒▒════════════════════
1009 virt-sysprep -d win7_x64
1010 cd
1011 virt-sparsify --compress win7_x64
1012 cd /mnt/
1013 ls
1014 ll
1015 virt-sparsify --compress win7_x64_624.raw
1016 virt-sparsify --compress win7_x64_624.raw ../win7_x64_624.raw
1017 qemu-img -f raw -O qcow2 win7_x64_624.raw win_x64_624_raw_to_qcow2.qcow2
1018 qemu-img convert -f raw -O qcow2 win7_x64_624.raw win_x64_624_raw_to_qcow2.qcow2
1019 ls
1020 l
1021 ll
1022 virt-sparsify --compress win_x64_624_raw_to_qcow2.qcow2
1023 virt-sparsify --compress win_x64_624_raw_to_qcow2.qcow2 ../win7_x64_624_raw_to_qcow2.qcow2
1024 history
[root@bogon mnt]#