All Projects → giovtorres → Kvm Install Vm

giovtorres / Kvm Install Vm

Licence: mit
Bash script to build local virtual machines using KVM/libvirt and cloud-init.

Programming Languages

shell
77523 projects

Projects that are alternatives of or similar to Kvm Install Vm

Robox
The tools needed to robotically create/configure/provision a large number of operating systems, for a variety of hypervisors, using packer.
Stars: ✭ 303 (+22.18%)
Mutual labels:  ubuntu, debian, centos, fedora, libvirt
Ansible Role Firewall
Ansible Role - iptables Firewall configuration.
Stars: ✭ 343 (+38.31%)
Mutual labels:  ubuntu, debian, centos, fedora
Anlinux Resources
Image and Script for LinuxOnAndroid App
Stars: ✭ 135 (-45.56%)
Mutual labels:  ubuntu, debian, centos, fedora
Anlinux App
AnLinux allow you to run Linux on Android without root access.
Stars: ✭ 614 (+147.58%)
Mutual labels:  ubuntu, debian, centos, fedora
Openvpn Install
OpenVPN road warrior installer for Ubuntu, Debian, AlmaLinux, Rocky Linux, CentOS and Fedora
Stars: ✭ 14,199 (+5625.4%)
Mutual labels:  ubuntu, debian, centos, fedora
Ansible Role Apache
Ansible Role - Apache 2.x.
Stars: ✭ 341 (+37.5%)
Mutual labels:  ubuntu, debian, centos, fedora
Open Build Service
Build and distribute Linux packages from sources in an automatic, consistent and reproducible way #obs
Stars: ✭ 599 (+141.53%)
Mutual labels:  ubuntu, debian, centos, fedora
packer-kvm
Create VM templates with Packer for usage with Libvirt/KVM virtualization : CentOS 7, CentOS 8, CentOS 8 Stream, Alma Linux, Rocky Linux, Bionic (Ubuntu 1804), Focal (Ubuntu 2004), Debian 11 (stable), Kali Linux, Fedora 33 and Fedora 34.
Stars: ✭ 99 (-60.08%)
Mutual labels:  debian, fedora, centos, kvm
Wireguard Install
WireGuard road warrior installer for Ubuntu, Debian, CentOS and Fedora
Stars: ✭ 650 (+162.1%)
Mutual labels:  ubuntu, debian, centos, fedora
Openvpn Install
Set up your own OpenVPN server on Debian, Ubuntu, Fedora, CentOS or Arch Linux.
Stars: ✭ 7,142 (+2779.84%)
Mutual labels:  ubuntu, debian, centos, fedora
Fpm Within Docker
Leverage fpm inside pre-baked docker images in order to build and test native DEB and RPM packages.
Stars: ✭ 80 (-67.74%)
Mutual labels:  ubuntu, debian, centos, fedora
darknet.py
darknet.py is a network application with no dependencies other than Python and Tor, useful to anonymize the traffic of linux servers and workstations.
Stars: ✭ 71 (-71.37%)
Mutual labels:  debian, ubuntu, fedora, centos
Terrible
An Ansible playbook that apply the principle of the Infrastructure as Code on a QEMU/KVM environment.
Stars: ✭ 161 (-35.08%)
Mutual labels:  ubuntu, debian, kvm, libvirt
Anlinux Adfree
AnLinux, Ad free version.
Stars: ✭ 127 (-48.79%)
Mutual labels:  ubuntu, debian, centos, fedora
ansible-role-daemonize
Ansible Role - Daemonize.
Stars: ✭ 14 (-94.35%)
Mutual labels:  debian, ubuntu, fedora, centos
Ansible Role Security
Ansible Role - Security
Stars: ✭ 398 (+60.48%)
Mutual labels:  ubuntu, debian, centos, fedora
Atilo
Linux installer for termux
Stars: ✭ 629 (+153.63%)
Mutual labels:  ubuntu, debian, centos, fedora
Vagrant Box Templates
Stars: ✭ 100 (-59.68%)
Mutual labels:  ubuntu, debian, centos, fedora
Postinstall
💻 Bash Script to automate post-installation steps
Stars: ✭ 104 (-58.06%)
Mutual labels:  ubuntu, debian, centos, fedora
Wslu
A collection of utilities for Windows 10 Linux Subsystems
Stars: ✭ 2,020 (+714.52%)
Mutual labels:  ubuntu, debian, centos

kvm-install-vm

A bash wrapper around virt-install to build virtual machines on a local KVM hypervisor. You can run it as a normal user which will use qemu:///session to connect locally to your KVM domains.

Tested on the latest Fedora.

Prerequisites

You need to have the KVM hypervisor installed, along with a few other packages (naming of packages can differ on other distributions):

  • genisoimage or mkisofs
  • virt-install
  • libguestfs-tools-c
  • qemu-img
  • libvirt-client
  • libosinfo

To install the dependencies, run:

  • Fedora example:
sudo dnf -y install genisoimage virt-install libguestfs-tools-c qemu-img libvirt-client wget libosinfo
  • Ubuntu example:
sudo apt install -y genisoimage virtinst libguestfs-tools qemu-utils libvirt-clients wget libosinfo-bin

If you want to resolve guests by their hostnames, install the libvirt-nss package:

  • Fedora example:
sudo dnf -y install libvirt-nss
  • Ubuntu example:
sudo apt install -y libnss-libvirt

Then, add libvirt and libvirt_guest to list of hosts databases in /etc/nsswitch.conf. See here for more information.

Usage

$ kvm-install-vm help
NAME
    kvm-install-vm - Install virtual guests using cloud-init on a local KVM
    hypervisor.

SYNOPSIS
    kvm-install-vm COMMAND [OPTIONS]

DESCRIPTION
    A bash wrapper around virt-install to build virtual machines on a local KVM
    hypervisor. You can run it as a normal user which will use qemu:///session
    to connect locally to your KVM domains.

COMMANDS
    help    - show this help or help for a subcommand
    create  - create a new guest domain
    list    - list all domains, running and stopped
    remove  - delete a guest domain

Creating Guest VMs

$ kvm-install-vm help create
NAME
    kvm-install-vm create [COMMANDS] [OPTIONS] VMNAME

DESCRIPTION
    Create a new guest domain.

COMMANDS
    help - show this help

OPTIONS
    -a          Autostart             (default: false)
    -b          Bridge                (default: virbr0)
    -c          Number of vCPUs       (default: 1)
    -d          Disk Size (GB)        (default: 10)
    -D          DNS Domain            (default: example.local)
    -f          CPU Model / Feature   (default: host)
    -g          Graphics type         (default: spice)
    -h          Display help
    -i          Custom QCOW2 Image
    -k          SSH Public Key        (default: $HOME/.ssh/id_rsa.pub)
    -l          Location of Images    (default: $HOME/virt/images)
    -L          Location of VMs       (default: $HOME/virt/vms)
    -m          Memory Size (MB)      (default: 1024)
    -M          Mac address           (default: auto-assigned)
    -p          Console port          (default: auto)
    -s          Custom shell script
    -t          Linux Distribution    (default: centos8)
    -T          Timezone              (default: US/Eastern)
    -u          Custom user           (default: $USER)
    -y          Assume yes to prompts (default: false)
    -n          Assume no to prompts  (default: false)
    -v          Be verbose

DISTRIBUTIONS
    NAME            DESCRIPTION                         LOGIN
    amazon2         Amazon Linux 2                      ec2-user
    centos8         CentOS 8                            centos
    centos7         CentOS 7                            centos
    centos7-atomic  CentOS 7 Atomic Host                centos
    centos6         CentOS 6                            centos
    debian9         Debian 9 (Stretch)                  debian
    debian10        Debian 10 (Buster)                  debian
    fedora29        Fedora 29                           fedora
    fedora29-atomic Fedora 29 Atomic Host               fedora
    fedora30        Fedora 30                           fedora
    fedora31        Fedora 31                           fedora
    fedora32        Fedora 32                           fedora
    opensuse15      OpenSUSE Leap 15.2                  opensuse
    ubuntu1604      Ubuntu 16.04 LTS (Xenial Xerus)     ubuntu
    ubuntu1804      Ubuntu 18.04 LTS (Bionic Beaver)    ubuntu
    ubuntu2004      Ubuntu 20.04 LTS (Focal Fossa)      ubuntu

EXAMPLES
    kvm-install-vm create foo
        Create VM with the default parameters: CentOS 8, 1 vCPU, 1GB RAM, 10GB
        disk capacity.

    kvm-install-vm create -c 2 -m 2048 -d 20 foo
        Create VM with custom parameters: 2 vCPUs, 2GB RAM, and 20GB disk
        capacity.

    kvm-install-vm create -t debian9 foo
        Create a Debian 9 VM with the default parameters.

    kvm-install-vm create -T UTC foo
        Create a default VM with UTC timezone.

Deleting a Guest Domain

$ kvm-install-vm help remove
NAME
    kvm-install-vm remove [COMMANDS] VMNAME

DESCRIPTION
    Destroys (stops) and undefines a guest domain.  This also remove the
    associated storage pool.

COMMANDS
    help - show this help

EXAMPLE
    kvm-install-vm remove foo
        Remove (destroy and undefine) a guest domain.  WARNING: This will
        delete the guest domain and any changes made inside it!

Attaching a new disk

$ kvm-install-vm help attach-disk
NAME
    kvm-install-vm attach-disk [OPTIONS] [COMMANDS] VMNAME

DESCRIPTION
    Attaches a new disk to a guest domain.

COMMANDS
    help - show this help

OPTIONS
    -d SIZE     Disk size (GB)
    -f FORMAT   Disk image format       (default: qcow2)
    -s IMAGE    Source of disk device
    -t TARGET   Disk device target

EXAMPLE
    kvm-install-vm attach-disk -d 10 -s example-5g.qcow2 -t vdb foo
        Attach a 10GB disk device named example-5g.qcow2 to the foo guest
        domain.

Setting Custom Defaults

Copy the .kivrc file to your $HOME directory to set custom defaults. This is convenient if you find yourself repeatedly setting the same options on the command line, like the distribution or the number of vCPUs.

Options are evaluated in the following order:

  • Default options set in the script
  • Custom options set in .kivrc
  • Option flags set on the command line

Notes

  1. This script will download a qcow2 cloud image from the respective distribution's download site. See script for URLs.

  2. If using libvirt-nss, keep in mind that DHCP leases take some time to expire, so if you create a VM, delete it, and recreate another VM with the same name in a short period of time, there will be two DHCP leases for the same host and its hostname will likely not resolve until the old lease expires.

  3. The Operating System information database (osinfo-db) provides Operating System specific information needed to create guests for the various systems supported by kvm-install-vm. The database files provided by your package manager may be out of date and not provide definitions for recent Operating System versions. If you encounter the following error message, you may need to update the database files: ERR: Unknown OS variant '<name>'. Please update your osinfo-db. If you have already updated your system, and the osinfo-db is still to old, then you can use the osinfo-db-import tool with the --local option, to install an up-to-date database in your home directory which will not conflict with your package manager files. The osinfo-db-import tool is provided by the rpm/deb packages osinfo-db-tools. See https://libosinfo.org/download for more information.

Testing

Tests are written using Bats. To execute the tests, run ./test.sh in the root directory of the project.

Use Cases

If you don't need to use Docker or Vagrant, don't want to make changes to a production machine, or just want to spin up one or more VMs locally to test things like:

  • high availability
  • clustering
  • package installs
  • preparing for exams
  • checking for system defaults
  • anything else you would do with a VM

...then this wrapper could be useful for you.

Troubleshooting

If you will encounter something similar:

ERR: Unknown OS variant 'fedora31'. Please update your osinfo-db.  See https://libosinfo.org/download for more information.

Then you need to update the DB in libosinfo. Check the url and select the latest date ( https://releases.pagure.org/libosinfo/ )

wget -O "/tmp/osinfo-db.tar.xz" https://releases.pagure.org/libosinfo/osinfo-db-20200515.tar.xz
sudo osinfo-db-import --local "/tmp/osinfo-db.tar.xz"
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].