磁盘和硬盘相比较,磁盘是带有正负极磁性的硬盘。磁盘的结构包括,盘道、磁道、扇区、柱面、磁头。负责存储的是磁道,负责读写数据的是磁头。
容量:Mb、Gb、Tb、Pb、Eb以上都是容量大小的单位,1024Mb=1Gb 1024Gb=1T吧,以此类推。
转速:指的是每分钟旋转的圈数,7200转、15000转
尺寸:磁盘的大小,3.5英寸、2.5英寸、1.8英寸
IOPS:inptu(输入),output(输出)
[a-z]或者[aa-zz]
系统中分区由数字编号表示,1~4留给主分区使用和扩展分区,逻辑分区从5开始,为什么分区还有限制?因为MBR分区只能分配4个主分区。还有一种新型的分区表GPT,GPT支持分配128个主分区。(MBR与GPT之间不能相互转换,转换的话会导致数据丢失)
~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 2G 0 part /boot
├─sda2 8:2 0 2G 0 part [SWAP]
└─sda3 8:3 0 36G 0 part /
sdb 8:16 0 20G 0 disk
sdc 8:32 0 20G 0 disk
sr0 11:0 1 4.4G 0 rom
#第一个分区
~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x6cf48971.
Command (m for help): n #n:新分区
Partition type:
p primary (0 primary, 0 extended, 4 free) #主分区
e extended #扩展分区
Select (default p): p #选择主分区
Partition number (1-4, default 1): #直接回车,默认创建第一个分区
First sector (2048-41943039, default 2048): #直接回车,默认创建第一个扇区
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +500M #给第一个分区分配 500M
Partition 1 of type Linux and of size 500 MiB is set
Command (m for help): w # w 保存操作
~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 2G 0 part /boot
├─sda2 8:2 0 2G 0 part [SWAP]
└─sda3 8:3 0 36G 0 part /
sdb 8:16 0 20G 0 disk
└─sdb1 8:17 0 500M 0 part
sdc 8:32 0 20G 0 disk
sr0 11:0 1 4.4G 0 rom
~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): e #创建扩展分区
Partition number (2-4, default 2): #直接回车默认第二分区
First sector (1026048-41943039, default 1026048): #直接回车默认第一个扇区
Using default value 1026048
Last sector, +sectors or +size{K,M,G} (1026048-41943039, default 41943039): #直接回车,默认将剩余的空间分配给第二分区
Using default value 41943039
Partition 2 of type Extended and of size 19.5 GiB is set
Command (m for help): w # w 保存操作
~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): n
Partition type:
p primary (1 primary, 1 extended, 2 free)
l logical (numbered from 5)
Select (default p): l #创建逻辑分区
Adding logical partition 5
First sector (1028096-41943039, default 1028096):
Using default value 1028096
Last sector, +sectors or +size{K,M,G} (1028096-41943039, default 41943039): +100M #分配100M空间
Partition 5 of type Linux and of size 100 MiB is set
Command (m for help): w
#格式化整块新磁盘
~]# mkfs.ext4 /dev/sdb
#格式化单个分区
~]# mkfs.ext4 /dev/sdb1
做好格式化的磁盘是无法直接使用的,需要挂载到某个目录下进行使用
~]# mkdir /data
~]# mount /dev/sdb1 /data/
#卸载
~]# umount /dev/sdb1 /data/
#用法
mount [设备] [挂载点(目录)]
#参数
-t:指定挂载的设备类型
-o:指定挂载的参数【rw 读写】【ro只读】
#例
##将设备sdc1挂载到/data/test3目录,指定为xfs类型,但是只允许读,不允许写
~]# mount -t xfs -o ro /dev/sdc1 /data/test3
#永久挂载需要将挂载内容写入/etv/fstab
~]# cat /etc/fstab
UUID=144555a1-7b4a-4add-a057-390e685a83ba / xfs defaults 0 0
UUID=2fe56857-bea6-441f-b39f-ad42ac3b299d /boot xfs defaults 0 0
UUID=fc2f0a9e-d436-43c4-a309-218d24383faa swap swap defaults 0 0
UUID:要挂载的设备或要挂载设备的UID
/:挂载点
xfs:文件格式
defaults:挂载参数
0:是否备份
0:是否检查
磁盘阵列可以提高磁盘的整体读写能力和冗余[rǒng yú]能力,通常我们将其称为磁盘阵列。
提高性能
保证安全
RAID 0 :RAID 0条带卷,最少两块磁盘。读写性能好但是没有容错机制。坏一块磁盘数据全部丢失。容量是所有磁盘之和。(通常应用在web服务器上)
RAID 1:RAID 1镜像卷,写入性能一般,读取性能快,有容错机制但是磁盘有50%浪费。RAID 1镜像卷需要准备一块热备盘,有磁盘坏了会自动顶替那个坏的磁盘,继承数据。
RAID 5:RAID 5校验卷,至少需要3块相同大小的磁盘,也需要准备一块热备盘,而且只允许坏一块磁盘,有效空间1/3,读写速度快。(坏掉一块磁盘,读的性能会变慢)
PS:RAID 5的容量计算方式:(n-1) = 磁盘容量。RAID 5无论由多少块磁盘组成,最多只允许坏一块磁盘。具备和RAID 0差不多的性能同时也具备RAID 1的稳定性。
RAID 10:先做RAID 1 再做RAID 0既有冗余又有性能,容量是1/2(成本高)。