查看CPU是否支持KVM
~$ egrep "(svm|vmx)" /proc/cpuinfo
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm cpuid_fault epb pti tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms xsaveopt dtherm ida arat pln pts
出现有vmx,现在大部分cpu都支持虚拟化。
安装KVM及相关依赖包
sudo apt-get install qemu-kvm
sudo apt-get install virt-manager
这两命令把其他需要的依赖包和工具都按装了,不需要另外安装。
通过KVM虚拟系统管理器安装虚拟机
sudo virt-manager
ssh连接,需要远端主机安装图形系统
yum group install "Server with Gui"
安装openssh-askpass,用于ssh图形界面下输入密码
yum install openssh-askpass
远程主机启用libvirtd
[root@localhost ~]# systemctl enable libvirtd
[root@localhost ~]# systemctl start libvirtd
根据图形提示安装介质即可,比较简单。
通过virsh命令行安装虚拟机
磁盘扩容
直接扩展qcow2磁盘
$ sudo qemu-img info winxp.qcow2
image: winxp.qcow2
file format: qcow2
virtual size: 5.0G (5368709120 bytes)
disk size: 4.9G
cluster_size: 65536
Format specific information:
compat: 1.1
lazy refcounts: true
refcount bits: 16
corrupt: false
$ sudo qemu-img resize winxp.qcow2 +5G
Image resized.
$ sudo qemu-img info winxp.qcow2
image: winxp.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 4.9G
cluster_size: 65536
Format specific information:
compat: 1.1
lazy refcounts: true
refcount bits: 16
corrupt: false
重启虚拟机,进入系统,新建分区或通过工具,把新增加的磁盘空间和并到现有分区。
宿主机访问虚机
第一步:在虚机里运行
[root@localhost ~]# grubby --update-kernel=ALL --args=“console=ttyS0”
第二步:重启虚机
[root@localhost ~]# reboot
即可
第三步:登录
[root@zxw6 ~]# virsh console centos7.0
连接到域 centos7.0
换码符为 ^]
CentOS Linux 7 (Core)
Kernel 3.10.0-514.el7.x86_64 on an x86_64
localhost login: root
密码:
Last login: Mon Jul 22 20:49:46 from 192.168.126.1
[root@localhost ~]#