KVM: VM creation
Create Torque reservation
Establish a SSH connection to a compute node using X-forwarding:
ssh -X arc.csc.ncsu.edu
qsub -I -X ...
Create VM
-
/usr/local/bin/virt-install-wrapper.sh is a wrapper for virt-install which takes all the commandline arguments you would normally pass to virt-install.
-
/usr/local/bin/virt-install-wrapper.sh must be invoked with sudo.
-
Disk images must be stored in /tmp, not /home. Shut down your VM and copy the disk image to login-0-0:/tmp/ before termination of your reservation. Again, please do NOT use /home to store Gigabyte sized images!!!
-
Interactive installs using --prompt are not supported.
-
Select a MAC address following the MAC guidelines.
-
For example, to create a CentOS VM named testvm, use the following command:
sudo /usr/local/bin/virt-install-wrapper.sh \
--name testvm \
--ram 500 \
--file-size 5 \
--nographics \
-l ftp://ftp.linux.ncsu.edu/pub/centos/5.5/os/x86_64 \
--file /tmp/testvm.img \
--extra-args='console=tty0 console=ttyS0,115200n8' \
--accelerate \
--vcpus=2 \
--network bridge:br0 \
--mac=54:52:00:00:xx:yy
The same command on a single line:
sudo /usr/local/bin/virt-install-wrapper.sh --name testvm --ram 500
--file-size 5 --nographics -l
ftp://ftp.linux.ncsu.edu/pub/centos/5/os/x86_64 --file /tmp/testvm.img
--extra-args='console=tty0 console=ttyS0,115200n8' --accelerate
--vcpus=2 --network bridge:br0 --mac=54:52:00:00:xx:yy
In this case we assume a network install. However, an ISO can be downloaded and used if needed.
-
NOTE: br0 must be specified as the network bridge.
-
NOTE: CentOS / RHEL guests require the 'console=...' kernel parameter so that the text-based installation works.
Fix MAC and enable VNC
-
Upon completion of the text-based installation, you will be greeted with a login prompt. Press Ctrl-] to exit the console connection.
-
NOTE: All virsh commands must always include the -c qemu:///system parameter.
virsh -c qemu:///system ...
-
Dump your VM's XML file so it can be edited.
virsh -c qemu:///system dumpxml testvm > testvm.xml
-
Edit testvm.xml by adding this line to enable VNC, in the <devices> section:
<graphics type='vnc' port='5900'/>
-
Destroy your VM and remove it from virsh, so you can reload the edited XML.
virsh -c qemu:///system destroy testvm
virsh -c qemu:///system undefine testvm
-
Add your edited XML to virsh and start the VM again.
virsh -c qemu:///system define testvm.xml
virsh -c qemu:///system start testvm
Complete installation with VNC
-
Use virsh to discover the VNC display for your VM:
virsh -c qemu:///system vncdisplay testvm
-
Use VNC to complete the post-install routine for your OS (assuming you've correctly configured X-forwarding):
vncviewer 127.0.0.1:<display number>
-
NOTE: virsh console will not work due to permissions issues. The installation must be completed using VNC.
-
Once finished, open a terminal using VNC and determine your IP address:
/sbin/ifconfig eth0
-
SSH should work to/from the VM / physical host.
Use multiple guests
-
Copy you your image file to create an identical guest:
cp /tmp/testvm.img /tmp/testvm2.img
-
Dump your VM's XML file so it can be edited.
virsh -c qemu:///system dumpxml testvm > testvm2.xml
-
Edit testvm2.xml file to change the MAC (to a different one than the one in testm.xml):
<mac address='54:52:00:00:xx:aa'/>
See MAC guidelines.
-
Add your testvm2.xml to virsh and start the VM.
virsh -c qemu:///system define testvm2.xml
virsh -c qemu:///system start testvm2