Archive | June, 2011

Install VMware ESX4.1 via PXE

We recently received 2 new servers that I needed to install the newest ESX on. I downloaded the IOSs, but I did not want to have to burn them. So I decided to try and install ESX via PXE. I did not have an answer file (kickstart), so I wanted to run an interactive install from PXE.

I already had a PXE/TFTP server configured, so I just needed to add a new instance to the pxelinux.cfg file.

KERNEL images/vmware/esx/vmlinuz
APPEND initrd=images/vmware/esx/initrd.img vmkopts=debugLogToSerial:1 mem=512M url=

The different options for “APPEND” can be found here. Works like a charm.

xcopy: permissions,recursive,incremental

I can never remember xcopy’s flags, so I am creating a post for myself.

xcopy SourceDrivePath DestDrivePath /X /C /E /H /Y /D

/X Perms
/C continue on error
/E Recursive with empty folders
/H (hidden and system) Copy hidden and system files
/Y (yes) No Prompts
/D (date) SourceDate is newer then DestDate (incremental)

PowerShell Function to get uptime on multiple computers

I wanted to create a function that I could use to find the uptime of several workstations. I did not want to read a list of machine name from csv, I just wanted pass a list of workstation names and get their uptime back. I also added a ping check to make sure the machine is alive.


Function Get-Computer-LastBootTime {
$Args | ForEach-Object -Process {
$ping = gwmi Win32_PingStatus -Filter ("Address='" + $_ + "'") | Select-Object StatusCode
if ($ping.statusCode -eq 0) {

$wmi = gwmi Win32_OperatingSystem -EA silentlycontinue -ComputerName $_
$localdatetime = $wmi.ConvertToDateTime($wmi.LocalDateTime)
$lastbootuptime = $wmi.ConvertToDateTime($wmi.LastBootUpTime)
$uptime = $localdatetime - $lastbootuptime
echo "$_ uptime: $days days $hours hours $mins mins"

else {
echo "$_ is offline"

php53 included in CentOS 5.6

I wish I read release notes, it would make my life easier. In my previous post, I was worried about CentOS 5.x not having a new enough version of PHP to run the soon to be release WordPress 3.2. Well, RedHat’s 5.6 release notes clearly say:

Version 5.3.3 of PHP is now available in Red Hat Enterprise Linux 5.6 as the separate php53 package

To move to the 5.3 version of PHP, I ran the following commands:

  • yum erase php\*
  • yum install php53 php53-gd php53-mysql php53-pdo php53-mbstring  php53-cli php53-devel php53-common php53-xml

That was easy.

“error establishing a database connection” in a previously working WordPress site

My site just crashed!!! I received the oh-so-helpful error “establishing a database connection” when I went to my site. Other sites on the server were fine.  The site was working fine, and my config had not changed. The httpd error log showed nothing.

Then I found this in the MySQL logs (/var/log/mysqld.log)

[ERROR] /usr/libexec/mysqld: Table ‘./db_name/wp_options’ is marked as crashed and should be repaired

To fix I ran:

mysql -e “use db_name;REPAIR TABLE wp_options”

And we are back . . .


I just learned about the script: /usr/bin/mysql_secure_installation. Very cool. Here are the commands that the script actually runs.

I am going to add these to my provisioning script (I already take care of the root password piece):

mysql -e “DROP DATABASE test;”
mysql -e “DELETE FROM mysql.user WHERE User=’root’ AND Host!=’localhost’;”
mysql -e “DELETE FROM mysql.user WHERE User=”;”

CentOS, NTPD, VMware and sleeping.

I have a MacPro at home, and I am running VMware Fusion on it. At night, I sleep the machine to save electricity. I have a CentOS guest running and the time is always out of sync. After the VM is restored from sleep, the NTP service is no longer running and my time really drifts.

I finally sat down and tried to figure out my time sync issues on CentOS and VMware. This document explains it all. At the bottom they say you should turn off VMware tools time sync and use NTPD.

To install NTPD (with the recommended changes from the above document)

  1. yum install ntp
  2. chkconfig ntpd on
  3. sed -i 1i”tinker panic 0″ /etc/ntp.conf
  4. sed -i “s/^server\t127.127.1.0/#server\t127.127.1.0/g” /etc/ntp.conf
  5. sed -i “s/^fudge\t127.127.1.0/#fudge\t127.127.1.0/g” /etc/ntp.conf
  6. service ntpd start

The “tinker panic 0” is the most important part. Now when my VMware Fusion wakes and the CentOS guest powers on, NTP gets everything setup correctly.

Powershell script to install Cygwin

I like having Cygwin installed on my machine, and since I always re-image, I needed a script to install Cygwin automatically.

function Install-Cygwin {
   param ( $TempCygDir="$env:temp\cygInstall" )
   if(!(Test-Path -Path $TempCygDir -PathType Container))
       $null = New-Item -Type Directory -Path $TempCygDir -Force
   $client = new-object System.Net.WebClient
   $client.DownloadFile("", "$TempCygDir\setup.exe" )
   Start-Process -wait -FilePath "$TempCygDir\setup.exe" -ArgumentList "-q -n -l $TempCygDir -s -R c:\Cygwin"
   Start-Process -wait -FilePath "$TempCygDir\setup.exe" -ArgumentList "-q -n -l $TempCygDir -s -R c:\Cygwin -P openssh"

This will download and install Cygwin and install the openssh package.

OpenVPN on windows with a TUN device

Since my laptop hard drive  died, I did not have access to my home VPN. I needed to set up OpenVPN on windows. I setup my PKI and installed the portable version of OpenVPN. Tried connecting and got this error:

There is a problem in your selection of –ifconfig endpoints [local=X.X.X.X, remote=X.X.X.X]. The local and remote VPN endpoints cannot use the first or last address within a given subnet.

The fix? Add the following to your server config:

topology subnet

Running a BASH script when my Laptop is opened at home – Part 1

My laptop hard drive died. I was upset only because there was data on my laptop that had not been moved over to my desktop. My desktop has time machine and is rsynced to several other drives and locations.

So I lost data. My own fault because I was not diligent in moving data off my laptop.

To make sure this did not happen again, I needed the ability to run a script when I open my laptop at home. But how?

  • First, I thought about identifying being at home by my wireless SSID. That was okay, but what if I was connected by wire?
  • Second, I thought about identifying home based on my subnet. Well, I could find myself on a network with the same range, and that could be bad.
  • Then I found this link that showed some code on how to get the MAC address of the defined Default Gateway. Perfect.

MAC addresses should be unique. Therefore the BASH script should only run when I am on my home network.

Here is the BASH script to find the Default Gateway’s MAC address

GATEWAY=`netstat -rn | grep default | cut -c20-35`
MACADDRESS=`arp -n $GATEWAY | cut -f4 -d' '`

Next step is to use this code when I open my Laptop lid.

Powered by WordPress. Designed by WooThemes