KVM : Management tools2020/06/02 |
Install useful tools for virtual machine management.
|
|
[1] | Install required packages. |
root@dlp:~# apt -y install libguestfs-tools virt-top
|
[2] | Get official OS image and Create a Virtual Machine. ( If you'd like to do from OS installation, refer to here of [1] ) |
# display available OS template root@dlp:~# virt-builder -l ..... ..... ubuntu-10.04 x86_64 Ubuntu 10.04 (Lucid) ubuntu-12.04 x86_64 Ubuntu 12.04 (Precise) ubuntu-14.04 x86_64 Ubuntu 14.04 (Trusty) ubuntu-16.04 x86_64 Ubuntu 16.04 (Xenial) ubuntu-18.04 x86_64 Ubuntu 18.04 (bionic) ubuntu-20.04 x86_64 Ubuntu 20.04 (focal) ..... ..... # create Ubuntu 18.04 VM image root@dlp:~# virt-builder ubuntu-18.04 --format qcow2 --size 10G -o /var/kvm/images/ubuntu1804.qcow2 --root-password password:myrootpassword [ 6.1] Downloading: http://builder.libguestfs.org/ubuntu-18.04.xz [ 111.2] Planning how to build this image [ 111.2] Uncompressing [ 116.2] Resizing (using virt-resize) to expand the disk to 10.0G ..... ..... Output file: /var/kvm/images/ubuntu1804.qcow2 Output size: 10.0G Output format: qcow2 Total usable space: 9.8G Free space: 8.3G (84%) # to configure VM with the image above, run virt-install root@dlp:~# virt-install \ --name ubuntu-18.04 \ --ram 4096 \ --disk path=/var/kvm/images/ubuntu1804.qcow2 \ --vcpus 2 \ --os-variant ubuntu18.04 \ --network bridge=br0 \ --graphics none \ --noautoconsole \ --boot hd \ --noreboot \ --import Starting install... Domain creation completed. You can restart your domain by running: virsh --connect qemu:///system start ubuntu-18.04 |
[3] | [ls] a directory in a virtual machine. |
root@dlp:~# virt-ls -l -d ubuntu2004 /root total 16 drwx------ 2 0 0 4096 Jun 2 02:14 . drwxr-xr-x 19 0 0 4096 Jun 2 02:24 .. -rw-r--r-- 1 0 0 3106 Dec 5 14:39 .bashrc -rw-r--r-- 1 0 0 161 Dec 5 14:39 .profile |
[4] | [cat] a file in a virtual machine. |
root@dlp:~# virt-cat -d ubuntu2004 /etc/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync ... ... |
[5] | Edit a file in a virtual machine. |
root@dlp:~# virt-edit -d ubuntu2004 /etc/fstab # /etc/fstab: static file system information. # # Use 'blkid' to print the universally unique identifier for a # device; this may be used with UUID= as a more robust way to name devices # that works even if disks are added and removed. See fstab(5). # # <file system> <mount point> <type> <options> <dump> <pass> /dev/mapper/vgubuntu-root / ext4 errors=remount-ro 0 1 # /boot/efi was on /dev/vda1 during installation UUID=54D9-A80A /boot/efi vfat umask=0077 0 1 /dev/mapper/vgubuntu-swap_1 none swap sw 0 0 |
[6] | Display disk usage in a virtual machine. |
root@dlp:~# virt-df -d ubuntu2004 Filesystem 1K-blocks Used Available Use% ubuntu2004:/dev/sda1 523248 4 523244 1% ubuntu2004:/dev/vgubuntu/root 18971044 2095356 15888964 12% |
[7] | Mount a disk for a virtual machine. |
root@dlp:~# guestmount -d ubuntu2004 -i /mnt root@dlp:~# ll /mnt total 88 drwxr-xr-x 19 root root 4096 Jun 1 20:24 ./ drwxr-xr-x 20 root root 4096 Jun 1 19:34 ../ lrwxrwxrwx 1 root root 7 Jun 1 20:14 bin -> usr/bin/ drwxr-xr-x 4 root root 4096 Jun 1 20:28 boot/ drwxr-xr-x 4 root root 4096 Jun 1 20:14 dev/ ... ... |
[8] | Display the status of virtual machines. |
root@dlp:~# virt-top virt-top 21:59:37 - x86_64 8/8CPU 2593MHz 11978MB 2 domains, 1 active, 1 running, 0 sleeping, 0 paused, 1 inactive D:0 O:0 X:0 CPU: 0.0% Mem: 6144 MB (6144 MB by guests) ID S RDRQ WRRQ RXBY TXBY %CPU %MEM TIME NAME 1 R 0.0 0.0 38:11.38 win2k19 - (ubuntu2004) |
Sponsored Link |
|