SUMMARY: How to determining where a partition was last mounted.

From: Jeff Putsch <putsch_at_mxim.com>
Date: Thu Feb 28 2002 - 13:23:00 EST
Howdy,

I had asked how to determine where a partition was last mounted while in the
jumpstart environment, my full question is included at the end of the
summary. I have received a few answers, with a perl script from Dave 
Mitchell's coming closest to what I was hoping for:

chakravarthi s viswanadh <chakri78@yahoo.com> and John Tan
<John.Tan@asx.com.au> suggested using /etc/mnttab. Unfortunately, under
the jumpstart environment /etc/mnttab does not reflect the disks
that are yet to be mounted and checked by me. If I can avoid it, 
I do not want to rely on any user-space modifiable file on disk to 
tell me what the system used to look like. That self-imposed limit
precludes searching for the old /etc/mnttab file and using it. In addition,
Solaris 8 machines do not really have a "real" mnttab file. It's more like
the proc file system.

Jay Lessert <jayl@accelerant.net> suggested "fsck -n". Not bad, but I'm 
concerned about how long this will take on really big filesystems. I don't
want to slow JumpStarts down while I fsck a file system that I may or
may not preserve.

dana@dtn.com and Paul Richards <paul@ultra5.co.uk> suggested using "newfs",
then telling it not to go ahead. That might work if I can automate it.

Dave Mitchell <davem@fdgroup.co.uk> sent a perl script to glean the
information from the superblock of the filesystem. I was contemplating
just such a program in C and adding to our mini-root environment for
JumpStart. I may pursue this if I cannot get the "newfs" approach to work.
I may pursue it anyway because newfs has a potentially dangerous side 
effect - unexpected errors/events may allow it to put a new file system
on a partition  I need to preserve. Dave's script is:

   #!/usr/bin/perl -w
   use strict;
     
   die "usage: $0 device" unless @ARGV == 1;
   my $dev = $ARGV[0];
   
   my $bs = 8192;
   my $mnt_offset = 212;   # fs_fsmnt[0] offset
   my $mnt_size = 512;     # sizeof(fs_fsmnt)
   
   my $mnt;
   
   open DEV, $dev or die "Can't open $dev: $!\n";
   
   # skip to start of superblock
   seek DEV, $bs, 0 or die "Cant seek to offset $bs: $!\n";
   
   # read in superblock (and more)
   my $r = read DEV, $mnt, $bs;
   die "Cant read mount label: $!\n" unless defined $r;
   die "truncated read: expected $bs, got $r\n" unless $r == $bs;
    
   # extract out the fs_fsmnt field
   $mnt = substr($mnt, $mnt_offset, $mnt_size);
   
   # truncate after the \0
   $mnt =~ s/\0.*$//;
   print $mnt,"\n";

Thanks to everyone for the advice and help, I'll be able to proceed
much more quickly now.

My original question:

> I would like to be able to determine where a partition was last mounted.
> I know fsck will tell me this, but I would like to know if there is a
> way to find out without running fsck. I also know I may be able to use/find
> the old /etc/vfstab file, but would like to avoid the odd-ball case where
> I come across two of those. For example two file systems mounted one at /
> and another a /export, say /etc/vfstab and /export/etc/vfstab both exist,
> When checking in an unknown, unmounted, state both vfstab files have the
> same path...
>  
> My particular application is under Solaris' JumpStart environment and
> I would like to scan all partitions on all disks to gather their last
> mounted location. I do not want to count on JumpStart to detect (guess)
> the right disk/partition as being the root filesystem and then finding
> an vfstab file on it -- I know from experience that it doesn't always
> get it right..

Jeff.
-- 
Jeff Putsch                       Email: putsch@mxim.com
Maxim Integrated Products        Office: (503)547-2037
High Frequency CAD Engineering
_______________________________________________
sunmanagers mailing list
sunmanagers@sunmanagers.org
http://www.sunmanagers.org/mailman/listinfo/sunmanagers
Received on Thu Feb 28 12:24:28 2002

This archive was generated by hypermail 2.1.8 : Thu Mar 03 2016 - 06:42:35 EST