Welcome 微信登录

首页 / 操作系统 / Linux / Virt相关命令总结

在CentOS下面多部分命令都是有包libguestfs-tools-c提供,所以,首先需要安装它

virt-ls

virt-ls可以列出虚拟机中目录下的文件或目录,用法如下
12virt-ls [--options] -d domname dir [dir ...]virt-ls [--options] -a disk.img [-a disk.img ...] dir [dir ...]
1virt-ls -d centos2 /etc/
可以像使用ls一样加一些参数,如-l等,具体请看virt-ls --help

virt-what

virt-what可以用来检测当前系统是不是一个虚拟机,如果不是虚拟机,执行virt-what将不会有任何输出,如果是虚拟机,它会打印一系列关于虚拟机的’facts’(如kvm)virt-what命令由同名包提供,要命令需要先安装(yum -y install virt-what)

virt-host-validate

这个命令可以用来检测本机是否正确配置以运行虚拟化,如果没有加参数,它会检查它所知道的所有的虚拟化驱动,可选的可以加qemulxc做限制
1virt-host-validate
输出类似这样
12345QEMU: Checking for hardware virtualization : PASSQEMU: Checking for device /dev/kvm : PASSQEMU: Checking for device /dev/vhost-net : PASSQEMU: Checking for device /dev/net/tun : PASS LXC: Checking for Linux >= 2.6.26 : PASS

virt-top

virt-top命令由同名软件包提供,和top命令相似,只是进程换成了虚拟机
12yum -y install virt-topvirt-top
输出
123456789virt-top 16:58:01 - x86_64 8/8CPU 2127MHz 7854MB 12.2% 12.0% 12.8% 12.0% 12.1% 12.0% 12.0% 12.0%4 domains, 3 active, 3 running, 0 sleeping, 0 paused, 1 inactive D:0 O:0 X:0CPU: 12.7% Mem: 2048 MB (2048 MB by guests)ID S RDRQ WRRQ RXBY TXBY %CPU %MEMTIME NAME40 R00 520 12.56.066:38.82 centos232 R03 2238K 13.5 16.026:28.82 win200340 R20 520 12.58.036:18.82 test - (centos3)

virt-cat

virt-cat可以虚拟机中文件的内容,用法如下
12virt-cat [--options] -d domname file [file ...]virt-cat [--options] -a disk.img [-a disk.img ...] file [file ...]
1virt-cat -d centos2 /etc/passwd
domname可以通过virsh list得到也可以对虚拟机的磁盘文件操作
1virt-cat-a /opt/images/centos2.img /etc/passwd

virt-edit

这个命令可以修改
12virt-edit [--options] -d domname file [file ...]virt-edit [--options] -a disk.img [-a disk.img ...] file [file ...]
例如
1virt-edit -d centos2 /etc/passwd
在我的系统中它会用vim打开文件,编辑完保存即可修改虚拟机内的文件内容也可以直接对虚拟机的磁盘文件进行操作
1virt-edit -a /opt/images/centos2.img /etc/passwd
Note: 如果虚拟机正在运行,使用第一种文件修改它的文件会有下面的报错
12345Libguestfs: error: error: domain is a live virtual machine.Writing to the disks of a running virtual machine ca cause disk corruption.Either use read-only access, or if the guest is running the guestfsd daemonspecify live access. In most libguestfs tools these options are --ro or--live respectively. Consult the documentation for further information.
但直接对虚拟机磁盘镜像文件操作不会有这个提示,并且可以修改成功,会不会出问题我就不知道了

virt-copy-out

virt-copy-out这个命令可以把虚拟机里的文件复制出来, 用法如下
12virt-copy-out -d domname file|dir [file|dir ...] localdirvirt-copy-out -a disk.img file|dir [file|dir ...] localdir
例子
1virt-copy-out -d centos2 /etc/passwd .
可以是多个文件或目录
12mkdir tmpvirt-copy-out -d centos2 /etc /home /root/.bashrc tmp
也可以直接对虚拟机磁盘文件操作,只需要将-d domname换成-a path_of_disk_file

virt-copy-in

virt-copy-in是将文件复制到虚拟机里面,用法和virt-copy-out基本相同,这里只举一个例子
1virt-copy-in -d centos2 test.txt /opt/
不出你的所料,如果虚拟机正在运行,上面的命令也会报错更多详情见请继续阅读下一页的精彩内容: http://www.linuxidc.com/Linux/2014-08/105140p2.htm
  • 1
  • 2
  • 3
  • 下一页
Arronax 让你轻松创建桌面启动文件在Ubuntu上创建和管??Redhat虚拟机相关资讯      Virt  本文评论 查看全部评论 (0)
表情: 姓名: 字数