Blah, etc. Blah

Thursday Jul 05, 2007

I wrote a script in attempt to help me learn a little bit about zfs.

Since I don't have an array with a lot of disks, this script uses the poor-man's technique of using files instead of disks.  It works the same way as disks would work.  We can think of it as using zfs in slow-motion.  :-)

Please comment and modify the script to facilitate learning zfs.  Please let me know if it was helpful to you.

Here's the script: zpool-spare-demo

 

Sunday Feb 25, 2007

Update: The latest version is here.

I was reading some Sun blogs tonight and found the other Jonathan's blog which reminded me of a script I wrote a long time ago.  This script does basically the same thing, but has a nice mnemonic name and does a little input checking for my own sanity.  Also, I must confess to a little bit of cleanup in the code since I'll be laying it out here on the web.

I hope this is useful to you. 

#!/bin/ksh

########################################################################################
#
# Program : mntiso
#
# Purpose : Mount an ISO image so we don't need to burn a CD or DVD to view the content.
#
# Author : Dale Sears
#
# Version : 0 (Initial Version)
#
# Notes : I think this script could use a few more features. Here are some ideas
# that I didn't bother to implement:
#
# It's rather root-centric in the defaults... There *are* other users, and
# maybe they don't have root access to mkdir /iso
#
# What if I wanted /iso/image1.iso AND /iso/image2.iso mounted at the same time
# for diffs or some other purpose? I could mount things like so:
#
# ~/iso/image1.iso/
# ~/iso/image2.iso/
#
# Check for spaces in filename? It could happen, and it would break
# my lame script.
#
# Use getopts:
#
# -f Force the mount by unmounting what is mounted on MOUNTPOINT.
# -h Usage.
# -? Usage.
# -m Set the mount point different from the default.
#
# I probably could have implemented a few of these instead of writing
# all of this...
#
#######################################################################################


MOUNTPOINT=/iso

usage() {
echo
echo "Usage: "
echo " $0 /the/fully/qualified/path.iso"
echo
}


######################################################################
# How many args?
######################################################################
if [ $# -ne 1 ]
then
usage; exit 1
fi


######################################################################
# Check for leading / on the ISO arg (needed by lofiadm):
######################################################################
case "$1" in

/* ) ISO="$1"
break
;;

* ) usage
exit 1
;;
esac


######################################################################
# Remove possibly existing lofi device for the given ISO:
######################################################################
/usr/sbin/lofiadm -d "$ISO" 2> /dev/null


######################################################################
# Add lofi device for the ISO:
######################################################################
LOFIDEVICE=`/usr/sbin/lofiadm -a "$ISO" 2> /dev/null`

if [ -z "$LOFIDEVICE" ]
then
echo
echo 'Uh, oh... : No lofi Device.'
echo
echo "Perhaps $ISO is already mounted?"
echo
echo "To unmount and try again, use this:"
echo
echo " umount $MOUNTPOINT; $0 $ISO"
echo
exit 2
fi


######################################################################
# Check for $MOUNTPOINT and create as needed:
######################################################################
if [ ! -d "$MOUNTPOINT" ]
then
/bin/mkdir -m 555 "$MOUNTPOINT"
fi


######################################################################
# We've passed enough tests, let's try to mount the ISO and 'mount'
# will complain if $MOUNTPOINT is a file or is busy:
######################################################################
/sbin/mount -F hsfs -o ro $LOFIDEVICE $MOUNTPOINT

Thursday Sep 21, 2006

I was recently at a customer site trying to determine why a Sun Fire v880 server would not consistently establish a link with the network equipment on the other end of a 1-Gig fiber.

I tried to configure ce.conf to force the link to 1-Gig instead of allowing it to auto-negotiate.  It might be that I was too lame to understand the examples in the ce.conf man pages, or maybe the man pages need a little help there.

Anyway, I ended up modifying a custom init script which the customer had written to tweak the /dev/ce driver at boot time.  They had the right idea, which was to force the link to a certain speed, but the problem was that they had multiple instances of this 1-Gig fiber card.  Our customer had mistakenly thought that if they did the following commands, they would operate on *all* instances of the /dev/ce type:

    ndd -set /dev/ce adv_autoneg_cap 0
ndd -set /dev/ce adv_1000fdx_cap 1

This situation seems perfectly reasonable to me since the interface names are 'ce0' and 'ce1' and we wanted to modify all of the interfaces, so we operate on /dev/ce driver with ndd and "It should just work!"  But things are not always so intuitive in UNIX.  I think this is what might be called a "modal interface with no visual feedback" and it defies all forms of intuition.  It's my opinion that when using ndd to operate on any driver and there exists more than one instance, ndd should emit a message to STDERR with a warning that multiple instances exist and it should also inform the user about which instance will receive the given changes.  Of course, ndd should have an option to make it suppress said messages...

OK, where was I...  Oh yeah, for a while, I also thought like the customer that using ndd on /dev/ce would operate on all of the ce* interfaces until it hit me like a brick that I needed to add a little tweak to their init script to make ndd operate on each instance like so:

    ndd -set /dev/ce instance 0          <---- added

    ndd -set /dev/ce adv_autoneg_cap 0 <---- original
    ndd -set /dev/ce adv_1000fdx_cap 1 <---- original

    ndd -set /dev/ce instance 1          <---- added
    ndd -set /dev/ce adv_autoneg_cap 0 <---- added
    ndd -set /dev/ce adv_1000fdx_cap 1 <---- added

They were so close!

It's easy to understand once you see the solution, but we needed to set the 'instance' parameter of the /dev/ce driver to "point to" a certain instance of the driver and then make the necessary changes.  So, ndd will only operate on the default instance (instance 0) without explicitly setting the 'instance' parameter.

I hope that was interesting and helpful enough to keep you from falling into the same little trap.