Stopping X windows / dropping to single-user mode

Installing the NVIDIA driver on Linux requires dropping to a command prompt without X windows running in the background.

Switch to root user:

Stop the window manager:

After this X windows will stop and a command prompt will be displayed. The option to enter the root password will be given. Enter it and then install the driver as root. To install the driver, do one of the following:

Option 1:

Option 2:

When done, start X windows again with:
/etc/init.d/gdm3 start

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:

Mount the image:

Verify that the image is connected:

Disconnect the image:

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:

Grep for the ones we are interested in:

Print only their IDs:

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

Run a loop to power them on:

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.

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

Grep for the VMs we want to power off:

Print only the world-id’s:

Run it in a loop:

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.

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”.

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:

…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.