在Solaris系统中,磁盘与分区管理是系统运维人员必须掌握的核心技能。尽管如今许多用户倾向于图形界面或自动化工具,但命令行方式始终是最稳定、最可控的解决方案,尤其在处理底层硬件时。下面以格式化一块Primary IDE Master硬盘为例,详细拆解整个操作流程,帮助你系统化理解Solaris磁盘管理的逻辑。
动手之前,务必确认IDE和SCSI设备在系统中的命名规则。这是所有后续操作的基础。例如,Primary IDE Master硬盘在Solaris下的设备名为c0d0。
所有步骤均需root权限,请先登录为root用户。
第一步:设备识别与准备
执行以下命令,让系统重新扫描并生成最新的设备节点:
# drvconfig
# disks
此举确保/devices目录和/dev下的磁盘入口均为最新状态。完成后,即可使用format命令进行操作。
第二步:使用format工具
运行format,系统将自动搜索所有可用磁盘:
# format
Searching for disks...done
A VAILABLE DISK SELECTIONS:
0. c0d0
/pci@0,0/pci-ide@7,1/ide@0/cmdk@0,0
1. c1t6d0
/pci@0,0/pci9004,8178@f/sd@6,0
Specify disk (enter its number): 0
此处选择0,因为目标正是c0d0。随后系统要求指定磁盘类型:
A VAILABLE DRIVE TYPES:
0. other
Specify disk type (enter its number): 0
正常情况下应出现DEFAULT选项,但Solaris常无法自动识别IDE硬盘参数,仅提供other。此时需手动输入硬盘的物理参数。
我的硬盘参数如下(这些信息可通过BIOS的Auto Detect功能查询,建议使用Auto模式,注意Heads不能超过16,Sectors不能超过63):
- Cylinders = 25232
- Heads = 16
- Sectors = 63
按提示依次输入:
Enter number of data cylinders: 25232
Enter number of alternate cylinders[2]:
Enter number of physical cylinders[25234]:
Enter number of heads: 16
Enter number of data sectors/track: 63
Enter rpm of drive[3600]:
Enter format time[default]:
Enter cylinder skew[default]:
Enter track skew[default]:
Enter tracks per zone[default]:
Enter alternate tracks[default]:
Enter alternate sectors[default]:
Enter cache control[default]:
Enter prefetch threshold[default]:
Enter minimum prefetch[default]:
Enter maximum prefetch[default]:
Enter disk type name (remember quotes): "cyl 25232 alt 2 hd 16 sec 63"
设置完成后,将看到selecting c0d0的提示,以及No current partition list和No defect list found的信息。这表明磁盘尚无分区表,接下来进入正式的分区操作。
第三步:使用fdisk创建Solaris分区
在format>提示符下,输入fdisk:
format> fdisk
系统会提示没有fdisk表,并询问是否接受默认的100% Solaris分区。对新硬盘,直接输入y接受默认设置即可。随后会出现警告,提示需要重新标记磁盘。
再次输入fdisk确认当前分区情况:
format> fdisk
Total disk size is 25232 cylinders
Cylinder size is 1008 (512 byte) blocks
Cylinders
Partition Status Type Start End Length %
========= ====== ======== ===== === ====== ===
WARNING: no partitions are defined!
尽管刚才接受了默认,但显示没有分区被定义,需要手动创建。
选择菜单中的1. Create a partition:
Enter Selection: 1
Select the partition type to create:
1=SOLARIS 2=UNIX 3=PCIXOS 4=Other
5=DOS12 6=DOS16 7=DOSEXT 8=DOSBIG
9=DOS16LBA A=x86 Boot B=Diagnostic C=FAT32
D=FAT32LBA E=DOSEXTLBA 0=Exit? 1
选择1创建Solaris分区。接着指定分区大小,这里要使用整个磁盘,输入100(百分比)。关于是否激活该分区,输入n即可。
完成后,再次查看分区表,确认分区已成功创建:
Cylinders
Partition Status Type Start End Length %
========= ====== ======== ===== === ====== ===
1 Solaris 1 25231 25231 100
选择4. Exit退出fdisk,并保存配置。系统会再次提醒需要重新标记磁盘。
第四步:定义分区表(slice)
回到format>提示符,输入partition进入分区菜单:
format> partition
先查看当前分区表:
partition> print
Current partition table (cyl):
Total disk cylinders a vailable: 25229 + 2 (reserved cylinders)
Part Tag Flag Cylinders Size Blocks
0 root wm 0 0 (0/0/0) 0
1 swap wu 0 0 (0/0/0) 0
2 backup wu 0 - 25228 12.13GB (25229/0/0) 25430832
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 0 0 (0/0/0) 0
7 unassigned wm 0 0 (0/0/0) 0
8 boot wu 0 - 0 0.49MB (1/0/0) 1008
9 alternates wm 1 - 2 0.98MB (2/0/0) 2016
注意:Part 2(backup分区)代表整个磁盘,Part 8是引导分区,Part 9是备用块。这三个分区不应改动。需要修改的是Part 0,用它来存放文件系统。
输入0选择修改分区0:
partition> 0
Part Tag Flag Cylinders Size Blocks
0 root wm 0 0 (0/0/0) 0
Enter partition id tag[root]:
标签保持root即可。权限标志也保持默认的wm(读写、可挂载)。
关键步骤:输入起始柱面号。从分区表可见,Part 8使用了柱面0,Part 9使用了柱面1和2。因此分区0必须从柱面3开始:
Enter new starting cyl[0]: 3
然后输入分区大小。可以使用柱面数、MB或块数。为精确起见,这里使用块数。系统会提示最大可用块数:
Enter partition size[0b, 0c, 0.00mb, 0.00gb]: ?
Expecting up to 25427808 blocks, 25226 cylinders, 12415.92 megabytes, or 12.12 gigabytes
Enter partition size[0b, 0c, 0.00mb, 0.00gb]: 25427808b
确认后,再次print查看分区表,确保一切正确:
partition> print
Current partition table (cyl):
Total disk cylinders a vailable: 25229 + 2 (reserved cylinders)
Part Tag Flag Cylinders Size Blocks
0 root wm 3 - 25228 12.13GB (25226/0/0) 25427808
1 swap wu 0 0 (0/0/0) 0
2 backup wu 0 - 25228 12.13GB (25229/0/0) 25430832
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 0 0 (0/0/0) 0
7 unassigned wm 0 0 (0/0/0) 0
8 boot wu 0 - 0 0.49MB (1/0/0) 1008
9 alternates wm 1 - 2 0.98MB (2/0/0) 2016
一切无误后,输入label将分区表写入磁盘:
partition> label
Ready to label disk, continue? y
partition> quit
回到format>后,保险起见再执行一次label:
format> label
Ready to label disk, continue? y
format> quit
第五步:创建文件系统并挂载
分区完成后,使用newfs命令在分区0上创建UFS文件系统:
# newfs /dev/rdsk/c0d0s0
newfs: construct a new file system /dev/rdsk/c0d0s0: (y/n)? y
这里的c0d0s0含义是:c0d0为硬盘名称,s0代表分区0。系统会输出大量super-block备份信息,属正常现象。
接下来,创建挂载点并手动挂载:
# cd /mnt
# mkdir newhd
# mount /dev/dsk/c0d0s0 /mnt/newhd
如需开机自动挂载,需编辑/etc/vfstab文件:
# vi /etc/vfstab
在文件末尾添加一行(注意各字段顺序):
/dev/dsk/c0d0s0 /dev/rdsk/c0d0s0 /mnt/newhd ufs 1 yes -
保存退出后,新硬盘配置完成。整个流程看似步骤较多,但每条命令都有明确用途。只要掌握了设备命名规则和分区表逻辑,Solaris下的磁盘管理便不再神秘。
