diff options
| author | Your Name <you@example.com> | 2024-12-21 16:45:32 +0800 |
|---|---|---|
| committer | Your Name <you@example.com> | 2024-12-21 16:45:32 +0800 |
| commit | e94b275f5630e032a6971831f8be520ae81a5d02 (patch) | |
| tree | c6819daab6bceff1477647f40d52fa23f2c88628 | |
| parent | be3dde6ce14698c5818f21f65037a4beef1199cf (diff) | |
v1vm3-done
| -rwxr-xr-x | others/vm3/.config/init/make_rootkey.sh | 4 | ||||
| -rwxr-xr-x | others/vm3/compute/create.sh | 11 | ||||
| -rw-r--r-- | others/vm3/compute/start.sh | 4 | ||||
| -rwxr-xr-x | others/vm3/image/fedora.sh | 12 |
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 | ||
| 3 | sudo mkdir -p ~/keys | 3 | sudo mkdir -p /root/k |
| 4 | ssh-keygen -t ed25519 -f ~/keys/k1 -N "" | 4 | ssh-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 | |||
| 14 | if [ $# -ne 5 ]; then | 14 | if [ $# -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 |
| 18 | fi | 21 | fi |
| 19 | 22 | ||
| @@ -41,20 +44,20 @@ fi | |||
| 41 | sudo virt-install --name $vmname \ | 44 | sudo 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 | ||
| 53 | sudo virsh define $xml &> /dev/null || { echo "Failed to define the new VM."; exit 1; } | 56 | sudo virsh define $xml #&> /dev/null || { echo "Failed to define the new VM."; exit 1; } |
| 54 | 57 | ||
| 55 | sudo qemu-img resize $new_vm +$disk_gb"G" #&> /dev/null | 58 | sudo qemu-img resize $new_vm +$disk_gb"G" #&> /dev/null |
| 56 | 59 | ||
| 57 | sudo virsh start $vmname | 60 | sudo virsh start $vmname |
| 58 | 61 | ||
| 59 | sudo 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 | ||
| 9 | image_url="https://download.fedoraproject.org/pub/fedora/linux/releases/41/Cloud/x86_64/images/Fedora-Cloud-Base-Generic-41-1.4.x86_64.qcow2" | 9 | image_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 | ||
| 11 | sshkeysdir="/root/keys" | 11 | sshkeysdir="/root/k" |
| 12 | 12 | ||
| 13 | scriptdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #&& echo $scriptdir | 13 | scriptdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #&& echo $scriptdir |
| 14 | dir_path="/var/lib/libvirt/images/.image_store" | 14 | dir_path="/var/lib/libvirt/images/.image_store" |
| 15 | src_file="${dir_path}/fedora40.qcow2" | 15 | src_file="${dir_path}/fedora40.qcow2" |
| 16 | config_dir="/var/lib/libvirt/images/.temp" | 16 | config_dir="/var/lib/libvirt/images/.temp" |
| 17 | user_data="${config_dir}/user_data" | 17 | user_data="${config_dir}/user-data" |
| 18 | meta_data="${config_dir}/meta_data" | 18 | meta_data="${config_dir}/meta-data" |
| 19 | seed_iso="${config_dir}/seed.iso" | 19 | seed_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 | ||
| 21 | if [ $# -ne 1 ]; then | 22 | if [ $# -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 | ||
| 46 | runcmd: | 48 | runcmd: |
| 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 |
| 54 | EOF | 56 | EOF |
| 55 | 57 | ||
