RHEL_9_Foreman_Guide

Knowledge Base Install Discovery and Provisioning libvirt proxmox external DNS&DHCP diskless pxe-boot using zfs

libvirt

install

$ su root

create the folders needed for libvirt and the ssh keys

$ mkdir /usr/share/foreman/.ssh
$ mkdir /usr/share/foreman/.cache
$ mkdir /usr/share/foreman/.cache/libvirt
$ mkdir /usr/share/foreman/.cache/libvirt/virsh
$ chown foreman:foreman /usr/share/foreman/.cache/libvirt/virsh
$ chmod 700 -R /usr/share/foreman/.cache 
$ chown foreman:foreman /usr/share/foreman/.cache

install libvirt:

$ dnf install qemu-kvm libvirt virt-install virt-viewer
$ for drv in qemu network nodedev nwfilter secret storage interface; do systemctl start virt${drv}d{,-ro,-admin}.socket; done

validate:

$ virt-host-validate

enable and start libvirt:

$ systemctl start libvirtd
$ virt-manager

check if the Virtual Bridge 0” interface was created

virbr0

$ ifconfig
enp2s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
       inet 192.168.2.100  netmask 255.255.255.0  broadcast 192.168.2.255
...
virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
       inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
...

config

add a host mapping

edit /etc/ssh/sshd_config:

...
Include /etc/ssh/sshd_config.d/*.conf
PermitRootLogin yes

the tricky part here is:

login to foreman:

$ su foreman -s /bin/bash

add ssh key:

bash-5.1$ ssh-keygen

copy the key (thats where we need root):

bash-5.1$ ssh-copy-id root@kvm.mapping.com
 ...
 root@kvm.mapping.com's password:  <<------- ROOT
 Number of key(s) added: 1
 Now try logging into the machine, with:   "ssh 'root@kvm.mapping.com'"
 and check to make sure that only the key(s) you wanted were added.

try the ssh connection:

 bash-5.1$ 'root@kvm.mapping.com'

test the kvm-hypervisor connection:

bash-5.1$ virsh -c qemu+ssh://root@kvm.mapping.com/system
Willkommen bei virsh, dem interaktiven Virtualisierungsterminal.
Tippen Sie:  'help' für eine Hilfe zu den Befehlen
     'quit' zum Beenden
virsh # 

exit the shell:

bash-5.1$ exit

try to add the libvirt compute resource in foreman:


Creating and Configuring a Network Bridge on Linux Using nmcli (OPTIONAL)

The commands you executed are part of the process to create and configure a network bridge on a Linux system. This setup allows virtual machines (VMs) to communicate directly with the physical network, as if they were directly connected to the network via a physical network interface. Here’s a comprehensive guide translated into English and formatted in Markdown:

Step 1: Create a Network Bridge

$ sudo nmcli conn add type bridge con-name br0 ifname br0

Step 2: Add a Physical Interface as a Slave to the Bridge

$ sudo nmcli conn add type ethernet slave-type bridge con-name bridge-br0 ifname enp2s0 master br0

Step 3: Activate the Bridge

$ sudo nmcli conn up br0

Step 4: Assign an IP Address to the Bridge (Optional)

$ sudo nmcli conn modify br0 ipv4.addresses "192.168.200.100/24" ipv4.method manual sudo nmcli conn up br0
Knowledge Base Install Discovery and Provisioning libvirt proxmox external DNS&DHCP diskless pxe-boot using zfs