CentOS Stream 8
Sponsored Link

KVM : Use VirtualBMC2022/02/04

 
Install VirtualBMC to enable IPMI commands to Virtual mashines.
VirtualBMC supports a small part of IPMI commands like power on/off operation, however, it is sometimes useful.
[1] Install VirtualBMC on KVM Host.
[root@dlp ~]#
dnf -y install python3-virtualenv ipmitool
# download Python virtual environment under the [/opt/virtualbmc]

[root@dlp ~]#
python3 -m virtualenv --system-site-packages --download /opt/virtualbmc
Using base prefix '/usr'
New python executable in /opt/virtualbmc/bin/python3
Also creating executable in /opt/virtualbmc/bin/python
Installing setuptools, pip, wheel...done.

# install VirtualBMC

[root@dlp ~]#
/opt/virtualbmc/bin/pip3 install virtualbmc
# create a systemd setting file

[root@dlp ~]#
vi /usr/lib/systemd/system/virtualbmc.service
# create new

[Unit]
Description=Virtual BMC Service
After=network.target libvirtd.service

[Service]
Type=simple
ExecStart=/opt/virtualbmc/bin/vbmcd --foreground
ExecStop=/bin/kill -HUP $MAINPID
User=root
Group=root

[Install]
WantedBy=multi-user.target

[root@dlp ~]#
systemctl daemon-reload

[root@dlp ~]#
systemctl enable --now virtualbmc.service
# show status (OK if shown no error)

[root@dlp ~]#
/opt/virtualbmc/bin/vbmc list
[2] Set VirtualBMC to virtual machines.
[root@dlp ~]#
virsh list --all

 Id   Name         State
-----------------------------
 -    centos-st8   shut off
 -    rx-7         shut off
 -    rx-8         shut off

# set VirtualBMC to a VM [rx-7]
# for [port], [username], [password], it's OK to set any values you like

[root@dlp ~]#
/opt/virtualbmc/bin/vbmc add rx-7 --port 6230 --username vbmcadmin --password adminpassword
[root@dlp ~]#
/opt/virtualbmc/bin/vbmc list

+-------------+--------+---------+------+
| Domain name | Status | Address | Port |
+-------------+--------+---------+------+
| rx-7        | down   | ::      | 6230 |
+-------------+--------+---------+------+

# start VirtualBMC

[root@dlp ~]#
/opt/virtualbmc/bin/vbmc start rx-7
[root@dlp ~]#
/opt/virtualbmc/bin/vbmc list

+-------------+---------+---------+------+
| Domain name | Status  | Address | Port |
+-------------+---------+---------+------+
| rx-7        | running | ::      | 6230 |
+-------------+---------+---------+------+

[root@dlp ~]#
/opt/virtualbmc/bin/vbmc show rx-7

+-----------------------+----------------+
| Property              | Value          |
+-----------------------+----------------+
| active                | True           |
| address               | ::             |
| domain_name           | rx-7           |
| libvirt_sasl_password | ***            |
| libvirt_sasl_username | None           |
| libvirt_uri           | qemu:///system |
| password              | ***            |
| port                  | 6230           |
| status                | running        |
| username              | vbmcadmin      |
+-----------------------+----------------+

# show status of power on [rx-7] via VirtualBMC

[root@dlp ~]#
ipmitool -I lanplus -H 127.0.0.1 -p 6230 -U vbmcadmin -P adminpassword power status

Chassis Power is off
# power on via VirtualBMC

[root@dlp ~]#
ipmitool -I lanplus -H 127.0.0.1 -p 6230 -U vbmcadmin -P adminpassword power on

Chassis Power Control: Up/On
[root@dlp ~]#
virsh list --all

 Id   Name         State
-----------------------------
 1    rx-7         running
 -    centos-st8   shut off
 -    rx-8         shut off

# power off via VirtualBMC

[root@dlp ~]#
ipmitool -I lanplus -H 127.0.0.1 -p 6230 -U vbmcadmin -P adminpassword power off

Chassis Power Control: Down/Off
[root@dlp ~]#
virsh list --all

 Id   Name         State
-----------------------------
 -    centos-st8   shut off
 -    rx-7         shut off
 -    rx-8         shut off
[3] If you'd like to use VirtualBMC not on KVM Host but on other Hosts, configure like follows.
For SSH key-pair settings, it had beetr to change sshd setting to [PermitRootLogin prohibit-password] after setting key-pair.
# generate SSH key-pair and set to own host

[root@dlp ~]#
ssh-keygen -q -N ""

Enter file in which to save the key (/root/.ssh/id_rsa):
[root@dlp ~]#
ssh-copy-id 10.0.0.30

root@10.0.0.30's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '10.0.0.30'"
and check to make sure that only the key(s) you wanted were added.

[root@dlp ~]#
virsh list --all

 Id   Name         State
-----------------------------
 1    rx-7         running
 -    centos-st8   shut off
 -    rx-8         shut off

# set VirtualBMC to [rx-8]
# for [--libvirt-uri], specify KVM Host

[root@dlp ~]#
/opt/virtualbmc/bin/vbmc add rx-8 --port 6231 --username vbmcadmin --password adminpassword --libvirt-uri qemu+ssh://root@10.0.0.30/system

[root@dlp ~]#
/opt/virtualbmc/bin/vbmc start rx-8
[root@dlp ~]#
/opt/virtualbmc/bin/vbmc list

+-------------+---------+---------+------+
| Domain name | Status  | Address | Port |
+-------------+---------+---------+------+
| rx-7        | running | ::      | 6230 |
| rx-8        | running | ::      | 6231 |
+-------------+---------+---------+------+

[root@dlp ~]#
/opt/virtualbmc/bin/vbmc show rx-8

+-----------------------+----------------------------------+
| Property              | Value                            |
+-----------------------+----------------------------------+
| active                | True                             |
| address               | ::                               |
| domain_name           | rx-8                             |
| libvirt_sasl_password | ***                              |
| libvirt_sasl_username | None                             |
| libvirt_uri           | qemu+ssh://root@10.0.0.30/system |
| password              | ***                              |
| port                  | 6231                             |
| status                | running                          |
| username              | vbmcadmin                        |
+-----------------------+----------------------------------+

# if Firewalld is running, allow setting ports

[root@dlp ~]#
firewall-cmd --add-port=6231/udp

[root@dlp ~]#
firewall-cmd --runtime-to-permanent


# that's OK
# for SSH key-pair generated on KVM Host, it needs to transfer private-key [id_rsa] to the Hosts you'd like to use VirtualBMC
# for example, execute ipmitool on [rx-7] host to [rx-8] host
# got private key from KVM host

[root@rx-7 ~]#
ll .ssh

total 8
-rw-------. 1 root root 2602 Feb  4 19:04 id_rsa
-rw-r--r--. 1 root root  171 Feb  4 19:04 known_hosts
[root@rx-7 ~]#
ssh 10.0.0.30 hostname

dlp.srv.world
[root@rx-7 ~]#
ipmitool -I lanplus -H 10.0.0.30 -p 6231 -U vbmcadmin -P adminpassword power status

Chassis Power is off
[root@rx-7 ~]#
ipmitool -I lanplus -H 10.0.0.30 -p 6231 -U vbmcadmin -P adminpassword power on

Chassis Power Control: Up/On
[root@rx-7 ~]#
ssh 10.0.0.30 "virsh list"

 Id   Name   State
----------------------
 1    rx-7   running
 2    rx-8   running
Matched Content