#!/bin/bash
echo not a script
exit 1


# notes on how to run qemu against a physical disk (which is in use)
# in order to test whether the headless server you're running qemu on is likely to boot correctly
#
# the arguments used below were mostly derived from:
#   qemu-system-x86_64 -machine help
#   qemu-system-x86_64 -cpu help
#   qemu-system-x86_64 -net nic,model=?
#
# note the argument snapshot=on given to -drive,
# this will prevent the VM from modifying the physical drive
# unless you press CTRL-A followed by S so please don't do that


# the server ip and the sshd port
# (variables are used in both server and workstation commands)
IP=12.34.56.67
PORT=22


# on your local workstation, set up port forwarding for vnc
ssh -L 5900:127.0.0.1:5900 -p $PORT root@$IP


# ports to forward from the VM to the server's WAN,
# two ports in this example to cover cases of multiple sshd's
# (only used in the server command for starting qemu)
SSH1=12345
SSH2=23456


# once you've started the qemu process on the server,
# use any vnc client on your workstation and connect to 127.0.0.1
# (screen 0 which should be default in all clients, alternatively port 5900)


# on your server,
# starting qemu with drives /dev/sda and /dev/sdb in software raid
# emulating a scsi HDD controller and virtio network
qemu-system-x86_64 \
-machine q35,accel=kvm \
-enable-kvm \
-cpu host \
-smp cpus=4,sockets=1,cores=4,threads=1 \
-m 16384 \
-boot c \
-drive file=/dev/sda,index=0,if=scsi,media=disk,snapshot=on,cache=none,format=raw,werror=report,rerror=report \
-drive file=/dev/sdb,index=1,if=scsi,media=disk,snapshot=on,cache=none,format=raw,werror=report,rerror=report \
-netdev user,id=n0,hostfwd=tcp::$((SSH1+1))-$IP:$SSH1,hostfwd=tcp::$((SSH2+1))-$IP:$SSH2 \
-device virtio-net-pci,netdev=n0 \
-vga std \
-vnc 127.0.0.1:0 \
-rtc base=utc,clock=host


# if you get an error message about the drive interface being invalid
# (don't recall the exact error) then your qemu is too new:
#
#   "-drive if=scsi" does not work anymore with PC machine types, as it created an obsolete SCSI controller model. QEMU supports better controllers (megasas, mptsas, virtio-scsi) but which to use depends on the guest you are using.
#
# try if=virtio if your kernel was built with virtio support,
# or just drop the if=virtio to try the default of your qemu version
#
# and I never really figured out the -netdev stuff so that might be broken
