Posts tagged: virtualize

QEMU VNC: Change Your Password And Daemonize Your Monitor

I had a lovely time figuring this out. For obvious reasons you don’t pass the vnc password to the qemu command as it can be seen with a ps. The only other approved unimplemented option is to have a password file. At least with a password file you can secure it with file system permissions. My box has no users so to me whatever works works. Anyway…

The problem: daemonize your qemu while still allowing vnc with security! To change the vnc password you have to issue a command ‘change vnc password XXXXX’ to the qemu monitor. The monitor can work with stdio but that defeats the point of daemonize…

My solution: set the monitor to use a tcp port bound to localhost. This way you can continue to control the qemu monitor from the tcp socket. Then use netcat’s nc command to issue it the change vnc password command. I ran in to yet another problem. The nc command didn’t automatically exit and my scripts are non interactive start up scripts.

qemu-kvm -vnc 192.168.0.1:0,password -monitor telnet:127.0.0.1:4444,server,nowait –daemonize
echo change vnc password XXXXX; echo | nc 127.0.0.1 4444

Solution to new problem: Tell nc to execute a command rather than use stdio. The command would simply echo command then echo a new line and exit. This also solved my problem of how to tell qemu to stop running without simply issuing it a kill command. My script took arg1 as the vnc password.

nc 127.0.0.1 4444 -e /change_vnc.sh XXXXX

The fact that I’m using busybox to do all of this may have complicated the nc command so I don’t know if actual netcat would have had that problem. Regardless it was very simple.