Skip to content

Instantly share code, notes, and snippets.

@oBuTr471b
Created November 11, 2020 02:51
Show Gist options
  • Save oBuTr471b/ec248646a0d510f935af3098b22781d5 to your computer and use it in GitHub Desktop.
Save oBuTr471b/ec248646a0d510f935af3098b22781d5 to your computer and use it in GitHub Desktop.
# In The Name Of Allah .
# -- --- ---- -- ----- -
# Sun Nov 8 08:29:08 2020
# Written By : zer0err0r .
# ======= == = ========= =
# 6, Creating VMs with pools .
# First, Create a VM volume .
$ virsh vol-create-as my_pool centos1.raw 10G --format raw # raw, pool .
$ virsh vol-create-as my_pool centos1.qcow2 10G --format qcow2 # qcow2, pool .
$ virsh vol-info --pool my_pool centos1
= [virsh] only, No [dd] or [qemu-img] .
# Then, Create the VM .
$ virt-install \
--name centos1 \
--vcpus=1 \
--ram=1024 \
--network bridge:br0 \
--disk "vol=my_pool/centos1.qcow2" \
--graphics none \
--location /home/zer0err0r/centos7.iso \
--extra-args="console=tty0 console=ttyS0,115200" \
--os-variant centos7.0 \
#################################################################################
# The bash script .
#!/bin/bash
# Defining variables .
# Bash by default doesnt support [~/.bashrc] aliases inside scripts .
virsh='virsh --connect qemu:///system'
# [-] isnt supported as a variable name character in bash .
virt_install='virt-install --connect qemu:///system'
vm_name=centos1
# Creating the VM v_disk :
$virsh vol-create-as my_pool $vm_name.qcow2 10G --format qcow2
# Creating the VM .
# Dont write comments after the backslash[\] .
# Use double_quotes to enable variable expansion .
$virt_install \
--name $vm_name \
--vcpus=1 \
--ram=1024 \
--network bridge:br0 \
--disk "vol=my_pool/$vm_name.qcow2" \
--graphics none \
--location /home/zer0err0r/centos7.iso \
--extra-args="console=tty0 console=ttyS0,115200" \
--os-variant centos7.0
# ===== == ==== ======== =
# Peace Be Up0n Muhammed .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment