Install Virtual Machine Through KVM CLI
Steps for install KVM server on Debian Linux 9.x server
- The host server located in the remote data center and it is a headless server.
- All commands in this tutorial typed over the ssh based session.
- You need a vnc client to install the guest operating system.
- In this tutorial, you will learn how to install KVM software on Debian Linux 9.x server and use KVM to setup your first guest VM.
Follow installation steps of KVM on Debian Linux 9.x headless sever
$ sudo apt install qemu-kvm libvirt-clients libvirt-daemon-system bridge-utils libguestfs-tools genisoimage virtinst libosinfo-bin
Allow normal user to manage virtual machine
$ sudo adduser aman libvirt
$ sudo adduser aman libvirt-qemu
Please note that you need to use the following command to connect to KVM server:
$ virsh --connect qemu:///system
$ virsh --connect qemu:///system command
$ virsh --connect qemu:///system list --all
Step 2: Verify kvm installation on Debain
$ egrep --color 'vmx|svm' /proc/cpuinfo
I am going to create bridge Interface br0 as the network connection in VM guests configuration for eth0 interface:
$ sudo vi /etc/network/interfaces.d/br0
Append the following:
## make sure all config related to eth0 deleted ##
auto br0
iface br0 inet static
address 192.168.2.23
broadcast 192.168.2.255
netmask 255.255.255.0
gateway 192.168.2.254
bridge_ports eth0
bridge_stp off # disable Spanning Tree Protocol
bridge_waitport 0 # no delay before a port becomes available
bridge_fd 0 # no forwarding delay
|
|
$ sudo systemctl restart network-manager
To see current networking setting for KVM, run:
$ sudo virsh net-list --all
Sample outputs:
Name State Autostart Persistent
----------------------------------------------------------
default inactive no yes
|
You need to configure a KVM guest domain on a bridged network. So create a file named bridge.xml as follows a text editor such as NA command:
$ sudo vi /root/bridged.xml
<network>
<name>br0</name>
<forward mode="bridge"/>
<bridge name="br0"/>
</network>
|
Save and close the file in vi/vim.
$ sudo virsh net-define --file /root/bridged.xml
$ sudo virsh net-autostart br0
$ sudo virsh net-start br0
Step 4: Use virt-builder to create VM
$ virt-builder --list | more
opensuse-13.1 x86_64 openSUSE 13.1
opensuse-13.2 x86_64 openSUSE 13.2
opensuse-42.1 x86_64 openSUSE Leap 42.1
opensuse-tumbleweed x86_64 openSUSE Tumbleweed
centos-6 x86_64 CentOS 6.6
centos-7.0 x86_64 CentOS 7.0
centos-7.1 x86_64 CentOS 7.1
centos-7.2 x86_64 CentOS 7.2
centos-7.3 x86_64 CentOS 7.3
centos-7.4 x86_64 CentOS 7.4
cirros-0.3.1 x86_64 CirrOS 0.3.1
cirros-0.3.5 x86_64 CirrOS 0.3.5
debian-6 x86_64 Debian 6 (Squeeze)
debian-7 x86_64 Debian 7 (wheezy)
debian-8 x86_64 Debian 8 (jessie)
debian-9 x86_64 Debian 9 (stretch)
fedora-18 x86_64 Fedora® 18
fedora-19 x86_64 Fedora® 19
fedora-20 x86_64 Fedora® 20
fedora-21 x86_64 Fedora® 21 Server
fedora-22 x86_64 Fedora® 22 Server
fedora-23 x86_64 Fedora® 23 Server
fedora-24 x86_64 Fedora® 24 Server
fedora-25 x86_64 Fedora® 25 Server
fedora-26 x86_64 Fedora® 26 Server
fedora-27 x86_64 Fedora® 27 Server
freebsd-11.1 x86_64 FreeBSD 11.1
scientificlinux-6 x86_64 Scientific Linux 6.5
ubuntu-10.04 x86_64 Ubuntu 10.04 (Lucid)
ubuntu-12.04 x86_64 Ubuntu 12.04 (Precise)
ubuntu-14.04 x86_64 Ubuntu 14.04 (Trusty)
ubuntu-16.04 x86_64 Ubuntu 16.04 (Xenial)
|
_64 arch based VMs:
$ virt-builder --list | grep x86_64
Create Debian 9.x VM
Create Debian 9 VM with 10GB disk space, 2GB ram, 2 vCPU and random password for root account, run:
$ sudo virt-builder debian-9 \
--size=10G \
--format qcow2 -o /var/lib/libvirt/images/debian9-vm1.qcow2 \
--hostname debain9-vm1 \
--network \
--timezone Asia/Kolkata
Finally import image with virt-install command:
$ sudo virt-install --import --name debian9-vm1 \
--ram 2048 \
--vcpu 2 \
--disk path=/var/lib/libvirt/images/debian9-vm1.qcow2,format=qcow2 \
--os-variant debian9 \
--network=bridge=br0,model=virtio \
--noautoconsole
Sample outputs:
Starting install...
Creating domain...
Domain creation completed.
You can login to your VM using x0E4iZ8sHjA6ekb6 password for root account:
$ sudo virsh list --all
$ virsh console debian9-vm1
Useful commands
Let us see some useful commands.
Find the list of the accepted OS variants
$ osinfo-query os | less
$ osinfo-query os | grep debian
$ osinfo-query os | grep freebsd
List a running vms/domains
$ sudo virsh list
Shutodwn a vm/domain called debian9-vm1
$ sudo virsh shutdown debian9-vm1
Start a vm/domain called debian9-vm1
$ sudo virsh start debian9-vm1
Suspend a vm/domain called debian9-vm1
$ sudo virsh suspend debian9-vm1
Reboot (soft & safe reboot) a vm/domain called debian9-vm1
$ sudo virsh reboot debian9-vm1
Reset (hard reset/not safe) a vm/domain called debian9-vm1
$ sudo virsh reset debian9-vm1
Delete/remove a vm/domain called debian9-vm1
Grate post!!
ReplyDelete