1. In this tutorial, we will be connecting to our XenServer from a Linux machine via SSH. Before beginning the export process, ensure that the virtual machine that you are exporting is powered off. Open a terminal and enter the following command to SSH into your XenServer. Make sure to enter the hostname of your XenServer if different than xenserver.
2. If you have never used SSH to connect to your XenServer before, you will receive a message about the ‘authenticity of host ...’ Enter yes and press the Enter key on your keyboard to continue connecting.
3. You will then be prompted to enter the root password for your XenServer. Enter the root password and press Enter on your keyboard.
4. Once logged into your XenServer via SSH, your prompt should change to your XenServer terminal prompt like this:
5. Now we have to insert our USB flash drive into an empty USB slot on our XenServer. Since my Virtual Machines are Ubuntu 16.04 Server installs and since I am using the thin provisioning feature of XenServer, my virtual machines are relatively small and I can get away with a 32GB flash drive. Just make sure that the flash drive that you choose to hold the exported virtual machines is large enough to contain them or the process will fail.
6. After you have chosen and inserted your USB flash drive into your XenServer, the first thing to do is identify the name of the device file for our flash drive. In your terminal, enter the following command to identify your flash drive:
7. The output of the command should look similar to the image below.
8. Identify your device from the list. In my case, it is the last device in the list.
9. The next thing that we have to do is create a directory to which we will mount our device. Enter the following command into the terminal:
10. Now that the partition is mounted, we have to format the partition we are using to the EXT4 filesystem. To do this, enter the following into the terminal, replacing sdc1 with the partition you are using on your flash drive:
mkfs -t ext4 /dev/sdc1
11. Next, we will mount our device to the newly created directory. Note that we are mounting a partition of the device, not the entire device file. In my case, you can see from the image in step 8 that the partition that I must mount is /dev/sdc1.
mount /dev/sdc1 /mnt/usb
12. With our flash drive formatted and mounted, we can begin the export process. To view a list of the virtual machines on your XenServer, enter the following command into the terminal:
13. The output of the command should look similar to the following image. As you can see, I have 4 virtual machines plus the Control domain listed. I will be exporting the virtual machine named “Tutorial_VM”.
14. If you see from the output of the previous command that the virtual machine that you need to export is running, you can shut it down with the following command, replacing <the-vm-name> with the actual name of your virtual machine:
xe vm-shutdown vm=<the-vm-name>
15. The last step to exporting our virtual machine is to enter the following command into the terminal, replacing <the-vm-name> with the actual name of the virtual machine. Make sure to add the complete path to the partition we mounted earlier before the filename in the command:
xe vm-export vm=<the-vm-name> filename=/mnt/usb/<the-vm-name>.xva
16. After entering the previous command and pressing Enter on your keyboard, XenServer will begin exporting your virtual machine to your flash drive. This process will take awhile, especially if your virtual machine is very large. There will be no output from the process until the process completes. When the VM is exported, you will receive a message like the one in the image below:
17. To verify that your virtual machine has been successfully exported to your flash drive, enter the following command:
18. You should see your virtual machine in the output of the previous command.
19. You can now use the following command to unmount your flash drive before removing it.
20. You can now safely remove your flash drive.
21. To import your virtual machine into XenServer, simply locate and mount your flash drive’s partition containing you virtual machine to a directory located at mnt/usb like in the export steps. Then, only one command is needed to import you virtual machine. Enter the following into the terminal to import your virtual machine, replacing <the-vm-name> with the actual name of your virtual machine:
xe vm-import vm=<the-vm-name> filename=/mnt/usb/<the-vm-name>.xva
That’s all there is to exporting and importing virtual machines with Citrix XenServer. As you can see, it is a quick and painless procedure and an incredibly valuable feature of XenServer.