Sep 232012
 

I need to create virtual machine on XenServer (6.2.0) but I have access to console/SSH only

Solution:

  1. Virtual machine based on template. For select template execute:
    xe template-list
  2. After selecting template, create VM:
    xe vm-install template="Debian Wheezy 7.0 (32-bit)" new-name-label="newVM"

    so VM based on Debian Wheezy 7.0 (32-bit) template, VM name is newVM
    Last command execution produced UUID for created VM

  3. Disable boot from VM hard disk:
    xe vbd-list vm-uuid=[VM uuid] userdevice=0
    xe vbd-param-set uuid=[device UUID] bootable=false
    
  4. Choose boot disk for VM (in ths case – Debian install image from NFS):
    xe cd-list
    xe vm-cd-add vm="newVM" cd-name="debian-7.0.0-i386-netinst.iso" device=3
    xe vbd-list vm-name-label="newVM" userdevice=3
    xe vbd-param-set  uuid=[device uuid] bootable=true
    xe vm-param-set uuid=[VM uuid] other-config:install-repository=cdrom
    
  5. Get network interface list on host:
    xe network-list

    add physical network interface to VM:

    xe vif-create vm-uuid=[VM uuid] network-uuid=[network uuid] mac="[new mac address]" device=0
    
  6. Change memory settings. By default, XenServer create debian VM with 256M RAM, check it out
    xe vm-list name-label="newVM" params=all |grep memory
    

    and change VM RAM to 1GB if needed

    xe vm-memory-limits-set dynamic-max=1GiB dynamic-min=1GiB static-max=1GiB static-min=1GiB name-label="newVM"
    
  7. Change disk size. By default, XenServer create debian VM with 8 GB disk, check it out
    xe vm-disk-list vm="newVM"
    

    Change disk size, for example to 20 GB, if need

    xe vdi-resize uuid=[VDI uuid] disk-size=20GiB
    
  8. Start VM:
    xe vm-start vm=newVM
    

For connect to installed VM console use VNC:

  • retrieve VM domain number:
    xe vm-param-list uuid=[VM uuid] | grep dom-id
  • retrieve VNC port for this domain:
    xenstore-read /local/domain/[domain]/console/vnc-port
  • remote connection ([port] – last two digits from previous output):
    vncviewer -via root@[xenserver] localhost:[port]

  3 Responses to “Create virtual machine in XenServer from command line”

  1. Добрый день. При выполнение xe cd-list Необходимого образа нет в списке. Как подключить iso-образ, чтобы он был доступен при выполнении команды xe cd-list?

    • Здравствуйте,

      Для работы с iso нужно сначала подключить дополнительное хранилище, в котором они лежат (XenCenter->Storage->New SR->ISO Library)
      У меня это просто отдельный NAS, монтируемый по NFS

    • Можно так:

      xe sr-create name-label=local-ISO type=iso device-config:location=/root/ISO device-config:legacy_mode=true content-type=iso

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)