From 0cc29b348c7f60f9dc55738da6ec3eb2bbdfa229 Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Wed, 21 Jan 2026 01:06:47 -0500 Subject: [PATCH] fix and optimizations based on kvmhost5 --- .../files/simple/usr/local/bin/create-vm | 74 ++++++++++++------- 1 file changed, 48 insertions(+), 26 deletions(-) diff --git a/roles/kvmhost/files/simple/usr/local/bin/create-vm b/roles/kvmhost/files/simple/usr/local/bin/create-vm index b9ec76e..d205353 100755 --- a/roles/kvmhost/files/simple/usr/local/bin/create-vm +++ b/roles/kvmhost/files/simple/usr/local/bin/create-vm @@ -107,7 +107,8 @@ starts with disk_arrays=( and -l shows their free space. WARNING: If this script fails or is inturupted, it will output instructions -to undo what it has done. Be sure to read the output! +to undo what it has done. Be sure to read the output! Also, if debugging +this script, see dev notes at the end. -d --disk : Create and add an extra disk to an existing VM. DISK_NAME @@ -193,25 +194,13 @@ cli-arg-check() { ## from here, checks for when we are actually creating a vm - # TODO Remove this once we upgrade the kvmhosts to t9+ - if [[ ( $release == ecne || $release == aramo && $HOSTNAME == kvmhost[234] ) && \ + # note: alter this when we upgrade a kvmhost + if [[ $release == aramo && $HOSTNAME == kvmhost[234] && \ ! -d /srv/debootstrap-cache/$release/etc ]] ; then err "error: this os is too old to debootstrap $release. rsync it first to -/srv/debootstrap-cache/$release" +/srv/debootstrap-cache/$release +ecne exists on kvmhost3 & 5" - err 'For ecne, I initially generated it into kvmhost3 with: - -#!/bin/bash -set -xe -excludes=resolvconf -excludes+=,systemd-resolved -archive=http://us.archive.trisquel.info/trisquel -linux_pkg=linux-image-virtual -debootstrap --exclude=$excludes ecne $PWD $archive -for p in netplan.io networkd-dispatcher python3 python3.12 netplan-generator; do -m chroot . apt-get purge $p --auto-remove || break -done -' exit 1 fi if virsh list --all --name | grep -Fx $host &>/dev/null; then @@ -701,6 +690,7 @@ EOF local -i i=0 vg_set_count=0 disk_arrays_item_count=${#disk_arrays[@]} volgroups=() + first_vg_set=() while (( i < disk_arrays_item_count )); do i=$((i+1)) @@ -711,7 +701,7 @@ EOF # loop over a single array, checking if this array is the one asked for by the user while (( i < disk_arrays_item_count )) && [[ ${disk_arrays[i]} != , ]]; do vg=${disk_arrays[i]} - if [[ ! -d /dev/$vg ]]; then + if ! vgdisplay $vg &>/dev/null; then i=$(( i + 1 )) continue fi @@ -778,6 +768,10 @@ EOF volgroups=( ${this_vg_set[@]} ) break fi + + if (( vg_set_count == 1 )); then + first_vg_set=( ${this_vg_set[@]} ) + fi done if $dolist; then @@ -785,12 +779,12 @@ EOF fi ## if there is just one set on this machine, use it. - if [[ ! $vg_opt ]] && (( vg_set_count == 1 && this_vg_set_count == 3 )); then - volgroups=( ${this_vg_set[@]} ) + if [[ ! $vg_opt ]] && (( vg_set_count == 1 )); then + volgroups=( ${first_vg_set[@]} ) fi if (( ${#volgroups[@]} != 3 )); then - err "error: failed to find array of 3 volgroups, got: ${volgroups[*]}" + err "error: failed to find array of 3 volume groups, \${volgroups[*]}: ${volgroups[*]}, vg_set_count: $vg_set_count" err-cleanup exit 1 fi @@ -983,7 +977,7 @@ os-bootstrap() { excludes=resolvconf case $release in ecne) - excludes+=,netplan.io,systemd-resolved + excludes+=,systemd-resolved ;; aramo) # These dont exist in jammy, they only cause problems. @@ -1019,6 +1013,9 @@ os-bootstrap() { # then fails with exit code 2 and no error message. # So, I manually rsynced over this dir to t8 machines. m eatmydata debootstrap --exclude=$excludes $release /srv/debootstrap-cache/$release $archive + if [[ $release == ecne ]]; then + chroot /srv/debootstrap-cache/$release apt-get -y purge netplan.io networkd-dispatcher python3 python3.12 netplan-generator --auto-remove + fi fi m eatmydata cp -a /srv/debootstrap-cache/$release/* $target } @@ -1243,8 +1240,6 @@ create-vm() { fi var=ubuntu$var.04 - # TODO In newer libvirt versions, we probably want - # --cpu host-passthrough,cache.mode=passthrough vopts=( --name $host --graphics vnc @@ -1255,6 +1250,15 @@ create-vm() { --os-variant=$var --import ) + if virt-install '--cpu=?' | grep 'cache\.mode' &>/dev/null; then + vopts+=( + --cpu host-passthrough,cache.mode=passthrough + ) + else + vopts+=( + --cpu host-passthrough +) + fi #### Begin grub args #### boot_prefix=kernel=/var/lib/libvirt/images/grub-i386-netnames @@ -1301,10 +1305,19 @@ create-vm() { #### End network args #### - if $doceph; then + if grep -q '^Hugetlb:[[:space:]]*[1-9]' /proc/meminfo; then vopts+=( --memory=$ram,hugepages=true ) else - # Our newer trisquel OSes cant handle hugepages. I assume they could if I spent some time trying to configure it right. Example error: + # T12 hugepage setup: + # + #cat /etc/sysctl.d/40-hugepage.conf +#vm.nr_hugepages = 56320 +# +# for 110 gigs, this many pages: '110*1024*1024/2048' +# +# todo: automate this. + # + # Example error in t11 if we have no hugepages setup on boot: # #create-vm: virt-install --name inspect0d.fsf.org ... --memory=3000,hugepages=true # Starting install... @@ -1512,3 +1525,12 @@ if type -p backup-crypt-luks-keys &>/dev/null; then fi exit 0 + +###### dev notes ##### +# +# If you see a pattern in the output where a "pop:" line does +# not have a matching command on the previous line, that is probably a +# bug. Good output example: +# +#create-vm: umount /tmp/tmp.x86D7DDhRm/dev/pts +#pop: umount /tmp/tmp.x86D7DDhRm/dev/pts -- 2.25.1