KVM : Install VM Management Tools2021/07/27 |
Install useful tools for virtual machine management.
|
|
[1] | Install required packages. |
[root@dlp ~]# dnf -y install libguestfs-tools virt-top
|
[2] | Create a Virtual machine from officially provided images. |
# display available OS template [root@dlp ~]# virt-builder -l opensuse-13.1 x86_64 openSUSE 13.1 opensuse-13.2 x86_64 openSUSE 13.2 opensuse-42.1 x86_64 openSUSE Leap 42.1 opensuse-tumbleweed x86_64 openSUSE Tumbleweed centos-6 x86_64 CentOS 6.6 centos-7.0 x86_64 CentOS 7.0 centos-7.1 x86_64 CentOS 7.1 centos-7.2 aarch64 CentOS 7.2 (aarch64) centos-7.2 x86_64 CentOS 7.2 centos-7.3 x86_64 CentOS 7.3 centos-7.4 x86_64 CentOS 7.4 centos-7.5 x86_64 CentOS 7.5 centos-7.6 x86_64 CentOS 7.6 centos-7.7 x86_64 CentOS 7.7 centos-7.8 x86_64 CentOS 7.8 centos-8.0 x86_64 CentOS 8.0 centos-8.2 x86_64 CentOS 8.2 cirros-0.3.1 x86_64 CirrOS 0.3.1 cirros-0.3.5 x86_64 CirrOS 0.3.5 debian-10 x86_64 Debian 10 (buster) ..... ..... # create an image of fedora-34 # replace the [myrootpassword] to the root password you'd like to set [root@dlp ~]# virt-builder fedora-34 --format qcow2 --size 10G -o /var/kvm/images/fedora-34.qcow2 --root-password password:myrootpassword [ 5.9] Downloading: http://builder.libguestfs.org/fedora-34.xz [ 143.5] Planning how to build this image [ 143.5] Uncompressing [ 147.7] Resizing (using virt-resize) to expand the disk to 10.0G [ 185.3] Opening the new disk [ 191.3] Setting a random seed [ 191.3] Setting passwords [ 192.6] 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 fedora33 \ --network bridge=br0 \ --graphics none \ --serial pty \ --console pty \ --boot hd \ --import |
[3] | [ls] a directory in a virtual machine. |
[root@dlp ~]# virt-ls -l -d rocky8 /root total 32 dr-xr-x---. 2 root root 163 Jul 27 02:48 . dr-xr-xr-x. 17 root root 224 Jul 27 02:37 .. -rw-------. 1 root root 16 Jul 27 02:48 .bash_history -rw-r--r--. 1 root root 18 Mar 14 19:35 .bash_logout -rw-r--r--. 1 root root 176 Mar 14 19:35 .bash_profile -rw-r--r--. 1 root root 176 Mar 14 19:35 .bashrc -rw-r--r--. 1 root root 100 Mar 14 19:35 .cshrc -rw-r--r--. 1 root root 129 Mar 14 19:35 .tcshrc -rw-------. 1 root root 1352 Jul 27 02:46 anaconda-ks.cfg -rw-r--r--. 1 root root 1628 Jul 27 02:48 initial-setup-ks.cfg |
[4] | [cat] a file in a virtual machine. |
[root@dlp ~]# virt-cat -d rocky8 /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 operator:x:11:0:operator:/root:/sbin/nologin ..... ..... |
[5] | Edit a file in a virtual machine. |
[root@dlp ~]# virt-edit -d rocky8 /etc/fstab # # /etc/fstab # Created by anaconda on Tue Jul 27 02:35:49 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/rl-root / xfs defaults 0 0 UUID=57c6e2db-5fd3-4f5f-a55e-0b30b5124a7b /boot xfs defaults 0 0 /dev/mapper/rl-swap none swap defaults 0 0 |
[6] | Display disk usage in a virtual machine. |
[root@dlp ~]# virt-df -d rocky8 Filesystem 1K-blocks Used Available Use% rocky8:/dev/sda1 1038336 208192 830144 21% rocky8:/dev/rl/root 17811456 4294372 13517084 25% |
[7] | Mount a disk for a virtual machine. |
[root@dlp ~]# guestmount -d rocky8 -i /media [root@dlp ~]# ll /media total 24 lrwxrwxrwx. 1 root root 7 Mar 15 04:28 bin -> usr/bin dr-xr-xr-x. 5 root root 4096 Jul 27 11:47 boot drwxr-xr-x. 2 root root 6 Jul 27 11:35 dev drwxr-xr-x. 140 root root 8192 Jul 27 11:48 etc drwxr-xr-x. 3 root root 19 Jul 27 11:46 home ..... ..... |
[8] | Display the status of virtual machines. |
[root@dlp ~]# virt-top virt-top 12:36:30 - x86_64 8/8CPU 2593MHz 15831MB 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) |
Sponsored Link |