Using KVM from commandline without vnc

As part of a major server upgrade, I have changed my old Compaq DL360G1, with a single pentium III to a Dell 2U 2950 with 2 Xeon E5420.

As part of the upgrade I have changed my setup from 32 bit to 64 bit, from ext3 to ext4 and from XEN virtualization to KVM.

Usually when working with KVM you use vnc. This have its pros and cons. Though, as the host server itself of cause is headless and the clients I use for administration not all have a vnc client, I was looking for a cleaner solution. The result was a way with uses screen and ncurses, so I just need a ssh access to the server for controlling everything.

#!/bin/bash
 
# Script for using kvm virtualization from a console
 
NAME="MACHINENAME"
MEMORY="512"
CPUS="1"
VM_GROUP="/dev/KvmGroup/"
BRIDGE_SCRIPT="/root/Scripts/qemu-ifup-brKvm.sh"
# Using the easyMAC script for a xen mac
MAC_ADDRESS="00:50:56:27:XX:XX"
 
/usr/bin/screen -A -m -d -S "kvm_${NAME}" -t "${NAME}" \
/usr/bin/qemu-system-x86_64 \
--enable-kvm \
-m ${MEMORY} \
-name ${NAME} \
-smp ${CPUS} \
-drive file=${VM_GROUP}${NAME}_root,if=scsi,boot=on \
-drive file=${VM_GROUP}${NAME}_swap,if=scsi \
-net nic,macaddr=${MAC_ADDRESS} \
-net tap,script=${BRIDGE_SCRIPT} \
-k da \
-monitor unix:/var/run/kvm/monitors/${NAME},server,nowait \
-pidfile /var/run/kvm/pids/${NAME} \
-nographic \
-curses #\
#    -cdrom /root/ISO/install-amd64-minimal-20110421.iso \
#    -boot d

This is a crude example for how it is used. But should give some ideas for how it is used. Notice the two commented lines. This is for booting from a iso image.
The result is shown in the following figure:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.