红联Linux门户
Linux帮助

Ubuntu15.04安装KVM

发布时间:2015-12-24 16:13:52来源:linux网站作者:moyier123

一、虚拟机环境配置
刚装好的ubuntu15.04桌面版,没有vim编辑器,没有ssh连接,好郁闷!!

先配置网卡,让其能上网,咱们要安装点有用的应用
laks@laks:~$ sudo gedit /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 10.0.0.1
netmask 255.255.255.0
gateway 10.0.0.2
dns-search example.com
dns-nameservers 10.0.0.2
重启网卡
laks@laks:~$ sudo /etc/init.d/networking restart
laks@laks:~$ ping baidu.com
幸运的话,成功!!

OK!可以上网了,那我们安装一些应用
 
ubuntu15.04桌面版内置的编辑器为gedit,如果你不喜欢,希望安装vim,那么执行如下:
laks@laks:~$ sudo apt-get update
laks@laks:~$ sudo apt-get install vim-gtk
 
ubuntu15.04桌面版没有ssh,安装ssh执行如下:
laks@laks:~$ sudo apt-get install openssh-server


一.二、检查环境
laks@laks:~$ lsmod | grep kvm
kvm_intel             151552  0
kvm                   483328  1 kvm_intel
laks@laks:~$ grep vmx /proc/cpuinfo
flags        : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush
dts mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts nopl
xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq vmx ssse3 fma cx16 pcid
sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer xsave avx f16c rdrand hypervisor lahf_lm
abm 3dnowprefetch ida arat epb pln pts dtherm tpr_shadow vnmi ept vpid fsgsbase tsc_adjust bmi1
avx2 smep bmi2 invpcid rdseed adx smap xsaveopt

表示支持虚拟化


二、安装qemu-kvm
laks@laks:~$ sudo apt-get install qemu-kvm
laks@laks:~$ dpkg -l | grep qemu
ii  ipxe-qemu                                            1.0.0+git-20141004.86285d1-1ubuntu3        all          PXE boot firmware - ROM images for qemu
ii  qemu-kvm                                             1:2.2+dfsg-5expubuntu9.7                   amd64        QEMU Full virtualization
ii  qemu-system-common                                   1:2.2+dfsg-5expubuntu9.7                   amd64        QEMU full system emulation binaries (common files)
ii  qemu-system-x86                                      1:2.2+dfsg-5expubuntu9.7                   amd64        QEMU full system emulation binaries (x86)
ii  qemu-utils                                           1:2.2+dfsg-5expubuntu9.7                   amd64        QEMU utilities


三、安装libvirt
laks@laks:~$ sudo apt-get install libvirt-bin


四、安装virtinst(virt-install)
laks@laks:~$  sudo apt-get install virtinst
laks@laks:~$ sudo virsh list --all
Id    名称                         状态
----------------------------------------------------

laks@laks:~$ virsh --version
1.2.12


五、验证
镜像准备

laks@laks:~$ wget -c http://mirror.jmu.edu/pub/ubuntu-iso/14.04.1/ubuntu-14.04.1-server-amd64.iso
将其移动到/mnt文件夹下
cp ubuntu-14.04.1-server-amd64.iso /mnt/ubuntu-14.04.1-server-amd64.iso

磁盘准备

laks@laks:~$ sudo mkdir /mnt/kvm
laks@laks:~$ sudo qemu-img create -f qcow2 /mnt/kvm/ubuntu1204.img 10G
Formatting '/mnt/kvm/ubuntu1204.img', fmt=qcow2 size=10737418240 encryption=off cluster_size=65536 lazy_refcounts=off

创建虚拟机

laks@laks:~$ sudo qemu-system-x86_64 -hda /mnt/kvm/ubuntu1204.img -cdrom /mnt/ubuntu-14.04.3-server-amd64.iso -boot d -m 1024 -no-acpi
注意,这句命令必须在虚拟机里执行,不能用xshell里执行

Ubuntu15.04安装KVM

引导安装我就不赘述了,ubuntu虚拟机安装OK!


CentOS 5.5下安装KVM:http://www.linuxdiyf.com/linux/7047.html

Debian 6.0安装KVM并桥接网络:http://www.linuxdiyf.com/linux/5362.html

CentOS 6.3下安装KVM和创建KVM虚拟机:http://www.linuxdiyf.com/linux/1118.html