KVM : Management tools2019/04/24 |
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) 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 # create an image of Ubuntu 18.04 root@dlp:~# virt-builder ubuntu-18.04 --format qcow2 --size 20G -o ubuntu1804.qcow2 --root-password password [ 3.7] Downloading: http://libguestfs.org/download/builder/ubuntu-18.04.xz [ 74.0] Planning how to build this image [ 74.0] Uncompressing ..... ..... Output file: ubuntu1804.qcow2 Output size: 20.0G Output format: qcow2 Total usable space: 19.6G Free space: 18.1G (92%) # 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-type linux \ --os-variant ubuntu18.04 \ --network bridge=br0 \ --graphics none \ --serial pty \ --console pty \ --boot hd \ --noreboot \ --import |
[3] | [ls] a directory in a virtual machine. |
root@dlp:~# virt-ls -l -d ubuntu1904 /root total 20 drwx------ 2 0 0 4096 Apr 7 10:22 . drwxr-xr-x 22 0 0 4096 Apr 7 10:15 .. -rw------- 1 0 0 153 Apr 7 11:44 .bash_history -rw-r--r-- 1 0 0 570 Jan 31 2010 .bashrc -rw-r--r-- 1 0 0 140 Nov 19 2007 .profile |
[4] | [cat] a file in a virtual machine. |
root@dlp:~# virt-cat -d ubuntu1904 /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 ubuntu1904 /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/debian--vg-root / ext4 errors=remount-ro 0 1 # /boot was on /dev/vda1 during installation UUID=82c9915f-4b67-46cc-ac63-c6dd4d7662d1 /boot ext2 defaults 0 2 /dev/mapper/debian--vg-swap_1 none swap sw 0 0 |
[6] | Display disk usage in a virtual machine. |
root@dlp:~# virt-df -d ubuntu1904 Filesystem 1K-blocks Used Available Use% ubuntu1904:/dev/sda1 240972 33211 195320 14% ubuntu1904:/dev/debian-vg/root 29284444 958140 26815700 4% |
[7] | Mount a disk for a virtual machine. |
root@dlp:~# guestmount -d ubuntu1904 -i /mnt root@dlp:~# ll /mnt total 89 drwxr-xr-x 2 root root 4096 Apr 7 19:19 bin drwxr-xr-x 4 root root 1024 Apr 7 19:20 boot drwxr-xr-x 4 root root 4096 Apr 7 19:13 dev drwxr-xr-x 83 root root 4096 Apr 7 19:24 etc drwxr-xr-x 3 root root 4096 Apr 7 19:20 home ... ... |
[8] | Display the status of virtual machines. |
root@dlp:~# virt-top virt-top 21:58:43 - x86_64 4/4CPU 2801MHz 12158MB 3 domains, 1 active, 1 running, 0 sleeping, 0 paused, 2 inactive D:0 O:0 X:0 CPU: 0.0% Mem: 4096 MB (4096 MB by guests) ID S RDRQ WRRQ RXBY TXBY %CPU %MEM TIME NAME 6 R 0.0 0.0 0:04.92 ubuntu1904 - (template) - (win2k12R2) |
Sponsored Link |
|