#!/bin/sh
#
# Written by Xueshan Feng <sfeng@stanford.edu>
# Copyright 2012 Board of Trustees, Leland Stanford Jr. University
#
 
root_dev=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/mtab)
root_dev=$(echo ${root_dev} | sed -e 's/[0-9]$//')
/lib/udev/scsi_id --page=0x83 --whitelisted --device=${root_dev}

exit 0

# Documentation.  Use a hack to hide this from the shell.  Because of the
# above exit line, this should never be executed.
DOCS=<<__END_OF_DOCS__

=for stopwords
Xueshan Feng WWID WWN blacklist multipath multipath's
multipath-local-root-wwn

=head1 NAME

multipath-local-root-wwn - Find the WWID of the local root disk

=head1 SYNOPSIS

B<multipath-local-root-wwn>

=head1 DESCRIPTION

Run this script on a server that has multipath installed to determine the
WWID of the local root disk.  The WWID should be added to the blacklist
setting in F</etc/multipath.conf> to exclude it from multipath's control.

This script reads F</etc/mtab>, the mounted file systems file, and finds
the device name of the line associated with the root file system.  This
will be the line with a / as the second token.  Then, B<scsi_id> is used
to extract the WWN for the device.

The script is safe to run since it doesn't alter any files.

=head1 EXAMPLE

    % multipath-local-root-wwn 
    3600508e0000000009f0e8f3f5b4e9000

could result in a blacklist section in the F<multipath.conf> file of:

   blacklist {
      devnode "^(ram|raw|loop|fd|md|dm-|sr|scd|st)[0-9]*"
      devnode "^hd[a-z]"
      devnode "^cciss.*"
      wwid "3600508e0000000009f0e8f3f5b4e9000"
   }

Note, blacklists with C<devnode "^sda[0-9]*"> are not reliable, and 
should not be used in the F<multipath.conf> file.
 
=head1 AUTHOR

Xueshan Feng <sfeng@stanford.edu>

=cut

__END_OF_DOCS__
