08 Virtualization with SUSE


  • .

Virtualization is a technology that allows multiple operating systems to run simultaneously on a single physical hardware by utilizing a hypervisor.

  • KVM (Kernel-based Virtual Machine): A kernel-based hypervisor for Linux that leverages hardware virtualization capabilities like Intel VT-x and AMD-V.

  • Xen: An open-source hypervisor that supports full virtualization and paravirtualization.

Using KVM on SUSE

KVM Requirements

  1. Make sure the CPU supports hardware virtualization:

    egrep -c '(vmx|svm)' /proc/cpuinfo
    • A result greater than 0 indicates support for virtualization.
  2. Ensure virtualization is enabled in BIOS/UEFI.

Installing KVM

  1. Install KVM packages:

    sudo zypper install qemu-kvm libvirt virt-manager
  2. Enable and start the libvirt service:

    sudo systemctl enable libvirtd
    sudo systemctl start libvirtd

Creating a VM with KVM

Use virt-manager or the CLI command:

virt-install \
 --name vm_name \
 --ram 2048 \
 --vcpus 2 \
 --disk path=/var/lib/libvirt/images/vm_name.qcow2,size=20 \
 --os-type linux \
 --os-variant ubuntu20.04 \
 --cdrom /path/to/iso

Managing Virtual Machines (VMs) with libvirt and virt-manager

Libvirt is a library and toolset for managing hypervisors such as KVM and Xen. The main CLI tool is virsh.

Basic virsh Commands

  1. List all VMs:

    virsh list –all
  2. Start a VM:

    virsh start vm_name
  3. Shut down a VM:

    virsh shutdown vm_name
  4. Remove a VM:

    virsh undefine vm_name
  5. View VM information:

    virsh dominfo vm_name

Using virt-manager

Virt-manager is a GUI tool for managing VMs.

  1. Run virt-manager:

    virt-manager
  2. Main features:

    • Create, delete, and manage VMs.

    • View VM consoles.

    • Configure resources like CPU, RAM, and networking.

Using Containers with Docker on SUSE

Docker is a containerization platform that allows applications to run in isolated environments.

Installing Docker on SUSE

  1. Add the repositori Docker:

    sudo zypper addrepo https://download.docker.com/linux/sles/docker-ce.repo
  2. Install Docker:

    sudo zypper install docker-ce
  3. Enable and start the Docker service:

    sudo systemctl enable docker
    sudo systemctl start docker
  4. Verify the installation:

    docker –version

Basic Docker Commands

  1. Run a container:

    docker run -d -p 80:80 nginx
    • Runs an Nginx server in the background on port 80.
  2. View running containers:

    docker ps
  3. Stop a container:

    docker stop container_id
  4. Remove a container:

    docker rm container_id
  5. Download an image:

    docker pull image_name
  6. Build an image from a Dockerfile:

    docker build -t image_name .

Docker Compose

Docker Compose is a tool for managing multi-container applications.

  1. Install Docker Compose:

    sudo zypper install docker-compose
  2. Example docker-compose.yml file:

    version: '3'
    services:
      web:
        image: nginx
        ports:
          - "80:80"
      db:
        image: mysql
        environment:
          MYSQL_ROOT_PASSWORD: password
  3. Run the application:

    docker-compose up -d