diff options
| author | hc <hc@email.ch> | 2025-01-02 09:26:32 +0800 |
|---|---|---|
| committer | hc <hc@email.ch> | 2025-01-02 09:26:32 +0800 |
| commit | c33f0979f0312e7a6d43645aa0a5d5b1481751f5 (patch) | |
| tree | 49bd07cf9b6f02572586d22f3794da007bf794d1 /others/vm3/compute/create.sh | |
| parent | 181bc10748cd9162e85f16722d6c83ff04a2d39d (diff) | |
udpated
Diffstat (limited to 'others/vm3/compute/create.sh')
| -rwxr-xr-x | others/vm3/compute/create.sh | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/others/vm3/compute/create.sh b/others/vm3/compute/create.sh index a1d84f6..1a0411b 100755 --- a/others/vm3/compute/create.sh +++ b/others/vm3/compute/create.sh | |||
| @@ -49,8 +49,8 @@ xml="${workingdir}/xml" | |||
| 49 | 49 | ||
| 50 | image_dir_path="/var/lib/libvirt/images/.image_store" | 50 | image_dir_path="/var/lib/libvirt/images/.image_store" |
| 51 | src_file="${image_dir_path}/${os}.qcow2" | 51 | src_file="${image_dir_path}/${os}.qcow2" |
| 52 | new_vm_dir="/var/lib/libvirt/images/${vmname}" | 52 | new_vm_config_dir="/var/lib/libvirt/images/${vmname}.config" |
| 53 | new_vm="${new_vm_dir}/${vmname}.qcow2" | 53 | new_vm="/var/lib/libvirt/images/${vmname}.qcow2" |
| 54 | 54 | ||
| 55 | # Check mandatory arguments, basicaly checking for initial 1 argument. if it dont exist, vmname will be null | 55 | # Check mandatory arguments, basicaly checking for initial 1 argument. if it dont exist, vmname will be null |
| 56 | # image is os!! | 56 | # image is os!! |
| @@ -75,7 +75,7 @@ if [ ! -f "${src_file}" ]; then | |||
| 75 | exit 1 | 75 | exit 1 |
| 76 | fi | 76 | fi |
| 77 | 77 | ||
| 78 | sudo mkdir -p $new_vm_dir | 78 | sudo mkdir -p $new_vm_config_dir |
| 79 | 79 | ||
| 80 | sudo cp "$src_file" "$new_vm" &> /dev/null || { echo "Failed to create a new image."; exit 1; } | 80 | sudo cp "$src_file" "$new_vm" &> /dev/null || { echo "Failed to create a new image."; exit 1; } |
| 81 | 81 | ||
| @@ -90,11 +90,12 @@ fi | |||
| 90 | 90 | ||
| 91 | # Define the disk options based on OS type | 91 | # Define the disk options based on OS type |
| 92 | if [ "$os" = "debian12" ]; then | 92 | if [ "$os" = "debian12" ]; then |
| 93 | disk_opts="--disk path=$new_vm,format=qcow2" | 93 | disk_opts="--disk path=${new_vm},format=qcow2" |
| 94 | else | 94 | else |
| 95 | disk_opts="--disk path=$new_vm,format=qcow2 --disk path=$seed_iso,device=cdrom" | 95 | disk_opts="--disk path=${new_vm},format=qcow2 --disk path=$seed_iso,device=cdrom" |
| 96 | fi | 96 | fi |
| 97 | 97 | ||
| 98 | |||
| 98 | # Use the conditional disk options in virt-install | 99 | # Use the conditional disk options in virt-install |
| 99 | sudo virt-install --name $vmname \ | 100 | sudo virt-install --name $vmname \ |
| 100 | --vcpus $vcpu \ | 101 | --vcpus $vcpu \ |
| @@ -105,7 +106,8 @@ sudo virt-install --name $vmname \ | |||
| 105 | --virt-type kvm \ | 106 | --virt-type kvm \ |
| 106 | --graphics none \ | 107 | --graphics none \ |
| 107 | --network bridge=virbr0,model=virtio \ | 108 | --network bridge=virbr0,model=virtio \ |
| 108 | --print-xml > $xml || { sudo rm -rf $new_vm_dir; exit 1; } | 109 | --print-xml > $xml || { sudo rm -rf $new_vm; exit 1; } |
| 110 | # if you want this in a new storage pool, move it to a new storage pool after initialisation | ||
| 109 | 111 | ||
| 110 | sudo virsh define $xml #&> /dev/null || { echo "Failed to define the new VM."; exit 1; } | 112 | sudo virsh define $xml #&> /dev/null || { echo "Failed to define the new VM."; exit 1; } |
| 111 | 113 | ||
