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 带有 "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 系统工程师 (System Engineer, SE) 建议使用一个根分区,并通过另一个分区来存储系统磁盘的所有其他内容。简直是一派胡言!操作系统将磁盘上的每个分片都看作是单独的磁盘,因此,在测试磁盘上创建分片之前,让我们看一下我在这一点上为什么与 Sun 存在分歧。如果您愿意,您可以不同意我的观点,但最好写文章反驳我!
如果由于应用程序发生故障而导致填满 操作系统将每个分区视为一个单独的文件系统。这意味着,操作系统为其中的每个文件系统都创建高速缓存和缓冲区。这些额外的高速缓存和缓冲区会略微增大 I/O 负载。当然,您还会受到备份、互连速度和磁盘控制器的限制。但在进行大量 I/O 操作时,出现问题的可能性会有所减少。 好了,这个主题先告一段落,下面继续介绍 Partition Menu(分区菜单)。它将打开另一个菜单,如下所示:
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 Menu(分区菜单)后,只需按 '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]?
缺省情况下,将对当前分区进行修改,这样做是可以的。事实上,执行操作后,结果并没有多大差别。如果选择 Current partition table(当前分区表),
如果选择不使用 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
输入
如果打算试一试 现在,cache 选项显示了磁盘读写高速缓存菜单。并非所有 SCSI 磁盘都使用高速缓存,而且并非所有使用高速缓存的 SCSI 磁盘都允许更改 cache 选项。这里的高速缓存是指磁盘上的少量存储器,它与系统内存无关。这意味着,每个磁盘可能会略有不同,因而在执行操作时,每个磁盘的行为也会随之有所差异。我发现读高速缓存通常是处于打开状态的,这样设置不无道理,因为在读取操作过程中即使断电也不会丢失任何内容。数据仍然会保存在磁盘上。同样,我还发现写高速缓存通常是处于关闭状态的。这样设置也是有道理的,因为如果断电,写高速缓存中的所有数据将会丢失。我曾经将写高速缓存打开并使用 IOzone 比较 I/O 负载,写入操作提高的幅度从非常小到很显著,不一而足。这种提高因磁盘型号和供应商而异。
由于使用的 format> label [0] SMI Label [1] EFI Label Specify Label type[0]:
我确信 SMI 表示 Sun Microsystems。这是缺省选项,如果进入的 如果选择 EFI(Extensible Firmware Interface,可扩展固件接口)标签,则会显示另一个分区,如下所示。 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 Web 站点的 Extensible Firmware Interface(可扩展固件接口)页中找到有关 EFI 的更多信息。
我们从本文中学到了哪些知识?我希望我已经说清楚了可使用 关于作者 在最近 20 年中,Greg (shoe) Schuweiler 一直在美国民风淳朴的中西部地区工作,他做过顾问、嵌入式软件设计师、Oracle DBA 以及很多其他不同寻常的工作。他还曾在过去 8 年间担任 UNIX SA,这是一份受人敬重的职业。可通过以下方式与他取得联系:发送电子邮件至 gshoe@xadd.org。
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 | ||||||