Automatisiertes Schreiben von disk label unter Solaris

Wer unter Solaris mit UFS-Filesystemen arbeitet muss vor der Benutzung einer Platte selbige mit einem disk label (vtoc bzw. Partitionstabelle) versehen. Dazu startet man den Befehl “format”, wählt die gewünschte Disk aus, ändert unter “partition” die Größen für die Partitionen, speichert das mit “label” und beendet das Programm mit “quit”.

root@server # format
Searching for disks...done

AVAILABLE DISK SELECTIONS:
       0. c0t0d0 <SUN36G cyl 24620 alt 2 hd 27 sec 107>
          /ssm@0,0/pci@1a,700000/pci@1/SUNW,isptwo@4/sd@0,0
       1. c1t0d0 <SUN36G cyl 24620 alt 2 hd 27 sec 107>
          /ssm@0,0/pci@1b,700000/pci@1/SUNW,isptwo@4/sd@0,0
       2. c2t40d41 <EMC-SYMMETRIX-5772 cyl 49598 alt 2 hd 30 sec 128>
          /ssm@0,0/pci@1a,600000/pci@1/lpfc@4/sd@28,29
...
Specify disk (enter its number): 0
selecting c0t0d0
[disk formatted]

FORMAT MENU:
        disk       - select a disk
        type       - select (define) a disk type
        partition  - select (define) a partition table
        current    - describe the current disk
        format     - format and analyze the disk
        repair     - repair a defective sector
        label      - write label to the disk
        analyze    - surface analysis
        defect     - defect list management
        backup     - search for backup labels
        verify     - read and display labels
        save       - save new disk/partition definitions
        inquiry    - show vendor, product and revision
        volname    - set 8-character volume name
        !<cmd>     - execute <cmd>, then return
        quit
format> partition

PARTITION MENU:
        0      - change `0' partition
        1      - change `1' partition
        2      - change `2' partition
        3      - change `3' partition
        4      - change `4' partition
        5      - change `5' partition
        6      - change `6' partition
        7      - change `7' partition
        select - select a predefined table
        modify - modify a predefined partition table
        name   - name the current table
        print  - display the current table
        label  - write partition map and label to the disk
        !<cmd> - execute <cmd>, then return
        quit
partition> print
Current partition table (original):
Total disk cylinders available: 24620 + 2 (reserved cylinders)

Part      Tag    Flag     Cylinders         Size            Blocks
  0       root    wm       0 -  6812        9.39GB    (6813/0/0)  19682757
  1       swap    wu    6813 - 21330       20.00GB    (14518/0/0) 41942502
  2     backup    wm       0 - 24619       33.92GB    (24620/0/0) 71127180
  3 unassigned    wm       0                0         (0/0/0)            0
  4 unassigned    wm       0                0         (0/0/0)            0
  5        var    wm   21331 - 24233        4.00GB    (2903/0/0)   8386767
  6 unassigned    wm   24234 - 24596      512.06MB    (363/0/0)    1048707
  7 unassigned    wm   24597 - 24619       32.44MB    (23/0/0)       66447

partition> quit

FORMAT MENU:
        disk       - select a disk
        type       - select (define) a disk type
        partition  - select (define) a partition table
        current    - describe the current disk
        format     - format and analyze the disk
        repair     - repair a defective sector
        label      - write label to the disk
        analyze    - surface analysis
        defect     - defect list management
        backup     - search for backup labels
        verify     - read and display labels
        save       - save new disk/partition definitions
        inquiry    - show vendor, product and revision
        volname    - set 8-character volume name
        !<cmd>     - execute <cmd>, then return
        quit
format> quit

Im Bereich “partition” kann man mit “print” die aktuelle Partitionstabelle ansehen. Bei neuen Platten wird ein Standardvorschlag zur Partitionierung angezeigt, der natürlich abgeändert werden kann. Wird dies nicht getan und trotzdem “label” ausgeführt, wird dieser default-label geschrieben.

Hat man nun die Aufgabe eine größere Anzahl Platten zu partitionieren möchte man dann den Vorgang doch irgendwie automatisieren. Dazu gibt es die Tools prtvtoc und fmthard. Mit prtvtoc kann die Partitionstabelle einer Platte als Text in genormter Form ausgegeben werden.

root@server # prtvtoc /dev/rdsk/c0t0d0s0
* /dev/rdsk/c0t0d0s2 partition map
*
* Dimensions:
*     512 bytes/sector
*     107 sectors/track
*      27 tracks/cylinder
*    2889 sectors/cylinder
*   24622 cylinders
*   24620 accessible cylinders
*
* Flags:
*   1: unmountable
*  10: read-only
*
*                          First     Sector    Last
* Partition  Tag  Flags    Sector     Count    Sector  Mount Directory
       0      2    00          0  19682757  19682756
       1      3    01   19682757  41942502  61625258
       2      5    00          0  71127180  71127179
       5      7    00   61625259   8386767  70012025
       6      0    00   70012026   1048707  71060732
       7      0    00   71060733     66447  71127179

Diese Ausgabe läßt sich nun als Vorlage nutzen um Platten mit “fmthard” zu partitionieren. Sinn ergibt das natürlich nur bei Disks mit gleicher Größe.

prtvtoc /dev/rdsk/c0t0d0s2 | fmthard -s - /dev/rdsk/c1t0d0s2

Dummerweise bekommt man nun ziemlich wahrscheinlich einen I/O-error beim Schreiben der Partitionstabelle auf die zweite Platte (wenn diese neu ist). Hier des Rätsels Lösung:

manpage zu “fmthard

For disks under one terabyte, fmthard cannot write a VTOC on an unlabeled disk. Use format(1M) for this purpose.
SunOS 5.10          Last change: 11 Apr 2005

Na klasse, da läßt sich das Tool zum Automatisieren in der Masse der Anwendungsfälle also nicht nutzen. Weniger bekannt ist der folgende Workaround:

Man automatisiert das Schreiben eines Standard disk label mit “Format” und benutzt im Anschluss wie oben gezeigt “prtvtoc” und “fmthard” (üblicherweise wird immer die Slice 2 angegeben, da diese per Definition die komplette Disk umfassen sollte!).

echo label > /tmp/input
echo quit >> /tmp/input
format -d c1t0d0  -f /tmp/input
prtvtoc /dev/rdsk/c0t0d0s2 | fmthard -s - /dev/rdsk/c1t0d0s2

Um eine größere Zahl Disks zu partitionieren schreibt man ein kleines Skript:

cd /dev/rdsk/
echo label > /tmp/input
echo quit >> /tmp/input
DISKS=$(ls c4t50d*s2|sed 's/s2//')
export DISKS
for i in $DISKS
do
format -d $i -f /tmp/input
done

In diesem Beispiel werden alle LUNs am Controller 4 / Target 50 mit einem Standard disk label versehen.

Danach kann man z.B. das Partitionslayout einer Platte auf alle neuen Platten übertragen:

for i in $DISKS
do
prtvtoc /dev/rdsk/c0t0d0s2 | fmthard -s - /dev/rdsk/${i}s2
done

Alternativ könnte man aber auch die neuen Platten einem Diskset hinzufügen:

for i in $DISKS
do
metaset -s oradb -a $i
done

P.S.

Die Skripte kann man natürlich noch schöner schreiben. Ich will hier nur das Prinzip zeigen…

Hier noch etwas Lesestoff: http://docs.sun.com/app/docs/doc/817-5093/disksprep-103?a=view

This entry was posted in OpenSolaris, Solaris and tagged , , , , , . Bookmark the permalink.

Hinterlasse eine Antwort

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *

*

Du kannst folgende HTML-Tags benutzen: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>