Create a virtual machine on RHEL7 using KVM
The most important step in creating guest os using kvm is creating a bridge network.
- Create a bridge network
a. Verify whether bridging module network is loaded or not.
Bridging module are loaded on system boot by default. To verify run
# modinfo bridge
b. If the module is not loaded, you can load it using the following command.
# modprobe --first-time bridge
c. Install bridge-utils , if above command fails
# yum install bridge-utils -y
d. Create a file called “ifcfg-virbr0” at location /etc/sysconfig/network-scripts/
# vim /etc/sysconfig/network-scripts/ifcfg-virbr0DEVICE="virbr0"
BOOTPROTO="static"
IPADDR="192.168.10.25"
NETMASK="255.255.255.0"
GATEWAY="192.168.10.1"
DNS1=192.168.10.2
ONBOOT="yes"
TYPE="Bridge"
NM_CONTROLLED="no"
Modify above file based upon your environment. However ensure that you use NM_CONTROLLED=no
e. Find the ethernet adapter which is having physical network link.
# ifconfig It will show list of all the ethernet adapter.
Usually on a Dell machine 1G adapter have name em1, em2 ... and 10G adapter have names like p4p1, p4p2 etc.# ethtool em1 | grep "Link detected"Run this command for all the adapters to find the adapter which have output - Link detected: yes
f. Modify ethernet adapter file that have physical network link.
Here, it is em1.
# vim /etc/sysconfig/network-scripts/ifcfg-em1DEVICE=em1
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
NM_CONTROLLED=no
BRIDGE=virbr0
f. Restart the network
# systemctl restart network
Troubleshoot: If there is a problem in restarting the network :
— Ensure that all the ethernet adapter files at location /etc/sysconfig/network-scripts/ have NM_CONTROLLED=no
— Move all Ethernet adapter files which do not have uplink to a temp folder
# mkdir /etc/sysconfig/network-scripts/other-network
# mv ifcfg-em2 /etc/sysconfig/network-scripts/other-network
# systemctl restart network
g. Ensure that your bridge network now have the ip address instead on the physical ethernet adapter.
Here, virbr0 should have the ip instead on em1.
# ifconfig
2. Install KVM related package
#yum install qemu-kvm libvirt libvirt-python libguestfs-tools virt-install virt-manager
3. Start the libvirtd service
# systemctl enable libvirtd
# systemctl start libvirtd
4. Create the virtual machine
For windows guest OS# virt-install \
--ram=4096 \
--vcpus=8 \
--cdrom=/data/winserver2018.iso \
--name=winserver2018 \
--os-type=windows \
--network bridge=virbr0 \
--graphics=spice \
--disk path=/data/vmdisk/winserver2018.qcow2,size=500 \For linux type guest OS, modify the line
--os-type=linux.Modify above command as per your environment.
Thats It!