Solaris 作業系統中的「format」公用程式Greg (shoe) Schuweiler,2004 年 11 月 對許多人而言,硬碟無異於「黑盒子」,是個可儲存資料、程式和 (或) 作業系統的小型裝置。若您所在乎的僅止於此,那麼這種想法當然是沒有問題。但若您是系統管理員,保護資料則是您的主要考量之一。另一件應優先考量的事情,應該是資料能否在記憶體與實體磁碟之間快速移動。在此文中,我將探討 Solaris 作業系統中可用的基本公用程式之一:
除了 另一個警告字詞:即非破壞性指令,但是否要在系統上執行這類指令,由您自己決定。破壞性指令將會破壞磁碟上的資料;您必須確實瞭解自己在做什麼,才能執行這類指令。 我在此文中將使用下列指令: 磁碟標籤: 缺陷清單: 分割區表: 閱讀此文時,請牢記下列事項:
我希望您的系統已連結可供練習的磁碟,因為我希望這篇文章有互動效果。首先,請挑選即將執行 r_gps@holstein: format Searching for disks...done AVAILABLE DISK SELECTIONS: 0.c0t0d0 <SUN36G cyl 24620 alt 2 hd 27 sec 107> boot /pci@1f,4000/scsi@3/sd@0,0 1.c0t1d0 <SUN36G cyl 24620 alt 2 hd 27 sec 107> home /pci@1f,4000/scsi@3/sd@1,0 2.c2t1d0 <SUN36G cyl 24620 alt 2 hd 27 sec 107> trashme /pci@1f,4000/pci@5/SUNW,isptwo@4/sd@1,0 Specify disk (enter its number): 您可以鍵入「quit」以結束或備份某個功能表,或按下 <Ctrl-D> 以完全結束 « Warning: echo "adios data" | dd of=/dev/dsk/c2t1d0s2 bs=1 count=512 » 此時
r_gps@holstein: format
Searching for disks...done
c2t1d0: configured with capacity of 33.92GB
AVAILABLE DISK SELECTIONS:
0. c0t0d0 <SUN36G cyl 24620 alt 2 hd 27 sec 107> boot
/pci@1f,4000/scsi@3/sd@0,0
1. c0t1d0 <SUN36G cyl 24620 alt 2 hd 27 sec 107> home
/pci@1f,4000/scsi@3/sd@1,0
2. c2t1d0 <SUN36G cyl 24620 alt 2 hd 27 sec 107>
/pci@1f,4000/pci@5/SUNW,isptwo@4/sd@1,0
Specify disk (enter its number): 2
selecting c2t1d0
[disk formatted]
Disk not labeled. Label it now?
在此若要為磁碟加上標籤,請鍵入「y」,如此 Solaris 作業系統即可使用此磁碟。接著,請結束 r_gps@holstein: prtvtoc /dev/dsk/c2t1d0s2 * /dev/dsk/c2t1d0s2 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 262899 262898 1 3 01 262899 262899 525797 2 5 01 0 71127180 71127179 6 4 00 525798 70601382 71127179 您可以從 r_gps@holstein: format /dev/rdsk/c2t1d0s2
在出現 Current partition table (original): Total disk cylinders available: 24620 + 2 (reserved cylinders) Part Tag Flag Cylinders Size Blocks 0 root wm 0 - 90 128.37MB (91/0/0) 262899 1 swap wu 91 - 181 128.37MB (91/0/0) 262899 2 backup wu 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 unassigned wm 0 0 (0/0/0) 0 6 usr wm 182 - 24619 33.67GB (24438/0/0) 70601382 7 unassigned wm 0 0 (0/0/0) 0 partition>
有些資訊會與 r_gps@holstein: dd if=/dev/dsk/c2t1d0s2 of=wart.bin bs=512 count=1 1+0 records in 1+0 records out
如此會產生可執行 r_gps@holstein: od -x wart.bin 0000000 5355 4e33 3647 2063 796c 2032 3436 3230 0000020 2061 6c74 2032 2068 6420 3237 2073 6563 0000040 2031 3037 0000 0000 0000 0000 0000 0000 0000060 0000 0000 0000 0000 0000 0000 0000 0000 * 0000200 0000 0001 0000 0000 0000 0000 0008 0002 0000220 0000 0003 0001 0005 0001 0000 0000 0000 0000240 0000 0000 0000 0004 0000 0000 0000 0000 0000260 0000 0000 0000 0000 0000 0000 600d deee 0000300 0000 0000 0000 0000 0000 0000 0000 0000 * 0000640 0000 0000 2729 602e 0000 0000 0000 0001 0000660 602c 0002 001b 006b 0000 0000 0000 0000 0000700 0004 02f3 0000 005b 0004 02f3 0000 0000 0000720 043d 508c 0000 0000 0000 0000 0000 0000 0000740 0000 0000 0000 0000 0000 0000 0000 00b6 0000760 0435 4aa6 0000 0000 0000 0000 dabe 4297 0001000
八進制傾印中有許多資訊,而且已有很好的 Sun 文件加以討論 — 我不想在此贅述。請至 SunSolve 搜尋文件 ID 74087。值得注意的是,
r_gps@holstein: format /dev/rdsk/c2t1d0s2
selecting /dev/rdsk/c2t1d0s2
[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>
我很喜歡為每個磁碟指定磁碟區名稱,使系統較與眾不同。若您有多個系統使用相同的磁碟機 (在高可用性叢集中可能會出現此情況),這麼做會有很大的幫助。我已發現由一對 RAID 引擎所顯示的 120 餘個磁碟,在 VERITAS 叢集中有 15 個系統可看到這些磁碟。為每個磁碟指定磁碟區名稱,有助於識別已使用的磁碟。沒有磁碟區名稱的磁碟為未使用的磁碟。使用 format> volname Enter 8-character volume name (remember quotes)[""]:"pigsnot" Ready to label disk, continue? y format>
format> disk
AVAILABLE DISK SELECTIONS:
0. /dev/rdsk/c2t1d0s2 <SUN36G cyl 24620 alt 2 hd 27 sec 107> pigsnot
/pci@1f,4000/pci@5/SUNW,isptwo@4/sd@1,0
Specify disk (enter its number)[0]:
Current Disk = c2t1d0: pigsnot <SUN36G cyl 24620 alt 2 hd 27 sec 107> /pci@1f,4000/pci@5/SUNW,isptwo@4/sd@1,0
r_gps@holstein: ls /devices/pci@1f,4000/pci@5/SUNW,isptwo@4/sd@1,0* /devices/pci@1f,4000/pci@5/SUNW,isptwo@4/sd@1,0:a /devices/pci@1f,4000/pci@5/SUNW,isptwo@4/sd@1,0:a,raw /devices/pci@1f,4000/pci@5/SUNW,isptwo@4/sd@1,0:b /devices/pci@1f,4000/pci@5/SUNW,isptwo@4/sd@1,0:b,raw /devices/pci@1f,4000/pci@5/SUNW,isptwo@4/sd@1,0:c /devices/pci@1f,4000/pci@5/SUNW,isptwo@4/sd@1,0:c,raw /devices/pci@1f,4000/pci@5/SUNW,isptwo@4/sd@1,0:d /devices/pci@1f,4000/pci@5/SUNW,isptwo@4/sd@1,0:d,raw /devices/pci@1f,4000/pci@5/SUNW,isptwo@4/sd@1,0:e /devices/pci@1f,4000/pci@5/SUNW,isptwo@4/sd@1,0:e,raw /devices/pci@1f,4000/pci@5/SUNW,isptwo@4/sd@1,0:f /devices/pci@1f,4000/pci@5/SUNW,isptwo@4/sd@1,0:f,raw /devices/pci@1f,4000/pci@5/SUNW,isptwo@4/sd@1,0:g /devices/pci@1f,4000/pci@5/SUNW,isptwo@4/sd@1,0:g,raw /devices/pci@1f,4000/pci@5/SUNW,isptwo@4/sd@1,0:h /devices/pci@1f,4000/pci@5/SUNW,isptwo@4/sd@1,0:h,raw 含有「原始」一詞的實體裝置名稱為字元裝置,另一個則是區段裝置。字母「a」為分割區 0,字母「b」為分割區 1,依此類推。
format> verify Primary label contents: Volume name = < pigsnot> ASCII name = <SUN36G cyl 24620 alt 2 hd 27 sec 107> pcyl = 24622 ncyl = 24620 acyl = 2 nhead = 27 nsect = 107 Part Tag Flag Cylinders Size Blocks 0 root wm 0 - 90 128.37MB (91/0/0) 262899 1 swap wu 91 - 181 128.37MB (91/0/0) 262899 2 backup wu 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 unassigned wm 0 0 (0/0/0) 0 6 usr wm 182 - 24619 33.67GB (24438/0/0) 70601382 7 unassigned wm 0 0 (0/0/0) 0
#
# New disk/partition type saved on Fri Aug 6 06:34:05 2004
#
disk_type = "SUN36G" \
: ctlr = SCSI : ncyl = 24620 : acyl = 2 : pcyl = 24622 \
: nhead = 27 : nsect = 107 : rpm = 10025
...
最後,在我們用於收集磁碟資訊的選項清單中,會有 format> inq Vendor: FUJITSU Product: MAN3367M SUN36G Revision: 1502 format> 您必須注意的是修訂版等級。磁碟機的確會有韌體更新。此選項可讓您比較磁碟上的修訂版等級與磁碟供應商所提供的等級。我曾要求供應商針對大型 RAID 陣列的磁碟更新磁碟機韌體,但他們只有在別人要求時才肯做。很久以前,我曾更新過 SCSI 磁碟上的韌體一次或兩次。我不再做這種麻煩事了 — 主要是因為現今環境中的磁碟數目眾多,而且必要的停機時間過長(古諺有云:「沒壞掉的東西就不要修理」,有時候很有道理)。我還沒想出如何在不停機的情況下進行升級。我正在努力當中。
defect both dump /disks/c2t1d0-defect.dat r_gps@holstein: format -f c2t1d0.cmd /dev/rdsk/c2t1d0s2
但由於
警告:我已重製
r_gps@holstein: format /dev/rdsk/c2t1d0s2
selecting /dev/rdsk/c2t1d0s2
[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>
IPI 與 SMD 磁碟機,是過去我們必須執行此動作的磁碟機。請嘗試在 Google 上搜尋「ipi smd disk」磁碟機以找出些許相關資料,並瞭解有需要時可以在哪裡購買這些類型的磁碟機。
而這就牽扯到我對 Sun 非常不認同的一個領域。舉例來說,我所認識的 Sun 以及 Sun Systems Engineer (SE) ,近來不斷鼓吹系統磁碟應使用一個根分割區,並以另一個分割區處理其他的項目。真是胡說八道!對作業系統而言,磁碟上的每個磁碟片段都是獨立的磁碟,因此在我們切割測試磁碟之前,讓我們先瞭解一下為何我不認同 Sun 的這項觀點。您也可以不同意我的觀點,甚至自己另闢文章討論!
若 作業系統會將每個分割區視為個別的檔案系統。這表示它會分別為這些檔案系統建立快取與緩衝區。這些額外的快取與緩衝區會略為分散 I/O 負載。而您確實會受到備份、互連速度與磁碟控制器的限制。但在大量 I/O 的時候,就比較不會發生問題。 個人意見發表結束,現在繼續討論 [分割區功能表]。它會開啟另一個功能表,如下所示:
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
我認為處理磁碟分割最簡單的方式莫過於此:在 [分割區功能表] 中,按「P」鍵以選取 Current partition table (original): Total disk cylinders available: 24620 + 2 (reserved cylinders) Part Tag Flag Cylinders Size Blocks 0 root wm 0 - 90 128.37MB (91/0/0) 262899 1 swap wu 91 - 181 128.37MB (91/0/0) 262899 2 backup wu 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 unassigned wm 0 0 (0/0/0) 0 6 usr wm 182 - 24619 33.67GB (24438/0/0) 70601382 7 unassigned wm 0 0 (0/0/0) 0
此為預設分割區表,而我們必須加以變更;別忘了我們不希望出現重疊的分割區。修改分割區時,使用
當您輸入
partition> modify
Select partitioning base:
0. Current partition table (original)
1. All Free Hog
Choose base (enter number) [0]?
根據預設,您會修改目前的分割區,這點沒有問題。此動作執行與否並沒有多大的差別。當您選取目前的分割區表時,
若我選擇不使用 partition> 0 Part Tag Flag Cylinders Size Blocks 0 root wm 0 - 90 128.37MB (91/0/0) 262899 Enter partition id tag[root]: Enter partition permission flags[wm]: Enter new starting cyl[0]: Enter partition size [262899b, 91c, 90e, 128.37mb, 0.13gb]: 256mb 您也可以在分割區 ID 標記與權限旗標問題中輸入「?」,以取得可接受的回應。若再次按下「P」鍵,就會發現我有一個問題必須處理。 Part Tag Flag Cylinders Size Blocks 0 root wm 0 - 181 256.74MB (182/0/0) 525798 1 swap wu 91 - 181 128.37MB (91/0/0) 262899 ...分割區 0 與分割區 1 重疊。在您建立分割區的過程中,請確定您所建立的分割區沒有重疊的現象。您所建立的分割區數目及其大小,實際上取決於您的站點、需求、經驗等。作業完成後,產生了下列項目: Current partition table (original): Total disk cylinders available: 24620 + 2 (reserved cylinders) Part Tag Flag Cylinders Size Blocks 0 root wm 0 - 181 56.74MB (182/0/0) 525798 1 swap wu 182 - 272 128.37MB (1452/0/0) 4194828 2 backup wu 0 - 24619 33.92GB (24620/0/0) 71127180 3 unassigned wm 3540 - 4265 1.00GB (726/0/0) 2097414 4 unassigned wm 0 0 (0/0/0) 0 5 unassigned wm 4266 - 4991 1.00GB (726/0/0) 2097414 6 usr wm 273 - 2087 2.50GB (1815/0/0) 5243535 7 var wm 2088 - 3539 2.00GB (1452/0/0) 4194828
我們仍須寫出分割區表。只要鍵入
若您的磁碟購自 Sun,通常不太需要使用
我想之前針對
這不是很有趣嗎?在兩、三個磁碟上進行分割區的格式化與設定並不成問題 — 雖然需要輸入些許資料,但還可忍受。但若您在連接到大型 RAID 陣列後,而需要以相同方式配置 10 個甚或 200 個磁碟,該怎麼辦?我有個好朋友曾在一個大型影像專案中面臨此問題。她使用了
一如既往, * Partition Tag Flag First Sector Sector Count 0 2 00 4194828 1048707 1 7 00 5243535 4145715 2 5 00 0 71127180 3 3 01 0 4194828 4 0 00 9389250 2097414 5 0 00 11486664 8389656 6 4 00 19876320 6292242
因此,最理想的方式是使用 fmthard -i -n "" /dev/rdsk/c2t1d0s2 > ./mypartition.dat
前述指令會將 « fmthard -s mypartition.dat -n "volumename" /dev/rdsk/cxtydzs2 »
現在,若您已確實閱讀
-e Enable SCSI expert menu. Note this option is not
recommended for casual use.
我不知道你怎麼想啦,但我就是想試試這個選項。當您進入 scsi - independent SCSI mode selects cache - enable, disable or query SCSI disk cache
在您進入
若您想要試看看 此時,快取選項會顯示可提供磁碟讀寫快取的功能表。並非所有的 SCSI 磁碟皆有快取,而有快取的磁碟也並非全都允許您變更其快取選項。此快取乃是磁碟上的少量記憶體 — 與系統記憶體毫無關係。這表示,當您使用這些磁碟時,每個磁碟本身及其運作方式都會略有不同。我發現讀取快取通常為開啟狀態,我認為這很合理,因為在讀取期間才不會因電力中斷而遺失資料。資料仍應位於磁碟上。同樣地,我發現寫入快取一律為關閉狀態。這也合理,因為當電力中斷時,寫入快取中的所有資料都將遺失。當我加以開啟,並使用 IOzone 比較 I/O 負載時,寫入作業的提升不盡相同,有的微乎其微,有的則非常顯著。提升的程度會隨著磁碟型號與供應商而有所不同。
此時我們位於具有 format> label [0] SMI Label [1] EFI Label Specify Label type[0]:
我想 SMI 表示 Sun Microsystems。此為預設選項,當您進入不具 若您選取 EFI (可延伸韌體介面) 標籤,則會出現另一個分割區,如下所示。 ascii name = <FUJITSU MAN3367M SUN36G 1502 43d671f> bytes/sector = 512 sectors = 71132958 accessible sectors = 71132925 Part Tag Flag First Sector Size Last Sector 0 root wm 34 128.35MB 262898 1 swap wu 262899 128.37MB 525797 2 unassigned wm 0 0 0 3 unassigned wm 0 0 0 4 unassigned wm 0 0 0 5 unassigned wm 0 0 0 6 usr wm 525798 33.66GB 71116540 7 unassigned wm 0 0 0 8 reserved wm 71116541 8.00MB 71132924 format> 您可以在 Intel 網站的可延伸韌體介面頁面上,找到有關 EFI 的詳細資訊。
到目前為止我們有何收穫?我希望已經讓您瞭解 關於作者 Greg (shoe) Schuweiler 在人人皆好客的美國中西部擔任顧問已有 20 年的歷史,他是 Oracle DBA 的內嵌式軟體設計人員,除此之外還有很多奇怪的頭銜。過去八年來,他一直擔任 UNIX SA 這個崇高的工作。若想與他連絡,請透過 gshoe [at] xadd.org。
Comments (latest comments first)Discuss and comment on this resource in the BigAdmin Wiki
Unless otherwise licensed, code in all technical manuals herein (including articles, FAQs, samples) is provided under this License. |
BigAdmin SubscriptionsBigAdmin Areas
BigAdmin Sun Center
BigAdmin Topics | ||||||||||