17 February 2016

XenServer: Install a VM from the Command Line


Abbreviated from the official docs. This is the theory but in practice I found it didn't work: Nothing to boot: No such file or directory (http://ipxe.org/err/2d03e1)

Create the VM

Template

  • List the Templates to use: xe template-list
  • Filter according to a particular distro:
    xe template-list | grep "Ubuntu"
  • Output the storage repo list to a file then use the search feature to open it e.g.
    xe template-list > xe-template-list.txt
    vi xe-template-list.txt
    Then use / to enter a search term e.g. Ubuntu

Storage Repository

  1. List available storage repositories:
    xe sr-list
    You need the one with type LVM. Retain the UUID
  2. Check available space eg using UUID from 'Local Storage' in list above.
    List mount points: df -h
    List Available space: df -h /run/sr-mount/[some UUID]
    List used space: du -sh /run/sr-mount/[some UUID]

Create the VM

  1. Create a VM using the template and storage UUIDs and retain the UUID it returns:
    xe vm-install template="[template name(not UUID)]" new-name-label="[hostname]" \sr-uuid=[storage_repository_uuid]
  2. Rename the resulting Virtual Disk:
    xe vm-disk-list vm=[hostname]
    xe vdi-param-set uuid=[VD UUID] name-label="[hostname] Disk 0 VDI"

Memory and Network

  1. Increase memory (if needed):
    xe vm-param-list uuid=[VM UUID] | grep -i memory (look at memory-static-max)
    xe vm-memory-limits-set dynamic-max=2147483648 dynamic-min=2147483648 static-max=2147483648 static-min=2147483648 name-label=[hostname]
  2. Attach a network interface:
    1. xe network-list (You need the one attached to eth0)
    2. Create a VIF to connect the new VM to this network:
      xe vif-create vm-uuid=[vm_uuid] network-uuid=[network_uuid] mac=random device=0
    3. List to check:
      xe vm-vif-list vm="<VM name>"

Setup the Boot Disk

  1. Disable boot from VM hard disk (so can boot from mirror):
    xe vbd-list vm-uuid=[VM uuid] userdevice=0
    xe vbd-param-set uuid=[Device UUID (not VDI UUID)] bootable=false

Boot from ISO

See previous post on setting up ISO share.
  1. List the available ISOs
    xe cd-list
  2. List the existing devices:
    xe vbd-list vm-name-label="<VM name>"
  3. Attach the ISO to the VM:
    xe vm-cd-add vm="<VM name>" cd-name="<ISO name-lable>" device=1
  4. Get the UUID of the VBD you've just added:
    xe vbd-list vm-name-label="newVM" userdevice=1
  5. Set the VBD to bootable:
    xe vbd-param-set  uuid=[VBD device uuid, NOT vdi-uuid] bootable=true
  6. Set the install repo of the VM:
    xe vm-param-set uuid=[VM uuid] other-config:install-repository=cdrom

Boot from Network (Doesn't work for me)

  1. Set the install-repository key of the other-config parameter to the path of the network repository
    e.g. http://www.mirrorservice.org/sites/archive.ubuntu.com/ubuntu/dists/trusty/main/installer-amd64/current/images/netboot/xen/vmlinuz
    xe vm-param-set uuid=[vm_uuid] \other-config:install-repository=[mirror]

Start the VM

  1. Start the VM:
    xe vm-start uuid=[vm_uuid]
  2. Connect tot he VM console via XenCeter or VNC to complete the installation

Connect to the VM via VNC

  1. Get the VM domain number:
    xe vm-param-list uuid=[VM uuid] | grep dom-id
  2. Get the VNC port for this domain:
    xenstore-read /local/domain/<domain number>/console/vnc-port
  3. VNC viewer remote connection. Port = last two digits from previous output:
    vncviewer -via root@[xenserver] localhost:<port>

No comments:

Post a Comment