Category: Virtualization

  • How to connect to lxd container

    How to connect to lxd container

    lxd is an easy-to-use command-line interface for lxc (Linux container). In this blog post, I will show how to create an lxd container and connect to it.

    To create an lxd container, run

    lxc launch ubuntu:20.04 vm-1
    

    Here vm-1 is the name of the container. ubuntu:20.04 tells lxc to create a new container with Ubuntu version 20.04.

    To see the list of containers, you can use the command

    lxc ls
    

    list lxd containers

    This list IP address of the containers. If you have openssh-server installed and have a user name and password or SSH key set, you can login using the IP address.

    If you just created the container, you don’t have any login, then you can use the command

    lxc shell CONTAINER_NAME
    

    connect to lxd container with lxc shell command

    Another way is to use lxc exec

    lxc exec CONTAINER_NAME bash
    

    Example

    root@instance-20210627-0830:~# lxc exec vm-1 bash
    root@vm-1:~#
    

    If you have a login, then you can use the command

    lxc console CONTAINER_NAME
    

    This command will give you access to the console of the container.

    See lxd

  • libvirt qemu unexpectedly closed the monitor Failed to create chardev

    On CentOS 7 server, after installing KVM, i connected to server using Virt Manager. During VM creation, i get following error

    libvirt.libvirtError: internal error: qemu unexpectedly closed the monitor: 2021-02-01T18:09:38.214356Z qemu-kvm: -chardev pty,id=charserial0: Failed to create chardev

    To fix this, edit file

    vi /etc/fstab
    

    Find

    devpts          /dev/pts        devpts  defaults	    	0       0
    

    Replace with

    devpts          /dev/pts        devpts  gid=5,mode=620	0       0
    

    Reboot the server. After reboot, VM creation will work properly.

    See KVM

  • Install Linux KVM on CentOS 7

    Install kvm with

    yum install -y qemu-kvm
    

    Install libvirt, this is used to manage KVM virtual machines.

    yum install -y libvirt-daemon-kvm libvirt-client
    

    Enable libvirtd to start on boot

    systemctl enable libvirtd
    

    Start libvirtd

    systemctl start libvirtd
    

    To see status, run

    systemctl status libvirtd
    

    centos 7 kvm libvirtd status

    Install virt-install

    yum install virt-install
    

    Now you have Linux KVM installed. You can use virt-install or Virt Manager to create virtual machine.

    When i create a Virtual Machine on CentOS 7, i get error reated to Failed to create chardev. If you get this error, click here for solution.

    See KVM

  • Download OS Templates Virtualizor

    To create a Virtal Machine (VPS) on Virtualizor, you need OS Template. You can use pre-made OS templates or make your own OS template. You can see list of pre-made OS templates provided by Virtualizor at

    https://virtualizor.com/ostemplates

    To download an OS Template, login to Virtualizor, from left side menu, click on

    Media > Template Browser
    

    Click the check boxe right side of the OS Template you need to download. Once you selected all OS Templates you need, scroll down, click “Save Settins” button.

    Download OS Templates in Virtualizor

    See Virtualizor

  • Virtualizor Error No Gateway Found, Please assign a Gateway

    On a Virtualizor server, when starting virtnetwork, i get the following error

    [root@virtual2 ~]# service virtnetwork start
    Error: No Gateway Found, Please assign a Gateway.
    [root@virtual2 ~]# 

    This is because the network interface configuration doesn’t have GATEWAY defined. Find your network interface name with the command

    ip link

    Now check the configuration file for your network interface.

    On this server, I had following configuration

    [root@virtual2 ~]# cat  /etc/sysconfig/network-scripts/ifcfg-enp4s0 
    ### Hetzner Online GmbH installimage
    
    DEVICE=enp4s0
    ONBOOT=yes
    BOOTPROTO=none
    IPADDR=94.130.65.163
    PREFIX=32
    SCOPE="peer 94.130.65.129"
    DEFROUTE=yes
    
    IPV6INIT=yes
    IPV6ADDR=2a01:4f8:10b:2f1c::2/64
    IPV6_DEFAULTGW=fe80::1
    IPV6_DEFROUTE=yes
    IPV6_DEFAULTDEV=enp4s0
    [root@virtual2 ~]# 

    You need to find the gateway used by your server, this can be done with the command

    ip route

    On this server, I have

    [root@virtual2 ~]# ip route
    default via 94.130.65.129 dev enp4s0 
    94.130.65.129 dev enp4s0 proto kernel scope link src 94.130.65.163 
    169.254.0.0/16 dev enp4s0 scope link metric 1002 
    188.40.210.0/24 dev natbr3 proto kernel scope link src 188.40.210.32 
    [root@virtual2 ~]# 

    From above, the gateway used by the server is 94.130.65.129.

    Now edit the network interface configuration file

    vi /etc/sysconfig/network-scripts/ifcfg-enp4s0

    Find the line starting with

    IPADDR=

    Add below

    GATEWAY=YOUR_GATEWAY_IP_HERE

    In this case

    GATEWAY=94.130.65.129

    After this change restarting virtnetwork worked.

    [root@virtual2 ~]# service virtnetwork start
    Bringing up viifbr0 - OK
    Waiting for 10 seconds...1...2...3...4...5...6...7...8...9...10
    Internet connectivity check successful viifbr0 - OK
    [root@virtual2 ~]# 

    See Virtualizor

  • Virtualizor error fetching interface information

    When starting network in virtualizor server, i get following error

    [root@virtual2 ~]# service virtnetwork start
    eth0: error fetching interface information: Device not found
    Error: No ip address found.
    [root@virtual2 ~]# 
    

    To fix this error, find the network interface name with command

    [root@virtual2 ~]# ip link
    1: lo:  mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    2: enp4s0:  mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
        link/ether 34:97:f6:00:11:1f brd ff:ff:ff:ff:ff:ff
    3: natbr3:  mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default qlen 1000
        link/ether 52:54:00:d9:3c:1c brd ff:ff:ff:ff:ff:ff
    4: natbr3-nic:  mtu 1500 qdisc pfifo_fast master natbr3 state DOWN mode DEFAULT group default qlen 1000
        link/ether 52:54:00:d9:3c:1c brd ff:ff:ff:ff:ff:ff
    [root@virtual2 ~]# 
    

    In this case, the name is enp4s0, we need to add this name in

    Virtualizor Admin > Configuration > Master or Slave Settings > Network Settings > Network Interface

    Virtualizor Network Interface

    If you have master and slave severs, you need to select master or slave depending on where you get this error. If slave, there is a drop down, you need to select the correct server, then set the interface name.

    See Virtualizor

  • Copy a file from host into LXD container

    To copy file from host machine to LXD container run

    lxc file push FILE_NAME CONTAINER_NAME/FOLDER/

    Example

    lxc file push ant-media-server-enterprise-2.2.1-20201029_2042.zip centos8/root/
    lxc file copy

    To copy a file from the host machine to an lxd container, run

    lxc file push FILE_NAME CONTAINER_NAME/path/to/folder/
    copy file to lxd container

    To copy a file from LXD container to the local machine, run

    lxc file pull first-vm/root/2.txt .

    If you need to copy a folder and files inside, you can use option –recursive

    See LXD

  • Virtualizor list all vms from command line

    Virtualizor use libvirt to manage virtualmachines.

    To list all virtual machines in a server, login to server using SSH as root.

    run

    virsh list
    

    virtualizor virsh list

    See Virtualizor

  • Auto Start KVM Virtual Machine

    To auto start a KVM Virtual Machine on boot time, use command

    virsh autostart VMNAME_HERE
    

    To disable a VM from auto starting, run

    virsh autostart VMNAME_HERE --disable
    

    kvm virtual machine autostart

    See KVM

  • Proxmox VE Access Console of LXC Container

    To access console of a LXC container running under Proxmox, run

    pct enter CT_ID_HERE
    

    Example

    pct enter 106
    

    You don’t need to enter password, you will be logged in as user root.

    See proxmox

  • Proxmox take snapshot of Virtual Machine

    Proxmox take snapshot of Virtual Machine

    To take snapshot of virtual machine in proxmox, click on Virtual Machine, under Snapshots, clikc “Take Snapshot” button.

    proxmox snapshot

    To create snapshot through command line, login to Proxmox server as user root, then run

    qm snapshot VMID nameOfSnapShot
    

    nameOfSnapShot = no space or special chars allowed. Sould start/end with alphabet (numbers should NOT be used at start/end).

    proxmox  snapshot command

    See Proxmox

  • Proxmox pveperf

    pveperf is a command line benchmarking tool in proxmox server.

    root@server70:~# pveperf
    CPU BOGOMIPS:      59199.84
    REGEX/SECOND:      3672349
    HD SIZE:           38.32 GB (/dev/md2)
    BUFFERED READS:    79.99 MB/sec
    AVERAGE SEEK TIME: 8.39 ms
    FSYNCS/SECOND:     23.87
    DNS EXT:           16.46 ms
    DNS INT:           19.34 ms (hostonnet.com)
    root@server70:~# 
    

    Here is benchmark on another server – Intel(R) Core(TM) i7-3930K CPU @ 3.20GHz, 2 * 120 GB SSD ATA OCZ-VERTEX3

    root@Proxmox-VE ~ # pveperf
    CPU BOGOMIPS:      76805.76
    REGEX/SECOND:      1126262
    HD SIZE:           14.70 GB (/dev/mapper/vg0-root)
    BUFFERED READS:    321.65 MB/sec
    AVERAGE SEEK TIME: 0.20 ms
    FSYNCS/SECOND:     1026.63
    DNS EXT:           14.69 ms
    root@Proxmox-VE ~ #