分类 技术存档 下的文章 - 80vps 博客 

分类 技术存档 下的文章

linux下使用virsh批量关闭或开启KVM虚拟机

批量关闭(软关机)

  1. for i in $(virsh list --name --autostart);do virsh shutdown $i;done

批量关闭(硬关机)

  1. for i in $(virsh list --name --autostart);do virsh destroy $i;done

批量开启

  1. for i in $(virsh list --name --autostart);do virsh start $i;done

批量开启关闭状态的虚拟机

  1. for i in $(virsh list --name --inactive);do virsh start $i;done

Convert Citrix Xenserver XVA Image to KVM

qemu-img is a tool apart of the qemu-utils package that lets you convert a wide variety of disk images from one hypervisor to another. However Citrix Xenserver image format XVA is not an option for qemu-img, so lets add it!

Here’s how to convert an XVA image to KVM.

Extract the XVA image.

A XVA file is a carefully created tarball we will need to extract.

1
2
mkdir xva_uncompressed
tar -xf virtual_machine.xva -C xva_uncompressed

Create a raw image

Use xva-img to create a raw disk image from the extracted xva data.

First we will build xva-img:

1
2
3
4
5
cd xva-img/
cmake .
sudo make install
cd ../

Create raw disk image: Note the Ref\:1 may be different.

1
xva-img -p disk-export xva_uncompressed/Ref\:1/ virtual_machine.raw

Convert RAW image to KVM using qemu-img

Install qemu-utils

1
2
3
4
#Debian/Ubuntu
sudo apt-get install qemu-utils
#RHEL/CentOS/Fedora
sudo yum install qemu-kvm qemu-img

Covert raw image to qcow2

1
qemu-img convert -f raw -O qcow2 virtual_machine.raw virtual_machine.qcow2

Import qcow2 disk image to KVM

Import the qcow2 image to your KVM environment, then attach the image to a VM. In my environment, I use oVirt:

XenServer7.6命令行导出导入虚拟机(迁移)

导出/导入虚拟机:
1、关闭需要导出的虚拟机

[root@xenserver /]# xe vm-reset-powerstate force=truevm=虚拟机名
1
2、导出虚拟机

[root@xenserver /]#  xe vm-export vm=虚拟机名 filename=/my_iso/虚拟机名.xva
1
参数说明:
filename=导出虚拟机的路径,compress=true
vm-export: 执行导出操作 

compress:对于导出的VM做压缩处理,取值:true,false
vm:需要导出的虚拟机

 

 

3、导入虚拟机(可导入到本地或其他xenserver上)

[root@xenserver /]# xe vm-import filename=/my_iso/虚拟机的名字.xva
1
创建/导出快照:
创建快照:

[root@xenserver /]# xe vm-snapshot new-name-label=新快照名称 vm=虚拟机名称
1
参数说明:
new-name-label=新快照名称
vm=虚拟机名称

导出快照:
1、查看要导出快照的uuid

[root@xenserver /]# xe snapshot-list name-label=快照名称
uuid ( RO) : 914b9c49-5051-5db5-1ab9-bfdd3d3287b8
name-label ( RW): win2012
name-description ( RW):

2、导出快照

[root@xenserver /]# xe snapshot-export-to-template snapshot-uuid=914b9c49-5051-5db5-1ab9-bfdd3d3287b8
filename=/my_iso/win2012.xva
1
2
参数说明:
snapshot-uuid=快照的uuid
filename=导出快照的存放路径
3、导入快照
跟导入虚拟机命令一样

[root@xenserver /]# xe vm-import filename=/my_iso/快照名.xva

2018shijiebei w88 18luck 188bet beplay manbet 12bet 95zz shenbo weide1946 ca88