summaryrefslogtreecommitdiff
path: root/others/vm3/compute/create.sh
diff options
context:
space:
mode:
authorYour Name <you@example.com>2024-12-23 16:06:31 +0800
committerYour Name <you@example.com>2024-12-23 16:06:31 +0800
commit456f72de0592e801213df04f042f6684ea2cc439 (patch)
tree898a537b1390405225a3a50852f581397fa1b997 /others/vm3/compute/create.sh
parentf7f159a04671690786de2f84e34046c103521d58 (diff)
udpate
Diffstat (limited to 'others/vm3/compute/create.sh')
-rwxr-xr-xothers/vm3/compute/create.sh43
1 files changed, 26 insertions, 17 deletions
diff --git a/others/vm3/compute/create.sh b/others/vm3/compute/create.sh
index 0bb2e63..84646d7 100755
--- a/others/vm3/compute/create.sh
+++ b/others/vm3/compute/create.sh
@@ -7,7 +7,8 @@
vcpu=8
ram_gb=4
disk_gb=32
-os="fedora40.qcow2"
+os="fedora40"
+ostype="linux"
# parse arguments
while [[ $# -gt 0 ]]; do
@@ -41,35 +42,39 @@ while [[ $# -gt 0 ]]; do
esac
done
+scriptdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #&& echo $scriptdir
+workingdir="/var/lib/libvirt/images/.temp"
+seed_iso="${workingdir}/seed.iso"
+xml="${workingdir}/xml"
+
+image_dir_path="/var/lib/libvirt/images/.image_store"
+src_file="${image_dir_path}/${os}.qcow2"
+new_vm_dir="/var/lib/libvirt/images/${vmname}"
+new_vm="${new_vm_dir}/${vmname}.qcow2"
+
# Check mandatory arguments, basicaly checking for initial 1 argument. if it dont exist, vmname will be null
# image is os!!
if [ -z "$vmname" ] ; then
- echo "Usage: $0 <vm-name> [--image <os>.qcow2] [--vcpu N] [--ram N] [--disk-size N]"
+ echo ""
+ echo "Usage: $0 <vm-name> [--image <os>] [--vcpu N] [--ram N] [--disk-size N]"
echo "seed.iso and image file have to be present! Default os is fedora"
echo ""
echo "Available images:"
- sudo ls /var/lib/libvirt/images/.image_store
+ sudo ls -1 /var/lib/libvirt/images/.image_store | sed 's/\.qcow2$//'
+ echo ""
+ echo "Available images to download:"
+ sudo ls -1 "${scriptdir}/../.config/cloud-init-generator/" | sed 's/\.sh$//'
exit 1
fi
-scriptdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #&& echo $scriptdir
-workingdir="/var/lib/libvirt/images/.temp"
-seed_iso="${workingdir}/seed.iso"
-xml="${workingdir}/xml"
-
-image_dir_path="/var/lib/libvirt/images/.image_store"
-src_file="${image_dir_path}/${os}"
-new_vm_dir="/var/lib/libvirt/images/${vmname}"
-new_vm="${new_vm_dir}/${vmname}.qcow2"
+# run the script to make the cloud init files
+sudo bash "${scriptdir}/../.config/cloud-init-generator/${os}.sh" "${vmname}"
if [ ! -f "${src_file}" ]; then
echo -e "${os} image file is cannot be found. please make it available in ${image_dir_path}"
exit 1
fi
-# run the script to make the cloud init files
-sudo bash "${scriptdir}/../.config/cloud-init-files/$(basename "$os" .qcow2).sh" "${vmname}"
-
sudo mkdir -p $new_vm_dir
sudo cp "$src_file" "$new_vm" &> /dev/null || { echo "Failed to create a new image."; exit 1; }
@@ -79,13 +84,17 @@ if sudo virsh list --all | awk "\$2==\"$vmname\"" | grep -q .; then
exit 1
fi
+if [[ ${os,,} == *"freebsd"* ]]; then
+ ostype="generic"
+fi
+
sudo virt-install --name $vmname \
--vcpus $vcpu \
--memory "$((ram_gb * 1024))"\
--disk path=$new_vm,format=qcow2 \
--disk path=$seed_iso,device=cdrom \
- --os-type linux \
- --os-variant $(basename "$os" .qcow2) \
+ --os-type $ostype \
+ --os-variant $os \
--virt-type kvm \
--graphics none \
--network bridge=virbr0,model=virtio \