KVM : Install VM Management Tools2020/05/07 |
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 fedora-28 i686 Fedora® 28 Server (i686) fedora-28 x86_64 Fedora® 28 Server fedora-29 aarch64 Fedora® 29 Server (aarch64) fedora-29 i686 Fedora® 29 Server (i686) fedora-29 ppc64le Fedora® 29 Server (ppc64le) fedora-29 x86_64 Fedora® 29 Server fedora-30 aarch64 Fedora® 30 Server (aarch64) fedora-30 i686 Fedora® 30 Server (i686) fedora-30 x86_64 Fedora® 30 Server fedora-31 x86_64 Fedora® 31 Server ..... ..... # create an image of fedora-31 [root@dlp ~]# virt-builder fedora-31 --format qcow2 --size 10G -o /var/kvm/images/fedora-31.qcow2 --root-password password [ 3.7] Downloading: http://builder.libguestfs.org/fedora-31.xz ######################################################################## 100.0% [ 193.5] Planning how to build this image [ 193.5] Uncompressing [ 199.0] Resizing (using virt-resize) to expand the disk to 10.0G [ 242.4] Opening the new disk [ 249.3] Setting a random seed [ 249.4] Setting passwords [ 250.9] Finishing off Output file: /var/kvm/images/fedora-31.qcow2 Output size: 10.0G Output format: qcow2 Total usable space: 9.4G Free space: 8.1G (86%) # to create a VM with the image above, run [virt-install] [root@dlp ~]# virt-install \
--name fedora-31 \ --ram 4096 \ --disk path=/var/kvm/images/fedora-31.qcow2 \ --vcpus 2 \ --os-type linux \ --os-variant fedora30 \ --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 fedora32 /root total 28 dr-xr-x---. 2 root root 135 May 7 09:42 . dr-xr-xr-x. 17 root root 224 May 7 09:39 .. -rw-------. 1 root root 16 May 7 09:42 .bash_history -rw-r--r--. 1 root root 18 Jan 30 18:15 .bash_logout -rw-r--r--. 1 root root 141 Jan 30 18:15 .bash_profile -rw-r--r--. 1 root root 429 Jan 30 18:15 .bashrc -rw-r--r--. 1 root root 100 Jan 30 18:15 .cshrc -rw-r--r--. 1 root root 129 Jan 30 18:15 .tcshrc -rw-------. 1 root root 1284 May 7 09:40 anaconda-ks.cfg |
[4] | [cat] a file in a virtual machine. |
[root@dlp ~]# virt-cat -d fedora32 /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 fedora32 /etc/fstab # # /etc/fstab # Created by anaconda on Mon Nov 18 03:56:43 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/fedora-root / xfs defaults 0 0 UUID=72524353-b859-4543-8020-f85a2df3c183 /boot xfs defaults 0 0 /dev/mapper/fedora-swap none swap defaults 0 0 |
[6] | Display disk usage in a virtual machine. |
[root@dlp ~]# virt-df -d fedora32 Filesystem 1K-blocks Used Available Use% fedora32:/dev/sda1 1038336 154604 883732 15% fedora32:/dev/fedora/root 15718400 1531412 14186988 10% |
[7] | Mount a disk for a virtual machine. |
[root@dlp ~]# guestmount -d fedora32 -i /media [root@dlp ~]# ll /media total 16 lrwxrwxrwx. 1 root root 7 Jan 28 15:30 bin -> usr/bin dr-xr-xr-x. 5 root root 4096 May 7 07:39 boot drwxr-xr-x. 2 root root 6 May 7 07:35 dev drwxr-xr-x. 94 root root 8192 May 7 07:41 etc drwxr-xr-x. 3 root root 20 May 7 07:39 home ..... ..... |
[8] | Display the status of virtual machines. |
[root@dlp ~]# virt-top virt-top 12:00:08 - x86_64 8/8CPU 2593MHz 12019MB 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 |