一、服务器磁盘
1、磁盘的物理组成:
- 圆形的磁盘盘
- 机械手臂,与在机械手臂上的磁盘读取头
- 主轴马达,可以转动磁盘盘,让机械手臂的读取头在磁盘盘上读写数据
磁盘主要存储数据的是磁盘盘,磁盘盘组成:
1、扇区(sector)是最小的物理存储单位,有512bytes和4K两种格式
2、将扇区组成一个圆是磁柱
3、最小分区单位通常为扇区
4、磁盘分区表主要有两种格式,一种是限制较多的MBR分区,一种是GPT格式
5、MBR分区中,第一个扇区最重要,主要存放开机区的MBR和分区表
6、GPT分区表除了分区数量扩充较多之外,支持的磁盘容量超过2TB
2、文件系统:
只有将磁盘分区格式化之后,才能成为操作系统能够利用的文件系统格式
3、硬盘读写数据过程:
现代硬盘寻道都是采用CHS的方式,即Cylinder(柱面)、Head(磁头)、Sector(扇区),硬盘读取数据时,读写磁头沿径向移动,移到要读取的扇区所在磁道的上方,这段时间称为寻道时间
因读写磁头的起始位置与目标位置之间的距离不同,寻道时间也不同。目前硬盘一般为2到30毫秒,平均约为9毫秒。磁头到达指定磁道后,然后通过盘片的旋转,使得要读取的扇区转到读写磁头的下方,这段时间称为旋转延迟时间
4、磁盘容量的计算:
只要知道了硬盘的CHS的数目,即可确定硬盘的容量:
硬盘的容量=柱面数(磁道数) * 磁头数 * 单磁道扇区数 * 单个容量扇区大小(一般初始为512字节)
二、磁盘分区核心命令介绍
1、fdisk命令
查看系统的分区详细信息
命令选项:
- fdisk -l 列出分区表
[root@localhost ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000814e7
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 1332 10485760 83 Linux
/dev/sda3 1332 1592 2088960 82 Linux swap / Solaris
/dev/sda4 1592 1617 208008+ 83 Linux
- fdisk device 对磁盘进行分区
示例1:创建分区
[root@localhost ~]# fdisk /dev/sda
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Selected partition 4
First cylinder (1592-2610, default 1592):
Using default value 1592
Last cylinder, +cylinders or +size{
K,M,G} (1592-2610, default 2610): +2G
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
【注】:以上所示表示创建 /dev/sda4 分区,默认从1592柱面开始,指定大小为2G,然后保存[w]
示例2:删除分区
[root@localhost ~]# fdisk /dev/sda
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): d
Partition number (1-4): 4
Command (m for help): w
The partition table has been altered!
...
【注】:以上所示表示删除 /dev/sda4 分区,然后保存[w]
当然,在这里,我们也可以执行命令帮助,里面详细说明了如创建分区等多个选项意义
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
2、文件系统管理工具命令
1.创建文件系统的工具
mkfs
mkfs.ext2, mkfs.ext3, mkfs.ext4, mkfs.xfs, mkfs.vfat, …
示例:
[root@localhost ~]# mkfs.ext2 /dev/sda4
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
512064 inodes, 2046070 blocks
102303 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2097152000
63 block groups
32768 blocks per group, 32768 fragments per group
8128 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Writing inode tables: done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
2.检测及修复文件系统的工具
fsck
fsck.ext2, fsck.ext3, …
示例:
[root@localhost ~]# fsck.ext2 /dev/sda4
e2fsck 1.41.12 (17-May-2010)
/dev/sda4: clean, 11/512064 files, 36645/2046070 blocks
3.查看其属性的工具
dumpe2fs, tune2fs
示例:
[root@localhost ~]# dumpe2fs /dev/sda4
dumpe2fs 1.41.12 (17-May-2010)
Filesystem volume name: <none>
Last mounted on: <not available>
Filesystem UUID: 61bb29bb-9b61-4821-aa8c-5cee0b06ebf4
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: ext_attr resize_inode dir_index filetype sparse_super large_file
Filesystem flags: signed_directory_hash
Default mount options: (none)
Filesystem state: clean
...
Group 0: (Blocks 0-32767)
Primary superblock at 0, Group descriptors at 1-1
Reserved GDT blocks at 2-500
Block bitmap at 501 (+501), Inode bitmap at 502 (+502)
Inode table at 503-1010 (+503)
31751 free blocks, 8117 free inodes, 2 directories
Free blocks: 1017-32767
Free inodes: 12-8128
Group 1: (Blocks 32768-65535)
Backup superblock at 32768, Group descriptors at 32769-32769
Reserved GDT blocks at 32770-33268
Block bitmap at 33269 (+501), Inode bitmap at 33270 (+502)
Inode table at 33271-33778 (+503)
31757 free blocks, 8128 free inodes, 0 directories