summaryrefslogtreecommitdiff
path: root/others/vm3
diff options
context:
space:
mode:
authorYour Name <you@example.com>2024-12-21 16:45:32 +0800
committerYour Name <you@example.com>2024-12-21 16:45:32 +0800
commite94b275f5630e032a6971831f8be520ae81a5d02 (patch)
treec6819daab6bceff1477647f40d52fa23f2c88628 /others/vm3
parentbe3dde6ce14698c5818f21f65037a4beef1199cf (diff)
v1vm3-done
Diffstat (limited to 'others/vm3')
-rwxr-xr-xothers/vm3/.config/init/make_rootkey.sh4
-rwxr-xr-xothers/vm3/compute/create.sh11
-rw-r--r--others/vm3/compute/start.sh4
-rwxr-xr-xothers/vm3/image/fedora.sh12
4 files changed, 20 insertions, 11 deletions
diff --git a/others/vm3/.config/init/make_rootkey.sh b/others/vm3/.config/init/make_rootkey.sh
index 5d07472..f725985 100755
--- a/others/vm3/.config/init/make_rootkey.sh
+++ b/others/vm3/.config/init/make_rootkey.sh
@@ -1,4 +1,4 @@
1#!/bin/bash 1#!/bin/bash
2 2
3sudo mkdir -p ~/keys 3sudo mkdir -p /root/k
4ssh-keygen -t ed25519 -f ~/keys/k1 -N "" 4ssh-keygen -t ed25519 -f /root/k/k1 -N ""
diff --git a/others/vm3/compute/create.sh b/others/vm3/compute/create.sh
index 6d83a03..649cd86 100755
--- a/others/vm3/compute/create.sh
+++ b/others/vm3/compute/create.sh
@@ -14,6 +14,9 @@ disk_gb=$5
14if [ $# -ne 5 ]; then 14if [ $# -ne 5 ]; then
15 echo "Usage: $0 <vm-name> <os> <vcpu> <ram(gb)> <disk(gb)>" 15 echo "Usage: $0 <vm-name> <os> <vcpu> <ram(gb)> <disk(gb)>"
16 echo "seed.iso and image file have to be present!" 16 echo "seed.iso and image file have to be present!"
17 echo ""
18 echo "Available images"
19 sudo ls /var/lib/libvirt/images/.image_store
17 exit 1 20 exit 1
18fi 21fi
19 22
@@ -41,20 +44,20 @@ fi
41sudo virt-install --name $vmname \ 44sudo virt-install --name $vmname \
42 --vcpus $vcpu \ 45 --vcpus $vcpu \
43 --memory "$((ram_gb * 1024))"\ 46 --memory "$((ram_gb * 1024))"\
44 --disk path=$new_vm_path,size=$disk_gb,format=qcow2 \ 47 --disk path=$new_vm,format=qcow2 \
45 --disk path=$seed_iso,device=cdrom \ 48 --disk path=$seed_iso,device=cdrom \
46 --os-type linux \ 49 --os-type linux \
47 --os-variant $os \ 50 --os-variant $os \
48 --virt-type kvm \ 51 --virt-type kvm \
49 --graphics none \ 52 --graphics none \
50 --network bridge=virbr0,model=virtio \ 53 --network bridge=virbr0,model=virtio \
51 --print-xml > $xml || { echo "Failed to print XML."; exit 1; } 54 --print-xml > $xml #|| { echo "Failed to print XML."; exit 1; }
52 55
53sudo virsh define $xml &> /dev/null || { echo "Failed to define the new VM."; exit 1; } 56sudo virsh define $xml #&> /dev/null || { echo "Failed to define the new VM."; exit 1; }
54 57
55sudo qemu-img resize $new_vm +$disk_gb"G" #&> /dev/null 58sudo qemu-img resize $new_vm +$disk_gb"G" #&> /dev/null
56 59
57sudo virsh start $vmname 60sudo virsh start $vmname
58 61
59sudo rm "${workingdir}"/* 62#sudo rm "${workingdir}"/*
60 63
diff --git a/others/vm3/compute/start.sh b/others/vm3/compute/start.sh
new file mode 100644
index 0000000..5a2b3aa
--- /dev/null
+++ b/others/vm3/compute/start.sh
@@ -0,0 +1,4 @@
1#!/bin/bash
2
3# starts vm
4# need to remove seed.iso first if vm have the seed iso
diff --git a/others/vm3/image/fedora.sh b/others/vm3/image/fedora.sh
index 109f4fc..cd05e10 100755
--- a/others/vm3/image/fedora.sh
+++ b/others/vm3/image/fedora.sh
@@ -8,15 +8,16 @@
8 8
9image_url="https://download.fedoraproject.org/pub/fedora/linux/releases/41/Cloud/x86_64/images/Fedora-Cloud-Base-Generic-41-1.4.x86_64.qcow2" 9image_url="https://download.fedoraproject.org/pub/fedora/linux/releases/41/Cloud/x86_64/images/Fedora-Cloud-Base-Generic-41-1.4.x86_64.qcow2"
10 10
11sshkeysdir="/root/keys" 11sshkeysdir="/root/k"
12 12
13scriptdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #&& echo $scriptdir 13scriptdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #&& echo $scriptdir
14dir_path="/var/lib/libvirt/images/.image_store" 14dir_path="/var/lib/libvirt/images/.image_store"
15src_file="${dir_path}/fedora40.qcow2" 15src_file="${dir_path}/fedora40.qcow2"
16config_dir="/var/lib/libvirt/images/.temp" 16config_dir="/var/lib/libvirt/images/.temp"
17user_data="${config_dir}/user_data" 17user_data="${config_dir}/user-data"
18meta_data="${config_dir}/meta_data" 18meta_data="${config_dir}/meta-data"
19seed_iso="${config_dir}/seed.iso" 19seed_iso="${config_dir}/seed.iso"
20# note that cloud init specifically looks for "user-data" and "meta-data" in the seed.iso disk. do not deviate from the naming convention.
20 21
21if [ $# -ne 1 ]; then 22if [ $# -ne 1 ]; then
22 echo "Usage: $0 <vm-name>" 23 echo "Usage: $0 <vm-name>"
@@ -43,13 +44,14 @@ cat >> "$user_data" << 'EOF'
43 sudo: ['ALL=(ALL) NOPASSWD:ALL'] 44 sudo: ['ALL=(ALL) NOPASSWD:ALL']
44 groups: wheel 45 groups: wheel
45 shell: /bin/bash 46 shell: /bin/bash
47 password: 123
46runcmd: 48runcmd:
47 - sudo growpart /dev/sda 1 49 - sudo growpart /dev/sda 1
48 - sudo xfs_growfs / 50 - sudo xfs_growfs /
49 - sudo dnf install -y vim git 51 - sudo dnf install -y vim git
50 - cd /home/user 52 - cd /home/user
51 - git clone https://git.0nom.ch/setup 53 - #git clone https://git.0nom.ch/setup
52 - sudo ./setup/setup.sh 54 - #sudo ./setup/setup.sh
53 - touch /home/user/runcmd_done 55 - touch /home/user/runcmd_done
54EOF 56EOF
55 57