KVM : Management tools2019/07/23 |
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 ..... ..... cirros-0.3.1 x86_64 CirrOS 0.3.1 cirros-0.3.5 x86_64 CirrOS 0.3.5 debian-6 x86_64 Debian 6 (Squeeze) debian-7 sparc64 Debian 7 (Wheezy) (sparc64) debian-7 x86_64 Debian 7 (wheezy) debian-8 x86_64 Debian 8 (jessie) debian-9 x86_64 Debian 9 (stretch) fedora-26 aarch64 Fedora® 26 Server (aarch64) ..... ..... # create an image of Debian 9 root@dlp:~# virt-builder debian-9 --format qcow2 --size 10G -o debian-9.qcow2 --root-password password [ 3.7] Downloading: http://builder.libguestfs.org/debian-9.xz ######################################################################### 100.0% [ 110.6] Planning how to build this image [ 110.6] Uncompressing [ 116.0] Resizing (using virt-resize) to expand the disk to 10.0G ..... ..... Output file: debian-9.qcow2 Output size: 10.0G Output format: qcow2 Total usable space: 9.8G Free space: 9.0G (91%) # to configure VM with the image above, run virt-install root@dlp:~# virt-install \
--name debian-9 \ --ram 4096 \ --disk path=/var/kvm/images/debian-9.qcow2 \ --vcpus 2 \ --os-type linux \ --os-variant debian9 \ --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 debian /root total 20 drwx------ 2 0 0 4096 Jul 23 01:44 . drwxr-xr-x 18 0 0 4096 Jul 23 01:26 .. -rw------- 1 0 0 32 Jul 23 02:33 .bash_history -rw-r--r-- 1 0 0 570 Jan 31 2010 .bashrc -rw-r--r-- 1 0 0 148 Aug 17 2015 .profile |
[4] | [cat] a file in a virtual machine. |
root@dlp:~# virt-cat -d debian /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 debian /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=fb3e573f-3b9c-4876-a5af-07c860a14128 /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 debian Filesystem 1K-blocks Used Available Use% debian:/dev/sda1 240972 48975 179556 21% debian:/dev/debian-vg/root 16182156 967052 14373376 6% |
[7] | Mount a disk for a virtual machine. |
root@dlp:~# guestmount -d debian -i /mnt root@dlp:~# ll /mnt total 73 lrwxrwxrwx 1 root root 7 Jul 23 10:24 bin -> usr/bin drwxr-xr-x 4 root root 1024 Jul 23 10:31 boot drwxr-xr-x 4 root root 4096 Jul 23 10:24 dev drwxr-xr-x 70 root root 4096 Jul 23 11:29 etc drwxr-xr-x 3 root root 4096 Jul 23 10:32 home ..... ..... |
[8] | Display the status of virtual machines. |
root@dlp:~# virt-top virt-top 19:41:31 - x86_64 6/6CPU 2593MHz 16042MB 1 domains, 1 active, 1 running, 0 sleeping, 0 paused, 0 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 1 R 0.0 0.0 0:07.37 debian |
Sponsored Link |