Deleting a KVM virtual machine using “virsh” is a multi-step process. You need to stop the virtual machine, find the storage device used by them VM, and remove the storage devices. Then undefine the virtual machine.
Here are the commands used to delete a KVM VM with the name win10.
First shutdown the VM
virsh shutdown win10
If it did not stop, you can force stop with the command
virsh destroy win10
Find information about the VM with the command “virsh dumpxml –domain VM_NAME”
I have a KVM virtual machine running Windows, and when I try to shutdown, it never stopped.
root@sok:~# virsh list
Id Name State
--------------------------
1 iredmail running
3 win10 running
root@sok:~# virsh shutdown win10
Domain win10 is being shutdown
root@sok:~# virsh list
Id Name State
--------------------------
1 iredmail running
3 win10 running
root@sok:~#
To force shutdown a KVM virtual machine using virsh, you can use the command
virsh destroy VM_NAME
Example
root@sok:~# virsh destroy win10
Domain win10 destroyed
root@sok:~# virsh list
Id Name State
--------------------------
1 iredmail running
root@sok:~# virsh start win10
Domain win10 started
root@sok:~# virsh list
Id Name State
--------------------------
1 iredmail running
4 win10 running
root@sok:~#
On Ubuntu 20.04 server we have the following network configuration
root@mail:~# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether d8:cb:8a:e3:c7:c9 brd ff:ff:ff:ff:ff:ff
inet 37.157.249.137/32 scope global enp2s0
valid_lft forever preferred_lft forever
inet6 fe80::dacb:8aff:fee3:c7c9/64 scope link
valid_lft forever preferred_lft forever
root@mail:~#
“netplan get all” command show following
netplan config file has the following
root@mail:~# cat /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
enp2s0:
addresses: [ 37.157.249.137/32 ]
nameservers:
search: [ venus.dedi.server-hosting.expert ]
addresses:
- "8.8.8.8"
- "1.1.1.1"
routes:
- to: 0.0.0.0/0
via: 37.157.249.129
on-link: true
root@mail:~#
Before you can use bridge in netplan, you need to install bridge-utils
apt-get install bridge-utils
To configure bridge networking, modify the file as follows
network:
version: 2
renderer: networkd
ethernets:
enp2s0:
dhcp4: no
dhcp6: no
bridges:
br0:
dhcp4: no
dhcp6: no
interfaces: [enp2s0]
addresses: [ 37.157.249.137/32 ]
nameservers:
addresses:
- "8.8.8.8"
- "1.1.1.1"
routes:
- to: 0.0.0.0/0
via: 37.157.249.129
on-link: true
To check if there is any error in netplan configuration, run
LXC containers get dynamic IP from DHCP. When you stop and start a container, its IP gets changed. If you hosting some web application on this container, you need to point the application to new IP. To avoid this, you can configure static IP on the container.
LXC containers get IP in the range 10.0.3.2-255. To make CentOS container IP static, edit file
On a Debian server, I installed lxc, but when I create a container, it is missing IP address. When I did “lxc-attack VM_NAME”, and checked the network interface with “ip link” command, i can only see the loopback interface “lo”.
On Host machine, when I checked network interfaces, lxcbr0 was missing. To fix this, edit file
vi /etc/default/lxc
Find
USE_LXC_BRIDGE="false"
Replace with
USE_LXC_BRIDGE="true"
Now restart lxc-net service
systemctl restart lxc-net
At this point, you will see the network interface “lxcbr0”.
root@b24:~# brctl show
bridge name bridge id STP enabled interfaces
br-52702762660a 8000.024201845e4b no
docker0 8000.0242ee9122d8 no
lxcbr0 8000.00163e000000 no vethDED0EK
lxdbr0 8000.00163e7d81a2 no
root@b24:~#
root@b24:~# lxc storage list
+---------+--------+--------------------------------------------+-------------+---------+
| NAME | DRIVER | SOURCE | DESCRIPTION | USED BY |
+---------+--------+--------------------------------------------+-------------+---------+
| default | btrfs | /var/snap/lxd/common/lxd/disks/default.img | | 7 |
+---------+--------+--------------------------------------------+-------------+---------+
root@b24:~#
In this installation, we use btrfs file system for storing containers. The file location is /var/snap/lxd/common/lxd/disks/default.img. It is used by 7 containers.