KVM : Management tools for VM2025/04/21 |
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 ubuntu2504 /root total 20 drwx------ 3 0 0 4096 Apr 15 17:22 . drwxr-xr-x 20 0 0 4096 Apr 21 06:29 .. -rw-r--r-- 1 0 0 3106 Apr 9 12:06 .bashrc -rw-r--r-- 1 0 0 132 Apr 9 12:06 .profile drwx------ 2 0 0 4096 Apr 21 06:31 .ssh |
[3] | [cat] a file in a virtual machine. |
root@dlp:~# virt-cat -d ubuntu2504 /etc/passwd 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 mail:x:8:8:mail:/var/mail:/usr/sbin/nologin ..... ..... |
[4] | Edit a file in a virtual machine. |
root@dlp:~# virt-edit -d ubuntu2504 /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-2chnzgqb86EFzSdrustX3xXUwtkYcuGZhR60eojm1QAGH3qEQ8vt0likLQCPGoTS / ext4 defaults 0 1 # /boot was on /dev/vda2 during curtin installation /dev/disk/by-uuid/33daf87f-5d53-4ad3-a76a-b453ad95baec /boot ext4 defaults 0 1 /swap.img none swap sw 0 0 |
[5] | Display disk usage in a virtual machine. |
root@dlp:~# virt-df -d ubuntu2504 Filesystem 1K-blocks Used Available Use% ubuntu2504:/dev/sda2 1790136 109272 1571604 7% ubuntu2504:/dev/ubuntu-vg/ubuntu-lv 18631360 6791216 10868368 37% |
[6] | Mount disk image of a virtual machine. |
root@dlp:~# guestmount -d ubuntu2504 -i /mnt root@dlp:~# ll /mnt total 4003936 drwxr-xr-x 20 root root 4096 Apr 21 06:29 ./ drwxr-xr-x 20 root root 4096 Apr 21 04:04 ../ lrwxrwxrwx 1 root root 7 Apr 9 12:06 bin -> usr/bin/ drwxr-xr-x 4 root root 4096 Apr 21 06:29 boot/ dr-xr-xr-x 2 root root 4096 Apr 15 22:38 cdrom/ drwxr-xr-x 5 root root 4096 Apr 15 17:22 dev/ drwxr-xr-x 108 root root 4096 Apr 21 06:31 etc/ drwxr-xr-x 3 root root 4096 Apr 21 06:31 home/ ..... ..... |
[7] | Display the status of virtual machines. |
root@dlp:~# virt-top virt-top 07:54:58 - x86_64 8/8CPU 2399MHz 15478MB 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 - (ubuntu2504) - (win2k25) |
Sponsored Link |