KVM : Install VM Management Tools2019/10/08 |
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-8.0 x86_64 CentOS 8.0 ..... ..... # create an image of centos-8.0 [root@dlp ~]# virt-builder centos-8.0 --format qcow2 --size 10G -o /var/kvm/images/centos-8.0.qcow2 --root-password password [ 3.4] Downloading: http://libguestfs.org/download/builder/centos-8.0.xz [ 152.9] Planning how to build this image [ 152.9] Uncompressing ..... ..... Output file: /var/kvm/images/centos-8.0.qcow2 Output size: 10.0G Output format: qcow2 Total usable space: 9.3G Free space: 8.1G (86%) # to create a VM with the image above, run [virt-install] [root@dlp ~]# virt-install \
--name centos-8.0 \ --ram 4096 \ --disk path=/var/kvm/images/centos-8.0.qcow2 \ --vcpus 2 \ --os-type linux \ --os-variant rhel8.0 \ --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 centos8 /root total 28 dr-xr-x---. 2 root root 135 Oct 7 10:41 . dr-xr-xr-x. 17 root root 224 Oct 7 10:32 .. -rw-------. 1 root root 80 Oct 7 11:31 .bash_history -rw-r--r--. 1 root root 18 May 11 15:33 .bash_logout -rw-r--r--. 1 root root 176 May 11 15:33 .bash_profile -rw-r--r--. 1 root root 176 May 11 15:33 .bashrc -rw-r--r--. 1 root root 100 May 11 15:33 .cshrc -rw-r--r--. 1 root root 129 May 11 15:33 .tcshrc -rw-------. 1 root root 1501 Oct 7 10:40 anaconda-ks.cfg |
[4] | [cat] a file in a virtual machine. |
[root@dlp ~]# virt-cat -d centos8 /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 centos8 /etc/fstab # # /etc/fstab # Created by anaconda on Mon Oct 7 19:30:49 2019 # # 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/cl-root / xfs defaults 0 0 UUID=6abde099-da06-4bd4-82f9-2663b5eacba2 /boot ext4 defaults 1 2 /dev/mapper/cl-swap swap swap defaults 0 0 |
[6] | Display disk usage in a virtual machine. |
[root@dlp ~]# virt-df -d centos8 Filesystem 1K-blocks Used Available Use% centos8:/dev/sda1 999320 115100 815408 12% centos8:/dev/cl/root 27245572 3858592 23386980 15% |
[7] | Mount a disk for a virtual machine. |
[root@dlp ~]# guestmount -d centos8 -i /media [root@dlp ~]# ll /media total 20 lrwxrwxrwx. 1 root root 7 May 11 09:33 bin -> usr/bin dr-xr-xr-x. 6 root root 4096 Oct 7 19:38 boot drwxr-xr-x. 2 root root 6 Oct 7 19:30 dev drwxr-xr-x. 133 root root 8192 Oct 7 20:16 etc drwxr-xr-x. 3 root root 18 Oct 7 19:39 home ..... ..... |
[8] | Display the status of virtual machines. |
[root@dlp ~]# virt-top virt-top 20:46:23 - x86_64 6/6CPU 2593MHz 18052MB 3 domains, 1 active, 1 running, 0 sleeping, 0 paused, 2 inactive D:0 O:0 X:0 CPU: 19.1% Mem: 4096 MB (4096 MB by guests) |
Sponsored Link |