store vmimages in /lmn/vm and mount media in /lmn/media

This commit is contained in:
Raphael Dannecker 2023-08-14 16:18:34 +02:00
parent 68239b56cb
commit e64008c714
14 changed files with 150 additions and 94 deletions

View file

@ -11,19 +11,19 @@ if [[ $# -ne 1 ]]; then
fi
# change to image-directory
cd /var/lib/libvirt/images
cd /lmn/vm
VM_NAME=$1
VM_DIR="/tmp/${UID}/vmimages"
VM_XML="${VM_DIR}/xml/${VM_NAME}-clone.xml"
VM_DIR="/tmp/${UID}/vm"
VM_XML="${VM_DIR}/${VM_NAME}-clone.xml"
if ! [[ -f "xml/${VM_NAME}.xml" && -f "${VM_NAME}.qcow2" ]] && ! [[ -f "${VM_DIR}/xml/${VM_NAME}.xml" && -f "${VM_DIR}/${VM_NAME}.qcow2" ]]; then
if ! [[ -f "${VM_NAME}.xml" && -f "${VM_NAME}.qcow2" ]] && ! [[ -f "${VM_DIR}/${VM_NAME}.xml" && -f "${VM_DIR}/${VM_NAME}.qcow2" ]]; then
echo "xml or qcow2 File does not exists." >&2
exit 1
fi
# Create User-VM-Dir and link system VM-Images
[[ -d "${VM_DIR}/xml" ]] || mkdir -p "${VM_DIR}/xml"
[[ -d "${VM_DIR}" ]] || mkdir -p "${VM_DIR}"
sudo /usr/local/bin/link-images.sh
# Create backing file
@ -31,7 +31,7 @@ cd "${VM_DIR}"
qemu-img create -f qcow2 -F qcow2 -b "${VM_NAME}.qcow2" "${VM_NAME}-clone.qcow2"
# Create machine-definition-file
cp "${VM_DIR}/xml/${VM_NAME}.xml" "${VM_XML}"
cp "${VM_DIR}/${VM_NAME}.xml" "${VM_XML}"
# set VM_DIR:
sed -i "s:VMIMAGEDIR:${VM_DIR}:" "${VM_XML}"