Fix “Unable to find the binary installation directory (answer BINDIR)” When Reinstalling VMware Tools

If a previous VMware Tools installation on a Linux guest was botched, the installer may refuse to uninstall it and abort the new install.

The Error

A previous installation of VMware Tools has been detected.
The previous installation was made by the tar installer (version 4).

Keeping the tar4 installer database format.

You have a version of VMware Tools installed. Continuing this install will
first uninstall the currently installed version. Do you wish to continue?
(yes/no) [yes]

Answering yes produces:

Error: Unable to find the binary installation directory (answer BINDIR)
in the installer database file "/etc/vmware-tools/locations".
Uninstall failed. Please correct the failure and re run the install.

Execution aborted.

The Fix

Remove the corrupted installer database file, then run the VMware Tools installer again:

rm /etc/vmware-tools/locations
./vmware-install.pl

If the reinstall then complains about existing kernel modules, see fixing the clobber error when reinstalling VMware Tools.

Fix the “Clobber” Error When Reinstalling VMware Tools on Linux

When you reinstall or upgrade VMware Tools on a Linux guest, the installer can stop with an error about existing kernel modules (such as vmxnet, vmci, or pvscsi) that it won’t overwrite. Tell it to replace them with the --clobber-kernel-modules option.

From the extracted vmware-tools-distrib folder, run:

./vmware-install.pl --clobber-kernel-modules=vmxnet,vmci,vmxnet3,pvscsi,vmmemctl

Related: installing VMware Tools on CentOS.

Replace sysklogd with rsyslog on CentOS and Forward Logs to Splunk

Older CentOS servers use sysklogd, which can’t forward logs over TCP with a disk queue. Here’s how to swap it for rsyslog and send everything to Splunk.

1. Swap sysklogd for rsyslog

Use yum shell to remove and install in one transaction:

yum shell
remove sysklogd
install rsyslog
run
exit

2. Add the Splunk Forwarding Rule

Edit /etc/rsyslog.conf and paste in this block, replacing your-splunk-server with your Splunk host:

# ### begin forwarding rule ###
# The statement between the begin ... end define a SINGLE forwarding
# rule. They belong together, do NOT split them. If you create multiple
# forwarding rules, duplicate the whole block!
# Remote Logging (we use TCP for reliable delivery)
#
# An on-disk queue is created for this action. If the remote host is
# down, messages are spooled to disk and sent when it is up again.
$WorkDirectory /var/lib/rsyslog # where to place spool files
$ActionQueueFileName fwdRule1 # unique name prefix for spool files
$ActionQueueMaxDiskSpace 1g # 1gb space limit (use as much as possible)
$ActionQueueSaveOnShutdown on # save messages to disk on shutdown
$ActionQueueType LinkedList # run asynchronously
$ActionResumeRetryCount -1 # infinite retries if host is down
# remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional
*.* @@your-splunk-server:514
# ### end of the forwarding rule ###

3. Enable and Restart rsyslog

chkconfig rsyslog on
service rsyslog restart

See also forwarding CentOS syslog to Splunk with rsyslog.

Fix iSCSI Latency on Dell R815 with Broadcom NICs in VMware ESXi

Our new Dell PowerEdge R815 hosts had strange latency on iSCSI traffic running over Broadcom NICs on a dedicated, segregated storage LAN.

The Fix: Update the Broadcom NetXtreme II Driver

The solution was the updated Broadcom NetXtreme II driver bundle:

BCM-NetXtremeII-5.0-offline_bundle-940344.zip
  1. Import the offline bundle into VMware Update Manager.
  2. Attach it to the hosts in a baseline and remediate.
  3. Reboot each host.

After one reboot, the latency was gone and everyone was happy.

How to Add a Persistent Cron Job on a VMware ESX/ESXi Host

On VMware ESX/ESXi, changes to the root crontab are lost when the host reboots. Here’s how to add a cron job that survives reboots by re-creating it from /etc/rc.local.

Enable SSH on the host first, then log in as root.

1. Add the Job to the Root Crontab

  1. Edit /var/spool/cron/crontabs/root.
  2. Add your job on a single line, for example:
5 0 * * * /full/path/to/script arguments/with/full/path > /full/path/to/logfile 2>&1
  1. The file is read-only, so save and quit vi with Esc then :wq!.

5 0 * * * means 5 minutes past midnight every day. See the crontab(5) man page for the full schedule syntax.

2. Re-create the Job at Boot via /etc/rc.local

Edit /etc/rc.local (for example, vi /etc/rc.local) and add these three lines at the end. The first stops crond, the second appends your job to the root crontab, and the third starts crond again:

/bin/kill $(cat /var/run/crond.pid)
/bin/echo '5 0 * * * /full/path/to/script arguments/with/full/path > /full/path/to/logfile 2>&1' >> /var/spool/cron/crontabs/root
/bin/busybox crond

Save and exit, then run the command below so your /etc/rc.local change itself survives a reboot:

auto-backup.sh

Remember: every time you change the cron job, update /etc/rc.local too and run auto-backup.sh again.

After a P2V Conversion: Fix the Windows HAL and Clean Up Old Hardware in VMware

After converting a physical Windows server to a VMware virtual machine (P2V), there’s some cleanup to do, especially if you went from a multi-processor system to a single vCPU. Here’s my checklist.

1. Switch the HAL from Multi-Processor to Uni-Processor

If you change from a multi-processor to a uni-processor system, you have to change the Windows HAL manually after the conversion.

  1. Let the VM boot and discover its new hardware, then open Device Manager.
  2. Expand Computer, right-click the processor entry, and choose Update Driver.
  3. Choose Install from a specific location, then Don’t search. I will choose the driver to install.
  4. Select Show all compatible hardware and pick the right one. For example, going from dual CPU to single CPU, choose ACPI Uniprocessor PC instead of ACPI Multiprocessor PC.
  5. Reboot.

To check which HAL is in use, right-click C:\Windows\System32\hal.dll, open the Version tab, and look at Internal Name: halmacpi.dll means multi-processor ACPI and halacpi.dll means uni-processor ACPI.

2. Remove Non-Present (Ghost) Hardware

Open a Command Prompt and run:

SET DEVMGR_SHOW_NONPRESENT_DEVICES=1
DEVMGMT.MSC

In Device Manager, choose View → Show hidden devices and delete any old, grayed-out hardware.

3. Remove Vendor-Specific Software and Drivers

  • Uninstall hardware vendor tools in Add/Remove Programs. On an HP server, for example, remove the HP management agents, survey utility, array configuration utility, and version control agent.
  • Make sure the NIC isn’t using vendor-specific drivers or software, such as NIC teaming.
  • Review Services and disable anything tied to the old hardware vendor.

Enable Apache mod_rewrite (AllowOverride All) for WordPress Permalinks

If WordPress “post name” permalinks return 404 errors on an Apache server, Apache probably isn’t allowing the .htaccess rewrite rules WordPress depends on. The fix is a one-line change.

Steps

  1. Open the Apache configuration file at /etc/httpd/conf/httpd.conf.
  2. Find the Directory block for your DocumentRoot, normally <Directory "/var/www/html">.
  3. Change AllowOverride None to AllowOverride All.
  4. Restart Apache.
<Directory "/var/www/html">
    AllowOverride All
</Directory>
service httpd restart

This step is essential for WordPress post name permalinks to work.

How to Set Up MySQL and Apache for WordPress on CentOS

Before installing WordPress on a CentOS server, you need a web server, PHP, and a MySQL database with a dedicated user. Here’s the quick setup I use.

1. Install MySQL and Apache

yum install mysql
yum install mysql-server
chkconfig mysqld on
service mysqld start
sudo yum install php-gd
yum install httpd
chkconfig httpd on
service httpd start

2. Create the WordPress Database and User

Open the MySQL client and create a database, then grant a user full rights on it. Replace databasename, username, hostname, and password with your own values:

$ mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> CREATE DATABASE databasename;
Query OK, 1 row affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON databasename.* TO "username"@"hostname"
    -> IDENTIFIED BY "password";
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

mysql> EXIT
Bye

Use these database details in wp-config.php when you install WordPress. For pretty permalinks, also enable mod_rewrite in Apache.

How to Mount a Samba (CIFS) Share with a Username and Password in Linux

Many Samba shares on Linux, and shares on Windows Vista and Windows 7, require a username and password before they’ll let you in. Those credentials are set on the server:

  • Windows Vista/7: the login username and password of the share owner on that machine.
  • Linux Samba: any member of the server’s Samba user database who is allowed by the share’s definition.

Mount the Share with Credentials

Instead of the guest option, pass username= and password=:

mount -t cifs -o username=server_user,password=secret //192.168.44.100/share /path_to/mount

To mount it at boot, or to fix write permissions for non-root users, see fixing CIFS mount permissions with file_mode and dir_mode.

Cloning WordPress from Dev to Production: The Search-Replace DB Tool

I spent days beating my head against the wall trying to move WordPress data between my development environment and production, using VMware clones and various other methods. The trouble is that WordPress stores its site URL all through the database, including inside serialized data, so a simple find-and-replace breaks things.

Then I found the Search Replace DB tool from Interconnect/IT, which made the job much easier. It safely updates URLs and paths across the whole database, serialized data included.

Search and Replace for WordPress Databases (Interconnect/IT)

Give it a look and see what you think. Delete the script from your server when you’re done, since it gives full database access.