Skip to content

uvewexyz/virtui

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 

Repository files navigation

Descriptions and Supports

This script is used for creating a VM based on libvirtd. Your system will be checked for availability for running virtualization with the following prompts:

  • Checking the compatibility system for serving virtualization
  • Checking and installing the libvirtd dependency packages
  • Checking the compatibility of your system with nested virtualization
  • Make sure the 'workdir' directory is ready

After checking is finished, then you must fill out several questions below:

  • Give a name for your VM
  • How much memory
  • Allocate several cores of CPU
  • Select a base image and OS
  • Create a primary disk for the VM
  • Determine many peripheral disks for the VM
  • Select a virtual network
  • Specify IPv4 for the VM
  • Configure a user, password, and key to access your VM
  • Validate if the VM is successfully created or not

Attention please, this script currently only supports running on the Ubuntu base system. Next to do:

  • Ubuntu 20 or later
  • Debian
  • Rhel
  • CentOS
  • Alpine

Prerequisites

Don't worry if you are running this script. Your system will install the following dependency packages while running this script:

  1. cpu-checker
  2. ipcalc
  3. whois
  4. qemu-system
  5. libvirt-daemon-system
  6. virtinst
  7. libosinfo-bin

Tips and Tricks

  1. If you want to running this script rootless. You must uncomment the #unix_sock_group = "libvirt" parameter in the /etc/libvirt/libvirtd.conf file
sed -i 's/^#unix_sock_group = "libvirt"/unix_sock_group = "libvirt"/g' /etc/libvirt/libvirtd.conf
  1. Suppose you encounter a problem like this
image

The solutions is add the uri_default = "qemu:///system" parameter in the .config/libvirt/libvirt.conf file and allow all permissions to the libvirt-sock file. Here is the reference

cat << EOF > .config/libvirt/libvirt.conf
uri_default = "qemu:///system"
EOF
sudo chmod 777 /var/run/libvirt/libvirt-sock
  1. Here is the example xml if you don't have a virtual network. You can customize as you wish. Click this reference
<network>
  <name>default</name>
  <bridge name='virbr0'/>
  <forward/>
  <ip address='192.168.1.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.1.2' end='192.168.1.254'/>
    </dhcp>
  </ip>
</network>
  1. Allow all permissions and change owner the workdir and images directory to avoid script can't cloning base image.
  • The reasons is on bellow line in script
qemu-img create -q -b "${src_dir}/${src_img}" -f qcow2 -F qcow2 "${dst_path}" "${vm_disk1_size}"G
  • This is way to allow all permissions to workdir and images directory
sudo chmod -R 777 /var/lib/libvirt/workdir/
sudo chmod -R 777 /var/lib/libvirt/images/
  • This is way to change owner the workdir and images directory
sudo chown -R libvirt-qemu:kvm /var/lib/libvirt/workdir/
sudo chown -R libvirt-qemu:kvm /var/lib/libvirt/images/
  1. Clone this repository
git clone https://github.com/uvewexyz/create-vm-automatically.git
  1. Give the execute permissions to the virtui.sh script
cd ~/create-vm-automatically
chmod +x virtui.sh && ls -l virtui.sh
  1. Before running the virtui.sh script. These are recommended OS image, if you want to install. Follow bellowing step by step:
  • Move the current/working directory
cd /var/lib/libvirt/workdir/
  • Installing almalinux9 image
wget https://repo.almalinux.org/almalinux/9/cloud/x86_64/images/AlmaLinux-9-GenericCloud-latest.x86_64.qcow2
  • Installing centos-stream9 image
wget https://cloud.centos.org/altarch/9-stream/x86_64/images/CentOS-Stream-GenericCloud-9-latest.x86_64.qcow2
  • Installing alpine-virt-3.21 image
wget https://dl-cdn.alpinelinux.org/alpine/v3.21/releases/x86_64/alpine-virt-3.21.3-x86_64.iso
qemu-img convert -f raw -O qcow2 alpine-virt-3.21.3-x86_64.iso alpine-virt-3.21.3-x86_64.qcow2
  • Installing ubuntu22.04 image
wget https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img
  • Installing ubuntu20.04 image
wget https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img
  • Installing, extract, and convert extension to qcow2 the openwrt image
wget https://downloads.openwrt.org/releases/24.10.1/targets/x86/generic/openwrt-24.10.1-x86-generic-generic-ext4-combined.img.gz
gunzip openwrt-24.10.1-x86-generic-generic-ext4-combined.img.gz
qemu-img convert -f raw -O qcow2 openwrt-24.10.1-x86-generic-generic-ext4-combined.img openwrt-24.10.1-x86-generic-generic-ext4-combined.qcow2
  1. Run the script bellow in this way
./virtui.sh
  1. Easily to create or change user password, run the command in bellow
echo "user1:Str0ngPass!" | chpasswd
  1. Demonstration

virtui_demo virtui_demo_access

Legends Color information's

Legend Colour
INFO $\textsf{\color{lightblue}Blue}$
SUCCESS $\textsf{\color{lightgreen}Green}$
FAIL $\textsf{\color{red}Red}$
TIPS $\textsf{\color{yellow}Yellow}$

Reference

About

To create a VM automatically, you can use this script to do so. I used this script in a QEMU/KVM environment.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages