在虚拟化技术快速发展的今天,我们往往在虚拟机中搭建一套云平台,因此虚拟化嵌套支持就不得不开启,下面讲解如何在主流的centos7以及Ubuntu server16操作系统上开启嵌套虚拟化。同时,修改网卡命名参数为ethx,以使程序员更易于理解。

Centos7:

  1. 安装开发工具包
yum groupinstall "Development Tools" -y
yum install net-tools -y
yum install tcpdump -y
yum install vim -y
yum install tree -y
yum install wget -y

2.修改网卡名称为eth0

修改/etc/sysconfig/netwok-scripts/ifcfg-xxx
将NAME=eth0
将DEVICE=eth0
修改:vim /etc/default/grub
[root@localhost ~]# cat /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=cl/root rd.lvm.lv=cl/swap rhgb quiet net.ifnames=0 biosdevname=0"
GRUB_DISABLE_RECOVERY="true"
执行:grub2-mkconfig -o /boot/grub2/grub.cfg 重新生成启动文件

3.开启嵌套虚拟化(nested)

执行:cat /sys/module/kvm_intel/parameters/nested输出为N,表示不支持嵌套虚拟化
修改:vim /etc/default/grub
[root@localhost ~]# cat /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=cl/root rd.lvm.lv=cl/swap rhgb quiet net.ifnames=0 biosdevname=0 kvm-intel.nested=1"
GRUB_DISABLE_RECOVERY="true"
执行:grub2-mkconfig -o /boot/grub2/grub.cfg 重新生成启动文件
reboot
执行:cat /sys/module/kvm_intel/parameters/nested  输出为Y,表示嵌套虚拟化已经开启

Ubuntu Server 16.04:

  1. 安装开发工具包
sudo apt-get install build-essential -y
sudo apt-get install tree -y
sudo apt-get install wget -y

2.网卡eth0

root@bogon:~# cat /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
#The primary network interface
auto eth0
iface eth0 inet dhcp
#vim /etc/default/grub 
在”GRUB_CMDLINE_LINUX_DEFAULT”中添加参数net.ifnames=0 biosdevname=0

3.开启嵌套虚拟化(nested)

执行:cat /sys/module/kvm_intel/parameters/nested输出为N,表示不支持嵌套虚拟化
修改:vim /etc/default/grub
[root@localhost ~]# cat /etc/default/grub
GRUB_DEFAULT=0
#GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=2
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="net.ifnames=0 biosdevname=0 quiet splash kvm-intel.nested=1"
GRUB_CMDLINE_LINUX=""
执行:grub-mkconfig -o /boot/grub/grub.cfg 重新生成启动文件
reboot
执行:cat /sys/module/kvm_intel/parameters/nested  输出为Y,表示嵌套虚拟化已经开启