SUMMARY: mapping prtconf info to disk names?

From: David Harnick-Shapiro (davidhs@intelenet.net)
Date: Mon Dec 18 2000 - 15:38:05 CST


For my purposes, the two best approaches were the 'plfs' script and
combining/comparing the various outputs of 'iostat'. Thanks for the
info and suggestions, everyone!

David Harnick-Shapiro

My original query:

> Is there any reliable way to map the output of 'prtconf' to the names
> of disks?
>
> For example, if I start with
>
> # prtconf | grep -v 'driver not attached'
> ...
> espdma, instance #0
> esp, instance #0
> sd, instance #0
> sd, instance #1
> sd, instance #2
> sd, instance #6
> st, instance #4
> SUNW,hme, instance #0
> SUNW,fas, instance #0
> sd, instance #31
> sd, instance #33
> sd, instance #34
> SUNW,hme, instance #1
> SUNW,fas, instance #1
> sd, instance #7
> sd, instance #8
>
> Under the "esp, instance #0", things are easy: they're just
> "c0t0d0", "c0t1d0", "c0t2d0" and so on. However, fas0/sd31
> is c1t1d0, and fas1/sd8 is c2t1d0.
>
> Can I rely on controller number (c0, c1, c2) increasing in
> the order of prtconf's output? Is there any way to derive
> the target number (tX) from the sd instance? Or is there
> some other tool I should use, to inventory disks on a system?
> (I want to be sure I catch wasted disk space and slices that
> are dedicated to database raw partitions, not just current
> Unix filesystems and swap areas.)
>
> Please reply directly to me; I will happily summarise to the
> list; thanks in advance for any suggestions!

And here are the replies (redundant copies of my message have
been removed for conciseness):

------- Forwarded Messages

Date: Thu, 14 Dec 2000 16:50:15 -0500
From: Andrew J Caines <AJCaines@borg.uunt.net>
Subject: Re: mapping prtconf info to disk names?

David,

> Or is there some other tool I should use, to inventory disks on a system?
> (I want to be sure I catch wasted disk space and slices that
> are dedicated to database raw partitions, not just current
> Unix filesystems and swap areas.)

Sure is - plfs. Attached.

- -Andrew-
- --
 _______________________________________________________________________
| -Andrew J. Caines- Unix Systems Engineer AJCaines@borg.uunt.net |
| --==<O> UUNET Enterprise Web Hosting - UNIX Ops Group <0>==-- |
| Desk: 703-758-6628 Mobile: 703-675-1561 Page: AJCaines-pager@uu.net |

- --cmJC7u66zC7hs+87
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: attachment; filename="plfs"
Content-Transfer-Encoding: 8bit

#! /usr/bin/env perl
#
# plfs.pl,v 1.13.2.4 1999/10/05 07:28:07 marchand Exp
#
# This file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This file is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with it; see the file COPYING. If not, write to the Free
# Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.
#

use Sys::Hostname;
use Getopt::Long;

my $host=hostname;
my $timestr=localtime;

$dfcmd="/usr/bin/df -kFufs";
$metastatcmd="";
$metadbcmd="";
$formatinitcom="0\nq\n";
$formatinitcmd="echo \"$formatinitcom\" | /usr/sbin/format";
$formatcom="p\np\nq\nq\n";
$formatcmd="echo \"$formatcom\" | /usr/sbin/format -d";
$swapcmd="/usr/sbin/swap -l";
$disksuite=0;

########################################################################
# YOU SHOULD NOT HAVE TO CHANGE ANYTHING BELOW THIS LINE
#
# plfs.pl,v
# Revision 1.13.2.4 1999/10/05 07:28:07 marchand
#
# - file systems are sorted according to vfstab order
# - disks are sorted according to format output order
# - fixed bug when using -f option without SDS
#
# Revision 1.13.2.3 1999/08/02 16:35:02 marchand
#
# - fixed bug of --disk option
# - fixed bug of --metadevice option
#
# Revision 1.13.2.2 1999/08/02 12:04:01 marchand
#
# - warning when normal swap fs are used while using SDS
#
# Revision 1.13.2.1 1999/07/30 14:04:35 marchand
#
# - fixed bug when a single stripe is divided in several slices
#
# Revision 1.13 1999/07/29 08:35:47 marchand
#
# - names added when listing disks
#
# Revision 1.12 1999/07/27 17:36:10 marchand
#
# - message improved for non-ok meta-devices
#
# Revision 1.11 1999/07/27 16:15:51 marchand
#
# - --warnings (-w) option added
#
# Revision 1.10 1999/07/19 17:35:34 marchand
#
# - warning if a mirrored fs has only one (or zero) submirror.
# - warning if normal filesystems are found while disksuite is used
#
# Revision 1.9 1999/07/19 11:41:53 algarott
# (Re)Added short options
#
# Revision 1.8 1999/07/15 16:58:07 marchand
#
# - summary added
#
# Revision 1.7 1999/07/13 15:11:58 marchand
#
# - allow use without disksuite
#
# Revision 1.6 1999/07/08 15:21:26 marchand
#
# - correction of fslist when --metadevice option is used
#
# Revision 1.5 1999/07/08 14:45:20 marchand
#
# - Use of long options
# - options --list* added
#
# Revision 1.4 1999/07/05 16:23:23 marchand
#
# - error messages modified
#
# Revision 1.3 1999/07/02 16:06:25 marchand
#
# - options -d, -f and -m added
# - version number appears in header
#
# Revision 1.2 1999/06/28 15:22:12 marchand
#
# - check host system type (Solaris 2.5 or newer required)
#
# Revision 1.1 1999/06/25 13:39:29 marchand
# - replace former plfs for distribution purposes
#
# Revision 1.1.1.1 1999/06/24 12:42:19 marchand
# import version initiale
#
#
$version="1.1.patch4";

my $usage="
usage : $0 [options]

List of available options (abbreviations are allowed if not ambiguous):

- -k --disk=disk1 : print only informations about disk1
- -f --file-system=fs1 : print only informations about filesystem fs1
- -m --metadevice=md1 : print only informations about metadevice md1

Only one of these three options is allowed, but it can appear several times
e.g. $0 --disk=0 --disk=1

- -K --list-disk : print the list of disks
- -M --list-metadevice : print the list of metadvices
- -F --list-file-system : print the list of local file-systems
- -h, --help : print this message and exit
- -V, --version : print version number and exit
- -w, --warnings : just print warnings about metadevices or file-systems
                     needing attention
";

my $susage="
- -D, --debug : print additionnal information for debugging purposes
- -H, --hidden-help : print this message and exit
- -T, --try : do not really run format command, use content of
                    files formatinit, format<diskname> instead.
                    This is intended to allow tests without running as
                    root
";

# parsing switches

Getopt::Long::config("auto_abbrev","bundling");
#getopts('d:Df:hHm:TV',\%opts) || die "$usage";
GetOptions(
"k=i" => \@dskl,
"disk=i" => \@dskl,
"D" => \$debug,
"debug" => \$debug,
"K" => \$ldisk,
"list-disk" => \$ldisk,
"F" => \$lfs,
"list-file-system" => \$lfs,
"M" => \$lmd,
"list-metadevice" => \$lmd,
"f=s" => \@fs,
"file-system=s" => \@fs,
"h" => \$help,
"help" => \$help,
"H" => \$Hhelp,
"hidden-help" => \$Hhelp,
"m=s" => \@mdl,
"metadevice=s" => \@mdl,
"T" => \$try,
"try" => \$try,
"V" => \$vers,
"version" => \$vers,
"w" => \$warnings,
"warnings" => \$warnings) || die "$usage\n";

if ($#ARGV >= 0 || $help)
  {
    print STDERR "$usage";
    exit 0;
  }

if ($Hhelp)
  {
    print STDERR "$susage";
    exit 0;
  }

if ($vers)
  {
    print "plfs version $version\n";
    exit 0;
  }

if (($#dskl >= 0 && ($#mdl >= 0 || $#fs >= 0)) || ($#mdl >= 0 && $#fs >= 0))
  {
    die "Only one of the following options is accepted : --disk, --file-system
or --metadevice\n";
  }

die "Not Super-User\n" if ($> != 0 && ! $try);

# printing header

print " ----------------------------------------------------------------\n";
print " plfs-$version\t$host\t$timestr\n";
print " ----------------------------------------------------------------\n";

# subs

sub splitdf
  {
    my $warned=0;
    my $number=1;

    open(DF,"$dfcmd |") || die "Cannot fork to df : $!";
    while (<DF>)
      {
        @line =split(" ");
        if ( $disksuite ) {
          if ( $line[0] =~ m/^\/dev\// )
            {
              if ($line[0] =~ m/dev/dsk && ! $warned) {
                warn "\aCAUTION : although you are using disksuite, normal file
 systems have been found.\nThis can lead to false results.\n";
                $warned=1;
              }
              my $fs = $line[5];
              
              $numfs{$fs}=$number++;
              print "$fs $numfs{$fs}\n" if ($debug);
              $mdfs{$fs}=$line[0];
              $mdfs{$fs}=~ s/dev/md/dsk/;
              $fullmd{$mdfs{$fs}}=$line[0];
              
              $size{$fs}=$line[1];
              $used{$fs}=$line[4];
            }
        }
        else {
          if ( $line[0] =~ m/^\/dev\// )
            {
              my $fs = $line[5];
              
              $numfs{$fs}=$number++;
              $diskfs{$fs}=$line[0];
              $diskfs{$fs}=~ s/dev/dsk/;
              $fulldisk{$diskfs{$fs}}=$line[0];
              
              $size{$fs}=$line[1];
              $used{$fs}=$line[4];
              $mountdir{$diskfs{$fs}}=$fs;
            }
        }
      }
    close DF || die $! ? "Error closing df pipe : $!"
                           : "Error running df : exit status $?";
  }

sub splitswap
  {
    open(SWAP,"$swapcmd |") || die "Cannot fork to swap : $!";
    while (<SWAP>)
      {
        @line =split(" ");
        if ( $disksuite ) {
          if ($line[0] =~ m/dev/dsk && ! $warned) {
            warn "\aCAUTION : although you are using disksuite, normal swap fil
e systems have been found.\nThis can lead to false results.\n";
            $warned=1;
          }

          if ( $line[0] =~ m^/dev/md/dsk/(d[0-9]+) )
            {
              my $md = $+;
              if ( $#$md >= 0 )
                {
                  foreach my $submir (@$md)
                    {
                      foreach my $stripe (0..$#{$slice{$submir}})
                        {
                          $debug && print "$stripe\n";
                          foreach my $slc (@{$slice{$submir}[$stripe]}) {
                            $mountdir{$slc}="Swap";
                          }
                        }
                    }
                }
              else
                {
                  foreach my $stripe (0..$#{$slice{$md}})
                    {
                      foreach my $slc (@{$slice{$md}[$stripe]}) {
                        $mountdir{$slc}="Swap";
                      }
                    }
                }
            }
        }
        else {
          if ( $line[0] =~ m^/dev/dsk/(c\d+t\d+d\d+s\d+) )
            {
              my $dev = $+;
              $mountdir{$dev}="Swap";
            }
        }
      }
    close SWAP || die $! ? "Error closing swap pipe : $!"
                           : "Error running swap : exit status $?";
  }

sub splitmeta
  {
    my $md;
    open(META,"$metastatcmd |") || die "Cannot fork to metastat : $!";
      while (<DEFANGED_META>)
        {
          @line=split(" ");
          next unless ($#line >= 0);

          if ( $line[0] =~ m/^(d[0-9]+):$/ )
            {
              $submir=$+;
              if ( $line[1] !~ m/^Submirror$/ )
                {
                  $md = $submir;
                  $typemd{$md}=$line[1];
                }
              else
                {
                  ( "$line[3]" eq "$md" ) || warn "submirror $submir of metadev
ice $line[3] out of order";
                  push (@$md, $submir);
                  $mainmd{$submir}=$md;
                }
            }
          elsif ( "$line[0]" eq "State:")
            {
              shift @line;
              $statemd{$submir}="@line";
              warn "Metadevice $submir : $statemd{$submir}\n" unless ($line[0]
eq "Okay") || ("$md" eq "$submir") ;
            }
          elsif ( "$line[0]" eq "Size:")
            {
              $sizemd{$submir}=$line[1];
            }
          elsif ( $line[0] =~ m/^c[0-9]+t[0-9]+d[0-9]+s[0-9]+$/)
            {
              push ( @{$slice{$submir}[$stripe]}, $line[0]);
            }
          elsif ( "$line[0]" eq "Stripe" )
            {
              $stripe=$line[1];
              $stripe =~ s/:$//;
            }
            
        }
    close META || die $! ? "Error closing metastat pipe : $!"
                           : "Error running metastat : exit status $?";

    foreach my $fs (keys %mdfs)
      {
        $md=$mdfs{$fs};
        $typefs{$fs}=$typemd{$md};
        if ( $#$md >= 0 )
          {
            if ($#$md == 0) {
              warn "\aWarning : filesystem $fs has only 1 submirror\n";
            }
            foreach my $submir (@$md)
              {
                foreach my $stripe (0..$#{$slice{$submir}})
                  {
                    foreach my $slc (@{$slice{$submir}[$stripe]}) {
                      $mountdir{$slc}=$fs;
                    }
                  }
              }
          }
        else
          {
            if ($typemd{$md} eq "Mirror") {
              warn "\aWarning : filsystem $fs has type Mirror and no submirror\
n";
            }
              
            $debug && print "$md : $#{$slice{$md}} + 1 slices\n";
            foreach my $stripe (0..$#{$slice{$md}})
              {
                foreach my $slc (@{$slice{$md}[$stripe]}) {
                  $debug && print " $slc\n";
                  $mountdir{$slc}=$fs;
                }
              }
          }
      }
                              
  }

sub splitformat
  {
    my $compteur=0;

    foreach my $sd ( keys %diskhash)
      {
        $dev=$diskhash{$sd};
        if ($try)
          {
            $opencmd="< resformat$dev";
          }
        else
          {
            $opencmd="$formatcmd $dev |";
          }
        open (FORM, $opencmd) || die "Cannot fork to format : $!";
        while (<FORM>)
          {
            my @line=split(" ");
            if ( ($#line == 8 || $#line == 6) && $line[0] =~ m/^[0-7]$/ )
              {
                my $device="${dev}s$line[0]";
                $diskphy{$device}=$sd;
                $part{$device}=$line[0];
                $tag{$device}=$line[1];
                $flag{$device}=$line[2];
                if ($#line == 8)
                  {
                    $cyl{$device}="$line[3] $line[4] $line[5]";
                    $size{$device}=$line[6];
                    $blocks{$device}="$line[7] $line[8]";
                  }
                else
                  {
                    $cyl{$device}=$line[3];
                    $size{$device}=$line[4];
                    $blocks{$device}="$line[5] $line[6]";
                  }
                if ( ! $mountdir{$device})
                  {
                    if ( $part{$device} == 2 )
                      {
                        $mountdir{$device}="N/A backup";
                      }
                    elsif ("$size{$device}" eq "0")
                      {
                        $mountdir{$device}="Null";
                      }
                    else
                      {
                        $mountdir{$device}="** FREE **";
                      }
                  }
              }
          }
        close FORM || die $! ? "Error closing format pipe : $!"
                           : "Error running format : exit status $?";
      }
  }

sub splitformatinit
  {
    if ($try)
      {
        $opencmd="< resformatinit";
      }
    else
      {
        $opencmd="$formatinitcmd |";
      }
    my $number=1;
    open (FORMAT, $opencmd) || die "Cannot fork to format";
    while (<FORMAT>)
      {
        my @line = split " ";
        
        next if ($#line < 0);
        if ($line[0] =~ m/^([0-9]+)\.$/)
          {
            $numdisk{$+}=$number++;
            if ( $disksuite ) {
              ($diskhash{$+}=$line[1]) =~ s,/dev/rdsk/(c\d+t\d+d\d+)s\d+,$1, ;
            }
            else {
              $diskhash{$+}=$line[1];
            }
          }
      }
    close FORMAT || die $! ? "Error closing format pipe : $!"
                           : "Error running format : exit status $?";
  }

sub splitmetadb
  {
    open (MDB, "$metadbcmd |") || die "Cannot fork to metadb";
    while (<MDB>)
      {
        my @line = split(" ");
        
        if ($line[$#line] =~ m^/dev/dsk/(c\d+t\d+d\d+s\d+))
          { $mountdir{$+}="MetaDB"; }
      }
    close MDB || die $! ? "Error closing metadb pipe : $!"
                           : "Error running metadb : exit status $?";
  }

sub plfs
  {
    my $fspointer=shift;
    return if ($#$fspointer < 0);

    print "--------------\n";
    print "file systems :\n";
    print "--------------\n";

    foreach my $fs (sort {$numfs{$a} <=> $numfs{$b}} @$fspointer)
      {
        if ( $disksuite ) {
          my $md=$mdfs{$fs};
          printf "\n\n** file system %-10s %-20s %-16s %-6s (%3s)\n", $fs, $typ
efs{$fs}, $fullmd{$md}, $size{$fs}, $used{$fs};
          if ( $#$md >= 0 )
            {
              foreach my $submir (@$md)
                {
                  printf"\n %4s: Submirror of %-3s State : %-10s Size : %10d
blocks\n", $submir, $md, $statemd{$submir}, $sizemd{$submir};
                  foreach my $stripe (0..$#{$slice{$submir}})
                    {
                      foreach my $slc (@{$slice{$submir}[$stripe]}) {
                        printf " Stripe %2d: %-10s (disk %2d)\n", $stripe,
 $slc, $diskphy{$slc};
                      }
                    }
                }
            }
          else
            {
              printf "\n %4s: Size: %10d blocks\n", $md, $sizemd{$md};
              foreach my $stripe (0..$#{$slice{$md}})
                {
                  foreach my $slc (@{$slice{$md}[$stripe]}) {
                    printf " Stripe %2d: %-10s (disk %2d)\n", $stripe, $sl
c, $diskphy{$slc};
                  }
                }
            }
        }
        else {
          my $dsk=$diskfs{$fs};
          printf "\n** file system %-10s %-20s %-6s (%3s)\n", $fs, $fulldisk{$d
sk}, $size{$fs}, $used{$fs};
        }
      }
    print "\n\n\n";
  }

sub pldisks
  {
    my $diskpointer=shift;
    return if ($#$diskpointer < 0);

    print "-------\n";
    print "disks :\n";
    print "-------\n";

    $sizefreecyls=0;
    foreach my $sd (sort {$numdisk{$a} <=> $numdisk{$b}} @$diskpointer)
      {
        print "\ndisk $sd:\n";
        print "\nPart Tag Flag Cylinders Size Mount Dir
ectory Partition\n";
        
        $dev=$diskhash{$sd};

        my $partition=0;
        while ($partition < 8)
          {
            my $device="${dev}s$partition";
            printf "%3d %10s %4s %16s %10s %20s %10s\n",$partition++, $tag{$dev
ice}, $flag{$device}, $cyl{$device}, $size{$device}, $mountdir{$device}, $devic
e;
          }

        print "\n";
# looking for unassigned cylinders
        my ($firstcyl, $aux, $lastcyl) = split (" ", $cyl{"${dev}s2"});
        my $factor=(&mbsize($size{"${dev}s2"})/($lastcyl-$firstcyl+1));
        $partition=-1;
        $nextcyl=$firstcyl;
        while (++$partition < 8)
          {
            if ($partition == 2) { $cylpart[$partition]=[0,0]; next }
            $device="${dev}s$partition";
            @aux=split (" ", $cyl{$device});
            if ($#aux < 2) {$cylpart[$partition]=[0,0]; next}
            $cylpart[$partition]=[$aux[0],$aux[2]];
          }
         @sortedpart = @cylpart[sort { $cylpart[$a][0] <=> $cylpart[$b][0]} 0..$
#cylpart];
         $partition=-1;
         while (++$partition < 8)
           {
             next unless ($sortedpart[$partition][1] > 0);
             if ( $nextcyl > $sortedpart[$partition][0] )
               {
                if ($nextcyl <= $sortedpart[$partition][1] )
                  {
                    $c=$nextcyl-1
                  }
                else
                  {
                    $c=$sortedpart[$partition][1];
                  }
                 printf " OVERLAY from cylinder %d to cylinder %d\n",$sortedpart
[$partition][0],$c ;
               }
             elsif( $nextcyl < $sortedpart[$partition][0] )
               {
                my $free=($sortedpart[$partition][0]-$nextcyl)*$factor;
                $sizefreecyls += $free;
                my $unit;
                if ($free >= 1024)
                  {
                    $free /= 1024;
                    $unit = "GB";
                  }
                else
                  {
                    $unit = "MB";
                  }
                 printf " UNASSIGNED cylinders from %4d to %4d : %4.2f %s free\n
",$nextcyl,$sortedpart[$partition][0]-1, $free, $unit;
               }
             $nextcyl=$sortedpart[$partition][1]+1 if ($nextcyl <= $sortedpart[$
partition][1]);
           }
        if ( $nextcyl <= $lastcyl)
          {
            my $free=($lastcyl-$nextcyl+1)*$factor;
            $sizefreecyls += $free;
            my $unit;
            if ($free >= 1024)
              {
                $free /= 1024;
                $unit = "GB";
              }
            else
              {
                $unit = "MB";
              }
            printf " UNASSIGNED cylinders from %4d to %4d : %4.2f %s free\n",$n
extcyl,$lastcyl, $free, $unit;
          }
      }
    my $unit;
    if ($sizefreecyls >= 1024)
      {
        $sizefreecyls /= 1024;
        $cunit = "GB";
      }
    else
      {
        $cunit="MB";
      }
    print "\n\n\n";
  }

sub plfpart
  {
    print "-----------------\n";
    print "free partitions :\n";
    print "-----------------\n";

    $freepsum=0;

    foreach my $sd (keys %diskhash)
      {
        my $dev=$diskhash{$sd};
        $free="no";
        my $partition = 0;
        while ( $partition < 8)
          {
            my $device="${dev}s$partition";

            my $mount=$mountdir{$device};

            if ("$mount" eq "** FREE **")
              {
                if ( "$free" eq "no")
                  {
                    print "\ndisk $sd :\n\n";
                    $free = "yes";
                  }
                printf " %3d %10s %4s %16s %10s %20s\n", $partition, $tag{$devi
ce}, $flag{$device}, $cyl{$device}, $size{$device}, $blocks{$device};

                $freepsum += &mbsize($size{$device});
              }
            $partition++;
          }
      }

    if ( $freepsum >= 1024)
      {
        $freepsum /= 1024;
        $punit="GB";
      }
    else
      {
        $punit="MB";
      }
    print "\n\n\n";
  }

sub plsummary
  {
    print "---------\n";
    print "summary :\n";
    print "---------\n\n\n";

    printf " Total size of unassigned cylinders on all disks : %.2f $cunit\n",
$sizefreecyls;
    printf " Total free space in unassigned partitions : %.2f $punit\n", $freep
sum;
    printf " Total number of disks : %2d\n", $#disklist+1;
    printf " Total number of local file-systems : %3d\n", $#fslist+1;
    $nbmirfs=0;
     if ($disksuite) {
       foreach my $fs (@fslist) {
          if ($typefs{$fs} =~ m/^Mirror$/) {
           $nbmirfs += 1;
         }
      }
     }

    printf " Total number of mirrored file-systems : %2d\n",$nbmirfs;
    print "\n\n\n";
  }

sub mbsize
  {
    my $size=shift;
    if ( $size =~ m/^([0-9.]*)MB$/)
      {
        $mbsize = $+;
      }
    elsif ( $size =~ m/^([0-9.]*)GB$/)
      {
        $mbsize = $+ * 1024 ;
      }
    return $mbsize;
  }

sub unique
  {
    my @array=@_;
    
    my $i=-1;

    while (++$i <= $#array)
      {
        $j=$i;
        while (++$j <= $#array)
          {
            splice (@array, $j, 1) if ( $array[$i] eq $array[$j]);
          }
      }
    return @array;
  }

sub selectdev
  {
    if ( $#fs >= 0 )
      {
        foreach my $fs (@fs)
          {
            $fs="/$fs" unless ($fs =~ m,^/,);
            die "file system $fs not found by df\n" unless (exists $mdfs{$fs} |
| exists $diskfs{$fs});
            push (@fslist, $fs);
          }
        foreach my $sd (keys %diskhash)
          {
            foreach my $partition (0..7)
              {
                my $trouve=0;
                foreach my $fs (@fslist)
                  {
                    if ($mountdir{"$diskhash{$sd}s$partition"} eq $fs)
                      {
                        push (@disklist, $sd);
                        $trouve=1;
                        last;
                      }
                  }
                last if $trouve;
              }
          }
      }
    elsif ($#dskl >= 0)
      {
        foreach my $dsk ( @dskl )
          {
            die "disk $dsk not found.\n Please run format to see the list of di
sks.\n" unless exists $diskhash{$dsk};
            foreach my $partition (0..7)
              {
                $_ = $mountdir{"$diskhash{$dsk}s$partition"};
                if ( m^/)
                  {
                    push (@fslist,$_);
                  }
              }
            push (@disklist, $dsk);
          }
      }
    elsif ($#mdl >= 0)
      {
        foreach my $md (@mdl)
          {
            $debug && print "metadevice $md : $#{$md} + 1 submirs\n";
            die "meta-device $md not found by metastat\n" unless exists $sizemd
{$md};
            if ( $#$md >= 0 )
              {
                # md is a mirrored metadevice. let us consider each submirror
                foreach my $submir (@$md)
                  {
                    foreach my $slice (0..$#{$slice{$submir}})
                      {
                        foreach my $slc (@{$slice{$submir}[$stripe]}) {
                          push (@fslist, $mountdir{$slc}) if exists $mdfs{$moun
tdir{$slc}};
                          push (@disklist, $diskphy{$slc});
                        }
                      }
                  }
              }
            elsif (exists $mainmd{$md})
              # md is a submirror, we shall examine the whole mirror
              {
                $debug && print "submirror of $mainmd{$md}\n";
                $md=$mainmd{$md};
                redo;
              }
            else
              # md is not a mirrored meta-device
              {
                foreach my $stripe (0..$#{$slice{$md}})
                  {
                    foreach my $slc (@{$slice{$md}[$stripe]}) {
                      push (@fslist, $mountdir{$slc}) if ($mountdir{$slc} =~ m^
/);
                      push (@disklist, $diskphy{$slc});
                    }
                  }
              }
          }
      }
    else
      {
        if ( $disksuite ) { @fslist=keys %mdfs }
        else { @fslist = keys %diskfs }
        @disklist=keys %diskhash;
      }
    
    @fslist = &unique(@fslist);
    @disklist = &unique(@disklist);
  }
#
# main
#

# look for local filesystems
&splitdf;
if ( $lfs ) { @fslist=sort {$numfs{$a} <=> $numfs{$b}} keys %numfs; $"="\n"; pr
int "\nlist of local file-systems:\n\n@fslist\n"; exit 0 }
# look for disks
&splitformatinit;
if ( $ldisk ) {
  print "\n list of disks:\n\n";
  foreach my $disk (sort {$numdisk{$a} <=> $numdisk{$b}} keys %diskhash) {
    print "$disk ($diskhash{$disk})\n";
  }
  exit 0;
}

if ($disksuite) {
# look for partitions associated with filesystems
  &splitmeta;
  if ( $lmd ) {
    foreach my $fs (keys %mdfs){
      my $md=$mdfs{$fs};
      push (@mdlist, $md);
      if ( $#$md >= 0 ) {
        foreach my $submir (@$md) {
          push (@mdlist, $submir);
        }
      }
    }
    @mdlist = sort @mdlist;
    $"="\n"; print "\n list of metadevices:\n\n@mdlist\n"; exit 0
  }
# look for meta data base
  &splitmetadb;
}
# look for swap space
&splitswap;
# look for partitions on each disk
&splitformat;
#
exit 0 if ($warnings);
# select devices on which informations should be printed
&selectdev;
print "@fslist\n" if ($debug);
#print per filesystem results
&plfs(\@fslist);
# print per disk results
&pldisks(\@disklist);
# list free partitions
if ( $#fs < 0 && $#dskl < 0 && $#mdl < 0) {
  &plfpart;
  &plsummary;
}

------- Message 2

Date: Thu, 14 Dec 2000 13:49:12 -0800
From: David Evans <David.J.Evans@oracle.com>
Subject: Re: mapping prtconf info to disk names?

David,

There is a reliable but not easy way. Use /etc/path_to_inst (if
you look at it you should have no problems) and compare that
against prtconf and and `ls -l /dev/dsk`. I did this a few years
and many sites ago with a perl4 script.

This should help (and brush up on your perl skills too).

David

- --
   =======================================================================
    Oracle | David.J.Evans@Oracle.com | There is magic in the web.
    Corporation | Telephone: +1-650-506-2120 | Othello Act 3 Scene 4 by
                | Facsimile: +1-650-633-0594 | William Shakespeare
   =======================================================================
        All of the statements and opinions expressed here are my own,
        and do not necessarily represent those of Oracle Corporation.

------- Message 3

Date: Thu, 14 Dec 2000 16:03:03 -0600
From: Al Hopper <al@logical-approach.com>
Subject: Re: mapping prtconf info to disk names?

On Thu, 14 Dec 2000, David Harnick-Shapiro wrote:

> Is there any reliable way to map the output of 'prtconf' to the names
> of disks?

This is something I got from a list a while back - can't remember the
original author. It's in two pieces:

prtdisks
prtdisk

Note: prtdisks simply calls prtdisk - you'll see by looking at it.
run as follows:

prtdisks

or

prtdisk /dev/dsk/c1t0d0s2 (where you can specify any slice)

Here is prtdisks:

#! /usr/bin/ksh
for j in /dev/dsk/c*t*d*s0
do
        echo $j ------- $(/usr/local/bin/prtdisk $j)
done

Here is prtdisk:

#!/bin/csh
set dev = `/bin/ls -l $1 | nawk '{ n = split($11, a, "/"); split(a[n],b,":");
for(i = 4; i < n; i++) printf("/%s",a[i]); printf("/%s\n", b[1]) }'`
if ( $dev == "" ) exit
nawk -v dev=$dev '$1 ~ dev { n = split(dev, a, "/"); split(a[n], b, "@"); print
f("%s%s\n", b[1], $2) }' /etc/path_to_inst

- ----------

Please let me know if this does the trick for you.

Regards,

Al Hopper Logical Approach Inc, Plano, TX. al@logical-approach.com
           Voice: 972.379.2133 Fax: 972.379.2134
MicroSoft "ILOVEYOU". Thanks for engineering a 100% Virus Enabled Platform!

------- Message 4

Date: Thu, 14 Dec 2000 14:05:58 -0800
From: Darren Dunham <ddunham@taos.com>
Subject: Re: mapping prtconf info to disk names?

> Can I rely on controller number (c0, c1, c2) increasing in
> the order of prtconf's output?

No, because crontrollers may be added in a different order. Each time a
new controller is seen by the hardware, it is assigned a unique number
and that number is stored in /etc/path_to_inst.

> Is there any way to derive
> the target number (tX) from the sd instance? Or is there
> some other tool I should use, to inventory disks on a system?

iostat -nx (cxtxdxsx format) compared with iostat -x (sdx format) is one
of the better ways. It doesn't work with every single drive though
(like rm6 controlled drives).

- --
Darren Dunham ddunham@taos.com
Unix System Administrator Taos - The SysAdmin Company
Got some Dr Pepper? San Francisco, CA bay area
      < Please move on, ...nothing to see here, please disperse >

------- Message 5

Date: Fri, 15 Dec 2000 11:44:38 +1030
From: blymn@baesystems.com.au (Brett Lymn)
Subject: Re: mapping prtconf info to disk names?

According to David Harnick-Shapiro:

>Can I rely on controller number (c0, c1, c2) increasing in
>the order of prtconf's output?

Mmmm probably.

> Is there any way to derive
>the target number (tX) from the sd instance?

I think that (instance number) mod 15 will give you the target number.

> Or is there
>some other tool I should use, to inventory disks on a system?

Well, for disks that have mounted partitions you can do this:

for f in `mount | grep /dev/dsk | cut -d' ' -f3 | egrep '^/dev' | sed 's/s[0-9]
$/s2/' | sort | uniq | sed 's./dsk/./rdsk/.'`
do
  prtvtoc $f
done

Which will print out the volume table of contents for all disks that
have at least one mounted partition. If you diddle with the command
on the for line you should be able to get _all_ disks (perhaps by
analysing the output of format maybe)

- --
===============================================================================
Brett Lymn, Computer Systems Administrator, BAE SYSTEMS
===============================================================================

------- Message 6

Date: Fri, 15 Dec 2000 09:18:04 +0100
From: Jimmy De Laet <jimmy.delaet@just.fgov.be>
Subject: mapping prtconf info to disk names?

David Harnick-Shapiro writes:

Recently somebody asked something similar on this list. He was looking how to
find which device-number ( C?t?d? ) corresponded to which physical disk in his
E450. After some discussing and contacting Sun he found out that for the first
4 you can calculate it ( how to do this is mentioned in the answerbooks ). The
rest is trial and error, which can be very tricky when you have to replace 1
disk of mirror which is broke. You have 50% chance of crashing your system.

- ----------------------------------------------------------------------------
                Jimmy De Laet - jimmy.delaet@just.fgov.be

  "I used to herd dairy cows. Now I herd lusers. Apart from the isolation,
   I think I preferred the cows. They were better conversation, easier to
   milk, and if they annoyed me enough, I could shoot them and eat them."
- ----------------------------------------------------------------------------

------- Message 7

Date: Mon, 18 Dec 2000 12:34:03 -0500
From: Changa Anderson <canderson@sitesmith.com>
Subject: Re: mapping prtconf info to disk names?

One way to get corresponding sd to c0 entries is to run iostat -e and then
iostat -en (the n only works with Solaris 2.6 and above, I think).

Changa

- --
Changa Anderson
Site Manager for SiteSmith, Inc.
485 Spring Park Place
Suite 1500
Herndon, VA 20170
703-467-5780 (W), 703-467-5799 (F)

------- End of Forwarded Messages

_______________________________________________
sunmanagers mailing list
sunmanagers@sunmanagers.org
http://www.sunmanagers.org/mailman/listinfo/sunmanagers



This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:14:24 CDT