fix(image_to_vm): Replace qemu's config file with a script.

The recommended command using the config file was triggering a massive
memory leak in qemu because it was adding both the default virtual
hardware nic as well as the virtio nic. This could be worked around by
adding something like -net none or moving all the -net commands from the
file to the command line but eh. Clearly qemu config files are used and
tested by nobody else so lets just use a trusty script instead.
This commit is contained in:
Michael Marineau 2013-08-01 23:32:02 -04:00
parent 99982182b9
commit c7ba8cd4a4

View File

@ -280,52 +280,36 @@ _write_qemu_conf() {
local src_name=$(basename "$VM_SRC_IMG") local src_name=$(basename "$VM_SRC_IMG")
local dst_name=$(basename "$VM_DST_IMG") local dst_name=$(basename "$VM_DST_IMG")
local dst_dir=$(dirname "$VM_DST_IMG") local dst_dir=$(dirname "$VM_DST_IMG")
local conf_path="${dst_dir}/$(_src_to_dst_name "${src_name}" ".conf")" local script="${dst_dir}/$(_src_to_dst_name "${src_name}" ".sh")"
# FIXME qemu 1.4/5 doesn't support these options in config files cat >"${script}" <<EOF
# Seems like submitting a patch to fix that and documenting this #!/bin/sh
# format would be a worthy projects...
# name=${VM_NAME}
# uuid=${VM_UUID}
# m=${vm_mem}
# cpu=kvm64
# smp=2
cat >"${conf_path}" <<EOF SCRIPT_DIR="\`dirname "\$0"\`"
# qemu config file DISK_IMAGE="\${SCRIPT_DIR}/${dst_name}"
# Default to KVM, fall back on full emulation # Default to KVM, fall back on full emulation
[machine] exec qemu-system-x86_64 \
accel = "kvm:tcg" -name "${VM_NAME}" \
-uuid "${VM_UUID}" \
[drive] -m ${vm_mem} \
media = "disk" -machine accel=kvm:tcg \
index = "0" -drive index=0,if=virtio,media=disk,format=qcow2,file="\${DISK_IMAGE}" \
# if = "virtio" -net nic,vlan=0,model=virtio \
file = "${dst_name}" -net user,vlan=0,hostfwd=tcp::2222-:22 \
format = "raw" "\$@"
[net]
type = "nic"
vlan = "0"
model = "virtio"
[net]
type = "user"
vlan = "0"
hostfwd = "tcp::2222-:22"
EOF EOF
chmod +x "${script}"
cat >"${VM_README}" <<EOF cat >"${VM_README}" <<EOF
If you have qemu installed, you can start the image with: If you have qemu installed, you can start the image with:
cd $(relpath "${dst_dir}") ./path/to/$(basename "${script}") -curses
qemu-system-x86_64 -curses -m ${vm_mem} -readconfig "${conf_path##*/}"
SSH into that host with: SSH into that host with:
ssh 127.0.0.1 -p 2222 ssh 127.0.0.1 -p 2222
EOF EOF
VM_GENERATED_FILES+=( "${conf_path}" "${VM_README}" ) VM_GENERATED_FILES+=( "${script}" "${VM_README}" )
} }
# Generate the vmware config file # Generate the vmware config file