KVM : Install VM Management Tools2021/03/10 |
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 centos-8.2 # replace the [myrootpassword] to the root password you'd like to set [root@dlp ~]# virt-builder centos-8.2 --format qcow2 --size 10G -o /var/kvm/images/centos-8.2.qcow2 --root-password password:myrootpassword [ 5.9] Downloading: http://builder.libguestfs.org/centos-8.2.xz [ 171.8] Planning how to build this image [ 171.8] Uncompressing [ 176.8] Resizing (using virt-resize) to expand the disk to 10.0G [ 217.4] Opening the new disk [ 223.1] Setting a random seed [ 223.1] Setting passwords [ 224.4] Finishing off Output file: /var/kvm/images/centos-8.2.qcow2 Output size: 10.0G Output format: qcow2 Total usable space: 9.3G Free space: 8.0G (85%) # to create a VM with the image above, run [virt-install] [root@dlp ~]# virt-install \
--name centos-8.2 \ --ram 4096 \ --disk path=/var/kvm/images/centos-8.2.qcow2 \ --vcpus 2 \ --os-variant centos8 \ --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 centos-st8 /root total 28 dr-xr-x---. 2 root root 135 Mar 9 05:53 . dr-xr-xr-x. 17 root root 224 Mar 9 02:40 .. -rw-------. 1 root root 16 Mar 9 05:53 .bash_history -rw-r--r--. 1 root root 18 May 11 2019 .bash_logout -rw-r--r--. 1 root root 176 May 11 2019 .bash_profile -rw-r--r--. 1 root root 176 May 11 2019 .bashrc -rw-r--r--. 1 root root 100 May 11 2019 .cshrc -rw-r--r--. 1 root root 129 May 11 2019 .tcshrc -rw-------. 1 root root 1310 Mar 9 02:46 anaconda-ks.cfg |
[4] | [cat] a file in a virtual machine. |
[root@dlp ~]# virt-cat -d centos-st8 /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 centos-st8 /etc/fstab # # /etc/fstab # Created by anaconda on Tue Mar 9 02:40:07 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/cs-root / xfs defaults 0 0 UUID=32d220bc-65a1-4997-83d2-a4a112deba1e /boot xfs defaults 0 0 /dev/mapper/cs-swap none swap defaults 0 0 |
[6] | Display disk usage in a virtual machine. |
[root@dlp ~]# virt-df -d centos-st8 Filesystem 1K-blocks Used Available Use% centos-st8:/dev/sda1 1038336 142068 896268 14% centos-st8:/dev/cs/root 27245572 1883128 25362444 7% |
[7] | Mount a disk for a virtual machine. |
[root@dlp ~]# guestmount -d centos-st8 -i /media [root@dlp ~]# ll /media total 20 lrwxrwxrwx. 1 root root 7 May 19 2020 bin -> usr/bin dr-xr-xr-x. 5 root root 4096 Mar 9 11:44 boot drwxr-xr-x. 2 root root 6 Mar 9 11:40 dev drwxr-xr-x. 100 root root 8192 Mar 9 14:02 etc drwxr-xr-x. 3 root root 18 Mar 9 11:45 home ..... ..... |
[8] | Display the status of virtual machines. |
[root@dlp ~]# virt-top virt-top 15:59:16 - x86_64 8/8CPU 2593MHz 15830MB 3 domains, 1 active, 1 running, 0 sleeping, 0 paused, 2 inactive D:0 O:0 X:0 CPU: 0.0% Mem: 768 MB (768 MB by guests) |
Sponsored Link |
|