Ubuntu 22.04
Sponsored Link

KVM : Use VirtualBMC2022/04/28

 
Install VirtualBMC to enable IPMI commands to Virtual machines.
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:~#
apt -y install python3-pip python3-venv ipmitool
# create Python virtual environment under the [/opt/virtualbmc]

root@dlp:~#
python3 -m venv --system-site-packages /opt/virtualbmc
# 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 no error is shown)

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

 Id   Name   State
-----------------------
 -    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
-----------------------
 3    rx-7   running
 -    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
-----------------------
 -    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 better 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:~#
mv ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys

root@dlp:~#
ssh 10.0.0.30 hostname

dlp.srv.world
root@dlp:~#
virsh list --all

 Id   Name   State
-----------------------
 -    rx-7   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                        |
+-----------------------+----------------------------------+

# 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

root@rx-7:~#
ll .ssh

total 20
drwx------ 2 root root 4096 Sep 21 07:16 ./
drwx------ 5 root root 4096 Sep 21 07:13 ../
-rw------- 1 root root    0 Sep 21 07:06 authorized_keys
-rw------- 1 root root 2602 Sep 21 07:15 id_rsa
-rw------- 1 root root  978 Sep 21 07:14 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
----------------------
 4    rx-7   running
 5    rx-8   running
Matched Content