Debian 9 Stretch
Sponsored Link

仮想管理ツール2017/06/22

 
仮想マシンを管理できるツール群をインストールしておくと、仮想管理がより容易になります。
[1] 仮想管理ツールをインストールします。
root@dlp:~#
apt -y install libguestfs-tools virt-top
[2] 仮想マシン内のあるディレクトリを ls する。
# 仮想マシン [debian] の [/root] を ls -l

root@dlp:~#
virt-ls -l -d debian /root

total 20
drwx------  2 0 0 4096 Jun 23 00:22 .
drwxr-xr-x 22 0 0 4096 Jun 22 12:40 ..
-rw-------  1 0 0   16 Jun 23 00:22 .bash_history
-rw-r--r--  1 0 0  570 Jan 31  2010 .bashrc
-rw-r--r--  1 0 0  148 Aug 17  2015 .profile
[3] 仮想マシン内のあるファイルを cat する。
# 仮想マシン [debian] の [/etc/passwd] を cat

root@dlp:~#
virt-cat -d debian /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
...
...
[4] 仮想マシン内のあるファイルを編集する。
# 仮想マシン [debian] の [/etc/fstab] を編集

root@dlp:~#
virt-edit -d debian /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/debian--vg-root /               ext4    errors=remount-ro 0       1
# /boot was on /dev/vda1 during installation
UUID=dc739636-cfd3-40d5-8f9e-69b7d1bc3d67 /boot           ext2    defaults
  0       2
/dev/mapper/debian--vg-swap_1 none            swap    sw              0       0
[5] 仮想マシン内のディスク使用量を表示する。
# 仮想マシン [debian] のディスク使用量を表示

root@dlp:~#
virt-df -d debian

Filesystem                           1K-blocks       Used  Available  Use%
template:/dev/sda1                      240972      37022     191509   16%
template:/dev/debian-vg/root          26453796     925232   24161732    4%
[6] 仮想マシンのディスクをマウントする。
# 仮想マシン [debian] のディスクを [/mnt] にマウント

root@dlp:~#
guestmount -d debian -i /mnt

root@dlp:~#
ll /mnt

total 89
drwxr-xr-x  2 root root  4096 Jun 22 22:58 bin
drwxr-xr-x  4 root root  1024 Jun 22 22:59 boot
drwxr-xr-x  4 root root  4096 Jun 22 21:35 dev
drwxr-xr-x 76 root root  4096 Jun 23 09:22 etc
drwxr-xr-x  3 root root  4096 Jun 22 22:59 home
.....
.....
[7] 仮想マシンの状態を表示する。
root@dlp:~#
virt-top

virt-top 21:58:43 - x86_64 4/4CPU 2801MHz 12158MB
3 domains, 1 active, 1 running, 0 sleeping, 0 paused, 2 inactive D:0 O:0 X:0
CPU: 0.0%  Mem: 4096 MB (4096 MB by guests)

   ID S RDRQ WRRQ RXBY TXBY %CPU %MEM    TIME   NAME
    6 R                      0.0  0.0   0:04.92 debian
    -                                           (template)
    -                                           (win2k12R2)
関連コンテンツ