From e94b275f5630e032a6971831f8be520ae81a5d02 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 21 Dec 2024 16:45:32 +0800 Subject: v1vm3-done --- others/vm3/.config/init/make_rootkey.sh | 4 ++-- others/vm3/compute/create.sh | 11 +++++++---- others/vm3/compute/start.sh | 4 ++++ others/vm3/image/fedora.sh | 12 +++++++----- 4 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 others/vm3/compute/start.sh 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 @@ #!/bin/bash -sudo mkdir -p ~/keys -ssh-keygen -t ed25519 -f ~/keys/k1 -N "" +sudo mkdir -p /root/k +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 if [ $# -ne 5 ]; then echo "Usage: $0 " echo "seed.iso and image file have to be present!" + echo "" + echo "Available images" + sudo ls /var/lib/libvirt/images/.image_store exit 1 fi @@ -41,20 +44,20 @@ fi sudo virt-install --name $vmname \ --vcpus $vcpu \ --memory "$((ram_gb * 1024))"\ - --disk path=$new_vm_path,size=$disk_gb,format=qcow2 \ + --disk path=$new_vm,format=qcow2 \ --disk path=$seed_iso,device=cdrom \ --os-type linux \ --os-variant $os \ --virt-type kvm \ --graphics none \ --network bridge=virbr0,model=virtio \ - --print-xml > $xml || { echo "Failed to print XML."; exit 1; } + --print-xml > $xml #|| { echo "Failed to print XML."; exit 1; } -sudo virsh define $xml &> /dev/null || { echo "Failed to define the new VM."; exit 1; } +sudo virsh define $xml #&> /dev/null || { echo "Failed to define the new VM."; exit 1; } sudo qemu-img resize $new_vm +$disk_gb"G" #&> /dev/null sudo virsh start $vmname -sudo rm "${workingdir}"/* +#sudo rm "${workingdir}"/* 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 @@ +#!/bin/bash + +# starts vm +# 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 @@ 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" -sshkeysdir="/root/keys" +sshkeysdir="/root/k" scriptdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #&& echo $scriptdir dir_path="/var/lib/libvirt/images/.image_store" src_file="${dir_path}/fedora40.qcow2" config_dir="/var/lib/libvirt/images/.temp" -user_data="${config_dir}/user_data" -meta_data="${config_dir}/meta_data" +user_data="${config_dir}/user-data" +meta_data="${config_dir}/meta-data" seed_iso="${config_dir}/seed.iso" +# note that cloud init specifically looks for "user-data" and "meta-data" in the seed.iso disk. do not deviate from the naming convention. if [ $# -ne 1 ]; then echo "Usage: $0 " @@ -43,13 +44,14 @@ cat >> "$user_data" << 'EOF' sudo: ['ALL=(ALL) NOPASSWD:ALL'] groups: wheel shell: /bin/bash + password: 123 runcmd: - sudo growpart /dev/sda 1 - sudo xfs_growfs / - sudo dnf install -y vim git - cd /home/user - - git clone https://git.0nom.ch/setup - - sudo ./setup/setup.sh + - #git clone https://git.0nom.ch/setup + - #sudo ./setup/setup.sh - touch /home/user/runcmd_done EOF -- cgit v1.2.3-70-g09d2