三,上述环境搭建完毕后,就可以正式的安装啦。
(1),
生成一个img文件,该文件格式为qcow2,命令为:
qemu-img create -f qcow2 win7.img 30G
此命令会生成一个img文件,该文件格式是qcow2,一会将会把Windows系统安装到这个文件内。文件存放位置为当前路径下,最好是移动到/opt目录下,如果是root目录下,会有权限问题。
(2),
Windows7纯净版ISO文件和virt驱动文件也在/opt目录下
[root@slave1 opt]# pwd /opt [root@slave1 opt]# ll total 13423720 -rw-r--r-- 1 qemu qemu 3419052032 May 3 21:53 cn_windows_7_ultimate_with_sp1_x64_dvd_618537(1).iso drwxr-xr-x 2 root root 6 Mar 26 2015 rh -rw-r--r-- 1 qemu qemu 160755712 May 3 21:51 virtio-win-0.1.102.iso
(3)
正式的安装命令,该命令将会启动一个服务,此服务可以通过vnc连接。端口定义为5922
virt-install --name win7 --os-variant=win7 --ram 512 --vcpus=1 --disk path=/opt/win7.img,size=30,format=qcow2,bus=ide --accelerate --disk device=cdrom,path=/opt/cn_windows_7_ultimate_with_sp1_x64_dvd_618537\(1\).iso --disk device=cdrom,path=/opt/virtio-win-0.1.102.iso --vnc --vncport=5922 --vnclisten=0.0.0.0 --network bridge=br0,model=virtio --noautoconsole
(4)
这里需要注意了,由于是虚拟机套虚拟机,因此,安装的时候需要将CPU定义为映射。定义的方法为:首先先在host上执行virsh -c qemu:///system进入libvirt的shell。然后edit {你的虚拟机名字}。这里由于上面的定义名称是win7,因此,是edit win7 即可,此时就会打开/etc/libvirt/qemu/下的一个名为win7的xml文件。
那么,我们直接打开这个文件然后修改可以吗?这样的修改是不可以的,必须是libvirt的shell修改才会即时生效的哦。这里要注意了。~!!!!!!!!!!
这个文件的内容应该是这样的:
<!-- WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE OVERWRITTEN AND LOST. Changes to this xml configuration should be made using: virsh edit win7 or other application using the libvirt API. --> <domain type='kvm'> <name>win7</name> <uuid>03dc4185-7581-4c1e-9c13-f1f67cedba1f</uuid> <memory unit='KiB'>524288</memory> <currentMemory unit='KiB'>524288</currentMemory> <vcpu placement='static'>1</vcpu> <os> <type arch='x86_64' machine='pc-i440fx-rhel7.6.0'>hvm</type> <boot dev='hd'/> <bootmenu enable='yes'/> </os> <features> <acpi/> <apic/> <hyperv> <relaxed state='on'/> <vapic state='on'/> <spinlocks state='on' retries='8191'/> </hyperv> </features> <cpu mode='host-passthrough' check='partial'> <model fallback='allow'/> </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> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <pm> <suspend-to-mem enabled='no'/> <suspend-to-disk enabled='no'/> </pm> <devices> <emulator>/usr/libexec/qemu-kvm</emulator> <disk type='file' device='disk'> <driver name='qemu' type='qcow2'/> <source file='/opt/win7.img'/> <target dev='hda' bus='ide'/> <address type='drive' controller='0' bus='0' target='0' unit='0'/> </disk> <disk type='file' device='cdrom'> <driver name='qemu' type='raw'/> <source file='/opt/cn_windows_7_ultimate_with_sp1_x64_dvd_618537(1).iso'/> <target dev='hdb' bus='ide'/> <readonly/> <address type='drive' controller='0' bus='0' target='0' unit='1'/> </disk> <disk type='file' device='cdrom'> <driver name='qemu' type='raw'/> <source file='/opt/virtio-win-0.1.102.iso'/> <target dev='hdc' bus='ide'/> <readonly/> <address type='drive' controller='0' bus='1' target='0' unit='0'/> </disk> <controller type='usb' index='0' model='ich9-ehci1'> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x7'/> </controller> <controller type='usb' index='0' model='ich9-uhci1'> <master startport='0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0' multifunction='on'/> </controller> <controller type='usb' index='0' model='ich9-uhci2'> <master startport='2'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x1'/> </controller> <controller type='usb' index='0' model='ich9-uhci3'> <master startport='4'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x2'/> </controller> <controller type='pci' index='0' model='pci-root'/> <controller type='ide' index='0'> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> </controller> <interface type='bridge'> <mac address='52:54:00:87:6e:6b'/> <source bridge='br0'/> <model type='virtio'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface> <serial type='pty'> <target type='isa-serial' port='0'> <model name='isa-serial'/> </target> </serial> <console type='pty'> <target type='serial' port='0'/> </console> <input type='tablet' bus='usb'> <address type='usb' bus='0' port='1'/> </input> <input type='mouse' bus='ps2'/> <input type='keyboard' bus='ps2'/> <graphics type='vnc' port='5922' autoport='no' listen='0.0.0.0'> <listen type='address' address='0.0.0.0'/> </graphics> <video> <model type='vga' vram='16384' heads='1' primary='yes'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> </video> <memballoon model='virtio'> <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/> </memballoon> </devices> </domain>
其中 这个mode的原值是host-model,修改成host-passthrough映射模式。如果不修改,将会在安装的时候一直卡在startwindows那个界面。
这个配置文件里定义了上面那两个文件,也就是那两个ISO文件的存放路径,也就是类似这样的定义:
source file='/opt/cn_windows_7_ultimate_with_sp1_x64_dvd_618537(1).iso'
这里又得注意了,三个设备,安装磁盘win7.img 和挂载的两个ISO光驱格式都是bus='ide',如果用别的格式,比如virt,那么,安装的时候第一次重启后,将会无法再开机的哦。
我们发现一个问题,这个时候还没有开始安装系统,但启动的时候是直接启动硬盘的,原因是有一个地方没有更改
<os> <type arch='x86_64' machine='pc-i440fx-rhel7.6.0'>hvm</type> <boot dev='hd'/> </os>
上述内容里,将hd更改为cdrom即可从cdrom启动啦。
(四)Windows的安装