Run VIO commands from the HMC using “viosvrcmd” without VIOs Passwords

IBM Systems Director can not only gather standard inventory information from the operating system running inside the VIOS but also virtualized resources. This information comes from the communication with the Hardware Management Console and the viosvrcmd command. The virtual resources and the client LPARs are stored in the Systems Director database. There is nothing to be configured on the VIOS for this data gathering.

Recently we got a situation where we don’t know the passwords of either padmin/root of VIOS but need to run commands in VIOs. Found an interesting command in HMC called “viosvrcmd“, which will enable us to run commands on VIOs through HMC.

# viosvrcmd -m managed-system {-p partition-name | --id partition-ID} -c "command" [--help]

Description: viosvrcmd issues an I/O server command line interface (ioscli) command to a virtual I/O server partition.

The ioscli commands are passed from the Hardware Management Console (HMC) to the virtual I/O server partition over an RMC session.

RMC does not allow interactive execution of ioscli commands.

  • -m: VIOs managed system name.
  • -p: VIOs hostname.
  • –id: The partion ID of the VIOs.
  • -c: The I/O server command line interface (ioscli) command to issue to the virtual I/O server partition.
  • –help: Display the help text for this command and exit.
Note: You must either use this option to specify the ID of the partition, or use the -p option to specify the partition’s name. The –id and the -p options are mutually exclusive. The command must be enclosed in double quotes. Also, the command cannot contain the semicolon (;), greater than (>), or vertical bar (|) characters.

Here is an example:

hscroot@umhmc:~> viosvrcmd -m umfrm570 -p umvio1 -c "ioslevel"
2.2.0.0

Since we can’t give the ; or > or | in the command, if you need to process the output using filters, you can use that after “”.

hscroot@umhmc:~> viosvrcmd -m umfrm570 -p umvio1 -c "lsdev -virtual" | grep vfchost0
vfchost0         Available   Virtual FC Server Adapter

What if you want to run command as root (oem_setup_env)? I’ve got a method from internet:

hscroot@umhmc:~> viosvrcmd -m umfrm570 -p umvio1 -c "oem_setup_env
> whoami"
root

You can run in one shot like below:

hscroot@umhmc:~> viosvrcmd -m umfrm570 -p umvio1 -c "oem_setup_env\n whoami"
root

If you need to run multiple commands, you can use them by assigning the commands to a variable and calling the variable in place of the command parameter.

hscroot@umhmc:~>command=`printf  "oem_setup_env\nchsec -f /etc/security/lastlog -a unsuccessful_login_count=0 -s padmin"`

hscroot@umhmc:~>viosvrcmd -m umfrm570 -p umvio1 -c "$command"

Conclusion

When integrating with VIOS, PowerVM NovaLink uses the viosvrcmd command, which allows a legitimate user to run commands against a VIOS in a manner similar to the HMC viosvrcmd command.

Related Post