mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-24 23:21:17 +02:00
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:
parent
99982182b9
commit
c7ba8cd4a4
@ -280,52 +280,36 @@ _write_qemu_conf() {
|
||||
local src_name=$(basename "$VM_SRC_IMG")
|
||||
local dst_name=$(basename "$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
|
||||
# Seems like submitting a patch to fix that and documenting this
|
||||
# format would be a worthy projects...
|
||||
# name=${VM_NAME}
|
||||
# uuid=${VM_UUID}
|
||||
# m=${vm_mem}
|
||||
# cpu=kvm64
|
||||
# smp=2
|
||||
cat >"${script}" <<EOF
|
||||
#!/bin/sh
|
||||
|
||||
cat >"${conf_path}" <<EOF
|
||||
# qemu config file
|
||||
SCRIPT_DIR="\`dirname "\$0"\`"
|
||||
DISK_IMAGE="\${SCRIPT_DIR}/${dst_name}"
|
||||
|
||||
# Default to KVM, fall back on full emulation
|
||||
[machine]
|
||||
accel = "kvm:tcg"
|
||||
|
||||
[drive]
|
||||
media = "disk"
|
||||
index = "0"
|
||||
# if = "virtio"
|
||||
file = "${dst_name}"
|
||||
format = "raw"
|
||||
|
||||
[net]
|
||||
type = "nic"
|
||||
vlan = "0"
|
||||
model = "virtio"
|
||||
|
||||
[net]
|
||||
type = "user"
|
||||
vlan = "0"
|
||||
hostfwd = "tcp::2222-:22"
|
||||
exec qemu-system-x86_64 \
|
||||
-name "${VM_NAME}" \
|
||||
-uuid "${VM_UUID}" \
|
||||
-m ${vm_mem} \
|
||||
-machine accel=kvm:tcg \
|
||||
-drive index=0,if=virtio,media=disk,format=qcow2,file="\${DISK_IMAGE}" \
|
||||
-net nic,vlan=0,model=virtio \
|
||||
-net user,vlan=0,hostfwd=tcp::2222-:22 \
|
||||
"\$@"
|
||||
EOF
|
||||
chmod +x "${script}"
|
||||
|
||||
cat >"${VM_README}" <<EOF
|
||||
If you have qemu installed, you can start the image with:
|
||||
cd $(relpath "${dst_dir}")
|
||||
qemu-system-x86_64 -curses -m ${vm_mem} -readconfig "${conf_path##*/}"
|
||||
./path/to/$(basename "${script}") -curses
|
||||
|
||||
SSH into that host with:
|
||||
ssh 127.0.0.1 -p 2222
|
||||
EOF
|
||||
|
||||
VM_GENERATED_FILES+=( "${conf_path}" "${VM_README}" )
|
||||
VM_GENERATED_FILES+=( "${script}" "${VM_README}" )
|
||||
}
|
||||
|
||||
# Generate the vmware config file
|
||||
|
Loading…
x
Reference in New Issue
Block a user