KVM : Install VM Management Tools2023/02/28 |
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 opensuse-tumbleweed x86_64 openSUSE Tumbleweed alma-8.5 x86_64 AlmaLinux 8.5 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) ..... ..... # create an image of [alma-8.5] # replace the [myrootpassword] to the root password you'd like to set [root@dlp ~]# virt-builder alma-8.5 --format qcow2 --size 10G -o /var/kvm/images/alma-8.5.qcow2 --root-password password:myrootpassword [ 6.2] Downloading: http://builder.libguestfs.org/alma-8.5.xz [ 129.8] Planning how to build this image [ 129.8] Uncompressing [ 134.2] Resizing (using virt-resize) to expand the disk to 10.0G [ 201.1] Opening the new disk [ 206.4] Setting a random seed [ 206.4] Setting passwords [ 207.5] SELinux relabelling [ 217.3] Finishing off Output file: /var/kvm/images/alma-8.5.qcow2 Output size: 10.0G Output format: qcow2 Total usable space: 9.4G Free space: 7.8G (82%) # to create a VM with the image above, run [virt-install] [root@dlp ~]# virt-install \
--name almalinux8 \ --ram 4096 \ --disk path=/var/kvm/images/alma-8.5.qcow2 \ --vcpus 2 \ --os-variant almalinux8 \ --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 almalinux9 /root total 28 dr-xr-x---. 2 root root 135 Jan 19 04:53 . dr-xr-xr-x. 18 root root 235 Jan 19 04:46 .. -rw-------. 1 root root 16 Jan 19 04:53 .bash_history -rw-r--r--. 1 root root 18 Aug 10 04:16 .bash_logout -rw-r--r--. 1 root root 141 Aug 10 04:16 .bash_profile -rw-r--r--. 1 root root 429 Aug 10 04:16 .bashrc -rw-r--r--. 1 root root 100 Aug 10 04:16 .cshrc -rw-r--r--. 1 root root 129 Aug 10 04:16 .tcshrc -rw-------. 1 root root 1100 Jan 19 04:50 anaconda-ks.cfg |
[4] | [cat] a file in a virtual machine. |
[root@dlp ~]# virt-cat -d almalinux9 /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 almalinux9 /etc/fstab # # /etc/fstab # Created by anaconda on Wed Jan 19 04:45:38 2022 # # 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=0b07140d-5c31-4323-8097-ce20fe13908d /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 almalinux9 Filesystem 1K-blocks Used Available Use% almalinux9:/dev/sda1 1038336 185388 852948 18% almalinux9:/dev/cs/root 17811456 1407800 16403656 8% |
[7] | Mount a disk for a virtual machine. |
[root@dlp ~]# guestmount -d almalinux9 -i /media [root@dlp ~]# ll /media total 20 dr-xr-xr-x. 2 root root 6 Aug 9 15:40 afs lrwxrwxrwx. 1 root root 7 Aug 9 15:40 bin -> usr/bin dr-xr-xr-x. 5 root root 4096 Jan 18 22:52 boot drwxr-xr-x. 2 root root 6 Jan 18 22:45 dev drwxr-xr-x. 99 root root 8192 Jan 18 22:52 etc ..... ..... |
[8] | Display the status of virtual machines. |
[root@dlp ~]# virt-top virt-top 00:00:48 - x86_64 8/8CPU 2593MHz 15735MB 3 domains, 0 active, 0 running, 0 sleeping, 0 paused, 3 inactive D:0 O:0 X:0 CPU: 0.0% Mem: 0 MB (0 MB by guests) |
Sponsored Link |