您的位置:首页 > 其它

磁盘知识总结

2011-08-15 18:46 399 查看
一、磁盘的分类
1. IDE磁盘
ATA接口的IDE硬盘的设备识别名称是/dev/hdX;
SATA接口的IDE硬盘的设备识别名称是/dev/sdX;
2. SCSI 磁盘
设备识别名称是/dev/sdX;
3.软盘
设备识别名称是/dev/fdX;
4.移动磁盘

二、磁盘的结构

一块硬盘是由若干张磁盘构成,每张磁盘的表面都会涂一层薄薄的磁粉。
磁盘会提供一个或多个读写头,硬盘就由读写磁头来改变磁盘上磁性物质的方向,由此存储0或者1的数据。
磁盘内部结构:



磁面(Head):每一张磁盘的表面。
磁道(Track):每一个磁面的空间,会逻辑的切割出许多磁道。
扇区(Sector):每一磁道可以在切割出扇区,也是调用磁盘的最小单位。默认为512Bytes。
磁柱(Cylinder):多张磁盘的统一编号的磁道就组成了磁柱。

三、主引导记录

整个磁盘的第0号磁柱的第0号磁面的第0个扇区,就是“Master Boot Record, MBR”,叫做“主引导扇区”。

1. 初始化程序加载器(Initial Program Loader,IPL): 466B ,用来存储操作系统的内核。
2.分区数据表(Partiton Table): 64B ,存储磁盘的分区信息。
3.验证码(Checksum):2B ,用来存放初始化程序加载器的检查码。

当计算机启动的时候,操作系统会加载主引导扇区的前446字节,同时根据分区表可以获得磁盘的分区信息。此时,如果,
操作系统无法获取分区信息,则此磁盘无法使用。

可以使用dd命令来备份和还原主引导分区的内容:
备份: dd if=/dev/XXX of=bakfile bs=512 count=1
还原: dd of=/dev/XXX if=bakfile bs=512 count=1

四、分区

1.主要分区(Primary Partition)

分区信息存放在主引导扇区的分区表中,成为主分区。
由于主引导记录的分区数据表大小为64B,而每一条分区信息占用16B,所以一块磁盘最多只能拥有4个主分区。

2.扩展分区(Extended Partition)

有一种特殊的分区,专门用来存储更多的分区,就成为扩展分区。

注意:
扩展分区只能存储分区,无法存储文件的数据。
扩展分区的信息必须存储在主引导扇区的分区数据表中。扩展分库可以看为一种特殊的主要分区。

3.逻辑分区(Logic Partiton)

分区信息存储在扩展分区的分区成为逻辑分区。每一个逻辑分区都可以存储一个文件系统。

根据扩展分区的不同,可以建立的逻辑分区的个数也不相同。

1)系统标示符为5-Extended的扩展分区:最多12个逻辑分区。
2)系统标示符为85-Linux Extended的扩展分区:

注意:
系统标示符可以在进入fdisk命令的交互界面后,用“ l - list known partition types “ 命令来查看。
IDE磁盘最多分60个逻辑分区,SCSI磁盘最多可分12个逻辑分区。

主要分区与扩展分区使用1~4的识别号码。逻辑分区使用5~63的识别号码。

五、磁盘相关命令

1.hdparm--动态修改磁盘参数

hdparm - get/set hard disk parameters - version v9.16

Usage: hdparm [options] [device] ..

Options:

-a get/set fs readahead

-A get/set the drive look-ahead flag (0/1)

-b get/set bus state (0 == off, 1 == on, 2 == tristate)

-B set Advanced Power Management setting (1-255)

-c get/set IDE 32-bit IO setting

-C check drive power mode status

-d get/set using_dma flag

-D enable/disable drive defect management

-E set cd/dvd drive speed

-f flush buffer cache for device on exit

-F flush drive write cache

-g display drive geometry

-h display terse usage information

-H read temperature from drive (Hitachi only)

-i display drive identification

-I detailed/current information directly from drive

-k get/set keep_settings_over_reset flag (0/1)

-K set drive keep_features_over_reset flag (0/1)

-L set drive doorlock (0/1) (removable harddisks only)

-M get/set acoustic management (0-254, 128: quiet, 254: fast)

-m get/set multiple sector count

-N get/set max visible number of sectors (HPA) (VERY DANGEROUS)

-n get/set ignore-write-errors flag (0/1)

-p set PIO mode on IDE interface chipset (0,1,2,3,4,...)

-P set drive prefetch count

-q change next setting quietly

-Q get/set DMA queue_depth (if supported)

-r get/set device readonly flag (DANGEROUS to set)

-R obsolete

-s set power-up in standby flag (0/1) (DANGEROUS)

-S set standby (spindown) timeout

-t perform device read timings

-T perform cache read timings

-u get/set unmaskirq flag (0/1)

-U obsolete

-v defaults; same as -acdgkmur for IDE drives

-V display program version and exit immediately

-w perform device reset (DANGEROUS)

-W get/set drive write-caching flag (0/1)

-x obsolete

-X set IDE xfer mode (DANGEROUS)

-y put drive in standby mode

-Y put drive to sleep

-Z disable Seagate auto-powersaving mode

-z re-read partition table

--dco-freeze freeze/lock current device configuration until next power cycle

--dco-identify read/dump device configuration identify data

--dco-restore reset device configuration back to factory defaults

--direct use O_DIRECT to bypass page cache for timings

--drq-hsm-error crash system with a "stuck DRQ" error (VERY DANGEROUS)

--fibmap show device extents (and fragmentation) for a file

--fibmap-sector show absolute LBA of a specfic sector of a file

--fwdownload Download firmware file to drive (EXTREMELY DANGEROUS)

--fwdownload-mode3 Download firmware using min-size segments (EXTREMELY DANGEROUS)

--fwdownload-mode3-max Download firmware using max-size segments (EXTREMELY DANGEROUS)

--fwdownload-mode7 Download firmware using a single segment (EXTREMELY DANGEROUS)

--idle-immediate idle drive immediately

--idle-unload idle immediately and unload heads

--Istdin read identify data from stdin as ASCII hex

--Istdout write identify data to stdout as ASCII hex

--make-bad-sector deliberately corrupt a sector directly on the media (VERY DANGEROUS)

--prefer-ata12 use 12-byte (instead of 16-byte) SAT commands when possible

--read-sector read and dump (in hex) a sector directly from the media

--security-help display help for ATA security commands

--trim-sectors tell SSD firmware to discard unneeded data sectors (lba and count)

--verbose display extra diagnostics from some commands

--write-sector repair/overwrite a (possibly bad) sector directly on the media (VERY DANGEROUS)

2.fdisk--使用交互方式,进行分区管理

最常用的就是fdisk -l查看磁盘分区信息。

[root@localhost ~]# fdisk -h

Usage:

fdisk [options] <disk> change partition table

fdisk [options] -l <disk> list partition table(s)

fdisk -s <partition> give partition size(s) in blocks

Options:

-b <size> sector size (512, 1024, 2048 or 4096)

-c switch off DOS-compatible mode

-h print help

-u <size> give sizes in sectors instead of cylinders

-v print version

-C <number> specify the number of cylinders

-H <number> specify the number of heads

-S <number> specify the number of sectors per track

3.sfdisk--以命令列方式管理磁盘分区。
[root@localhost ~]# sfdisk

sfdisk (util-linux-ng 2.17.2)

Usage: sfdisk [options] device ...

device: something like /dev/hda or /dev/sda

useful options:

-s [or --show-size]: list size of a partition

-c [or --id]: print or change partition Id

-l [or --list]: list partitions of each device

-d [or --dump]: idem, but in a format suitable for later input

-i [or --increment]: number cylinders etc. from 1 instead of from 0

-uS, -uB, -uC, -uM: accept/report in units of sectors/blocks/cylinders/MB

-T [or --list-types]:list the known partition types

-D [or --DOS]: for DOS-compatibility: waste a little space

-R [or --re-read]: make kernel reread partition table

-N# : change only the partition with number #

-n : do not actually write to disk

-O file : save the sectors that will be overwritten to file

-I file : restore these sectors again

-v [or --version]: print version

-? [or --help]: print this message

dangerous options:

-g [or --show-geometry]: print the kernel's idea of the geometry

-G [or --show-pt-geometry]: print geometry guessed from the partition table

-x [or --show-extended]: also list extended partitions on output

or expect descriptors for them on input

-L [or --Linux]: do not complain about things irrelevant for Linux

-q [or --quiet]: suppress warning messages

You can override the detected geometry using:

-C# [or --cylinders #]:set the number of cylinders to use

-H# [or --heads #]: set the number of heads to use

-S# [or --sectors #]: set the number of sectors to use

You can disable all consistency checking with:

-f [or --force]: do what I say, even if it is stupid

4.parted -- 交互方式修改磁盘分区等,比fdisk更强大,可以处理大于8T的分区。

5.partprobe -- fdisk修改磁盘分区表后,需要执行此命令,通知操作系统。有时候,fdisk分了区通过fdisk -l查看没有变化,估计是没有执行此命令的缘故。
Usage: partprobe [OPTION] [DEVICE]...

Inform the operating system about partition table changes.

-d, --dry-run do not actually inform the operating system

-s, --summary print a summary of contents

-h, --help display this help and exit

-v, --version output version information and exit

When no DEVICE is given, probe all partitions.

6.kpartx -- 对多路径的磁盘分区后,需要使用kpartx添加,产生相应映射文件。很多

[root@localhost ~]# kpartx

usage : kpartx [-a|-d|-l] [-v] wholedisk

-a add partition devmappings

-d del partition devmappings

-l list partitions devmappings that would be added by -a

-p set device name-partition number delimiter

-g force GUID partition table (GPT)

-v verbose

-s sync mode. Don't return until the partitions are created

参考书:

《Red Hat Enterprise Linux 5 系统管理宝典》

以上命令帮助输出,基于CentOS6.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: