Advertisement
vonschutter

Untitled

Jan 25th, 2023
789
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.66 KB | None | 0 0
  1. # Debian provides several sources that may be used to install software from including the operating system.
  2. # These sources will be used to build virtual machines from.
  3. export _DEBIAN_SOURCE_URL="http://ftp.us.debian.org/debian/dists/bullseye/main/installer-amd64/"
  4. export _DEBIAN_FRONTEND_GTK_KERNEL="${_DEBIAN_SOURCE_URL}/current/images/netboot/gtk/debian-installer/amd64/linux"
  5. export _DEBIAN_FRONTEND_GTK_INITRD="${_DEBIAN_SOURCE_URL}/current/images/netboot/gtk/debian-installer/amd64/initrd.gz"
  6. export _DEBIAN_FRONTEND_DEFAULT_KERNEL="${_DEBIAN_SOURCE_URL}/current/images/netboot/debian-installer/amd64/linux"
  7. export _DEBIAN_FRONTEND_DEFAULT_INITRD="${_DEBIAN_SOURCE_URL}/current/images/netboot/debian-installer/amd64/initrd.gz"
  8.  
  9.  
  10. make_kvm_virtual_machine_now_from_debian_org ()
  11. {
  12. # Description: Function to create a Debian KVM virtual michine disk and define a VM. This function should be
  13. # used on a Qemu/KVM virtual host that the virtual guest is to be used on.
  14. # NOTE: QCOW2 is a storage format for virtual .
  15. # machine disk images QCOW stands for QEMU copy on write. The QCOW2 format decouples the physical storage
  16. # layer from the virtual layer by adding a mapping between logical and physical blocks.
  17. # NOTE2: Kernel-based Virtual Machine (KVM) is an open source virtualization technology built into Linux®.
  18. # Specifically, KVM lets you turn Linux into a hypervisor that allows a host machine to run multiple,
  19. # isolated virtual environments called guests or virtual machines (VMs). KVM is part of Linux.
  20. # For complete info: https://www.redhat.com/en/topics/virtualization/what-is-KVM
  21. #
  22. # Use the check_dependencies function to make sure the needed software is available.
  23. # Usage: Either simply call this function to use the defaults or:
  24. # Call this function with "function" "RAM_SIZE" "DISK_SIZE" "DISK_FORMAT" "DISK_FILE"
  25. # Omitting any of the arguments will us the default instead.
  26. #
  27. # Globals:
  28. # Arguments: None
  29. # Outputs:
  30. # Returns:
  31. # Usage:
  32. # End of Documentation
  33.  
  34.     write_status "${FUNCNAME[0]}:"
  35.     count=1
  36.     for i in qemu-utils qemu-tools qemu-kvm qemu-system-x86 virt-install
  37.     do
  38.         write_status "🧩 ${count} - Verifying dependencies ( ${i} )..."
  39.         check_dependencies $i &>/dev/null
  40.         count=$((count + 1))
  41.     done
  42.  
  43.     # Lookup specific binaries: use full path since they may just have been added and not in $PATH yet, and set variables.
  44.     : "${bin_virt_install:=$(type -p virt-install)}"
  45.     : "${PRESEED_FILE:="$(make_preseed_cfg $( mktemp -d ) ssh-server )"}"
  46.     if echo "${CONFIG:="ssh-server"}" |grep server &>/dev/null ; then : "${SRVorVDI="server"}" ; else : "${SRVorVDI="desktop"}" ; fi
  47.  
  48.  
  49.     case "${SRVorVDI}" in
  50.         server | Server )
  51.                 : "${vm_kernel="${_DEBIAN_FRONTEND_DEFAULT_KERNEL}"}"
  52.                 : "${vm_initrd="${_DEBIAN_FRONTEND_DEFAULT_INITRD}"}"
  53.                 : "${ui_diplay_style="theme=light"}"
  54.                 : "${vm_usecase="Server"}"
  55.                 ;;
  56.         desktop | Desktop )
  57.                 : "${vm_kernel="${_DEBIAN_FRONTEND_GTK_KERNEL}"}"
  58.                 : "${vm_initrd="${_DEBIAN_FRONTEND_GTK_INITRD}"}"
  59.                 : "${ui_diplay_style="theme=dark"}"
  60.                 : "${vm_usecase="VDI"}"
  61.                 ;;
  62.         *)  ;;
  63.     esac
  64.  
  65.     write_status "🔎  - Discovering what the appropriate VM net interface is (default or br'0 - n')"
  66.     : ${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)"}
  67.     : ${source_url:="${_DEBIAN_SOURCE_URL}"}
  68.  
  69.     _summary_message="The virtual machine (Debian_${vm_usecase}_${SRVFUNC}_${CONFIG}_${RANDOM}) \n
  70.     📋 - Using the instructions in PRESEED: ${PRESEED_FILE} \n
  71.     🔧 - And Using this source for the packages and files to download: \n
  72.     🌎 - ${source_url} \n
  73.     🌎 - ${vm_kernel} \n
  74.     🌎 - ${vm_initrd} \n
  75.     ✅ - Using the network: ${virt_net} \n
  76.     ✅ - Memory: ${3:-2048} \n
  77.     ✅ - CPU's: ${2:-2} \n
  78.     ✅ - Disk Size: ${4:-40} \n You may attach to this server and see the progress at IP: $(hostname -I))"
  79.  
  80.  
  81.     # create image and run installer
  82.     "${bin_virt_install}" --name Debian_${vm_usecase}_"${SRVFUNC}"_"${CONFIG}"_"${RANDOM}" \
  83.         --vcpus "${2:-2}" \
  84.         --memory "${3:-2048}" \
  85.         --network "${virt_net}" \
  86.         --location="${source_url}" \
  87.         --disk size="${4:-40}" \
  88.         --os-variant="${1:-debian10}" \
  89.         --video "virtio" --channel "spicevmc" \
  90.         --initrd-inject="${PRESEED_FILE}" \
  91.         --install kernel="${vm_kernel}",initrd="${vm_initrd}" \
  92.         --extra-args "ks=file:/$(basename $PRESEED_FILE) ${ui_diplay_style}" \
  93.         --noautoconsole && $RTD_GUI --backtitle "$BRANDING" --title "NOTICE!" --msgbox "${_summary_message}" 0 0 \
  94.     || ( read -p "💥 - An ERROR has occurred. Please press [ENTER] to continue..." && return 1 )
  95.  
  96.     for i in  PRESEED_FILE vm_kernel vm_initrd source_url CONFIG ui_diplay_style ; do unset $i ; done
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement