Contents

Centos和Debian安装KVM

Centos

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#安装依赖
yum -y install qemu-kvm libvirt virt-install bridge-utils

#启动libvirtd
systemctl status libvirtd
systemctl start libvirtd


#删除默认生成的网桥

virsh net-list --all
virsh net-destroy default
virsh net-undefine default 

#拷贝网卡配置文件,原机器已经配置了eth0为静态IP
cp ifcfg-eth0 ifcfg-br0

##############
#ifcfg-br0
NAME=br0
DEVICE=br0
ONBOOT=yes
NETBOOT=yes
TYPE=Bridge
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=172.16.0.80
PREFIX=24
GATEWAY=172.16.0.1
DNS1=172.16.0.1
DNS1=8.8.8.8
DEFROUTE=yes
IPV6INIT=yes
IPV6_AUTOCONF=yes
#################

##############
#ifcfg-eth0
NAME=eth0
DEVICE=eth0
BOOTPROTO=none
NM_CONTROLLED=no
ONBOOT=yes
BRIDGE=br0
#################

#重启网络服务
systemctl restart network

Debian

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#安装依赖
sudo apt install -y qemu qemu-kvm qemu-system qemu-utils libvirt-clients libvirt-daemon-system virtinst bridge-utils 


#启动libvirtd
sudo systemctl status libvirtd
sudo systemctl start libvirtd




#删除默认生成的网桥

virsh net-list --all
virsh net-destroy default
virsh net-undefine default 

#网卡配置文件
# /etc/network/interfaces
#############################
#
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

#eth0
auto eth0
iface eth0 inet manual

#br0
auto br0
iface br0 inet static
address 172.16.0.200
netmask 255.255.255.0
gateway 172.16.0.1
bridge_ports eth0
bridge_stp off
bridge_fd 0
bridge_maxwait 0
dns-nameservers 172.16.0.104
#############################

#重启网咯
systemctl restart networking

导入vmdk文件

1
2
3
4
5
6
#如果导入的是Centos的vmdk,切记将bus改为ide,否则有时候起不来
qemu-img convert -f vmdk -O qcow2 debian10-disk1.vmdk deb.qcow2
virt-install --name deb --memory 400 --vcpus 4 --disk /data/vms/deb/deb.qcow2,bus=sata --import --os-variant debian10 --network=bridge:br0,model=virtio --cpu host-passthrough --noreboot --quiet


#如果想要启用virsh console,需要在grub加入console=ttyS0参数