Virt相關命令總結

來源:互聯網
上載者:User

Virt相關命令總結

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

virt-ls

virt-ls可以列出虛擬機器中目錄下的檔案或目錄,用法如下

12
virt-ls [--options] -d domname dir [dir ...]virt-ls [--options] -a disk.img [-a disk.img ...] dir [dir ...]

如

1
virt-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

這個命令可以用來檢測本機是否正確配置以運行虛擬化,如果沒有加參數,它會檢查它所知道的所有的虛擬化驅動,可選的可以加qemu或lxc做限制

1
virt-host-validate

輸出類似這樣

12345
  QEMU: Checking for hardware virtualization                       : PASS  QEMU: Checking for device /dev/kvm                               : PASS  QEMU: Checking for device /dev/vhost-net                         : PASS  QEMU: Checking for device /dev/net/tun                           : PASS   LXC: Checking for Linux >= 2.6.26                               : PASS
virt-top

virt-top命令由同名軟體包提供,和top命令相似,只是進程換成了虛擬機器

12
yum -y install virt-topvirt-top

輸出

123456789
virt-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 %MEM    TIME   NAME  40 R    0    0   52    0 12.5  6.0  66:38.82 centos2  32 R    0    3   22  38K 13.5 16.0  26:28.82 win2003  40 R    2    0   52    0 12.5  8.0  36:18.82 test   -                                           (centos3)
virt-cat

virt-cat可以虛擬機器中檔案的內容,用法如下

12
virt-cat [--options] -d domname file [file ...]virt-cat [--options] -a disk.img [-a disk.img ...] file [file ...]

如

1
virt-cat -d centos2 /etc/passwd

domname可以通過virsh list得到

也可以對虛擬機器的磁碟檔案操作

1
virt-cat  -a /opt/images/centos2.img /etc/passwd
virt-edit

這個命令可以修改

12
virt-edit [--options] -d domname file [file ...]virt-edit [--options] -a disk.img [-a disk.img ...] file [file ...]

例如

1
virt-edit -d centos2 /etc/passwd

在我的系統中它會用vim開啟檔案,編輯完儲存即可修改虛擬機器內的檔案內容

也可以直接對虛擬機器的磁碟檔案進行操作

1
virt-edit -a /opt/images/centos2.img /etc/passwd

Note: 如果虛擬機器正在運行,使用第一種檔案修改它的檔案會有下面的報錯

12345
Libguestfs: 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這個命令可以把虛擬機器裡的檔案複製出來, 用法如下

12
virt-copy-out -d domname file|dir [file|dir ...] localdirvirt-copy-out -a disk.img file|dir [file|dir ...] localdir

例子

1
virt-copy-out -d centos2 /etc/passwd .

可以是多個檔案或目錄

12
mkdir 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基本相同,這裡只舉一個例子

1
virt-copy-in -d centos2 test.txt /opt/

不出你的所料,如果虛擬機器正在運行,上面的命令也會報錯

更多詳情見請繼續閱讀下一頁的精彩內容:

  • 1
  • 2
  • 3
  • 下一頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.