feat: ephvm-run.sh virtio devices, require kvm
This commit is contained in:
@@ -130,15 +130,13 @@ main() {
|
|||||||
CLEANUP_OVERLAY=$(mktemp -d)
|
CLEANUP_OVERLAY=$(mktemp -d)
|
||||||
local overlay="$CLEANUP_OVERLAY/overlay.qcow2"
|
local overlay="$CLEANUP_OVERLAY/overlay.qcow2"
|
||||||
qemu-img create -f qcow2 -b "$(realpath "$image")" -F qcow2 "$overlay" "$disk_size"
|
qemu-img create -f qcow2 -b "$(realpath "$image")" -F qcow2 "$overlay" "$disk_size"
|
||||||
drive_arg="file=$overlay,format=qcow2"
|
drive_arg="if=none,id=hd0,file=$overlay,format=qcow2,cache=writeback,aio=threads,discard=unmap,detect-zeroes=unmap"
|
||||||
else
|
else
|
||||||
drive_arg="file=$image,format=qcow2,snapshot=on"
|
drive_arg="if=none,id=hd0,file=$image,format=qcow2,snapshot=on,cache=writeback,aio=threads,discard=unmap,detect-zeroes=unmap"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
command -v qemu-system-x86_64 &>/dev/null || die "qemu-system-x86_64 not found"
|
command -v qemu-system-x86_64 &>/dev/null || die "qemu-system-x86_64 not found"
|
||||||
|
[ -r /dev/kvm ] || die "/dev/kvm not readable; kvm is required"
|
||||||
local accel="tcg"
|
|
||||||
[ -r /dev/kvm ] && accel="kvm"
|
|
||||||
|
|
||||||
# auto-allocate ssh port unless serial mode
|
# auto-allocate ssh port unless serial mode
|
||||||
if [ "$serial" = false ] && [ -z "$ssh_port" ]; then
|
if [ "$serial" = false ] && [ -z "$ssh_port" ]; then
|
||||||
@@ -148,26 +146,25 @@ main() {
|
|||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local nic_arg="user"
|
local nic_arg="user,model=virtio-net-pci"
|
||||||
if [ -n "$ssh_port" ]; then
|
if [ -n "$ssh_port" ]; then
|
||||||
nic_arg="user,hostfwd=tcp:127.0.0.1:${ssh_port}-:22"
|
nic_arg="user,model=virtio-net-pci,hostfwd=tcp:127.0.0.1:${ssh_port}-:22"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local -a qemu_args=(
|
local -a qemu_args=(
|
||||||
qemu-system-x86_64
|
qemu-system-x86_64
|
||||||
-accel "$accel"
|
-accel kvm
|
||||||
|
-cpu host
|
||||||
-m "$memory"
|
-m "$memory"
|
||||||
-smp "$cpus"
|
-smp "$cpus"
|
||||||
-drive "$drive_arg"
|
-drive "$drive_arg"
|
||||||
|
-device "virtio-blk-pci,drive=hd0"
|
||||||
|
-device virtio-rng-pci
|
||||||
-nic "$nic_arg"
|
-nic "$nic_arg"
|
||||||
-nographic
|
-nographic
|
||||||
-sandbox "on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny"
|
-sandbox "on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny"
|
||||||
)
|
)
|
||||||
|
|
||||||
if [ "$accel" != "tcg" ]; then
|
|
||||||
qemu_args+=(-cpu host)
|
|
||||||
fi
|
|
||||||
|
|
||||||
local fs_id=0 mount_path name tag
|
local fs_id=0 mount_path name tag
|
||||||
for mount_path in "${mounts[@]}"; do
|
for mount_path in "${mounts[@]}"; do
|
||||||
[ -e "$mount_path" ] || die "--mount path does not exist: $mount_path"
|
[ -e "$mount_path" ] || die "--mount path does not exist: $mount_path"
|
||||||
@@ -200,7 +197,7 @@ main() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
info "---"
|
info "---"
|
||||||
info "Accel: $accel"
|
[ -n "$ssh_port" ] && info "SSH: ssh -p $ssh_port matej@localhost"
|
||||||
info "---"
|
info "---"
|
||||||
|
|
||||||
if [ "$serial" = true ]; then
|
if [ "$serial" = true ]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user