先查看虛擬機列表
[root@xenserver-mis-test ~]# xe vm-list uuid ( RO) : 3577edda-0410-cbc7-dc5b-0bbcd7bb1513 name-label ( RW): CentOS 6 (64-bit) power-state ( RO): running uuid ( RO) : d8dbb9a5-0c12-4d8a-821f-23f5b8f2cb52 name-label ( RW): Control domain on host: xenserver-xttnntmj power-state ( RO): running uuid ( RO) : 694a9e8a-8abc-20f4-faf9-b6996fcc75b7 name-label ( RW): CentOS 6 (64-bit) 2 power-state ( RO): running
如果虛擬機正在運作需要先stop可以用以下兩種方式關閉
[root@xenserver-mis-test ~]# xe vm-shutdown uuid=694a9e8a-8abc-20f4-faf9-b6996fcc75b7 force=true [root@xenserver-mis-test ~]# xe vm-shutdown vm='CentOS 6 (64-bit)' force=true
開啟導出虛擬機
xe vm-export uuid=3577edda-0410-cbc7-dc5b-0bbcd7bb1513 filename=/mnt/'CentOS 6 (64-bit).xva' xe vm-export uuid=694a9e8a-8abc-20f4-faf9-b6996fcc75b7 filename=/mnt/'CentOS 6 (64-bit) 2.xva'
批量導入
cd /mnt ls |awk '/xva/'|sed 's/ /\\ /g;s/(/\\(/g;s/)/\\)/'|xargs -i xe vm-import filename={}
導入指定硬碟
xe vm-import sr-uuid=自行替換 filename=/mnt/'虛擬機.xva'