Ubuntu 16.04 搭建KVM虚拟机

查看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 ~]#

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值