There are a lot of possibilties to manage the qemu kvm monitor and serial ports. Here is one solution to provide these two ports for a user which only has a chroot home with a small busybox (with microcom). First of all qemu-kvm has to know how the interfaces should be exported. This solution uses the ‘pty’ (pseudo terminal) interfaces/devices (“-monitor pty -seriak pty”). The qemu-kvm instance creates to ptys which will be show up in /dev/pts. To provide this devices to the chroot user, just create the same character devices inside the chroot. Now the user can use microcom to connect to both ports. To automate this process the following script does the magic:

#!/bin/bash
manage_home=/home/chroot/kvm
HN=disk
KVM_USER=XYZ
nohup qemu-kvm -daemonize -no-acpi-nographic -m 378 -localtime \
  -hda ${HN}.img -monitor pty -serial pty

pty_mon=`head -1 nohup.out | awk '{ print $5; }'`
pty_ser=`tail -1 nohup.out | awk '{ print $5; }'`

rm -f $manage_home/$KVM_USER/${HN}_mon
rm -f $manage_home/$KVM_USER/${HN}_ser
mknod $manage_home/$KVM_USER/${HN}_ser c 136 ${pty_ser##*/}
mknod $manage_home/$KVM_USER/${HN}_mon c 136 ${pty_mon##*/}
chown $KVM_USER $manage_home/$KVM_USER/${HN}_mon $manage_home/$KVM_USER/${HN}_ser
chmod 600 $manage_home/$KVM_USER/${HN}_mon $manage_home/$KVM_USER/${HN}_ser
rm -f nohup.out

Comments are closed.