Skip to content

Commit 55fd85e

Browse files
committed
kludging our way
1 parent 87347e7 commit 55fd85e

File tree

7 files changed

+115
-17
lines changed

7 files changed

+115
-17
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
*~
1+
*~
2+
vms
3+
*.ks
4+
*.tar
5+

config/VMCPUS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4

config/VMDISKSIZE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
200

config/VMMEM

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4096

vminstall.sh

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,61 @@
1-
total_memory=${VMMEMORY:-$(free -m | awk '/^Mem:/{print $2}')}
2-
ram_allocation=${VMRAM:-$((total_memory * 3 / 4))}
3-
total_cores=${VMCORES:-$(nproc)}
1+
#!/bin/bash
2+
3+
scriptdir=$(dirname $(realpath $0))
4+
configdir=$scriptdir/config
5+
6+
# defaults for launching vms from the created image
7+
[[ -z $VMMEM ]] && [[ -a $configdir/VMMEM ]] && VMMEM=$(cat $configdir/VMMEM);
8+
VMMEM=${VMMEM:-8G}
9+
[[ -z $VMCPUS ]] && [[ -a $configdir/VMCPUS ]] && VMCPUS=$(cat $configdir/VMCPUS);
10+
VMCPUS=${VMCPUS:-4}
11+
[[ -z $VMDISKSIZE ]] && [[ -a $configdir/VMDISKSIZE ]] && VMDISKSIZE=$(cat $configdir/VMDISKSIZE);
12+
VMDISKSIZE=${VMDISKSIZE:-200}
13+
14+
15+
total_memory=$(free -m | awk '/^Mem:/{print $2}')
16+
# try to do the install using 1/4 of the free memory
17+
# install_ram_allocation=$((total_memory * 1 / 4))
18+
# default to do the install with the same amount of memory the VM default memory
19+
# size will be
20+
install_ram_allocation=${VMMEM}
21+
# try go do the install using 1/2 of the cores
22+
# default to do the install with the same amount of memory the VM default memory
23+
# size will be
24+
# install_total_cores=$(($(nproc)/2))
25+
#install_total_cores=$(($(nproc)/2))
26+
install_total_cores=${VMCPUS}
27+
28+
29+
430
ARCH=$(uname -i)
531
DOMAIN=${1:-basevm-$ARCH}
632
VMUSER=${2:-user}
733
VMPASSWD=${3:-user}
834
FEDORARELEASE=38
35+
VMSDIR=vms
36+
37+
LOCATION=${LOCATION:-"https://download.fedoraproject.org/pub/fedora/linux/releases/$FEDORARELEASE/Everything/$(uname -i)/os/"}
938

10-
LOCATION=${LOCATION:-"https://download.fedoraproject.org/pub/fedora/linux/releases/FEDORARELEASE/Everything/$(uname -i)/os/"}
39+
info() {
40+
echo configdir:$configdir VMMEM:$VMMEM VMCPUS:$VMCPUS VMDISKSIZE:$VMDISKSIZE
41+
echo Install using: memory:$install_ram_allocation cpus:$install_total_cores
42+
echo ARCH:$ARCH DOMAIN:$DOMAIN VMUSER:$VMUSER VMPASSWD:$VMPASSWD
43+
echo FEDORARELEASE:$FEDORARELEASE
44+
echo FEDORAURL:$LOCATION
45+
echo VMSDIR:$VMSDIR DOMAIN: $DOMAIN
46+
}
1147

1248
if [[ -z $DOMAIN ]]; then
1349
echo "USAGE: $0 <DOMAIN NAME>"
1450
exit -1
1551
fi
1652

53+
info
54+
55+
if [[ ! -d $VMSDIR ]]; then
56+
mkdir ${VMSDIR}
57+
fi
58+
1759
if [[ ! -a $DOMAIN.ks ]]; then
1860
# create $DOMAIN.ks
1961
cat >$DOMAIN.ks <<EOF
@@ -99,12 +141,13 @@ make
99141
EOF
100142
fi
101143

144+
102145
virt-install \
103146
--name $DOMAIN \
104-
--ram $ram_allocation \
105-
--disk path="$(pwd)/disk/$DOMAIN.qcow2,size=200,format=qcow2" \
147+
--memory="memory=$install_ram_allocation" \
148+
--disk path="$(pwd)/${VMSDIR}/$DOMAIN.qcow2,size=${VMDISKSIZE},format=qcow2" \
106149
--check disk_size=off \
107-
--vcpus $total_cores \
150+
--vcpus $install_total_cores \
108151
--network bridge=virbr0 \
109152
--graphics none \
110153
--console pty,target_type=serial \

vmresize

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
#set -x
3+
vmhost=${VMHOST:-abeast1-sesa.bu.edu}
4+
if [[ $vmhost != $(hostname) ]]; then
5+
pre="ssh -x $vmhost"
6+
pretty="ssh -x -t $vmhost"
7+
else
8+
unset pre
9+
unset pretty
10+
fi
11+
arch=${VMARCH:-$($pre uname -i)}
12+
base=${VMBASEVM:-basevm-$arch}
13+
14+
domain=$1
15+
cpus=$2
16+
ram=$3
17+
18+
if [[ -z $domain ]]; then
19+
echo "USAGE:vmvresize <name> [cpus] [ram]"
20+
echo " where name is a the name of one of your existing vms:"
21+
$pre virsh list --all | grep -v $base
22+
echo " You can use vmnew to create a new one from the base."
23+
echo " Base vm is $base ... you should not use this one directly"
24+
exit -1
25+
fi
26+
27+
28+
if [[ -z $cpus && -z $ram ]]; then
29+
echo "$DOMAIN: cpus: $($pre virsh vcpucount)"
30+
31+
$pre virsh setmem ${DOMAIN} ${VMMEM} --config
32+
$pre virsh setvcpus ${DOMAIN} ${VMCPUS} --config
33+
34+
if ! $pretty virsh console --force $domain; then
35+
$pre virsh start $domain
36+
if ! $pretty virsh console --force $domain; then
37+
echo "WTF: can't seem to start or attach to kele console" > /dev/stderr
38+
exit -1
39+
fi
40+
fi

vmsave.sh

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,32 @@
33

44
ARCH=$(uname -i)
55
DOMAIN=${VMBASEVM:-basevm-$ARCH}
6-
DISKDIR=disk
7-
DISK=${DISKDIR}/${DOMAIN}.qcow2
8-
#SAVEDIR=save
9-
10-
#mkdir $SAVEDIR
6+
VMSDIR=vms
7+
DISK=${VMSDIR}/${DOMAIN}.qcow2
118

129
echo "shutdown down $DOMAIN" > /dev/stderr
1310
virsh shutdown $DOMAIN
1411

1512
echo "dumping xml for $DOMAIN" > /dev/stderr
16-
virsh dumpxml $DOMAIN > ${DISKDIR}/$DOMAIN.xml
13+
virsh dumpxml $DOMAIN > ${VMSDIR}/$DOMAIN.xml
1714

1815
# brittle but will do
19-
echo "attempting to save nvram" > /dev/stderr
20-
virsh vol-download --sparse --pool nvram basevm-aarch64_VARS.fd --file disk/${DOMAIN}_VARS.fd
16+
#echo "attempting to save nvram" > /dev/stderr
17+
#virsh vol-download --sparse --pool nvram basevm-aarch64_VARS.fd --file ${VMSDIR}/${DOMAIN}_VARS.fd
18+
19+
# JA: KLUDGE -- WHAT A PIECE OF @$%@$%@#$
20+
grep $USER ${VMSDIR}/basevm-aarch64.xml | grep -v $(pwd)/${VMSDIR} | while read file
21+
do
22+
file=${file#*>}
23+
file=${file%<*}
24+
if [[ -a ${file} ]]; then
25+
echo copying: ${file}
26+
cp -r $file ${VMSDIR}
27+
fi
28+
done
2129

2230
#echo "copying disk for $DOMAIN" > /dev/stderr
2331
#cp --sparse=always ${DISK} ${SAVEDIR}/
2432

2533
echo "create sparse tar ball"
26-
tar cvfS $DOMAIN.tar ${DISKDIR}
34+
tar cvfS $DOMAIN.tar ${VMSDIR}

0 commit comments

Comments
 (0)