KVM : Install VM Management Tools2021/05/11 |
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-30 i686 Fedora 30 Server (i686) fedora-30 x86_64 Fedora 30 Server fedora-31 x86_64 Fedora 31 Server fedora-32 x86_64 Fedora 32 Server fedora-33 x86_64 Fedora 33 Server fedora-34 x86_64 Fedora 34 Server ..... ..... # create an image of fedora-34 [root@dlp ~]# virt-builder fedora-34 --format qcow2 --size 10G -o /var/kvm/images/fedora-34.qcow2 --root-password password:myrootpassword [ 6.0] Downloading: http://builder.libguestfs.org/fedora-34.xz ######################################################################## 100.0% [ 337.3] Planning how to build this image [ 337.3] Uncompressing [ 341.9] Resizing (using virt-resize) to expand the disk to 10.0G [ 378.9] Opening the new disk [ 384.6] Setting a random seed [ 384.7] Setting passwords [ 385.9] Finishing off Output file: /var/kvm/images/fedora-34.qcow2 Output size: 10.0G Output format: qcow2 Total usable space: 10.0G Free space: 9.0G (90%) # to create a VM with the image above, run [virt-install] [root@dlp ~]# virt-install \ --name fedora-34 \ --ram 4096 \ --disk path=/var/kvm/images/fedora-34.qcow2 \ --vcpus 2 \ --os-variant fedora34 \ --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-34 |
[3] | [ls] a directory in a virtual machine. |
[root@dlp ~]# virt-ls -l -d fedora34 /root total 28 dr-xr-x---. 3 root root 149 May 11 02:18 . dr-xr-xr-x. 17 root root 224 May 11 02:03 .. -rw-------. 1 root root 76 May 11 02:19 .bash_history -rw-r--r--. 1 root root 18 Jan 28 11:17 .bash_logout -rw-r--r--. 1 root root 141 Jan 28 11:17 .bash_profile -rw-r--r--. 1 root root 429 Jan 28 11:17 .bashrc drwxr-xr-x. 3 root root 23 May 11 02:18 .cache -rw-r--r--. 1 root root 100 Jan 28 11:17 .cshrc -rw-r--r--. 1 root root 129 Jan 28 11:17 .tcshrc -rw-------. 1 root root 900 May 11 02:07 anaconda-ks.cfg |
[4] | [cat] a file in a virtual machine. |
[root@dlp ~]# virt-cat -d fedora34 /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 fedora34 /etc/fstab # # /etc/fstab # Created by anaconda on Tue May 11 02:02:41 2021 # # 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=8fdac9c3-a203-4d73-a43b-0554e6f35e53 /boot xfs defaults 0 0 |
[6] | Display disk usage in a virtual machine. |
[root@dlp ~]# virt-df -d fedora34 Filesystem 1K-blocks Used Available Use% fedora34:/dev/sda1 1038336 150168 888168 15% fedora34:/dev/fedora_fedora/root 15718400 3492884 12225516 23% |
[7] | Mount a disk for a virtual machine. |
[root@dlp ~]# guestmount -d fedora34 -i /media [root@dlp ~]# ll /media total 16 lrwxrwxrwx. 1 root root 7 Jul 28 03:22 bin -> usr/bin dr-xr-xr-x. 5 root root 4096 Nov 3 14:51 boot drwxr-xr-x. 2 root root 6 Nov 3 14:47 dev drwxr-xr-x. 99 root root 8192 Nov 3 14:53 etc drwxr-xr-x. 3 root root 20 Nov 3 14:51 home ..... ..... |
[8] | Display the status of virtual machines. |
[root@dlp ~]# virt-top virt-top 23:46:08 - x86_64 8/8CPU 2593MHz 16002MB 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) |
Sponsored Link |
|