制作OpenStack使用的windows镜像

时间:2023-03-09 07:37:02
制作OpenStack使用的windows镜像

1 安装vmware14

2 创建ubuntu-desktop-16.04虚拟机

制作OpenStack使用的windows镜像

选择自定义安装

制作OpenStack使用的windows镜像

制作OpenStack使用的windows镜像

选择ubuntu-16.04-desktop.iso

制作OpenStack使用的windows镜像

制作OpenStack使用的windows镜像

制作OpenStack使用的windows镜像

内存要大于2G,推荐4G。

制作OpenStack使用的windows镜像

制作OpenStack使用的windows镜像

制作OpenStack使用的windows镜像

磁盘要大于50G

制作OpenStack使用的windows镜像

制作OpenStack使用的windows镜像

制作OpenStack使用的windows镜像

制作OpenStack使用的windows镜像

关机,然后打开cpu虚拟化,以支持kvm虚拟化。

制作OpenStack使用的windows镜像

开机之后,使用命令查看cpu是否支持kvm虚拟化。输入有vmx支持,没有则不支持

制作OpenStack使用的windows镜像

3 安装虚拟机化软件

安装qemu,virt-manager

apt-get install qemu-kvm libvirt-bin virtinst virt-manager

制作OpenStack使用的windows镜像

安装vim编辑器

apt install vim

4 在ubuntu虚拟机中安装win7

4.1 下载win7镜像

4.2 下载win7驱动

https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.105-1/

制作OpenStack使用的windows镜像

之所以要额外下载驱动,是因为kvm虚拟化创建windows虚拟机时无法识别windows自带的原生驱动,比如无法识别磁盘就不能安装系统。下载kvm能够识别的驱动替换原生驱动。因为OpenStack使用的也是kvm,所以能正常启动。

4.3 将文件上传到ubuntu虚拟机中(直接拖动到虚拟机桌面)

3.3 将创建虚拟机的xml文件上传到ubuntu虚拟机桌面(xml文件附录本文末尾)

制作OpenStack使用的windows镜像

4.5 创建虚拟机

创建qcow2格式的磁盘作为系统的安装盘

qemu-img create -f qcow2 windows7.qcow2 15G

制作OpenStack使用的windows镜像

修改template.xml文件(xml文件在文末)

第一个disk文件,source写入自己创建的windows7.qcow2磁盘的路径。

制作OpenStack使用的windows镜像

第二个disk文件,source写入window的镜像的路径,这里为了方便重命名为win7.iso

制作OpenStack使用的windows镜像

第三个disk文件,source写入驱动文件的路径

制作OpenStack使用的windows镜像

使用template.xml文件定义虚拟机。虚拟机名为windows7

virsh define template.xml

制作OpenStack使用的windows镜像

启动虚拟机

virsh start windows7 

制作OpenStack使用的windows镜像

注意:如果没有成功需要删除虚拟机,要首先执行virsh undefine windows7取消虚拟机注册,然后执行virsh destroy window7,销毁虚拟机。

在启动器里找到virtual machine manager

制作OpenStack使用的windows镜像

找到刚刚创建的windows7,点击open打开虚拟机的页面。

制作OpenStack使用的windows镜像

制作OpenStack使用的windows镜像

制作OpenStack使用的windows镜像

制作OpenStack使用的windows镜像

选择安装磁盘时找不到磁盘,需要加载驱动。

制作OpenStack使用的windows镜像

选择软盘,然后选择最后一个   virtio->w7->amd64

制作OpenStack使用的windows镜像

制作OpenStack使用的windows镜像

制作OpenStack使用的windows镜像

制作OpenStack使用的windows镜像

制作OpenStack使用的windows镜像

制作OpenStack使用的windows镜像

制作OpenStack使用的windows镜像

制作OpenStack使用的windows镜像

更新设备。安装好的虚拟机缺少设备驱动,右击计算机,点击管理,找到设备管理器。有感叹号表示存在问题。

制作OpenStack使用的windows镜像

点击选择查找驱动

制作OpenStack使用的windows镜像

制作OpenStack使用的windows镜像

剩下两个同样操作。驱动都安装好之后显示正常

制作OpenStack使用的windows镜像

将虚拟机关机,就可以直接使用windows7.qcow2,大小为7个G。使用压缩命令将大小降到4个G以内。

qemu-img convert -c -O qcow2 windows7.qcow2 win_template.qcow2

制作OpenStack使用的windows镜像

最终完成的镜像

制作OpenStack使用的windows镜像

template.xml

<domain type='kvm'>
<name>windows7</name><!--可以替换成自己定义的名字-->
<uuid>073f1023-35df-418a-b57d-bf571d07f449</uuid>
<memory unit='KiB'>2097152</memory><!--内存大小-->
<currentMemory unit='KiB'>2097152</currentMemory>
<vcpu placement='static'>1</vcpu>
<resource>
<partition>/machine</partition>
</resource>
<os><!--系统启动顺序,先是cdrom,然后是hd-->
<type arch='x86_64' machine='pc-i440fx-xenial'>hvm</type>
<boot dev='cdrom'/>
<boot dev='hd'/>
</os>
<features>
<acpi/>
<apic/>
<hyperv>
<relaxed state='on'/>
<vapic state='on'/>
<spinlocks state='on' retries=''/>
</hyperv>
</features>
<cpu mode='custom' match='exact'>
<model fallback='allow'>SandyBridge</model>
</cpu>
<clock offset='localtime'>
<timer name='rtc' tickpolicy='catchup'/>
<timer name='pit' tickpolicy='delay'/>
<timer name='hpet' present='no'/>
<timer name='hypervclock' present='yes'/>
</clock><!--突发事件处理,如果poweroff则销毁,reboot则重启-->
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>restart</on_crash>
<pm>
<suspend-to-mem enabled='no'/>
<suspend-to-disk enabled='no'/>
</pm>
<devices><!--磁盘信息,一共定义了三块磁盘,分别是系统盘,window镜像,驱动盘-->
<emulator>/usr/bin/kvm-spice</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/home/ljk/Desktop/windows7.qcow2'/> <!--替换成自己创建的磁盘的路径-->
<backingStore/>
<target dev='vda' bus='virtio'/>
<alias name='virtio-disk0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<source file='/home/ljk/Desktop/win7.iso'/><!--替换成自己创建的window镜像的路径-->
<backingStore/>
<target dev='hda' bus='ide'/>
<readonly/>
<alias name='ide0-0-0'/>
<address type='drive' controller='' bus='' target='' unit=''/>
</disk>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<source file='/home/ljk/Desktop/virtio-win-0.1.105.iso'/><!--替换成自己创建的window驱动的路径-->
<backingStore/>
<target dev='hdb' bus='ide'/>
<readonly/>
<alias name='ide0-0-1'/>
<address type='drive' controller='' bus='' target='' unit=''/>
</disk>
<controller type='usb' index='' model='ich9-ehci1'>
<alias name='usb'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x7'/>
</controller>
<controller type='usb' index='' model='ich9-uhci1'>
<alias name='usb'/>
<master startport=''/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0' multifunction='on'/>
</controller>
<controller type='usb' index='' model='ich9-uhci2'>
<alias name='usb'/>
<master startport=''/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x1'/>
</controller>
<controller type='usb' index='' model='ich9-uhci3'>
<alias name='usb'/>
<master startport=''/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x2'/>
</controller>
<controller type='pci' index='' model='pci-root'>
<alias name='pci.0'/>
</controller>
<controller type='ide' index=''>
<alias name='ide'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
</controller>
<controller type='virtio-serial' index=''>
<alias name='virtio-serial0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
</controller>
<interface type='network'>
<mac address='52:54:00:39:6f:b4'/>
<source network='default' bridge='virbr0'/>
<target dev='vnet0'/>
<model type='virtio'/>
<alias name='net0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
<serial type='pty'>
<source path='/dev/pts/4'/>
<target port=''/>
<alias name='serial0'/>
</serial>
<console type='pty' tty='/dev/pts/4'>
<source path='/dev/pts/4'/>
<target type='serial' port=''/>
<alias name='serial0'/>
</console>
<channel type='spicevmc'>
<target type='virtio' name='com.redhat.spice.0' state='disconnected'/>
<alias name='channel0'/>
<address type='virtio-serial' controller='' bus='' port=''/>
</channel>
<input type='tablet' bus='usb'>
<alias name='input0'/>
</input>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<graphics type='vnc' port='' autoport='yes' listen='0.0.0.0'>
<listen type='address' address='0.0.0.0'/>
</graphics>
<sound model='ich6'>
<alias name='sound0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</sound>
<video>
<model type='qxl' ram='' vram='' vgamem='' heads=''/>
<alias name='video0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</video>
<redirdev bus='usb' type='spicevmc'>
<alias name='redir0'/>
</redirdev>
<redirdev bus='usb' type='spicevmc'>
<alias name='redir1'/>
</redirdev>
<memballoon model='virtio'>
<alias name='balloon0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
</memballoon>
</devices>
<seclabel type='dynamic' model='apparmor' relabel='yes'>
<label>libvirt-073f1023-35df-418a-b57d-bf571d07f449</label>
<imagelabel>libvirt-073f1023-35df-418a-b57d-bf571d07f449</imagelabel>
</seclabel>
</domain>