Ubuntu 14.04
Sponsored Link

Virt-tools2014/04/23

 
Install useful tools for virtual machine management.
[1] Install virt tools.
root@dlp:~#
apt-get -y install libguestfs-tools virt-top
# answer 'Yes'

[2] "ls" a directory in a virtual machine
root@dlp:~#
virt-ls -l -d www /root

total 24
drwx------  3 0 0 4096 Apr 23 12:27 .
drwxr-xr-x 22 0 0 4096 Apr 22 16:15 ..
-rw-------  1 0 0   71 Apr 23 12:36 .bash_history
-rw-r--r--  1 0 0 3106 Feb 20 02:43 .bashrc
drwx------  2 0 0 4096 Apr 23 12:26 .cache
-rw-r--r--  1 0 0  140 Feb 20 02:43 .profile
[3] "cat" a file in a virtual machine
root@dlp:~#
virt-cat -d www /etc/passwd

root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
...
[4] Edit a file in a virtual machine
root@dlp:~#
virt-edit -d www /etc/fstab


# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
/dev/mapper/www--vg-root /               ext4    errors=remount-ro 0       1
# /boot was on /dev/vda1 during installation
UUID=7a2a7f89-272e-4af9-b73c-9d674f5ac99e /boot           ext2    defaults        0       2
/dev/mapper/www--vg-swap_1 none            swap    sw              0       0
[5] Display disk usage in a virtual machine
root@dlp:~#
virt-df -d www

Filesystem                           1K-blocks       Used  Available  Use%
www:/dev/sda1                           240972      36383     192148   16%
www:/dev/www-vg/root                  28518268    1028500   26018076    4%
[6] Mount a disk for a virtual machine
root@dlp:~#
guestmount -d www -i /mnt

root@dlp:~#
ll /mnt

drwxr-xr-x 22 root root  4096 Apr 23 01:15 ./
drwxr-xr-x 22 root root  4096 Apr 18 19:24 ../
drwxr-xr-x  2 root root  4096 Apr 23 01:18 bin/
drwxr-xr-x  4 root root  1024 Apr 23 01:19 boot/
drwxr-xr-x  3 root root  4096 Apr 23 01:13 dev/
...
[7] Display the status of virtual machines
root@dlp:~#
virt-top

virt-top 21:51:32 - x86_64 4/4CPU 3301MHz 16042MB
2 domains, 0 active, 0 running, 0 sleeping, 0 paused, 2 inactive D:0 O:0 X:0
CPU: 0.0%  Mem: 0 MB (0 MB by guests)

   ID S RDRQ WRRQ RXBY TXBY %CPU %MEM    TIME   NAME
   19 R    0    0    0    0  0.0  8.0   0:12.86 www
    -                                           (template)
Matched Content