KVM : Install VM Management Tools2022/05/23 |
Install useful tools for virtual machine management.
|
|
[1] | Install required packages. |
[root@dlp ~]# dnf -y install guestfs-tools virt-top
|
[2] | Create a Virtual machine from officially provided images. |
# display available OS template [root@dlp ~]# virt-builder -l fedora-33 x86_64 Fedora® 33 Server fedora-34 x86_64 Fedora® 34 Server fedora-34 armv7l Fedora® 34 Server (armv7l) fedora-35 x86_64 Fedora® 35 Server fedora-35 aarch64 Fedora® 35 Server (aarch64) fedora-36 x86_64 Fedora® 36 Server ..... ..... # create an image of fedora-36 [root@dlp ~]# virt-builder fedora-36 --format qcow2 --size 10G -o /var/kvm/images/fedora-36.qcow2 --root-password password:myrootpassword ######################################################################### 100.0% [ 145.9] Planning how to build this image [ 145.9] Uncompressing [ 151.7] Resizing (using virt-resize) to expand the disk to 10.0G [ 190.5] Opening the new disk [ 197.4] Setting a random seed [ 197.4] Setting passwords [ 198.7] Finishing off Output file: /var/kvm/images/fedora-36.qcow2 Output size: 10.0G Output format: qcow2 Total usable space: 10.0G Free space: 8.7G (87%) # to create a VM with the image above, run [virt-install] [root@dlp ~]# virt-install \ --name fedora-36 \ --ram 4096 \ --disk path=/var/kvm/images/fedora-36.qcow2 \ --vcpus 2 \ --os-variant fedora36 \ --network bridge=br0 \ --graphics none \ --noautoconsole \ --boot hd \ --noreboot \ --import Starting install... Domain creation completed. You can restart your domain by running: virsh --connect qemu:///system start fedora-36 |
[3] | [ls] a directory in a virtual machine. |
[root@dlp ~]# virt-ls -l -d fedora36 /root total 28 dr-xr-x---. 2 root root 135 May 20 07:16 . dr-xr-xr-x. 18 root root 235 May 20 07:07 .. -rw-------. 1 root root 16 May 20 07:16 .bash_history -rw-r--r--. 1 root root 18 Jan 21 18:18 .bash_logout -rw-r--r--. 1 root root 141 Jan 21 18:18 .bash_profile -rw-r--r--. 1 root root 429 Jan 21 18:18 .bashrc -rw-r--r--. 1 root root 100 Jan 21 18:18 .cshrc -rw-r--r--. 1 root root 129 Jan 21 18:18 .tcshrc -rw-------. 1 root root 885 May 20 07:11 anaconda-ks.cfg |
[4] | cat] a file in a virtual machine. |
[root@dlp ~]# virt-cat -d fedora36 /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin ..... ..... |
[5] | Edit a file in a virtual machine. |
[root@dlp ~]# virt-edit -d fedora36 /etc/fstab # /etc/fstab # Created by anaconda on Fri May 20 07:06:33 2022 # # Accessible filesystems, by reference, are maintained under '/dev/disk/'. # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info. # # After editing this file, run 'systemctl daemon-reload' to update systemd # units generated from this file. # /dev/mapper/fedora_fedora-root / xfs defaults 0 0 UUID=26a333e9-42d3-4979-aa54-0ab2b568b890 /boot xfs defaults 0 0 |
[6] | Display disk usage in a virtual machine. |
[root@dlp ~]# virt-df -d fedora36 Filesystem 1K-blocks Used Available Use% fedora36:/dev/sda1 1038336 159760 878576 16% fedora36:/dev/fedora_fedora/root 15718400 1346032 14372368 9% |
[7] | Mount a disk for a virtual machine. |
[root@dlp ~]# guestmount -d fedora36 -i /media [root@dlp ~]# ll /media total 20 dr-xr-xr-x. 2 root root 6 Jan 20 12:04 afs lrwxrwxrwx. 1 root root 7 Jan 20 12:04 bin -> usr/bin dr-xr-xr-x. 5 root root 4096 May 20 16:10 boot drwxr-xr-x. 2 root root 6 May 20 16:06 dev drwxr-xr-x. 101 root root 8192 May 20 16:12 etc ..... ..... |
[8] | Display the status of virtual machines. |
[root@dlp ~]# virt-top virt-top 17:04:47 - x86_64 8/8CPU 2593MHz 15995MB 2 domains, 1 active, 1 running, 0 sleeping, 0 paused, 1 inactive D:0 O:0 X:0 CPU: 0.0% Mem: 1280 MB (1280 MB by guests) ID S RDRQ WRRQ RXBY TXBY %CPU %MEM TIME NAME 11 R 0.0 0.0 0:03.69 guestfs-vhect1l2ww92rdqn - (fedora36) ..... ..... |
Sponsored Link |