Libguestfs 工具

Libguestfs


Libgusetfs 是一個用於訪問和修改 disk image 的庫,該庫包含了一系列的工具,具體見 http://libguestfs.org。

  • 安裝
yum install libguestfs-tools

Virt-df


  • 示例:virt-df -h /home/images/Beta_ASF_1_0_0_2.qcow2
[root@localhost images]# virt-df -h  /home/images/owaspbwa124.img
Filesystem                                Size       Used  Available  Use%
owaspbwa124.img:/dev/sda5                 228M        43M       172M   20%
owaspbwa124.img:/dev/brokenwebapps/root   7.1G       5.6G       1.2G   79%
  • Virt-df 幫助
[root@localhost /]# virt-df --help
virt-df: display free space on virtual filesystems
Copyright (C) 2010 Red Hat Inc.
Usage:
  virt-df [--options] -d domname
  virt-df [--options] -a disk.img [-a disk.img ...]
Options:
  -a|--add image       Add image
  -c|--connect uri     Specify libvirt URI for -d option
  --csv                Output as Comma-Separated Values
  -d|--domain guest    Add disks from libvirt guest
  --format[=raw|..]    Force disk format for -a option
  -h|--human-readable  Print sizes in human-readable format
  --help               Display brief help
  -i|--inodes          Display inodes
  --one-per-guest      Separate appliance per guest
  -P nr_threads        Use at most nr_threads
  --uuid               Print UUIDs instead of names
  -v|--verbose         Verbose messages
  -V|--version         Display version and exit
  -x                   Trace libguestfs API calls
For more information, see the manpage virt-df(1)

Virt-ls


  • 示例:virt-ls -m /dev/brokenwebapps/root -a /home/images/owaspbwa124.img /
[root@localhost images]# virt-ls  -m /dev/brokenwebapps/root -a /home/images/owaspbwa124.img /
.gem
bin
boot
cdrom
dev
etc
home
... ...
  • Virt-ls 幫助
[root@localhost images]# virt-ls  --help
virt-ls: list files in a virtual machine
Copyright (C) 2010-2012 Red Hat Inc.
Usage:
  virt-ls [--options] -d domname dir [dir ...]
  virt-ls [--options] -a disk.img [-a disk.img ...] dir [dir ...]
Options:
  -a|--add image       Add image
  --checksum[=...]     Display file checksums
  -c|--connect uri     Specify libvirt URI for -d option
  --csv                Comma-Separated Values output
  -d|--domain guest    Add disks from libvirt guest
  --echo-keys          Don't turn off echo for passphrases
  --extra-stats        Display extra stats
  --format[=raw|..]    Force disk format for -a option
  --help               Display brief help
  -h|--human-readable  Human-readable sizes in output
  --keys-from-stdin    Read passphrases from stdin
  -l|--long            Long listing
  -m|--mount dev[:mnt[:opts[:fstype]]]
                       Mount dev on mnt (if omitted, /)
  -R|--recursive       Recursive listing
  --times              Display file times
  --time-days          Display file times as days before now
  --time-relative      Display file times as seconds before now
  --time-t             Display file times as time_t's
  --uids               Display UID, GID
  -v|--verbose         Verbose messages
  -V|--version         Display version and exit
  -x                   Trace libguestfs API calls
For more information, see the manpage virt-ls(1).

Virt-cat


  • 示例:virt-cat -m /dev/brokenwebapps/root -a /home/images/owaspbwa124.img /var/log/syslog
[root@localhost images]# virt-cat  -m /dev/brokenwebapps/root -a /home/images/owaspbwa124.img /var/log/syslog
Apr 13 06:41:50 owaspbwa rsyslogd: [origin software="rsyslogd" swVersion="4.2.0" x-pid="841" x-info="http://www.rsyslog.com"] rsyslogd was HUPed, type 'lightweight'.
Apr 13 07:09:01 owaspbwa CRON[18309]: (root) CMD (  [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) -delete)
... ...
  • Virt-cat 幫助
[root@localhost images]# virt-cat --help
virt-cat: display files in a virtual machine
Copyright (C) 2010 Red Hat Inc.
Usage:
  virt-cat [--options] -d domname file [file ...]
  virt-cat [--options] -a disk.img [-a disk.img ...] file [file ...]
Options:
  -a|--add image       Add image
  -c|--connect uri     Specify libvirt URI for -d option
  -d|--domain guest    Add disks from libvirt guest
  --echo-keys          Don't turn off echo for passphrases
  --format[=raw|..]    Force disk format for -a option
  --help               Display brief help
  --keys-from-stdin    Read passphrases from stdin
  -m|--mount dev[:mnt[:opts[:fstype]]]
                       Mount dev on mnt (if omitted, /)
  -v|--verbose         Verbose messages
  -V|--version         Display version and exit
  -x                   Trace libguestfs API calls
For more information, see the manpage virt-cat(1).

Virt-copy-out


  • 示例:virt-copy-out -a /home/images/owaspbwa124.img /var/log/lastlog /home/images/
[root@localhost images]# virt-copy-out -a /home/images/owaspbwa124.img /var/log/lastlog /home/images/
[root@localhost images]# 
[root@localhost images]# ls -l| grep lastlog
-rw-r--r-- 1 root root          292 Apr 23 12:51 lastlog
[root@localhost images]# 
  • Virt-copy-out 幫助
virt-copy-out -a disk.img /file|dir [/file|dir ...] localdir
virt-copy-out -d domain /file|dir [/file|dir ...] localdir

References:
http://libguestfs.org

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章