Citrix Xen: How to create VM and install Operating System via command line without XenCenter

root's picture

In this article, I will show you how to install (any) operating system via command line in Citrix Xen. And without too much comment, read on!

Create a VM from the Debian Lenny template. Output should be the VM's UUID:

xe vm-install template="Debian Wheezy 7.0 (64-bit)" new-name-label=debian

Execution:
[root@xenGZ cd]# xe vm-install template="Debian Wheezy 7.0 (64-bit)" new-name-label=debian
36f3763b-4011-055f-4945-92fe13a0027b

Get the root disk UUID of this new VM:

xe vbd-list vm-uuid=<vm_uuid> userdevice=0 params=uuid --minimal

Execution:
[root@xenGZ cd]# xe vbd-list vm-uuid=36f3763b-4011-055f-4945-92fe13a0027b userdevice=0 params=uuid --minimal
20b45191-8a7c-1c97-8995-8b1776866965

Using the UUID from the previous command, remove the bootable option from it:

xe vbd-param-set uuid=20b45191-8a7c-1c97-8995-8b1776866965 bootable=false

Execution:
[root@xenGZ cd]# xe vbd-param-set uuid=20b45191-8a7c-1c97-8995-8b1776866965 bootable=false
[root@xenGZ cd]#

List the name of the CD drives:

xe cd-list

Execution:
[root@xenGZ cd]# xe cd-list
uuid ( RO)          : f5875157-4df4-4ed3-88d6-00edd28375e4
    name-label ( RW): Old version of xs-tools.iso

uuid ( RO)          : f341651f-ded7-4e6b-9751-2f7e12725edb
    name-label ( RW): Old version of xs-tools.iso

uuid ( RO)          : cd64bfa2-457c-475a-8d84-2489f744e2c7
    name-label ( RW): xs-tools.iso

uuid ( RO)          : 8fd5825b-c65c-4065-b7be-58c126900fc8
    name-label ( RW): Old version of xs-tools.iso

uuid ( RO)          : e365d863-72a6-44ab-b62b-f73006bef547
    name-label ( RW): Old version of xs-tools.iso

uuid ( RO)          : 23a79add-fd2c-476e-9df7-fd45d738f8cc
    name-label ( RW): Old version of xs-tools.iso

uuid ( RO)          : acf6edec-c22a-448e-8d89-73a8f1e2d572
    name-label ( RW): Old version of xs-tools.iso

uuid ( RO)          : 27e7f532-4aaa-4dd3-825f-3b84c5b04855
    name-label ( RW): XenCenter.iso

uuid ( RO)          : 758ec20a-ce4a-481f-a582-1316c30101f7
    name-label ( RW): debian-8.2.0-amd64-CD-1.iso

Add the desired CD-ROM to the VM:

NOTE: if device number is occupied, try a higher number.
xe vm-cd-add vm=<vm_name> cd-name="<host_cd_drive_name_label>" device=<number>

Execution:
[root@xenGZ cd]# xe vm-cd-add vm=debian cd-name="debian-8.2.0-amd64-CD-1.iso" device=3
[root@xenGZ cd]#

Get the UUID of the VBD corresponding to the CD drive added previously:

xe vbd-list vm-uuid=<vm_uuid> type=CD params=uuid --minimal

Execution:
[root@xenGZ cd]# xe vbd-list vm-uuid=36f3763b-4011-055f-4945-92fe13a0027b type=CD params=uuid --minimal
41973dba-dece-0193-fa58-448837f85b6a

Make the virtual CD bootable:

xe vbd-param-set uuid=<cd_drive_uuid> bootable=true

Execution:
[root@xenGZ cd]# xe vbd-param-set uuid=41973dba-dece-0193-fa58-448837f85b6a bootable=true
[root@xenGZ cd]#

Configure the install repository as CD drive:

xe vm-param-set uuid=<vm_uuid> other-config:install-repository=cdrom

Execution:
[root@xenGZ cd]# xe vm-param-set uuid=36f3763b-4011-055f-4945-92fe13a0027b other-config:install-repository=cdrom
[root@xenGZ cd]#

Add and configure network adapter:

xe network-list
xe vif-create vm-uuid=<vm_uuid> network-uuid=<network_uuid> mac="<new_mac_address>" device=0
Note: if you do not specify the mac, the system will choose one automatically.

If needed, resize disk before proceeding:

xe vm-disk-list vm=debian
xe vdi-resize uuid=<vdi_uuid> disk-size=<new_size_in_GiB>

Start the VM:

[root@xenGZ cd]# xe vm-start vm=debian
[root@xenGZ cd]#

Connect to VM's VNC via SSH Tunneling (without XenCenter):

xe vm-list params=dom-id,resident-on name-label=<vm>
xenstore-read /local/domain/<dom-id>/console/vnc-port

Execution:
[root@xenGZ cd]# xe vm-list params=dom-id,resident-on name-label=debian
resident-on ( RO)    : 3664c511-cd7b-4705-8fcb-31f8b82d46d5
         dom-id ( RO): 14

[root@xenGZ cd]# xenstore-read /local/domain/14/console/vnc-port
5904

Create a tunnel from your machine to XEN via ssh:

ssh -L 7777:localhost:5904 root@xen_ip

Now use your favorite VNC client and connect to localhost:7777.
You should have the debian installer displayed.

After the installation remove the boot from cd and enable one from disk:

[root@xenGZ ~]# xe vm-shutdown vm=debian
[root@xenGZ ~]# xe vbd-param-set uuid=41973dba-dece-0193-fa58-448837f85b6a bootable=false
[root@xenGZ ~]# xe vbd-param-set uuid=20b45191-8a7c-1c97-8995-8b1776866965 bootable=true

That is pretty much it. Enjoy!

Thou shalt not steal!

If you want to use this information on your own website, please remember: by doing copy/paste entirely it is always stealing and you should be ashamed of yourself! Have at least the decency to create your own text and comments and run the commands on your own servers and provide your output, not what I did!

Or at least link back to this website.

Recent content