SUMMARY: Format commands

From: Michael Will (Michael_Will@kingcrab.nrl.navy.mil)
Date: Tue Oct 19 1999 - 08:32:03 CDT


Answers:

There where not to many answers on this topic...

Some recommended to use scripts within expect or tcl or via normal
UNIX scripts. Others stated you could only format drives on
different controllers at the same time. One person recommended to
use the "fmthard" command.

My question was based on the format command using the options of "-f"
and should have been the disk-list not the "-x" option.

However, the -f option works, but only one disk at a time... The man
pages seem to hint that by specifying a controller devices
/dev/rdsk/c1* (via the disk-list) one can format the entire
controller at once, but yet to figure this out.

Seems like when you if can format all the disks at once during
Solaris install, why not later on other devices?

Thanks for your help.

PS> Below is Perl script by David Foster that was also sent...

Michael

Question:

>Supposedly there is a way to issue a format command to format
>multiple disk all at once using the -f (format-file) option and the
>-x (drive-list).
>
>Problem, there are no examples of these files and I'm not having any
>luck with guessing the correct syntax.
>
>Anyone have any clues?

I've attached a Perl script FORMAT_JAZ which we use to format Jaz drives,
using both a -f and -x file, which I've also attached. Hope this is useful
I always like learning from examples.

Dave Foster
----------
X-Sun-Data-Type: default-app
X-Sun-Data-Description: default
X-Sun-Data-Name: format_jaz
X-Sun-Charset: us-ascii
X-Sun-Content-Lines: 271

#!/usr/local/bin/perl -T
#
# FORMAT_JAZ 8-24-99 DSFoster
#
# Perl script to format Iomega Jaz 2GB disks, and
# create a file system on the "backup" partition [2].
#
# Uses a separate file for format.dat formatting information, and
# reads the format commands from a command-file, to make this
# process non-interactive.
#
# CURRENTLY ONLY SUPPORTS THE FORMATTING OF 2GB DISKS!!
#
#
#================================================================
# IMPORTANT:
# The format command-file "format_jaz.dat" contains data
# which is *very* specific to the configuration of the system
# where the Jaz drive is installed. Be sure the commands
# are appropriate for the current system!
#
# The configuration section of this script also contains
# data which is very specific to the local configuration of
# the system.
#
# Current Local Host: Dim
#================================================================
#
# Gets formatting information in format.dat format, from the file:
#
# /usr/local/etc/format_jaz.dat [-x argument]
#
# Gets commands for format command from the file:
#
# /usr/local/etc/format_jazNGB.cmd [-f argument]
#
# where N is either 1 or 2, depending on the capacity of the disk
# being formatted.
#
# All local configuration is done within the "CONFIGURATION" section.
#
# This script uses no outside "tainted" data, and is therefore
# secure to use as a setuid script. ["Programming PERL", O'Reilly...]
#
# Usage:
#
# format_jaz [-1 | -2] [-d]
#
# -1 : format 1GB disk
# -2 : format 2GB disk
# -d : debug mode (echo commands)
#
# This script uses system() to perform commands similar to the
# following:
#
# /etc/format -d c1t4d0 -s -f /usr/local/etc/format_jaz1GB.cmd \
# -x /usr/local/etc/format_jaz.dat
#
# /usr/sbin/newfs -v -m 5 /dev/rdsk/c1t4d0s2
#
# NOTE: On older systems you must wrap this script within a C
# program, and make *this* C program setuid. This is because of
# a kernel bug which creates a "race condition" when a setuid
# root shell is fired up, creating a security hole. Perl scripts
# will not run setuid when this kernel bug is apparent.
# ["Programming PERL", O'Reilly..., pg. 360]
#
# Modifications:
#
# 8-20-99 DSF Created using format_sierra as template.
#
# To Do:
# - Parse $file_system to get $disk .

#--- CONFIGURATION ---------------------------------------------------

# For security reasons use absolute paths for all programs, devices and
# mount points!

$local_host = "dim"; # Local system
$prog_name = "format_jaz"; # Name of program

$format_file = "/usr/local/etc/format_jaz.dat"; # format.dat info
$format_cmds_1gb = "/usr/local/etc/format_jaz1GB.cmd"; # Format commands
$format_cmds_2gb = "/usr/local/etc/format_jaz2GB.cmd";
$file_system = "/dev/rdsk/c1t4d0s2"; # File system for disk
$disk = "c1t4d0"; # Disk name

$format_cmd = "/etc/format";
$newfs_cmd = "/usr/sbin/newfs";
@newfs_options = ( "-v", "-m", "5" );
$format_time = "1.5 hours"; # Estimated format time

$mount_cmd = "/usr/local/bin/jmount -s"; # For mounting/unmounting disk
$unmount_cmd = "/usr/local/bin/jmount -u -s";
$mount_point = "/jaz";

#---------------------------------------------------------------------

# Clean up the path for more secure operation in setuid mode

$ENV{PATH} = '/bin:/usr/bin';

# Set UID = EUID. Necessary to get NEWFS command to work (but not
# for FORMAT??). NOTE: Using $UID and $EUID didn't work here!

$orig_uid = $<; # Save original UID
$< = $>;

# Make sure the local host is correct!!

chop($host = `hostname`);
if ($host ne $local_host) {
        print "\n This program can only be run on $local_host\n";
        exit 0;
}

# Parse command-line arguments

$debug_mode = 0;
$disk_type = 0; # Disk type not specified
$disk_type = 2; # xxxx

for ($inc = 0; $inc <= $#ARGV; $inc++) {
        if ($ARGV[$inc] eq "-h") {
                print " \nUsage: $prog_name [-d]\n";
                #print " \nUsage: $prog_name [-1 | -2] [-d]\n"; #xxxx
                #print "\n -1 : format 1GB Jaz disk";
                #print "\n -2 : format 2GB Jaz disk";
                print "\n -d : debug mode (echo commands)\n\n";
                print " Currently supports formatting of 2GB disks
ONLY.\n\n"; #xxxx
                exit 0;
        }
        elsif ($ARGV[$inc] eq "-d") {
                $debug_mode = 1;
        }
        #elsif ($ARGV[$inc] eq "-1") { #xxxx
        # $disk_type = 1;
        #}
        #elsif ($ARGV[$inc] eq "-2") {
        # $disk_type = 2;
        #}
}

# Get disk type if not specified on command-line

while ($disk_type != 1 and $disk_type != 2) {
        print "\n\nIs this a 1GB or 2GB disk [1,2]? ";
        $ans = <STDIN>;
        chop($ans);
        $disk_type = $ans;
}

# Prompt user with a warning

#xxxx
print "\n\nCurrently you can ONLY format 2GB disks using \"$prog_name\".";

print "\n\nFormatting will destroy any data that may be on this Jaz disk,";
print "\nand will take approximately $format_time .";
print "\n\nAre you sure you wish to continue (y/n) [n]: ";
$ans = <STDIN>;
chop($ans);
if ($ans ne "y" and $ans ne "Y" and $ans ne "yes") {
        exit 0;
}

# Select command-file, and check for existence of command-file and
# disk format file

if ($disk_type == 1) {
        $format_cmds = $format_cmds_1gb;
        $disk_name = "Jaz 1GB";
}
elsif ($disk_type == 2) {
        $format_cmds = $format_cmds_2gb;
        $disk_name = "Jaz 2GB";
}

unless (-e $format_cmds) {
        die "\nFile not found: $format_cmds\n";
}
unless (-e $format_file) {
        die "\nFile not found: $format_file\n";
}

# Format the disk and create a new file system

print "\n\n Formatting $disk_name disk...\n";

@args = ( $format_cmd, "-d", $disk, "-s", "-f", $format_cmds,
                "-x", $format_file );
if ($debug_mode == 1) { pretty_print(@args) };

$status = system( @args ); ### Format the disk

if ($status != 0) {
        die "\n Error formatting $disk, command failed\n";
}
else {

        print "\n\n Creating new filesystem on $file_system...\n";
        @args = ( $newfs_cmd, @newfs_options, $file_system );

        if ($debug_mode == 1) { pretty_print(@args) };

        $status = system( @args ); ### Create new file system

        if ($status != 0) {
                die "\n Error creating filesystem for $disk:
command failed\n";
        }
        else {

                # Mount, set ownership and permissions, and unmount

                print "\n\n Setting permissions for $mount_point ...\n";
                $status = set_permissions($mount_point, $mount_cmd,
$unmount_cmd,
                                        $orig_uid);
        }
}

# Print an array of strings with freakin spaces between the elements!

sub pretty_print {
        for ($i = 0; $i <= $#_; $i++) { print "$_[$i] "; }
        print "\n";
}

# Set ownership and permissions for Mount-Point
#
# Usage: set_permissions($mount_pt, $mount_cmd, $unmount_cmd, $orig_uid);

sub set_permissions {

        @args = ( $_[1] ); # Mount the disk
        $status = system( @args );
        if ($debug_mode == 1) { pretty_print(@args); }
        if ($status != 0) {
                print "\n Error mounting $_[0]: cannot set permissions\n";
        }
        else {

                @args = ( "chmod", "775", $_[0] );
                if ($debug_mode == 1) { pretty_print(@args); }
                $status = system( @args );
                if ($status != 0) {
                        print "\n Error setting permissions for: $_[0]\n";
                }

                $owner = sprintf("%s", $_[3]);
                @args = ( "chown", $owner, $_[0] );
                if ($debug_mode == 1) { pretty_print(@args); }
                $status = system( @args );
                if ($status != 0) {
                        print "\n Error setting owner to \"$owner\"
for: $_[0]\n";
                }

                @args = ( $_[2] ); # Unmount the disk
                $status = system( @args );
                if ($debug_mode == 1) { pretty_print(@args); }
                if ($status != 0) {
                        print "\n Error unmounting $_[0]\n";
                }
        }
}
----------
X-Sun-Data-Type: default
X-Sun-Data-Description: default
X-Sun-Data-Name: format_jaz.dat
X-Sun-Charset: us-ascii
X-Sun-Content-Lines: 30

#
# FORMAT_JAZ.DAT DSFoster 8-20-99
#
# Information for formatting Iomega Jaz disks
# under Solaris 2.x
#

disk_type = "Jaz 1GB" \
        : ctlr=SCSI \
        : ncyl=1018 : acyl=2 : pcyl=1020 : nhead=64 \
        : nsect=32 : rpm=3600: bpt=16384

partition = "Jaz 1GB" \
        : disk="Jaz 1GB" : ctlr=SCSI \
        : 2=0,2084864

disk_type = "Jaz 2GB" \
        : ctlr=SCSI \
        : ncyl=1909 : acyl=2 : pcyl=1911 : nhead=64 \
        : nsect=32 : rpm=3600: bpt=16384

partition = "Jaz 2GB" \
        : disk="Jaz 2GB" : ctlr=SCSI \
        : 2=0,3903795

# For SunOS systems ONLY (replaces partition entry above)
#partition = "Jaz 2GB" \
# : disk="Jaz 2GB" : ctlr=SCSI \
# : c=0,3903795
----------
X-Sun-Data-Type: default
X-Sun-Data-Description: default
X-Sun-Data-Name: format_jaz2GB.cmd
X-Sun-Charset: us-ascii
X-Sun-Content-Lines: 48

type 2
format y
partition
2
backup
wu
0
3909632b
label y
quit
quit

#------------------------------------------------------------------------
# FILE: format_jaz2GB.dat
#
# LOCAL HOST: Dim
#
# This is a command file used to format Iomega Jaz 2MB disks.
# These commands assume that entries for formatting the the optical
# disks (in format.dat format) have been placed in the system file:
#
# /path/format_jaz.dat
#
# on the system where this command file will be used, and that the
# Jaz 2GB disk is the second option in this file (TYPE 2).
#
# To format the optical disk the command:
#
# /etc/format -d disk-name -s -f /path/format_jaz2GB.cmd \
# -x /path/format_jaz.dat
#
# is issued at root level, followed by commands to create a new
# file system and set access permissions.
#
# ONLY A SYSTEM ADMINISTRATOR SHOULD CHANGE THIS FILE !!!
#
# MODIFICATION HISTORY:
# 9/10/93 Dave Foster Original SUNOS 4.1.3 version.
# 6/2/94 jws Longer text message to reflect focus
# on PMO 650 and Solaris change.
# 7/14/94 jws Switch to use -f option and explicitly
# specifying disk to format. Removed host
# dependency and host keyword.
# 8/19/99 dsf Ported to NCMIR from command file for
# formatting Sierra disks, and converted to
# use with Jaz 2GB disks.
#
#------------------------------------------------------------------------



This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:13:29 CDT