為openstack制作可用的windows鏡像,目前官方授權的只有 http://www.cloudbase.it/windows-cloud-images/ 提供的 windows server 2012 R2 Evaluation Cloud Image.我們在網站上能看到這樣的字樣。
Microsoft Windows Server 2012 R2 Standard Evaluation is now available as a downloadable cloud image, customized by our engineers and ready to be be directly deployed in OpenStack.
理論上來說這個鏡像是可以直接使用glance部署到我們的openstack 上。但是多數情況下,用戶需要定制自己的windows鏡像。本文提供完整的鏡像制作過程。
制作環境 unbuntu 14.04 server
在使用kvm命令建立虛擬機時每次都要輸入很長的命令,容易出現輸入錯誤,可以使用libvirt管理虛擬機,libvirt支持kvm,xen等主流虛擬機的管理,安裝:
apt-get install qemu-kvm libvirt-bin virtinst
下載virtio驅動,因為win默認不支持virtio驅動,而通過openstack管理虛擬機是需要virtio驅動的。需要兩個virtio驅動,一個是硬盤的,一個是網卡的,即:virtio-win-0.1-30.iso和virtio-win-1.1.16.vfd
wget 'http://autosetup1.googlecode.com/files/virtio-win-1.1.16.vfd'
wget 'http://alt.fedoraproject.org/pub/alt/virtio-win/latest/images/bin/virtio-win-0.1-30.iso'
我在安裝的時候,第一個鏈接是可以正常使用,但是第二個是報錯404.所以我在另外的地方找到了一個比較新的版本 https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.105-1/ 注意選擇上面對應的兩個版本
下載了一個win7的官方純凈版鏡像 win7.iso 將三個文件放到ubuntu下的同一個子目錄下,/home/house/ 下
建立一個硬盤映射,用來存放我們將來生成的鏡像文件
qemu-img create -f qcow2 windows7.qcow2 15G
輸出: Formatting 'windows7.qcow2', fmt=qcow2 size=21474836480 encryption=off cluster_size=65536 lazy_refcounts=off
這時候你就能夠在剛才的目錄下看到這個文件了,下面創建鏡像
virt-install --connect qemu:///system \ --name windows7 --ram 2048 --vcpus 2 \ --network network=default,model=virtio \ --disk path=windows7.qcow2,format=qcow2,device=disk,bus=virtio \ --cdrom /home/house/win7.iso \ --disk path=/home/house/virtio-win-0.1.105.iso,device=cdrom \ --vnc 10.74.116.31:8 --os-type windows --os-variant win7
輸出: Starting install...
Creating domain... | 0 B 00:00
Cannot open display:
Run 'virt-viewer --help' to see a full list of available command line options
Domain installation still in progress. Waiting for installation to complete.
我們沒有安裝圖形界面,所以無法進行手動安裝,安裝了圖形界面的,直接使用virt-viewer進行操作,所以我們使用另外一個工具spice進行遠程安裝。http://www.spice-space.org/download.html
在上面的命令中,我們需要將--vnc替換為--graphics spice,listen=0.0.0.0即
virt-install --connect qemu:///system \ --name windows7 --ram 2048 --vcpus 2 \ --network network=default,model=virtio \ --disk path=windows7.qcow2,format=qcow2,device=disk,bus=virtio \ --cdrom /home/zhangjun/win7.iso \ --disk path=/home/zhangjun/virtio-win-0.1.105.iso,device=cdrom \ --os-type windows --os-variant win7 --graphics spice,listen=0.0.0.0
打開spice 在connection address處輸入你安裝機器的ip地址:spice://192.168.1.2:5900(端口號默認5900,若有其他安裝程序在,則自動+1)
點擊connec即可進入安裝界面 ,在驅動選擇界面 點擊加載驅動程序->瀏覽->驅動器virtio-win-0.1.1
可以看到RadHat virtIO SCSI 磁盤驅動。選擇,進入系統后在類似目錄下安裝網卡驅動。
note:安裝過程中也許會出現一些問題,推薦一些virt命令,來查看虛擬機狀態
virsh -c qemu:///system list//查看虛擬機 virsh shutdown windows7 //關閉 virsh destroy windows7 //刪除 virsh undefine windows7 //取消domin
這時候就大功告成了,我們成功的制作了一個qcow2的鏡像。接下來部署到glance上去
glance image-create --name "windows7" --file home/house/windows7.qcow2 --disk-format qcow2 --container-format bare --is-public True --progress
成功以后就可以在dashboard上看到這個虛擬機了。創建成功以后,注意需要給其所在的安全組添加規則 TCP 端口3389,關閉防火牆,開啟遠程桌面連接,即可ping通與遠程連接上了。