Archive for October, 2008

Virtual Serial Ports Under VMware

VMware has an option to create virtual serial ports. The “Named Pipe” used under Linux is actually a UNIX domain socket, which is not easily accessed by most tools. My goal was to be able to connect to the virtual serial port using minicom the same way I would connect to a physical device with a real serial port.

The solution is to use socat along with Unix98 pseudo-terminals (/dev/pts/*).

I set up the Virtual Machine to “Use named pipe”, “This end is the client”, “The other end is an application”, and “Yield CPU on poll”. I put the pipe in /export/vmware/DUT.serial0.

At host startup I run the following socat command using start-stop-daemon:

# start-stop-daemon --start --pidfile /var/run/socat.DUT.pid \
    --background --make-pidfile \
    --exec /usr/bin/socat -- \
    -ly -d -lpsocat:DUT \
    PTY,b115200,raw,link=/dev/ttyDUTSerial0,group=uucp,mode=660 \
    UNIX-LISTEN:/export/vmware/DUT.serial0,fork,owner=frank,group=frank,mode=755

DUT is a placeholder for the virtual machine’s name.

I can then make a minicom config using /dev/ttyDUTSerial0 for the serial port and work as usual.

The above is actually wrapped up in some Gentoo init scripts.
Read the rest of this entry »

Finding Average File Size with Perl

I was creating a new filesystem on a NetBSD box today, and wondered about the appropriate value for the “average file size” parameter. The first question I had was “what is the average filesize in my data set”, which I figured I could answer, since I had some representative data handy. I put together a quick one-liner to answer this question:

find /export -type f -print | perl -ne 'chomp; $count++; $total += (stat())[7]; END { print "$count files $total bytes total ", $total/$count, " byte average\n"; }

After running this, I was surprised at just how large the “average” size was, which led me to wonder just which average they were looking for here: mean or median? While I was at it, I decided to calculate the mode as well.

Read the rest of this entry »