Ubuntu 23.04
Sponsored Link

KVM : Management tools for VM2023/04/27

 
Install useful tools for virtual machine management.
[1] Install required packages.
root@dlp:~#
apt -y install libguestfs-tools virt-top
[2] [ls] a directory in a virtual machine.
root@dlp:~#
virt-ls -l -d ubuntu2304 /root

total 36
drwx------  5 0 0 4096 Apr 26 11:49 .
drwxr-xr-x 19 0 0 4096 Apr 26 08:05 ..
-rw-------  1 0 0  227 Apr 26 11:50 .bash_history
-rw-r--r--  1 0 0 3106 Oct 17  2022 .bashrc
drwx------  2 0 0 4096 Apr 26 09:14 .cache
-rw-------  1 0 0   20 Apr 26 11:49 .lesshst
-rw-r--r--  1 0 0  161 Oct 17  2022 .profile
drwx------  2 0 0 4096 Apr 26 08:06 .ssh
drwx------  4 0 0 4096 Apr 26 09:21 snap
[3] [cat] a file in a virtual machine.
root@dlp:~#
virt-cat -d ubuntu2304 /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
.....
.....
[4] Edit a file in a virtual machine.
root@dlp:~#
virt-edit -d ubuntu2304 /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>
# / was on /dev/ubuntu-vg/ubuntu-lv during curtin installation
/dev/disk/by-id/dm-uuid-LVM-kNELVUSiPmwppKWcaGqhQs5F0T7PDHegNO5Pmus2bf50rS3apM3bc4SdiajfiEKh / ext4 defaults 0 1
# /boot was on /dev/vda2 during curtin installation
/dev/disk/by-uuid/41676544-12f4-46c7-950f-2ef1451419e7 /boot ext4 defaults 0 1
[5] Display disk usage in a virtual machine.
root@dlp:~#
virt-df -d ubuntu2304

Filesystem                           1K-blocks       Used  Available  Use%
ubuntu2304:/dev/sda2                   1790136     164320    1516556   10%
ubuntu2304:/dev/ubuntu-vg/ubuntu-lv   10218772    8503508    1174592   84%
[6] Mount disk image of a virtual machine.
root@dlp:~#
guestmount -d ubuntu2304 -i /mnt

root@dlp:~#
ll /mnt

total 96
drwxr-xr-x  19 root root  4096 Apr 26 08:05 ./
drwxr-xr-x  19 root root  4096 Apr 21 03:59 ../
lrwxrwxrwx   1 root root     7 Apr 15 14:56 bin -> usr/bin/
drwxr-xr-x   4 root root  4096 Apr 26 10:09 boot/
drwxr-xr-x   4 root root  4096 Apr 15 14:59 dev/
drwxr-xr-x 145 root root 12288 Apr 26 11:44 etc/
drwxr-xr-x   3 root root  4096 Apr 26 08:06 home/
.....
.....
[7] Display the status of virtual machines.
root@dlp:~#
virt-top

virt-top 00:07:02 - x86_64 4/4CPU 2399MHz 7924MB
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
    -                                           (ubuntu2304)
    -                                           (win2k22)
.....
.....
Matched Content