Objective
Deployment of XenServer virtual machine using command line.
Requirements
Privileged access to XenServer’s command line as well as configured ISO image storage containing an ISO image of the Linux distribution you wish to install.
Difficulty
MODERATE
Instructions
Deploy VM template and gather information
In this guide we will be creating a new Ubuntu Linux based virtual machine. However, the below procedure will fit any decent Linux distribution as along as it is supported by XenServer, meaning that the template for the Linux distribution you would like to install is part of the XenServer’s repertoire. Let’s first search XenServer’s database for a template name.
In this case we are looking for Ubuntu 16.04:
# xe template-list | grep name-label | grep -i 16.04 name-label ( RW): Ubuntu Xenial Xerus 16.04
Next, install new virtual machine using the above template name:
# xe vm-install template="Ubuntu Xenial Xerus 16.04" new-name-label="Ubuntu 16.04.1 Desktop amd64" 784b1b7f-0c13-4e9a-9d06-6a3edd9c90c2
Save the output UUID and new VM name into a shell variable for later use. Using variables will make our further commands more user readable and understandable:
# UUID=784b1b7f-0c13-4e9a-9d06-6a3edd9c90c2 # NAME="Ubuntu 16.04.1 Desktop amd64"
Next, use cd-list
to list all available ISO images and store the relevant ISO image name into a variable, eg.:
# xe cd-list # ISO="ubuntu-16.04.1-desktop-amd64.iso"
Next, we deal with necessary networking bits. List, XenServer’s networks and save desired network UUID you wish to attach to your new VM:
# xe network-list uuid ( RO) : 23e21c78-dfa0-e6f4-9dcd-73da08870fe8 name-label ( RW): Host internal management network name-description ( RW): Network on which guests will be assigned a private link-local IP address which can be used to talk XenAPI bridge ( RO): xenapi uuid ( RO) : ae1299a0-c0db-bf00-7702-7e4ab09e1abd name-label ( RW): Pool-wide network associated with eth0 name-description ( RW): bridge ( RO): xenbr0
Save the network UUID:
# NETWORK=ae1299a0-c0db-bf00-7702-7e4ab09e1abd
We also have an option to bind a specific MAC addresses to a VM’s network interface. Store desired MAC address into a variable:
# MAC="4a:4d:42:ac:b3:7b"
Obtain virtual disk’s UUID so we can later update its size:
# xe vm-disk-list vm="$NAME" Disk 0 VBD: uuid ( RO) : 01ff5ffe-bde2-becc-ada1-9d1289e017a2 vm-name-label ( RO): Ubuntu 16.04.1 Desktop amd64 userdevice ( RW): 0 Disk 0 VDI: uuid ( RO) : 5eac954c-d6ce-4e0d-91de-85f9bd70123b name-label ( RW): 0 sr-name-label ( RO): Local storage virtual-size ( RO): 10737418240
Store VID’s UUID:
# VDI=5eac954c-d6ce-4e0d-91de-85f9bd70123b
Configure Virtual Machine
Now that we have all information gathered, it is time to configure our new VM. First, attach ISO image to new VM device and make the Virtual machine to boot from ISO:
# xe vm-cd-add uuid=$UUID cd-name=$ISO device=1 # xe vm-param-set HVM-boot-policy="BIOS order" uuid=$UUID
Next, create a network interface. If you do not include the MAC option as part of the a below command, the MAC address will be automatically generated:
# xe vif-create vm-uuid=$UUID network-uuid=$NETWORK mac=$MAC device=0 b5177fa9-81a2-3233-99c6-e545854dce8c
Specify RAM amount to be used by this virtual machine. Feel free to amend the below command with desired RAM size to fit your needs:
# xe vm-memory-limits-set dynamic-max=4000MiB dynamic-min=512MiB static-max=4000MiB static-min=512MiB uuid=$UUID
Lastly, update the size of your virtual disk. The below command will increase the size to 15GB:
# xe vdi-resize uuid=$VDI disk-size=15GiB
The above are some basic configurations required to start our new virtual machine. You may now also consider to update the information about CPUs, however, you can do that anytime after you perform the actual OS installation.
Start Virtual Machine
Now we are ready to start our new virtual machine:
# xe vm-start uuid=$UUID
Connect to VM installer
At this stage we use VNC client to connect to our new virtual machine. First, we need to get a VNC port number to connect to:
# DOMID=`list_domains | grep $UUID | awk '{ print $1 }'` # xenstore-read /local/domain/$DOMID/console/vnc-port 5901
Last two digits of the above command output will provide you with the VNC port number. In this case it’s 1
. Use vnc client to connect remotely:
$ vncviewer -via root@XENSERVER_IP localhost:1
