[4] Instalacja narzędzi dla MV
22 czerwca 2020Zainstalujemy teraz narzędzia do zarządzania maszynami wirtualnymi.
[1] Zainstaluj wymagane pakiety.
[root@lsr06vm ~]# dnf install virt-top libguestfs-tools
[2] Stwórz wirtualną maszynę z oficjalnych obrazów.
# lista dostępnych gotowych obrazów [root@lsr06vm ~]# virt-builder -l 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 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) centos-7.2 x86_64 CentOS 7.2 centos-7.3 x86_64 CentOS 7.3 centos-7.4 x86_64 CentOS 7.4 centos-7.5 x86_64 CentOS 7.5 centos-7.6 x86_64 CentOS 7.6 centos-7.7 x86_64 CentOS 7.7 centos-7.8 x86_64 CentOS 7.8 centos-8.0 x86_64 CentOS 8.0 centos-8.2 x86_64 CentOS 8.2 cirros-0.3.1 x86_64 CirrOS 0.3.1 cirros-0.3.5 x86_64 CirrOS 0.3.5 debian-10 x86_64 Debian 10 (buster) 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) fedora-26 armv7l Fedora® 26 Server (armv7l) fedora-26 i686 Fedora® 26 Server (i686) fedora-26 ppc64 Fedora® 26 Server (ppc64) fedora-26 ppc64le Fedora® 26 Server (ppc64le) fedora-26 x86_64 Fedora® 26 Server fedora-27 aarch64 Fedora® 27 Server (aarch64) fedora-27 armv7l Fedora® 27 Server (armv7l) fedora-27 i686 Fedora® 27 Server (i686) fedora-27 ppc64 Fedora® 27 Server (ppc64) fedora-27 ppc64le Fedora® 27 Server (ppc64le) fedora-27 x86_64 Fedora® 27 Server 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 fedora-32 x86_64 Fedora® 32 Server freebsd-11.1 x86_64 FreeBSD 11.1 scientificlinux-6 x86_64 Scientific Linux 6.5 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) # budowa obrazu systemu centos-8.2 [root@lsr06vm ~]# virt-builder centos-8.2 --format qcow2 --size 10G -o /var/kvm/images/centos-8.2 .qcow2 --root-password password [ 2,5] Downloading: http://libguestfs.org/download/builder/centos-8.2.xz ########################################################################################## 100,0% ########################################################################################## 100,0% [ 68,4] Planning how to build this image [ 68,4] Uncompressing [ 94,0] Resizing (using virt-resize) to expand the disk to 10,0G [ 213,1] Opening the new disk [ 219,2] Setting a random seed [ 219,2] Setting passwords [ 222,9] Finishing off Output file: /var/kvm/images/centos-8.2.qcow2 Output size: 10,0G Output format: qcow2 Total usable space: 9,3G Free space: 8,0G (85%) # tworzenie maszyny ze zbudowanego wcześniej obrazu [root@lsr06vm ~]# virt-install --name centos-8.2 --ram 2048 --disk path=/var/kvm/images/centos-8.2.qcow2 --vcpus 2 --os-type linux --os-variant rhel8.0 --network bridge=br0 --graphics none --serial pty --console pty --boot hd --import
[3] [ls] w katalogu maszyny wirtualnej – wirtualna maszyna wyłączona.
[root@lsr06vm ~]# virt-ls -l -d centos-8.2 /root total 24 dr-xr-x---. 2 root root 112 Jun 22 15:06 . dr-xr-xr-x. 17 root root 224 Jun 16 11:35 .. -rw-------. 1 root root 13 Jun 22 15:06 .bash_history -rw-r--r--. 1 root root 18 May 11 2019 .bash_logout -rw-r--r--. 1 root root 176 May 11 2019 .bash_profile -rw-r--r--. 1 root root 176 May 11 2019 .bashrc -rw-r--r--. 1 root root 100 May 11 2019 .cshrc -rw-r--r--. 1 root root 129 May 11 2019 .tcshrc
[4] [cat] pliku w maszynie wirtualnej
[root@lsr06vm ~]# virt-cat -d centos-8.2 /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] Edycja pliku w maszynie wirtualnej.
[root@lsr06vm ~]# virt-edit -d centos-8.2 /etc/fstab # # /etc/fstab # Created by anaconda on Tue Jun 16 11:29:01 2020 # # 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. # UUID=4fd120e4-1f6d-46b3-a404-5569ef6af1f9 / xfs defaults 0 0 UUID=0b3df967-65cc-4a48-8b98-f7f0badc0d91 /boot ext4 defaults 1 2 UUID=40f14688-2619-4046-a9eb-b7333fff1b84 swap swap defaults 0 0
[6] Wyświetlenie informacji o dysku w maszynie wirtualnej.
[root@lsr06vm ~]# virt-df -d centos-8.2 System plików K-bloki Użyte Dostępne Użycie% centos-8.2:/dev/sda2 999320 136916 793592 14% centos-8.2:/dev/sda4 8793792 1279516 7514276 15%
[7] Montowanie dysku dla maszyny wirtualnej
[root@lsr06vm ~]# guestmount -d centos-8.2 -i /media [root@lsr06vm ~]# ll /media razem 16 lrwxrwxrwx. 1 root root 7 2019-05-11 bin -> usr/bin dr-xr-xr-x. 6 root root 4096 06-22 16:49 boot drwxr-xr-x. 2 root root 6 06-16 13:29 dev drwxr-xr-x. 78 root root 8192 06-22 16:49 etc drwxr-xr-x. 2 root root 6 2019-05-11 home lrwxrwxrwx. 1 root root 7 2019-05-11 lib -> usr/lib lrwxrwxrwx. 1 root root 9 2019-05-11 lib64 -> usr/lib64 drwxr-xr-x. 2 root root 6 2019-05-11 media drwxr-xr-x. 2 root root 6 2019-05-11 mnt drwxr-xr-x. 2 root root 6 2019-05-11 opt drwxr-xr-x. 2 root root 6 06-16 13:29 proc dr-xr-x---. 2 root root 112 06-22 17:06 root drwxr-xr-x. 2 root root 6 06-16 13:29 run lrwxrwxrwx. 1 root root 8 2019-05-11 sbin -> usr/sbin drwxr-xr-x. 2 root root 6 2019-05-11 srv drwxr-xr-x. 2 root root 6 06-16 13:29 sys drwxrwxrwt. 7 root root 93 06-22 17:06 tmp drwxr-xr-x. 12 root root 144 06-16 13:32 usr drwxr-xr-x. 20 root root 278 06-22 16:49 var
[8] Wyświetlenie informacji o maszynie wirtualnej.
[root@lsr06vm ~]# virt-top virt-top 17:12:46 - x86_64 2/2CPU 3192MHz 3912MB 5 domains, 2 active, 2 running, 0 sleeping, 0 paused, 3 inactive D:0 O:0 X:0 CPU: 0,2% Mem: 2548 MB (2548 MB by guests) ID S RDRQ WRRQ RXBY TXBY %CPU %MEM TIME NAME 3 R 0 0 172 0 0,2 52,0 0:48.05 centos8 13 R 0 0 0,0 12,0 0:02.97 guestfs-as8imfmbmksb4a24 - (centos-8.2) - (template) - (template1)