柱面:每个盘片相同的同心圆环组成的一个立体结构
扇区:扇形区域
磁头:读取数据
磁盘在Linux上属于文件
一般HD开头(IDE接口的硬盘)或者SD(SATA接口的硬盘)开头
a、b、c标示第几块磁盘
一般都是sda、sdb等
sda1表示第一块硬盘的第一块分区
磁盘的分区
主流的分区机制有MBR和GPT
1:MBR:主引导记录。通常应用在使用BIOS的PC上(苹果机不是的),该机制会占用磁盘的头512个字节用来存放引导代码和分区表和启动标示55AA(其他的BIOS不能引导)
缺点:支持的分区有限;只支持小于2T的硬盘(因为于寻址空间是32)
分区:
1:主分区最多4个,可以直接使用
2:扩展分区,该扩展分区会占用一个主分区位置,之后必须创建逻辑分区才可以使用
2:GPT分区机制(64位寻址空间)
GPT分区机制:必须支持UEFI硬件才能使用,必须64位
磁盘分区的工具
1:fdisk,应用广泛,甚至包括救援模式下的Linux,但是不支持GPT模式
分区试验:
1:先在虚拟机中添加一块硬盘
2:
[root@gechong ~]# ll /dev | grep sd brw-rw----. 1 root disk 8, 0 11月 5 16:15 sda brw-rw----. 1 root disk 8, 1 11月 5 16:15 sda1 brw-rw----. 1 root disk 8, 2 11月 5 16:15 sda2
[root@gechong ~]# 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: 0x000ee95c Device Boot Start End Blocks Id System /dev/sda1 * 1 64 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 64 2611 20458496 8e Linux LVM Disk /dev/mapper/vg_gechong-lv_root: 17.7 GB, 17725128704 bytes 255 heads, 63 sectors/track, 2154 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: 0x00000000
可以看到有一块磁盘sda,有两个分区sda1和sda2
255 heads磁头, 63 sectors/track扇区, 2610 cylinders柱面
Start起始柱面 End结束柱面
添加一块磁盘后重新用fdisk -l命令查看:会显示多了一块磁盘
Disk /dev/sdb: 8589 MB, 8589934592 bytes 255 heads, 63 sectors/track, 1044 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: 0x00000000
但是其下面并没有分区,因为我们尚未分区,分完之后会显示在该、块硬盘的下面
[root@gechong ~]# fdisk /dev/sdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0xb8fdd7dd. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) 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):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)
进入交互式界面只需按照提示一步一步创建分区即可
n为创建新的分区
w保存后退出,否则不会生效
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e为扩展分区
p为主分区
一般为先建立主分区,之后建立扩展分区再在扩展分区上建立逻辑分区
注意:主分区ID为1-4 逻辑分区必须大于等于5
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1044, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1044, default 1044): +2G
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
Partition number (1-4): 5
Value out of range.
Partition number (1-4): 3
First cylinder (263-1044, default 263):
Using default value 263
Last cylinder, +cylinders or +size{K,M,G} (263-1044, default 1044): +2G
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (263-524, default 263):
Using default value 263
Last cylinder, +cylinders or +size{K,M,G} (263-524, default 524): +2G
[root@gechong ~]# fdisk -l | grep sdb Disk /dev/sdb: 8589 MB, 8589934592 bytes /dev/sdb1 1 262 2104483+ 83 Linux /dev/sdb2 263 524 2104515 5 Extended /dev/sdb5 263 524 2104483+ 83 Linux
如果没有显示,可以使用partprobe命令更新内核后重新查看
[root@gechong ~]# cat /proc/partitions major minor #blocks name 8 0 20971520 sda 8 1 512000 sda1 8 2 20458496 sda2 8 16 8388608 sdb 8 17 2104483 sdb1 8 18 1 sdb2 8 21 2104483 sdb5 252 0 17309696 dm-0 252 1 3145728 dm-1
或者
[root@gechong ~]# ll /dev/sd* brw-rw----. 1 root disk 8, 0 11月 5 16:59 /dev/sda brw-rw----. 1 root disk 8, 1 11月 5 16:40 /dev/sda1 brw-rw----. 1 root disk 8, 2 11月 5 16:40 /dev/sda2 brw-rw----. 1 root disk 8, 16 11月 5 16:59 /dev/sdb brw-rw----. 1 root disk 8, 17 11月 5 16:59 /dev/sdb1 brw-rw----. 1 root disk 8, 18 11月 5 16:59 /dev/sdb2 brw-rw----. 1 root disk 8, 21 11月 5 16:59 /dev/sdb5