Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- make_kvm_virtual_machine_now_from_ubuntu_com ()
- {
- # Description: Function to create a KVM virtual michine disk and define a VM. This function should be
- # used on a Qemu/KVM virtual host that the virtual guest is to be used on.
- # NOTE: QCOW2 is a storage format for virtual machine disk images.
- # QCOW stands for QEMU copy on write. The QCOW2 format decouples the physical storage
- # layer from the virtual layer by adding a mapping between logical and physical blocks.
- # NOTE2: Kernel-based Virtual Machine (KVM) is an open source virtualization technology built into Linuxยฎ.
- # Specifically, KVM lets you turn Linux into a hypervisor that allows a host machine to run multiple,
- # isolated virtual environments called guests or virtual machines (VMs). KVM is part of Linux.
- # For complete info: https://www.redhat.com/en/topics/virtualization/what-is-KVM
- #
- # Usage: Either simply call this function to use the defaults or:
- # Call this function with "function" "RAM_SIZE" "DISK_SIZE" "DISK_FORMAT" "DISK_FILE"
- # Omitting any of the arguments will us the default instead.
- #
- # Globals:
- # Arguments: None
- # Outputs:
- # Returns:
- # Usage:
- # Example:
- #
- # make_kvm_virtual_machine_now_from_ubuntu_com kubuntu
- #
- # If complete flexibility is needed simply use the virt-install binary and directly write the arguments.
- # Alternatively; edit the function with new defaults that suit the needs.
- # End of Documentation
- ubuntu_flavor="${1}"
- count=1
- for i in qemu-utils qemu-tools qemu-kvm qemu-system-x86 virt-install wget
- do
- write_status "๐งฉ ${count} - Verifying dependencies ( ${i} )..."
- check_dependencies ${i} &>/dev/null
- count=$((count + 1))
- done
- write_information "๐ Retreive list of available $ubuntu_flavor versions..."
- case "$ubuntu_flavor" in
- ubuntu)
- declare -a all_lts_versions=($(wget -O- releases.ubuntu.com -q | perl -ne '/Ubuntu (\d+.\d+.\d+)/ && print "$1\n"' | sort -Vu))
- dist_logo="$ubuntulogo"
- ;;
- kubuntu)
- declare -a all_lts_versions=($(wget -O- cdimage.ubuntu.com/kubuntu/releases -q | perl -ne '/ (\d+.\d+.\d+)/ && print "$1\n"' | sort -Vu))
- dist_logo="$kubuntulogo"
- ;;
- *)
- declare -a all_ubuntu_lts_versions=($(wget -O- releases.ubuntu.com -q | perl -ne '/Ubuntu (\d+.\d+.\d+)/ && print "$1\n"' | sort -Vu))
- dist_logo="$ubuntulogo"
- ;;
- esac
- tgt_ubuntu_ver=$($RTD_GUI --colors --title "Select Release Version of $ubuntu_flavor " --inputbox "\n ๐ Please pick an available \Z1 $ubuntu_flavor \Zn version by entering it below.
- Long Term Support Versions to choose from are the following:\Z4 ${all_lts_versions[*]} \Zn You may also enter an inbetween release version
- by typing its release number below as well. If you are not sure just let me choose intelligently for you... \n \Z1 ${dist_logo} \Zn" 30 90 "${all_lts_versions[-1]}" 3>&1 1>&2 2>&3)
- case $? in
- "$DIALOG_CANCEL") return ;;
- "$DIALOG_ESC") return ;;
- esac
- clear
- [ "$tgt_ubuntu_ver" ] || tgt_ubuntu_ver=${all_lts_versions[-1]}
- # Detect and set variables for key programs
- : ${bin_virt_install:=$(type -p virt-install)}
- : ${virt_net="$(if ls /sys/class/net |grep br |grep -v virbr >/dev/null; then echo "bridge:$(ls /sys/class/net)" |grep br ; else echo default;fi)"}
- : ${ubuntu_iso_url=$(rtd_oem_find_live_release $tgt_ubuntu_ver $ubuntu_flavor live)}
- : ${iso_filename:="$(basename $ubuntu_iso_url)"}
- : ${permanent_download_dir:="/var/lib/libvirt/boot/"}
- write_status "Checking if $iso_filename already downloaded..."
- iso=$(find "$permanent_download_dir" -name "$iso_filename")
- if [ ! -e "$iso" ]; then
- write_warning "$iso_filename is not in cache, downloading..."
- wget -nc $ubuntu_iso_url -P "$permanent_download_dir" || read -p "Failure to download ISO file"
- iso="$permanent_download_dir/$iso_filename"
- fi
- _summary_message="The virtual machine (VDI_${CONFIG}-${tgt_ubuntu_ver}-${RANDOM}) \n
- ๐ - Using the instructions in PRESEED: ${PRESEED_FILE} \n
- ๐ง - And Using this source for the packages and files to download: \n
- ๐ - ${ubuntu_iso_url} \n
- ๐ - ${iso} \n
- โ - Using the network: ${virt_net} \n
- โ - Memory: ${3:-2048} \n
- โ - CPU's: ${2:-2} \n
- โ - Disk Size: ${4:-40} \n You may attach to this server and see the progress at IP: $(hostname -I))"
- "${bin_virt_install}" --name VDI_${CONFIG}-${tgt_ubuntu_ver}-${RANDOM} \
- --vcpus "${2:-2}" \
- --memory "${3:-2048}" \
- --network "${virt_net}" \
- --disk size="${4:-30}" \
- --os-variant="ubuntu21.10" \
- --video "virtio" --channel "spicevmc" \
- --location="${iso},kernel=casper/vmlinuz,initrd=casper/initrd" \
- --extra-args="ks=file:$(basename $PRESEED_FILE) auto=true priority=critical debian-installer/locale=en_US keyboard-configuration/layoutcode=us \
- netcfg/get_hostname=${CONFIG}${tgt_ubuntu_ver} console-setup/ask_detect=false ubiquity/reboot=true languagechooser/language-name=English countrychooser/shortlist=US \
- localechooser/supported-locales=en_US.UTF-8 ubiquity/use_nonfree=true boot=casper automatic-ubiquity splash noprompt " \
- --initrd-inject="$PRESEED_FILE" \
- --initrd-inject="$( dirname ${PRESEED_FILE})/ks.cfg" \
- --noautoconsole && $RTD_GUI --backtitle "$BRANDING" --title "NOTICE!" --msgbox "${_summary_message}" 0 0 \
- || ( read -p "๐ฅ - An ERROR has occurred. Please press [ENTER] to continue..." && return 1 )
- for i in PRESEED_FILE vm_kernel vm_initrd source_url CONFIG tgt_ubuntu_ver ubuntu_iso_url iso_filename ; do unset $i ; done
- # extra args: quiet noshell
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement