39 lines
1.5 KiB
Bash
Executable File
39 lines
1.5 KiB
Bash
Executable File
#!/bin/bash
|
|
set -x
|
|
set -e
|
|
|
|
# Source image path
|
|
IMAGE=/data/image.bin
|
|
|
|
# TODO: With QEMU snapshots instead
|
|
if [ ! -w $IMAGE ]; then
|
|
echo "Data volume is not writable, assuming discardable VM and copying to tmpfs"
|
|
cp $IMAGE /tmp/image.bin
|
|
IMAGE=/tmp/image.bin
|
|
fi
|
|
|
|
# Create macvlan interface on Docker's eth0
|
|
ip link add link eth0 name macvtap0 type macvtap mode bridge
|
|
ip link set dev macvtap0 address ${MAC:?}
|
|
ip link set macvtap0 up
|
|
|
|
# No udev in Docker
|
|
IFS=: read major minor < <(cat /sys/devices/virtual/net/macvtap0/tap*/dev)
|
|
mknod "/dev/tap$(cat /sys/class/net/macvtap0/ifindex)" c $major $minor
|
|
|
|
# Launch QEMU instance
|
|
/usr/bin/qemu-system-x86_64 \
|
|
-machine pc-i440fx-4.2,accel=kvm \
|
|
-m 8192 \
|
|
-device virtio-scsi-pci,id=scsi0,bus=pci.0,addr=0x6 \
|
|
-blockdev "{\"driver\":\"file\",\"filename\":\"$IMAGE\",\"node-name\":\"libvirt-1-storage\",\"auto-read-only\":true,\"discard\":\"unmap\"}" \
|
|
-blockdev "{\"node-name\":\"libvirt-1-format\",\"read-only\":false,\"driver\":\"raw\",\"file\":\"libvirt-1-storage\"}" \
|
|
-device scsi-hd,bus=scsi0.0,channel=0,scsi-id=0,lun=0,device_id=drive-scsi0-0-0-0,drive=libvirt-1-format,id=scsi0-0-0-0,bootindex=2 \
|
|
-device virtio-net-pci,netdev=hostnet0,id=net0,mac=$(cat /sys/class/net/macvtap0/address) \
|
|
-device virtio-balloon-pci \
|
|
-usb \
|
|
-device usb-ehci,id=ehci \
|
|
-device usb-tablet,bus=usb-bus.0 \
|
|
-vnc :0 \
|
|
-netdev tap,id=hostnet0,vhost=on,fd=9 9<>/dev/tap$(cat /sys/class/net/macvtap0/ifindex)
|