shell script to mount filesystem

Hi, Gurus:

I need your help to finish a script that will mount two file systems automatically when saver is reboot or start.

I am working on a new Sun Sparc machine with Solaris 9 on it. This box got two disk. disk one has been partitioned to hold Solaris OS. disk two has been partitioned as two file systems for Oracle. When I reboot the machine, the mount point on disk two will lose. I have to manually mount them up. I would like to create a script in /etc/init.d or insert a piece of code in .profile file . The script should su - from oracle user to root user with passwd first, then mount /dev/dsk/c0t0d0s2 /u02, mount/dev/dsk/c0t0d0s3 /u03. After this, su - oracle user. In this process, the file system on disk two will be automatically mounted. Please advise me the basic code. Thanks.

If you want the filesystems to be mounted after/during a system reboot, why not make the entries for the filesystems in the /etc/vfstab file?

The format of the /etc/vfstab file is as follows:

#device         device          mount           FS      fsck    mount   mount
#to mount       to fsck         point           type    pass    at boot options

An example entry is like this:

/dev/dsk/c0t0d0s7       /dev/rdsk/c0t0d0s7      /test       ufs     1       yes      -

blowtorch:

Thanks so much. I do think your approach will work perfectly.

A few more question: what is difference between /dev/dsk/ and /dev/rdsk/?

I look at my vfstab file, why some filesystem choose mount at boot as 'no'. But it is still mounted. For eaxmple, filesystem /u01 on disk one, its choice on "mount at boot" is "no". After reboot, I type "df -k", I can see /u01 was mounted. Last question is: fsck, entry should be 1 or 2, which is better? Thanks again.

I checked some of my systems, and the only filesystem that I found with a mount at boot set to no is '/' itself. All other systems that are mounted are set to yes. About your filesystem, it could be that someone has mounted the filesystem manually after the system has booted.
About the fsck value, to be honest, I am not sure what the effect of changing the values would be, but conventionally, the value is set to 1 for '/' and 2 for all other filesystems.
It might be that fscking the / at one pass, then proceeding to boot and fscking the other filesystems at a later pass speeds up the boot process.

blowtorch:

Thanks so much for your advice. It worked perfectly. You are so good. I also changed fsck to 2 because your explanation is correct.

The files under /dev/dsk are block special files, when you do an "ls -l" you will see all line start with a "b".
The files under /dev/rdsk are character special files, when you do an "ls -l" you will see all lines start with a "c".

  •   regular files
    

d directory
b block special file
c character special file
l soft link
s socket
p named pipe

Block special files are used for mounting etc.
Character specal files are used for formatting and filesystem check etc

That is why eacht entry in your vfstab contains both the block and character specil file.

You do NOT check filesystems which or NON local disks during boot. If you mount NFS filesystems it is up to the system who exports those filesystems to maintain the integrity. So "fsck pass" should be "no" for NFS fllesystems

For those disks which are checked during boot the number indicates an order.
Those with the lowest number are checked first, next those with the 2nd lowest number, etc

The "/" filesystem should be checked priot to all other filesystems and therefore have the lowest number. A good concept would be whenever you mout a filesystem on another fileystem you increae to number by 1.

Suppose I have 5 filesystems

/
/usr
/var
/opt
/opt/oracle

In this case "/" would get "1"
"/usr", "/var" and "/opt" get "2" since they are mounted on "/"
"/opt/oracle" would get "3" since it is mount on "/opt" which is mounted on "/".

In this scenario "/" would be checked first
Next "/usr", "/var" and "/opt" similtaniously
and last "/opt/oracle"

sb008:

Thans so much for your informative explanation. This is the best answer I have ever got on this forum. You are guru. I will apply your advice in my vfstab file.