From 214070fd357bfcdd31b036febd13aeb676ea50d1 Mon Sep 17 00:00:00 2001 From: Beth Parker Date: Fri, 28 Mar 2025 14:49:26 -0500 Subject: [PATCH] added autodeflate option --- scripts/create.sh | 66 ++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 35 deletions(-) diff --git a/scripts/create.sh b/scripts/create.sh index b75eb1a..75d6ad5 100644 --- a/scripts/create.sh +++ b/scripts/create.sh @@ -24,9 +24,11 @@ where: -s subnet Subnet to place server on (default to 172.16.99.xx) -i ip_address Specify IP address to assign (default to next available in subnet) -b branch Specify branch of build_ansible to use (defult prod) - -a attach Attach existing extra disk (use full path to disK, default none)" + -a attach Attach existing extra disk (use full path to disK, default none) + -d autodeflate Autodeflate memory on use - default true, avoid for ipa-server" + # process flags -while getopts "h:n:c:r:d:v:p:m:s:i:b:" flag +while getopts "h:n:c:r:d:v:p:m:s:i:b:d:" flag do case "$flag" in n) name=${OPTARG};; @@ -40,6 +42,7 @@ do i) ip=${OPTARG};dhcp_opts+=" -i $ip";; b) branch=${OPTARG};; a) attach=${OPTARG};; + d) deflate=${OPTARG};; h) ;& *) echo "$usage";exit;; esac @@ -63,53 +66,46 @@ img=`./shared_scripts/download_install_image.sh $variant` # determine if extra disk should be attached if [ -n "$attach" ]; then attach="--disk ${attach},discard=unmap";fi -case "$variant" in - "archlinux") - # create cloud-init - replace by grabbing these directly from git - mkdir -p /tmp/cloud-init - - -echo "#cloud-config -users: +#determine if deflate should be on +if [ -n "$deflate" ]; then deflate="--memballoon model=virtio,autodeflate=on";else deflate="--memballoon model=virtio";fi - name: root ssh_authorized_keys: - ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILG56T1k766Cru14kyXI8WXSJwlO2sVhmH6JeRWy+mfe root@host.actcur.com" > /tmp/cloud-init/user-data + # create new base VM + virt-install --name=$name --vcpus=$cpu --memory=$memory --disk path=$path,size=$root_disk,sparse=true,discard=unmap,bus=scsi ${attach} --os-variant=$variant --network bridge=br1,mac=$mac $deflate --cdrom=$img --graphics vnc --cloud-init user-data="/tmp/cloud-init/user-data" --autoconsole=none - # create new base VM - virt-install --name=$name --vcpus=$cpu --memory=$memory --disk path=$path,size=$root_disk,sparse=true,discard=unmap,bus=scsi ${attach} --os-variant=$variant --network bridge=br1,mac=$mac --memballoon model=virtio,autodeflate=on --cdrom=$img --graphics vnc --cloud-init user-data="/tmp/cloud-init/user-data" --autoconsole=none + #wait until server is available + echo "Waiting for server to be available" + while true + do + sleep 1 + ping -c 1 ${lname}.actcur.com 2>&1 > /dev/null + if [ $? -eq 0 ]; then break;fi + done + echo "server up, waiting for ssh" - #wait until server is available - echo "Waiting for server to be available" - while true - do - sleep 1 - ping -c 1 ${lname}.actcur.com 2>&1 > /dev/null - if [ $? -eq 0 ]; then break;fi - done - echo "server up, waiting for ssh" + sleep 30 - sleep 30 + sed "s/REPLACE_HOSTNAME/${lname}.actcur.com/g" ../base_files/user_configuration.json > /tmp/user_configuration.json + rs=$((root_disk*1024-206)) + sed -i "s/REPLACE_SIZE/${rs}/g" /tmp/user_configuration.json - sed "s/REPLACE_HOSTNAME/${lname}.actcur.com/g" ../base_files/user_configuration.json > /tmp/user_configuration.json - rs=$((root_disk*1024-206)) - sed -i "s/REPLACE_SIZE/${rs}/g" /tmp/user_configuration.json + ssh-keygen -R ${lname}.actcur.com + ssh-keyscan ${lname}.actcur.com | grep -v "#" | grep "ecdsa-sha2-nistp256" >> ~/.ssh/known_hosts - ssh-keygen -R ${lname}.actcur.com - ssh-keyscan ${lname}.actcur.com | grep -v "#" | grep "ecdsa-sha2-nistp256" >> ~/.ssh/known_hosts - - scp -i $ssh_key_dir/id_arch_builder /tmp/user_configuration.json ${lname}.actcur.com:/tmp/user_configuration.json - ssh -i $ssh_key_dir/id_arch_builder ${lname}.actcur.com "systemctl mask reflector.service; echo 'Server = https://pkg.actcur.com/repo/archlinux/\$repo/os/\$arch' > /etc/pacman.d/mirrorlist" - ssh -i $ssh_key_dir/id_arch_builder ${lname}.actcur.com "archinstall --config /tmp/user_configuration.json --silent" - ssh -i $ssh_key_dir/id_arch_builder ${lname}.actcur.com "ln -s /usr/lib/systemd/system/sshd.service /mnt/archinstall/etc/systemd/system/multi-user.target.wants/sshd.service" - ssh -i $ssh_key_dir/id_arch_builder ${lname}.actcur.com "cp -r /root/.ssh/ /mnt/archinstall/root/;reboot" - ;; + scp -i $ssh_key_dir/id_arch_builder /tmp/user_configuration.json ${lname}.actcur.com:/tmp/user_configuration.json + ssh -i $ssh_key_dir/id_arch_builder ${lname}.actcur.com "systemctl mask reflector.service; echo 'Server = https://pkg.actcur.com/repo/archlinux/\$repo/os/\$arch' > /etc/pacman.d/mirrorlist" + ssh -i $ssh_key_dir/id_arch_builder ${lname}.actcur.com "archinstall --config /tmp/user_configuration.json --silent" + ssh -i $ssh_key_dir/id_arch_builder ${lname}.actcur.com "ln -s /usr/lib/systemd/system/sshd.service /mnt/archinstall/etc/systemd/system/multi-user.target.wants/sshd.service" + ssh -i $ssh_key_dir/id_arch_builder ${lname}.actcur.com "cp -r /root/.ssh/ /mnt/archinstall/root/;reboot" + ;; "alma") # set up kickstart file sed "s/REPLACE_HOSTNAME/${lname}.actcur.com/g" ../base_files/kickstart.cfg > /tmp/kickstart.cfg # create new VM - virt-install --name=$name --vcpus=$cpu --memory=$memory --disk path=$path,size=$root_disk,sparse=true,discard=unmap,bus=scsi --os-variant=almalinux9 --network bridge=br1,mac=$mac --memballoon model=virtio,autodeflate=on --location=$img --graphics vnc --initrd-inject /tmp/kickstart.cfg --extra-args "inst.ks=file:/kickstart.cfg" --autoconsole=none + virt-install --name=$name --vcpus=$cpu --memory=$memory --disk path=$path,size=$root_disk,sparse=true,discard=unmap,bus=scsi --os-variant=almalinux9 --network bridge=br1,mac=$mac $deflate --location=$img --graphics vnc --initrd-inject /tmp/kickstart.cfg --extra-args "inst.ks=file:/kickstart.cfg" --autoconsole=none echo "server up, waiting for install to complete"