Connect ISO file to server using RACADM

Using VNC to connect to the iDRAC of a server is a great way to avoid Oracles eternal Java upgrades, security flaws, etc. At the other hand the Java viewer allows for mapping of ISO files when installing the server OS. That’s not an option with VNC, so what to do? Easy: Launch the VNC session and map the ISO file separately from the command line:

Check status of virtual media:

C:\Users\jonas>racadm -r 192.168.0.120 -u root -p calvin remoteimage -s
Remote File Share is Disabled
UserName
Password
ShareName

Mount the image:

C:\Users\jonas>racadm -r 192.168.0.120 -u root -p calvin remoteimage -c -u user@domain.local -p demo -l //192.168.0.121/ISO/MSDN/Win2012R2-JP-EVAL.ISO
Remote Image is now Configured

Verify that the image is connected:

C:\Users\jonas>racadm -r 192.168.0.120 -u root -p calvin remoteimage -s
Remote File Share is Enabled
UserName
Password
ShareName //192.168.0.121/ISO/MSDN/Win2012R2-JP-EVAL.ISO

Disconnect the image:

C:\Users\jonas>racadm -r 192.168.0.120 -u root -p calvin remoteimage -d
Disable Remote File Started. Please check status using -s
option to know Remote File Share is ENABLED or DISABLED.

Power control of VMs on ESXi using a script on the command line

Automating VM power control over the command line can be very useful. Especially to simplify test scenarios when tens or hundreds of VM’s are used. A couple of simple examples below.

Unfortunately the commands for powering on and off are completely different. This means we have two separate scripts for each task:

Powering on:
List all VM’s so we can find the ones we want:

[root@vGPU-ESXi60-01:~] vim-cmd vmsvc/getallvms 
Vmid         Name                                  File                                 Guest OS          Version             Annotation           
1      vcenter60           [datastore1] vcenter60/vcenter60.vmx                   sles11_64Guest          vmx-08    VMware vCenter Server Appliance
13     VMW-vGPU-02         [datastore1] VMW-vGPU-02/VMW-vGPU-02.vmx               windows7_64Guest        vmx-11                                   
14     VMW-vGPU-01         [datastore1] VMW-vGPU-01/VMW-vGPU-01.vmx               windows7_64Guest        vmx-11                                   
15     Win2012R2-vGPU      [datastore1] Win2012R2-vGPU/Win2012R2-vGPU.vmx         windows8Server64Guest   vmx-11                                   
3      HorizonView6.1_CS   [datastore1] HorizonView6.1_CS/HorizonView6.1_CS.vmx   windows8Server64Guest   vmx-11                                   
[root@vGPU-ESXi60-01:~] 

Grep for the ones we are interested in:

[root@vGPU-ESXi60-01:~] vim-cmd vmsvc/getallvms | grep vGPU
13     VMW-vGPU-02         [datastore1] VMW-vGPU-02/VMW-vGPU-02.vmx               windows7_64Guest        vmx-11                                   
14     VMW-vGPU-01         [datastore1] VMW-vGPU-01/VMW-vGPU-01.vmx               windows7_64Guest        vmx-11                                   
15     Win2012R2-vGPU      [datastore1] Win2012R2-vGPU/Win2012R2-vGPU.vmx         windows8Server64Guest   vmx-11                                   
[root@vGPU-ESXi60-01:~] 

Print only their IDs:

[root@vGPU-ESXi60-01:~] vim-cmd vmsvc/getallvms | grep vGPU | awk '{print $1}'
13
14
15
[root@vGPU-ESXi60-01:~] 

Because we’re pedantic – sort them in correct order – just in case:

[root@vGPU-ESXi60-01:~] vim-cmd vmsvc/getallvms | grep vGPU | awk '{print $1}' | sort -n
13
14
15
[root@vGPU-ESXi60-01:~] 

Run a loop to power them on:

[root@vGPU-ESXi60-01:~] for i in `vim-cmd vmsvc/getallvms | grep vGPU | awk '{print $1}' | sort -n`
> do
> echo "Powering on number $i"
> vim-cmd vmsvc/power.on $i
> done

Powering off:
List all the processes:
By default esxcli lists the information on separate lines which makes scripting close to impossible. Therefore we use the –formatter option to list the output in CSV format.

[root@vGPU-ESXi60-01:~] esxcli --formatter=csv vm process list
ConfigFile,DisplayName,ProcessID,UUID,VMXCartelID,WorldID,
/vmfs/volumes/55015477-1d4dd911-786f-b083feca800f/vcenter60/vcenter60.vmx,vcenter60,0,56 4d eb 29 84 8f 47 7d-4a 9f fe 80 3e b7 3d 59,1380839,1380840,
/vmfs/volumes/55015477-1d4dd911-786f-b083feca800f/VMW-vGPU-01/VMW-vGPU-01.vmx,VMW-vGPU-01,0,42 22 22 66 b1 22 29 73-c2 e6 ce b6 44 74 b4 24,1382270,1382271,
/vmfs/volumes/55015477-1d4dd911-786f-b083feca800f/HorizonView6.1_CS/HorizonView6.1_CS.vmx,HorizonView6.1_CS,0,42 22 43 6b 80 77 c1 56-ac 2c 07 42 d3 74 bb e3,1382369,1382370,
/vmfs/volumes/55015477-1d4dd911-786f-b083feca800f/Win2012R2-vGPU/Win2012R2-vGPU.vmx,Win2012R2-vGPU,0,42 22 c2 1b f2 b1 2c f2-d8 55 da df 9a 26 15 71,1382460,1382461,
[root@vGPU-ESXi60-01:~]

To enable AWK we replace spaces with % (for example) and commas with spaces:

[root@vGPU-ESXi60-01:~] esxcli --formatter=csv vm process list | sed 's/ /%/g' | sed 's/,/ /g'
ConfigFile DisplayName ProcessID UUID VMXCartelID WorldID 
/vmfs/volumes/55015477-1d4dd911-786f-b083feca800f/vcenter60/vcenter60.vmx vcenter60 0 56%4d%eb%29%84%8f%47%7d-4a%9f%fe%80%3e%b7%3d%59 1380839 1380840 
/vmfs/volumes/55015477-1d4dd911-786f-b083feca800f/VMW-vGPU-01/VMW-vGPU-01.vmx VMW-vGPU-01 0 42%22%22%66%b1%22%29%73-c2%e6%ce%b6%44%74%b4%24 1382270 1382271 
/vmfs/volumes/55015477-1d4dd911-786f-b083feca800f/HorizonView6.1_CS/HorizonView6.1_CS.vmx HorizonView6.1_CS 0 42%22%43%6b%80%77%c1%56-ac%2c%07%42%d3%74%bb%e3 1382369 1382370 
/vmfs/volumes/55015477-1d4dd911-786f-b083feca800f/Win2012R2-vGPU/Win2012R2-vGPU.vmx Win2012R2-vGPU 0 42%22%c2%1b%f2%b1%2c%f2-d8%55%da%df%9a%26%15%71 1382460 1382461 
[root@vGPU-ESXi60-01:~]

Grep for the VMs we want to power off:

[root@vGPU-ESXi60-01:~] esxcli --formatter=csv vm process list | sed 's/ /%/g' | sed 's/,/ /g' | grep vGPU
/vmfs/volumes/55015477-1d4dd911-786f-b083feca800f/VMW-vGPU-01/VMW-vGPU-01.vmx VMW-vGPU-01 0 42%22%22%66%b1%22%29%73-c2%e6%ce%b6%44%74%b4%24 1382270 1382271 
/vmfs/volumes/55015477-1d4dd911-786f-b083feca800f/Win2012R2-vGPU/Win2012R2-vGPU.vmx Win2012R2-vGPU 0 42%22%c2%1b%f2%b1%2c%f2-d8%55%da%df%9a%26%15%71 1382460 1382461 
[root@vGPU-ESXi60-01:~]

Print only the world-id’s:

[root@vGPU-ESXi60-01:~] esxcli --formatter=csv vm process list | sed 's/ /%/g' | sed 's/,/ /g' | grep vGPU | awk '{print $6}'
1382271
1382461
[root@vGPU-ESXi60-01:~]

Run it in a loop:

[root@vGPU-ESXi60-01:~] for i in `esxcli --formatter=csv vm process list | sed 's/ /%/g' | sed 's/,/ /g' | grep vGPU | awk '{print $6}'`
> do
> esxcli vm process kill --type=soft --world-id=$i
> done
[root@vGPU-ESXi60-01:~]

Windows 2012R2 – Extend disk: “There is not enough space available on the disk(s) to complete this operation.”

I needed to extend the main storage of my fileserver this morning. While VMware happily extended the storage volume for the VM when I asked it to, Windows 2012 R2 was not so helpful. Luckily this is easily fixed.

In Disk Manager (diskmgmt.msc) make sure the disk to be extended is set to be “Dynamic”. If it is, simply Re-scan the disks. Now it can be extended just fine. Screenshots below:

Error when extending disk:

Windows-2012R2-disk-extension-01

Rescan disks:

Windows-2012R2-disk-extension-02

Disk extended to use the extra space:

Windows-2012R2-disk-extension-03

How to SSH using a public key instead of password

When accessing remote systems using SSH it can be handy to use RSA keys rather than having to enter a password every time. Especially handy if doing automation using Ansible or similar tools. Here’s how to do it:

Generate the key pair
One public and one private key will be created. The private key is kept securely on the client system. The public key is copied to the target server. The passphrase is optional. It helps secure they key if the private key is compromised. In this example we skip entering a passphrase.


jonas@nyx:~$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/jonas/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/jonas/.ssh/id_rsa.
Your public key has been saved in /home/jonas/.ssh/id_rsa.pub.
The key fingerprint is:
68:1f:bd:d2:80:3e:ad:fa:f0:eb:c0:2f:a2:23:8d:5a jonas@nyx
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|                 |
|                 |
|       o .       |
|      + S .      |
|   . o o + .     |
| oE + o + o      |
|+.o .= o .       |
|=o ..=B.         |
+-----------------+
jonas@nyx:~$ 

Copy the key to the remote system
We now copy over the public key to the remote system. Note that we need to enter the password to get the key copied. This is what we’re trying to fix. Note that we copy the .pub public key to a new name: “authorized_keys” in the .ssh directory for your user on the remote system. For example “/home/jonas/.ssh/authorized_keys”.


jonas@nyx:~$ scp ~/.ssh/id_rsa.pub 192.168.56.102:.ssh/authorized_keys
jonas@192.168.56.102's password: 
id_rsa.pub                                                 100%  391     0.4KB/s   00:00    
jonas@nyx:~$ 

Verify the solution
Repeat the SCP command but this time copy the public key to a random name to verify that SSH/SCP can be done without entering a password:


jonas@nyx:~$ scp ~/.ssh/id_rsa.pub 192.168.56.102:.ssh/test_file
id_rsa.pub                                                 100%  391     0.4KB/s   00:00    
jonas@nyx:~$ 

…and with Ansible
Below we finally compare pinging a host with RSA key auth enabled vs. server with password login only. Predictably one succeeds and one fails.


jonas@nyx:~$ ansible -m ping all 
192.168.56.102 | success >> {
    "changed": false, 
    "ping": "pong"
}

192.168.56.101 | FAILED => SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue
jonas@nyx:~$