wikiv2:install_kvm_ol9
Table of Contents
Instalação KVM - Oracle Linux 9
$ sudo dnf install qemu-kvm qemu-img libvirt virt-install
$ sudo systemctl enable --now libvirtd Created symlink /etc/systemd/system/multi-user.target.wants/libvirtd.service → /usr/lib/systemd/system/libvirtd.service. Created symlink /etc/systemd/system/sockets.target.wants/libvirtd.socket → /usr/lib/systemd/system/libvirtd.socket. Created symlink /etc/systemd/system/sockets.target.wants/libvirtd-ro.socket → /usr/lib/systemd/system/libvirtd-ro.socket.
$ systemctl status libvirtd
● libvirtd.service - Virtualization daemon
Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; enabled; preset: disabled)
Active: active (running) since Tue 2023-08-22 16:27:11 -03; 28s ago
TriggeredBy: ● libvirtd.socket
● libvirtd-ro.socket
○ libvirtd-tls.socket
○ libvirtd-tcp.socket
● libvirtd-admin.socket
Docs: man:libvirtd(8)
https://libvirt.org
Main PID: 19519 (libvirtd)
Tasks: 21 (limit: 32768)
Memory: 17.0M
CPU: 648ms
CGroup: /system.slice/libvirtd.service
├─19519 /usr/sbin/libvirtd --timeout 120
├─19623 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
└─19624 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
Aug 22 16:27:11 ol9-kvm-01 dnsmasq[19623]: compile time options: IPv6 GNU-getopt DBus no-UBus no-i18n IDN2 DHCP DHCPv6 no-Lua TFTP no-conntrack ipset auth >
Aug 22 16:27:11 ol9-kvm-01 dnsmasq-dhcp[19623]: DHCP, IP range 192.168.122.2 -- 192.168.122.254, lease time 1h
Aug 22 16:27:11 ol9-kvm-01 dnsmasq-dhcp[19623]: DHCP, sockets bound exclusively to interface virbr0
Aug 22 16:27:11 ol9-kvm-01 dnsmasq[19623]: reading /etc/resolv.conf
Aug 22 16:27:11 ol9-kvm-01 dnsmasq[19623]: using nameserver 131.255.224.10#53
Aug 22 16:27:11 ol9-kvm-01 dnsmasq[19623]: using nameserver 143.255.204.10#53
Aug 22 16:27:11 ol9-kvm-01 dnsmasq[19623]: using nameserver fe80::4a22:54ff:fe5d:1ef8%enp5s0f0#53
Aug 22 16:27:11 ol9-kvm-01 dnsmasq[19623]: read /etc/hosts - 2 addresses
Aug 22 16:27:11 ol9-kvm-01 dnsmasq[19623]: read /var/lib/libvirt/dnsmasq/default.addnhosts - 0 addresses
Aug 22 16:27:11 ol9-kvm-01 dnsmasq-dhcp[19623]: read /var/lib/libvirt/dnsmasq/default.hostsfile
$ sudo usermod -aG libvirt $USER $ sudo usermod -aG kvm $USER
$ sudo mkdir /datastore/images $ sudo mkdir /datastore/isos
$ sudo virsh pool-define-as --name default --type dir --target /datastore/images Pool default defined
$ sudo virsh pool-define-as --name isos --type dir --target /datastore/isos Pool isos defined
$ sudo virsh pool-autostart default Pool default marked as autostarted
$ sudo virsh pool-autostart isos Pool isos marked as autostarted
$ sudo virsh pool-start default
Pool default started
$ sudo virsh pool-start isos
Pool isos started
$ sudo virsh pool-list Name State Autostart ------------------------------- default active yes isos active yes
$ sudo getfacl -e /datastore/images/ getfacl: Removing leading '/' from absolute path names # file: datastore/images/ # owner: root # group: root user::rwx group::r-x other::r-x
$ sudo getfacl -e /datastore/isos/ getfacl: Removing leading '/' from absolute path names # file: datastore/isos/ # owner: root # group: root user::rwx group::r-x other::r-x
$ sudo setfacl -m u:qemu:rx /datastore/images/ $ sudo setfacl -m u:qemu:rx /datastore/isos/
$ sudo getfacl -e /datastore/images/ getfacl: Removing leading '/' from absolute path names # file: datastore/images/ # owner: root # group: root user::rwx user:qemu:r-x #effective:r-x group::r-x #effective:r-x mask::r-x other::r-x
$ sudo getfacl -e /datastore/isos/ getfacl: Removing leading '/' from absolute path names # file: datastore/isos/ # owner: root # group: root user::rwx user:qemu:r-x #effective:r-x group::r-x #effective:r-x mask::r-x other::r-x
$ sudo systemctl restart libvirtd
Criando máquina virtual por linha de comando
$ sudo wget http://cdimage.debian.org/mirror/cdimage/archive/11.7.0/amd64/iso-cd/debian-11.7.0-amd64-netinst.iso -P /datastore/isos/
$ osinfo-query os | grep debian debian1.1 | Debian GNU/Linux 1.1 | 1.1 | http://debian.org/debian/1.1 debian1.2 | Debian GNU/Linux 1.2 | 1.2 | http://debian.org/debian/1.2 debian1.3 | Debian GNU/Linux 1.3 | 1.3 | http://debian.org/debian/1.3 debian10 | Debian 10 | 10 | http://debian.org/debian/10 debian11 | Debian 11 | 11 | http://debian.org/debian/11 debian2.0 | Debian GNU/Linux 2.0 | 2.0 | http://debian.org/debian/2.0 debian2.1 | Debian GNU/Linux 2.1 | 2.1 | http://debian.org/debian/2.1 debian2.2 | Debian GNU/Linux 2.2 | 2.2 | http://debian.org/debian/2.2 debian3 | Debian GNU/Linux 3.0 | 3.0 | http://debian.org/debian/3 debian3.1 | Debian GNU/Linux 3.1 | 3.1 | http://debian.org/debian/3.1 debian4 | Debian GNU/Linux 4.0 | 4.0 | http://debian.org/debian/4 debian5 | Debian GNU/Linux 5.0 | 5.0 | http://debian.org/debian/5 debian6 | Debian 6.0 | 6.0 | http://debian.org/debian/6 debian7 | Debian 7 | 7 | http://debian.org/debian/7 debian8 | Debian 8 | 8 | http://debian.org/debian/8 debian9 | Debian 9 | 9 | http://debian.org/debian/9 debiantesting | Debian testing | testing | http://debian.org/debian/testing
$ sudo virt-install --virt-type kvm \ --name debian11 \ --description "Debian bullseye" \ --cdrom /datastore/isos/debian-11.7.0-amd64-netinst.iso \ --os-variant debian11 \ --disk size=16,format=qcow2,bus=virtio,cache=none \ --memory 1024 \ --vcpus 2 \ --cpu host-passthrough \ --network=default,model=virtio \ --graphics vnc,listen=0.0.0.0 \ --noautoconsole
Acessando remotamente
$ ssh-keygen -t ed25519 Generating public/private ed25519 key pair. Enter file in which to save the key (/home/gean/.ssh/id_ed25519): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/gean/.ssh/id_ed25519 Your public key has been saved in /home/gean/.ssh/id_ed25519.pub The key fingerprint is: SHA256:LRfyaMBCc+nFBbvUZw/4BIFxA+LeboyAByDqEl0zCXw gean@inspiron-15-5510 The key's randomart image is: +--[ED25519 256]--+ |o...*.oo+**. | |oo.oEB..++ + | |o o...+.+ + = | |.. o o.+ * * o | |... o . S + . . | |. . . = o | | . + | | . | | | +----[SHA256]-----+
$ ssh-copy-id 192.168.0.240 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/gean/.ssh/id_ed25519.pub" /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys gean@192.168.0.240's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh '192.168.0.240'" and check to make sure that only the key(s) you wanted were added.
$ sudo apt install virt-manager
$ virt-manager --connect qemu+ssh://gean@192.168.0.240/system
Referências
wikiv2/install_kvm_ol9.txt · Last modified: by 127.0.0.1

