免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1539 | 回复: 0
打印 上一主题 下一主题

[转]solaris下的磁盘管理 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-04-10 07:58 |只看该作者 |倒序浏览
OpenSolaris下的硬盘管理包括查看系统所使用的硬盘,对指定的硬盘进行格式化和label等操作,在指定slice上建立文件系统,将建立的文件系统mount到系统的文件目录树上。这篇文章详细叙述了OpenSolaris系统下常用的磁盘管理的操作和相关的背景知识。
硬盘基础知识
从物理的角度来看,一块硬盘是由坚硬金属材料制成的并涂以磁性介质的盘片,用来读取盘片上的信息的磁头,还有帮助磁头进行寻址的臂和控制电子线路组成。一块磁盘可以有一个或多个盘片,盘片的两面都可以存储信息。盘片以高速旋转(一般的SCSI硬盘转速达到15000转每秒),使的磁头和盘片间存在一定的空气间隙,从而使磁头和盘片之间没有物理摩擦。由于磁盘的读写过程中包含了磁头的物理移动,所以其速度相对于内存的读写来说慢很多。现代操作系统都通过内存缓冲的方式尽量减少对磁盘的访问,从而提高系统的性能。同时,现代的磁盘也通过排队,并行等方法来优化对磁盘的访问,从而提供系统性能。
从逻辑的角度来讲,磁盘是用来存储数据的介质,它可以从逻辑上被划分为不同的扇区(sector),磁道(track)和柱面(cylinder)。扇区是磁盘读写的最小单位,通常一个扇区(sector)包含256个字节的存储空间,由于磁盘是块设备系统每次从磁盘上至少读取一个扇区的大小;处于同一个半径,同一个盘片面上的所有扇区组成了一个磁道(track);所有盘片上相同半径处的磁道组成了一个柱面(cylinder)。
在使用PC时,我们已经习惯了分区的概念。在PC上,磁盘被分成不通的分区,包括主分区和逻辑分区。不同的操作系统可以安装的不同的主分区上,并通过存储在磁盘第一个扇区(MBR)的引导程序来boot不同的操作系统。由于UNIX是用在服务器中的,而服务器一般来说都有专用的功能,所以一台服务器只安装一个操作系统,执行指定的任务并长期保持开着的状态。所以在UNIX系统中没有对应的分区的概念,一般都是将操作系统安装在整块磁盘中(FreeBSD,OpenSolaris等等UNIX操作系统都开始使用在桌面系统中,通常会把PC上一个分区看作一块硬盘来处理)。不过UNIX也将一个磁盘分为不同的slice,不同的slice用来存储不同的数据。比如mount在/var上的slice用来保存系统的动态日志数据;mount在/export/home目录上的slice用来保存用户的数据。
磁盘通过不同的接口连接到系统上,常用的接口包括IDE,SCSI,SATA,SAS等。IDE是传统的PC上使用的一种磁盘接口,一个IDE的控制器可以有两个IDE的通道,同一个IDE通道可以连接2个IDE设备;SCSI被广泛使用在服务器中,具有比较高的性能和热插拔特性,当然随之而来的是比较昂贵的价格。IDE和SCSI都是采用并行的方式来传输数据,并行线之间的串扰,使得频率提升的空间越来越小。这个时候,SATA和SAS应运而生,他们分别是IDE和SCSI的继承者,并使用串行的方式传输数据。
OpenSolaris下的磁盘设备文件
OpenSolaris下磁盘设备文件的表示比其他操作系统要显得复杂些。比如,在Linux下面/dev/hda,/dev/hdb代表了系统中的第1,2个IDE硬盘;而/dev/sda,/dev/sdb则代表了系统中的第1,2个SCSI(或SAS或SATA或USB)设备;/dev/hdan,/dev/sdan则代表了其中的第n个分区(Linux中主分区最多为4个,逻辑分区是从你n=5开始的)。
和Linux下简单的表示方式不同的是,在OpenSolaris下表示一个slice是通过c#t#d#s#的方法表示的。其中,
c – 控制器(controller),其后的数字表示了系统中的第几个控制器。
t-目标(target),其后的数字表示了该控制器上的第几个通道。
d-设备(device),其后的数字表示了该通道上的第几个设备。
s-分区(slice),其后的数字表示了该设备上的第几个分区。
如,/dev/dsk/c0t0d0s0就代表了系统中第一个SCSI控制器的ID0上的第一个设备的第一个分区。
在OpenSolaris系统中,所有的设备都3种不同形式的名字,不同的场合下使用不同的名字:
逻辑设备名
物理设备名
实例名
物理设备名存放在/devices目录下,它根据系统中物理设备的连接方式,形成一个物理设备的目录树。该设备树在系统启动的时候枚举产生。典型的devices目录包含下面的文件和目录:

bash-3.00# ls /devices
agpgart           iscsi:devctl      
[email=pci@0,0:intr]pci@0,0:intr[/email]
      scsi_vhci
agpgart:agpgart   options           
[email=pci@0,0:reg]pci@0,0:reg[/email]
       scsi_vhci:devctl
isa               
[email=pci@0,0]pci@0,0[/email]
           pseudo            
[email=xsvc@0,0]xsvc@0,0[/email]
iscsi            
[email=pci@0,0:devctl]pci@0,0:devctl[/email]
    pseudo:devctl     
[email=xsvc@0,0:xsvc]xsvc@0,0:xsvc[/email]

逻辑设备名存放在/dev目录下,他们是到/devices下物理设备名的软连接。逻辑设备名一般使用在命令行中对设备的引用。系统中每个磁盘设备都同时存在于/dev/dsk和/dev/rdsk目录下,分别代表了block和raw模式的设备。它们的内容是一致的:

bash-3.00# ls /dev/dsk
c0t0d0s0 c0t0d0s4 c0t2d0s0 c0t2d0s4 c1t1d0s0 c1t1d0s4
c0t0d0s1 c0t0d0s5 c0t2d0s1 c0t2d0s5 c1t1d0s1 c1t1d0s5
c0t0d0s2 c0t0d0s6 c0t2d0s2 c0t2d0s6 c1t1d0s2 c1t1d0s6
c0t0d0s3 c0t0d0s7 c0t2d0s3 c0t2d0s7 c1t1d0s3 c1t1d0s7

实例名是内核指定的别名。比如,sdn中sd是硬盘名,n代表号码。sd0表示系统中的第一个SCSI硬盘,dad0(direct access disk)表示系统中的第一个IDE硬盘。文件/etc/path_to_inst中记录了实例名和物理设备名之间的映射。/etc/path_to_inst由内核维护和使用,所以一般来说没有必要去修改其中的内容。
查看系统中的硬盘
一般来说,有3种方法可以查看系统中的硬盘配置:
1.  查看/etc/path_to_inst文件
2.  prtconf命令
3.  format命令

bash-3.00# cat /etc/path_to_inst
#
#       Caution! This file contains critical kernel state
#
"/pseudo" 0 "pseudo"
"/options" 0 "options"
"/xsvc@0,0" 0 "xsvc"
"/scsi_vhci" 0 "scsi_vhci"
"/isa" 0 "isa"
"/isa/i8042@1,60" 0 "i8042"
"/isa/i8042@1,60/keyboard@0" 0 "kb8042"
"/isa/i8042@1,60/mouse@1" 0 "mouse8042"
...

上面省略了一部分内容。prtconf命令的输出:

bash-3.00# prtconf | grep -v not
System Configuration:  Sun Microsystems  i86pc
Memory size: 1024 Megabytes
System Peripherals (Software Nodes):

i86pc
    scsi_vhci, instance #0
    isa, instance #0
        i8042, instance #0
            mouse, instance #0
            keyboard, instance #0
        fdc, instance #0
            fd, instance #0
        asy, instance #0
        asy, instance #1
    pci, instance #0
        pci8086,2545, instance #0
            pci8086,1460, instance #2
                pci8086,341a, instance #0
                pci8086,341a, instance #1
                    sd, instance #1
                    sd, instance #2


format命令也可以查看系统中的硬盘配置:

bash-3.00# format
Searching for disks...done
AVAILABLE DISK SELECTIONS:
       0. c0t0d0
          /pci@0,0/pci8086,2545@3/pci8086,1460@1d/pci8086,341a@7,1/sd@0,0
       1. c0t1d0
          /pci@0,0/pci8086,2545@3/pci8086,1460@1d/pci8086,341a@7,1/sd@1,0
Specify disk (enter its number):

上面的输出中显示了系统中的两个SCSI硬盘。
向系统中添加硬盘
一般来说,向系统中添加硬盘包括如下步骤:
1.            在OpenSolaris文件系统的根目录下创建reconfigure文件,如#touch /reconfigure。该文件保证了系统重新启动后会对硬件进行重新扫描,生成新的设备目录树,并在/devices目录下创建该目录树。
2.            关闭系统,拔去电源,将所要添加的硬盘安装到系统中去。重新启动系统。
3.            进入系统后,在shell中执行format工具,对所安装的硬盘进行format,label等操作。
4.            在新创建的slice创建新的文件系统,并将文件系统安装到系统文件目录树上。
OpenSolaris下面管理磁盘的工具为format。Format是一个两层的命令行工具,在shell提示下输入format就可以进入第一层交互界面;在第一层交互界面里面输入命令进入相应命令的第二层交互界面。在我的服务器中,OpenSolaris安装在第一块SCSI硬盘中,我想在系统中再加入一个SCSI硬盘,然后将硬盘所有的空间用来作为备份空间,mount在/export/backup下。下面一步一步的解释如何做。
首先,运行format工具需要root的权限,所以需要使用root登陆。在进入shell后,运行format,并选择所要操作的磁盘:

bash-3.00# format
Searching for disks...done
AVAILABLE DISK SELECTIONS:
       0. c0t0d0
          /pci@0,0/pci8086,2545@3/pci8086,1460@1d/pci8086,341a@7,1/sd@0,0
       1. c0t1d0
          /pci@0,0/pci8086,2545@3/pci8086,1460@1d/pci8086,341a@7,1/sd@1,0
Specify disk (enter its number): 1
selecting c0t1d0
[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
        fdisk      - run the fdisk program
        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
        !     - execute , then return
        quit
format>

我们选择第二个SCSI硬盘进行操作。选择了硬盘后,format会打印出所有可用的命令,并在命令后面做了详细的说明。如果硬盘没有格式化过(如果已经格式化过,那尽量避免再格式化),那接下来的任务就是对硬盘进行格式化。格式化是一个很费时的操作,而且不可以中断。

format> format
Ready to format.  Formatting cannot be interrupted
and takes 21 minutes (estimated). Continue? y
Beginning format. The current time is Fri Jun 15 18:44:44 2007

Formatting...
  97% complete (00:00:17 remaining) done

格式化完成后,使用fdisk来创建分区(partition):

             Total disk size is 2231 cylinders
             Cylinder size is 16065 (512 byte) blocks
                                             Cylinders
      Partition  Status    Type          Start   End    Length    %
      ======  ====    =====         ===   ===    ======   ===
          1    Active   Solaris2        1     2230    2230      100

SELECT ONE OF THE FOLLOWING:
   1. Create a partition
   2. Specify the active partition
   3. Delete a partition
   4. Change between Solaris and Solaris2 Partition IDs
   5. Exit (update disk configuration and exit)
   6. Cancel (exit without updating disk configuration)
Enter Selection:

输入fdisk进入fdisk的交互界面。默认情况下,fdisk命令会将这个硬盘分成一个Solaris2的主分区,并将其激活。也可以使用工具提供的菜单,创建或删除其他格式的分区。重新回到format工具下,运行partition命令来划分各个slice:

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
        ! - execute , then return
        quit
partition> print
Current partition table (original):
Total disk cylinders available: 2228 + 2 (reserved cylinders)
Part      Tag    Flag     Cylinders        Size            Blocks
  0 unassigned    wm       0               0         (0/0/0)           0
  1 unassigned    wm       0               0         (0/0/0)           0
  2     backup    wu       0 - 2227       17.07GB    (2228/0/0) 35792820
  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 unassigned    wm       0               0         (0/0/0)           0
  7 unassigned    wm       0               0         (0/0/0)           0
  8       boot    wu       0 -    0        7.84MB    (1/0/0)       16065
  9 unassigned    wm       0               0         (0/0/0)           0
partition>

Partition打印出可以使用的命令,其中0-7用来修改slice0-slice7的大小和属性参数,print打印当前内存中的label表,label则将内存中的表写到硬盘上去。一个默认的OpenSolaris安装会将安装盘做如下的分区:

Part      Tag    Flag     Cylinders        Size            Blocks
  0      root   wm      67 -  963        6.87GB    (897/0/0)   14410305
  1     swap   wu       1 -   66      517.72MB    (66/0/0)     1060290
  2    backup  wm       0 - 4423       33.89GB    (4424/0/0)   71071560
  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 unassigned   wm       0               0         (0/0/0)           0
  7     home   wm     964 - 4423       26.50GB    (3460/0/0)  55584900
  8      boot   wu       0 -    0        7.84MB    (1/0/0)        16065
  9 unassigned   wm       0               0         (0/0/0)           0


其中,slice 2代表了整个硬盘,slice 0作为根目录文件系统,slice 1作为交换分区这些似乎都是约定俗成的,我们能改的应该是slice 7。在partition中选择7,逐一输入slice 7的各个属性:

partition> 7
Part      Tag    Flag     Cylinders        Size            Blocks
  7 alternates    wm       1 - 2226       17.05GB    (2226/0/0) 35760690

Enter partition id tag[alternates]:
Enter partition permission flags[wm]:
Enter new starting cyl[1]:
Enter partition size[35760690b, 2226c, 2226e, 17461.27mb, 17.05gb]: 2227c
partition> print
Current partition table (unnamed):
Total disk cylinders available: 2228 + 2 (reserved cylinders)

Part      Tag    Flag     Cylinders        Size            Blocks
  0 unassigned    wm       0               0         (0/0/0)           0
  1 unassigned    wm       0               0         (0/0/0)           0
  2     backup    wu       0 - 2227       17.07GB    (2228/0/0) 35792820
  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 unassigned    wm       0               0         (0/0/0)           0
  7 alternates    wm       1 - 2227       17.06GB    (2227/0/0) 35776755
  8       boot    wu       0 -    0        7.84MB    (1/0/0)       16065
  9 unassigned    wm       0               0         (0/0/0)           0
partition>

Label表中各个属性的描述如下表所示:

Term
Description

Part
The slice number. Valid slice numbers are 0 through 7.

Tag
The Tag field is historical in meaning and not used anymore.
A value that indicates how the slice is being used.
0 = unassigned
1 = boot
2 = root
3 = swap
4 = usr
5 = backup
6 = stand
8 = home
Veritas Volume Manager array tags:
14 = public (region)
15 = private (region)

Flag
The Flag field is historical in meaning and not used anymore.
00 wm = The disk slice is writable and mountable.
01 wu = The disk slice is writable and unmountable. This is the default state
of slices dedicated for swap areas.
10 rm = The disk slice is read-only and mountable.
11 ru = The disk slice is read-only and unmountable.

Cylinders
The starting and ending cylinder number for the disk slice.

Size
The slice size: Mbytes (MB), Gbytes (GB), blocks (b), or cylinders (c).

Blocks
The total number of cylinders and the total number of sectors per slice.


接下来,运行label命令,将内存中的label table写到磁盘中去,并从format中退出来。我们创建了slice 7,下面可以在这个slice上创建文件系统了,它的设备文件名应该是c0t1d0s7。
创建文件系统并安装
创建文件系统使用newfs命令,在没有任何参数的情况下,newfs会创建一个UFS文件系统,这正是我们所需要的:

# newfs /dev/rdsk/c0t1d0s7
newfs: construct a new file system /dev/rdsk/c0t1d0s7: (y/n)? y
Warning: 5902 sector(s) in last cylinder unallocated
/dev/rdsk/c0t1d0s7:     35776754 sectors in 5824 cylinders of 48 tracks, 128 sectors
        17469.1MB in 364 cyl groups (16 c/g, 48.00MB/g, 5824 i/g)
super-block backups (for fsck -F ufs -o b=#) at:
32, 98464, 196896, 295328, 393760, 492192, 590624, 689056, 787488, 885920,
Initializing cylinder groups:
.......
super-block backups for last 10 cylinder groups at:
34804000, 34902432, 35000864, 35099296, 35197728, 35296160, 35394592,
35493024, 35591456, 35689888

最后,可以使用mount将该文件系统安装在系统文件目录树上了。

# mkdir -p /export/backup
# mount /dev/dsk/c0t1d0s7 /export/backup/

在/etc/mnttab文件中加上如下行,则下次启动后autofs会自动加载该文件系统。

/dev/dsk/c0t1d0s7 /export/backup  ufs     rw,intr,largefiles,logging,xattr,onerror=panic,dev=880087       1181913158
总结
这篇文章讲述了OpenSolaris中磁盘管理的常用操作,包括系统中设备文件的表示,如何查看系统中的硬盘,如何格式化、分区磁盘并创建文件系统,最后将该文件系统安装在系统的文件目录树上。本文章的关键字包括:OpenSolaris,磁盘管理,format。



本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/42672/showart_524796.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP