KVM安装windows


1、查看CPU是否支持虚拟化

cat /proc/cpuinfo | grep --color vmx

2、安装KVM

yum install qemu-kvm libvirt libguestfs-tools virt-install virt-manager libvirt-python -y


3、启动KVM,添加开机自启动

systemctl start libvirtd

systemctl enable libvirtd

//查看

systemctl is-enabled libvirtd

lsmod | grep kvm

4、安装VNCserver,便于安装windows

yum -y install tigervnc tigervnc-server tigervnc-server-module


5、复制配置模板文件为vncserver@:1.service

cp /lib/systemd/system/[email protected] /lib/systemd/system/vncserver@:1.service

> /lib/systemd/system/vncserver@:1.service

vim /lib/systemd/system/vncserver@:1.service

[Unit]

Description=Remote desktop service (VNC)  

After=syslog.target network.target  

[Service]  

Type=forking  

ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'  

ExecStart=/usr/sbin/runuser -l root -c "/usr/bin/vncserver %i"  

PIDFile=/root/.vnc/%H%i.pid  

ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'  

[Install]  

WantedBy=multi-user.target

6、设置VNC用户密码

vncpasswd

7、重新载入system配置

systemctl daemon-reload

8、启动vncserver@:1.service服务,并设置开机自启

systemctl start vncserver@:1.service && systemctl enable vncserver@:1.service

//查看

systemctl is-enabled vncserver@:1.service

######如果启动报错 rm -rf /tmp/.X11-unix/* 然后再启动 ########

9、安装windows 

//下载镜像dvd

//挂着光盘

mount /dev/sdb /var/lib/libvirt/images/

10、安装windows

virt-install --name=win2008  --ram 512 --vcpus=1 --disk path=/var/lib/libvirt/images/win2008.img,size=30 --accelerate --cdrom /var/lib/libvirt/images/zh-\ Hans_windows_server_2008_datacenter_enterprise_standard_x86_dvd_x14-26742.iso --vnc --vncport=5917 --vnclisten=0.0.0.0 --network bridge=br0,model=virtio --noautoconsole

windows下用tightVNC viewer  远程连接10.0.0.121:5917  进行图形化安装,安装过程中会重启,需要手动启动virsh start win2008

virsh start win2008

virsh shutdown win2008

virsh autostart win2008

//临时添加网卡

virsh attach-interface win20018 --type network --source default

virsh attach-interface win20018 --type network --source default --config