磁盘分区 Raid
查看raid阵列卡型号
第1章 磁盘的内部原理
1.1 结构示意图

1.2 磁头 磁头数量===盘面数
从0开始 磁头用来写入和读取数据
在磁盘不工作时,磁头停在靠近主轴接触盘片的表面,即线速度最小的地方.这里是一个不存放任何数据的特殊区域,称为启停区或着陆区(Landing Zone) 启停区以外就是数据区.在磁盘的最外圈,离主轴最远的磁盘称为 0 磁道
1.3 磁道 track
磁盘在格式化时被划分成许多同心圆,这些同心圆的轨迹叫做磁道.
磁道由盘面从外向内依次从0开始顺序编号
0 磁道非常重要,系统的引导程序就在 0柱面0磁道1扇区的前446 Bytes
1.4 扇区sector 磁盘上面的最小的单位 默认大小512字节
扇区从 1 开始编号
操作系统是以扇区为单位将信息存储在磁盘上的 一般情况下,每个扇区512字节
一个扇区主要有2部分内容:存储数据地点的标识符和存储数据的数据段
1.5 柱面 cylinder不同盘面上面的相同磁道组成的圆柱体
磁盘默认是按照柱面进行读写的
柱面的数量===磁道数量
1.6 单元块 units 表示一个柱面的大小
[root@oldboyetu36 ~]# fdisk -l
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0x00035789
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 124 786432 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 124 1306 9493504 83 Linux
[root@oldboyetu36 ~]#
1.7 磁盘大小如何计算
- 255 heads, 63 sectors/track, 2610 cylinders 255 磁头 , 63扇区/每个磁道有, 2610个柱面
- 255*63*2610*512=磁盘大小
1.8 小结
#255 heads, 63 sectors/track, 1044 cylinders
#255个磁头, 63个扇区/磁道 每个磁道上面有63个扇区,1044 个柱面
##1.磁头数量===盘面数量
##2.柱面的数量 === 磁道数量
##3.units 柱面大小
记忆要点:
1)一块磁盘有2-14个盘片,每个盘片有两个面,每个面对应一个读写磁头,用磁头号来区分盘面,即盘面数就是磁头数,盘片数*2=磁头数(盘面数)
2)不同盘面的磁道被划分为多个扇区区域,每个区域就是一个扇区(Sector)。
3)同一个盘面,以盘片中心为圆心,每个不同半径的圆形轨迹就是一个磁道。
4)不同盘面相同半径的磁道组成一个圆柱面就是柱面
5)一个柱面包含多个磁道(这些磁道的半径相同),一个磁道包含多个扇区。
6)数据信息记录可表示为:某磁头,某磁道(柱面),某扇区
1.9 磁道柱面扇区总括
磁盘最基本的组成部分是由坚硬的金属材料制成的涂以磁性介质的盘片(一般有很多层),不同容量的磁盘的盘片数不等
记忆要点:
A. 磁头===盘面,磁盘/硬盘几个盘片,一块磁盘有2-14个盘面
B. 磁道:同一个盘面,以盘面中心为圆心,每个不同半径的圆形轨迹就是一个磁道 tradk
C. 柱面:不同盘面相同磁道组成一个圆柱体就是柱面
D. 不同盘面的磁道被划分为多个扇形区域, 每个区域就是一个扇区 sector
E. 一个柱面包含多个磁道(这些磁道的半径相同) 一个磁道包含多个扇区
F. 数据信息记录可表示为(如何找到一个扇区(数据)):三个条件:某磁头,某磁道(柱面)某扇区。
第2章 raid
磁盘阵列,获得更大的容量。获得更高的性能,获得更好的安全性
2.1 RAID 0
raid 0 又称为Stripe(条带化)火哦Striping(条带模式),它在所有RAID中具有最高的存储性能(磁盘容量不浪费,读写很快)
RAID 0提高存储性能的原理是把连续的数据分散到多个磁盘上存取,这样,系统有数据请求就可以被多个磁盘并行的执行,每个磁盘执行属于它自己的那部分数据请求,这种数据上的并行操作可以利用总线的带宽,显著提高磁盘整体存取性能
要制作RAID 0至少要1块物理磁盘,例如Dell的服务器带有RAID卡,如果不做RAID就不能使用磁盘,除非将磁盘直接接入主板,因此将一块磁盘做RAID 0使用

2.2 RAID 1
RAID 1又称为Mirror或Mirroring(镜像)它的宗旨是最大限度的保证用户数据的可用性和可修复性。RAID 1的操作方式是把用户写入硬盘的数据百分百的自动复制到另外一个硬盘上,从而实现存储双份的数据
要制作raid 1 ,只支持两块盘,整个raid大小等于两个磁盘中最小的那个容量,因此,最好使用同样大小的磁盘。在存储时同时写入两块磁盘,实现数据完整备份,但相对降低了写入性能,但是读取数据时可以并发,相当于两块raid 0 的读取效率

多余的重复或啰嗦内容(包括信息、语言、代码、结构、服务、软件、硬件等等)均称为冗余。冗余有两层含义,第一层含义是指多余的不需要的部分,第二层含义是指人为增加地重复部分,其目的是用来对原本的单一部分进行备份,以达到增强其安全性的目的,这在信息通,,信系统当中有着较为广泛的应用。
2.3 RAID 5
raid 5是一种存储性能,数据安全和存储成本兼顾的存储解决方案
raid 5需要三块或以上的物理磁盘,可以提供热备盘实现故障恢复,采用奇偶校验,可靠性强,只有同时损坏2块盘时数据才会损坏,只损坏1块盘时,系统会根据存储的奇偶校验位重建数据,临时提供服务,此时如果有热备盘,系统还会自动在热备盘上重建故障磁盘上的数据.

2.4 RAID 10

Dell服务器只有一个RAID 10的选项,不能先做RAID 1再做RAID 0
2.5 小结

第3章 磁盘分区
3.1 磁盘分区表
位置: 0磁头0磁道1扇区 (前446字节是MBR主引导记录,后64字节是分区表,一个分区占16字节 55AA表示的是结束标记


3.2 主分区 Primary
3.3 扩展分区 extended
3.4 逻辑分区 logical
3.5 磁盘分区注意要点
主分区:最多只能有4个主分区,分区表限制64字节 /dev/sda1 /dev/sda2 /dev/sda3 /dev/sda4
扩展分区:如果划分更多的分区,必须创建扩展分区,不能直接使用,之后创建逻辑分区才能使用
3.6 硬盘分区的设备名
在linux系统中,是通过设备名来访问设备的,设备名存放在 /dev目录中.
设备名称的定义规则如下,其他的分区可以以此类推:
—系统的第一块IDE接口的硬盘称为/dev/hda。
—系统的第二块IDE接口的硬盘称为/dev/hdb。
—系统的第一块SCSI接口的硬盘称为/dev/sda。
—系统的第二块SCSI接口的硬盘称为/dev/sdb。
SATA SAS都是sd开头
每个分区则使用磁盘名称加对应的数字编号表示.

3.7 磁盘分区的重点


第4章 创建分区
4.1 选项意思 m for help

a toggle a bootable flag 切换一个可引导的标志
b edit bsd disklabel b编辑bsd磁盘标签
c toggle the dos compatibility flag c切换dos兼容性标志
d delete a partition d删除一个分区
l list known partition types l列出已知的分区类型
m print this menu m打印这个菜单
n add a new partition n添加一个新的分区
o create a new empty DOS partition table 创建一个新的空DOS分区表
p print the partition table p打印分区表
q quit without saving changes 不保存更改就退出
s create a new empty Sun disklabel 创建一个新的空Sun磁盘标签
t change a partition's system id t改变分区的系统id
u change display/entry units u改变显示/输入单元
v verify the partition table v验证分区表
w write table to disk and exit 将表写入磁盘和退出
x extra functionality (experts only) x额外功能(只专家)
4.2 fdisk -l 查看硬盘分区信息
[root@oldboyedu37-nb ~]# fdisk -l|egrep "sdb|sdc"
Disk /dev/sdb: 106 MB, 106954752 bytes
Disk /dev/sdc: 106 MB, 106954752 bytes
4.3 怎么创建分区
fdisk /dev/sdb
fdisk -cu /dev/sdb
/dev/sdb 100M
10M 10M 10M 50M 20M
3主分区 1个扩展分区(70M) 1个逻辑分区50M 1个逻辑分区20M
4.3.1 第一-对sdb 进行分区
fdisk -cu /dev/sdb
4.3.2 第二-显示当前分区信息
Command (m for help): p
Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders, total 208896 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x80b13503
Device Boot Start End Blocks Id System
4.3.3 第三-根据要求添加分区
####第一个小脚印-添加第一个主分区
Command (m for help): n
Command action
e extended ##扩展分区
p primary partition (1-4) ##主分区
p
Partition number (1-4): 1 ###分区号码 即 sdb1
First sector (2048-208895, default 2048): ###分区的开始,按回车默认即可
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-208895, default 208895): +10M ##表示给10M的空间
Command (m for help): p ###查看结果
Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders, total 208896 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x80b13503
Device Boot Start End Blocks Id System
/dev/sdb1 2048 22527 10240 83 Linux
####第二个小脚印-添加第二个主分区
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First sector (22528-208895, default 22528):
Using default value 22528
Last sector, +sectors or +size{K,M,G} (22528-208895, default 208895): +10M
Command (m for help): p
Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders, total 208896 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x80b13503
Device Boot Start End Blocks Id System
/dev/sdb1 2048 22527 10240 83 Linux
/dev/sdb2 22528 43007 10240 83 Linux
####第三个小脚印-添加第三个主分区
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First sector (43008-208895, default 43008):
Using default value 43008
Last sector, +sectors or +size{K,M,G} (43008-208895, default 208895): +10M
Command (m for help): p
Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders, total 208896 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x80b13503
Device Boot Start End Blocks Id System
/dev/sdb1 2048 22527 10240 83 Linux
/dev/sdb2 22528 43007 10240 83 Linux
/dev/sdb3 43008 63487 10240 83 Linux
####第四个小脚印-添加扩展分区
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
Selected partition 4
First sector (63488-208895, default 63488):
Using default value 63488
Last sector, +sectors or +size{K,M,G} (63488-208895, default 208895):
Using default value 208895
Command (m for help): p
Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders, total 208896 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x80b13503
Device Boot Start End Blocks Id System
/dev/sdb1 2048 22527 10240 83 Linux
/dev/sdb2 22528 43007 10240 83 Linux
/dev/sdb3 43008 63487 10240 83 Linux
/dev/sdb4 63488 208895 72704 5 Extended
####第五个小脚印-添加剩下两个扩展分区
Command (m for help): n
First sector (65536-208895, default 65536):
Using default value 65536
Last sector, +sectors or +size{K,M,G} (65536-208895, default 208895): +50M
Command (m for help): p
Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders, total 208896 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x80b13503
Device Boot Start End Blocks Id System
/dev/sdb1 2048 22527 10240 83 Linux
/dev/sdb2 22528 43007 10240 83 Linux
/dev/sdb3 43008 63487 10240 83 Linux
/dev/sdb4 63488 208895 72704 5 Extended
/dev/sdb5 65536 167935 51200 83 Linux
4.4 创建一个100M分区,把他挂载到/mnt上面。
解决过程
4.4.1 ##第一-添加一个分区给所有容量
[root@oldboyedu37-nb ~]# fdisk -cu /dev/sdb
Command (m for help): p
Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders, total 208896 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x3dcc5d75
Device Boot Start End Blocks Id System
Command (m for help): n
Command action
e extended 延伸的;扩展的
p primary partition (1-4) 主分区;基本分区
p
Partition number (1-4): 1
First sector (2048-208895, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-208895, default 208895):
Using default value 208895
Command (m for help): p
Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders, total 208896 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x3dcc5d75
Device Boot Start End Blocks Id System
/dev/sdb1 2048 208895 103424 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
4.4.2 ##第二,通知系统/dev/sdb 的分区表更改了
[root@oldboyedu37-nb ~]# partprobe /dev/sdb
4.4.3 ##第三,装修-格式化(创建文件系统)
[root@oldboyedu37-nb ~]# mkfs.ext4 /dev/sdb1 ===== mkfs -t ext4
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
25896 inodes, 103424 blocks
5171 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
13 block groups
8192 blocks per group, 8192 fragments per group
1992 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
4.4.4 ##第四-调整
tune2fs -c -1 -i 1 /dev/sdb1
[root@oldboyedu37-nb ~]# tune2fs -c 0 -i 0 /dev/sdb1
tune2fs 1.41.12 (17-May-2010)
Setting maximal mount count to -1
Setting interval between checks to 0 seconds
4.4.5 ##第五-临时挂载并检查结果
mount -t ext4 /dev/sdb1 /mnt
df -h
cat /proc/mounts
[root@oldboyedu37-nb ~]# mount /dev/sdb1 /mnt/
[root@oldboyedu37-nb ~]#
[root@oldboyedu37-nb ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 6.9G 2.3G 4.3G 35% /
tmpfs 926M 0 926M 0% /dev/shm
/dev/sda1 190M 35M 146M 19% /boot
/dev/sdb1 94M 1.6M 88M 2% /mnt
4.5 开机自动挂载
4.5.1 方法一: 适合网络文件系统
把mount /dev/sdb1 /mnt 放入/etc/rc.local,适合网络文件系统,NFS,MFS,GFS。
4.5.2 方法二: 适合本地磁盘
按照fstab的格式加入上述挂载信息。/etc/fstab,适合本地磁盘。
要挂载的设备可以是设备路径,也可以是对应的UUID
特别注意:执行mount -a测试挂载,否则开机可能导致系统起不来

fstab被破坏了,导致系统无法启动,怎么修复?
mount文件系统只读案例应用
4.6 实际在CS6云服务器挂载个数据盘
1 2018-09-19 11:46:33 root df -h
2 2018-09-19 11:46:45 root free -h
3 2018-09-19 11:49:20 root fdisk -l
4 2018-09-19 12:00:46 root fdisk /dev/vdb
5 2018-09-19 13:12:56 root fdisk -cu /dev/vdb
6 2018-09-19 13:16:02 root fdisk -l
7 2018-09-19 13:18:27 root yum install partprobe
8 2018-09-19 13:21:15 root fdisk -l
9 2018-09-19 13:22:51 root mkfs.ext4 /dev/vdb1
10 2018-09-19 13:24:19 root tune2fs -c 0 -i 0 /dev/vdb1
11 2018-09-19 13:24:37 root ll /
12 2018-09-19 13:24:50 root mkdir /data
13 2018-09-19 13:25:08 root mount /dev/vdb1 /data/
14 2018-09-19 13:25:11 root df -h
15 2018-09-19 13:26:24 root vim /etc/fstab
16 2018-09-19 13:29:40 root mount -a
17 2018-09-19 13:31:43 root df -h
18 2018-09-19 13:32:01 root mkdir /home
19 2018-09-19 13:32:17 root ln -s /home /data/home
20 2018-09-19 13:32:20 root ll /data/home
21 2018-09-19 13:32:26 root df -h
[root@ecs-201809-0002 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/vda2 36G 1.3G 33G 4% / tmpfs 7.8G 0 7.8G 0% /dev/shm [root@ecs-201809-0002 ~]# fdisk -l Disk /dev/vda: 42.9 GB, 42949672960 bytes 16 heads, 63 sectors/track, 83220 cylinders Units = cylinders of 1008 * 512 = 516096 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00011386 Device Boot Start End Blocks Id System /dev/vda1 3 8325 4194304 82 Linux swap / Solaris Partition 1 does not end on cylinder boundary. /dev/vda2 * 8325 83221 37747712 83 Linux Partition 2 does not end on cylinder boundary. Disk /dev/vdb: 536.9 GB, 536870912000 bytes 16 heads, 63 sectors/track, 1040253 cylinders Units = cylinders of 1008 * 512 = 516096 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 [root@ecs-201809-0002 ~]# fdisk -cu /dev/vdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0xd3f341c4. 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) Command (m for help): p ##### 显示当前分区信息 Disk /dev/vdb: 536.9 GB, 536870912000 bytes 16 heads, 63 sectors/track, 1040253 cylinders, total 1048576000 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xd3f341c4 Device Boot Start End Blocks Id System Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First sector (2048-1048575999, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-1048575999, default 1048575999): Using default value 1048575999 Command (m for help): p Disk /dev/vdb: 536.9 GB, 536870912000 bytes 16 heads, 63 sectors/track, 1040253 cylinders, total 1048576000 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xd3f341c4 Device Boot Start End Blocks Id System /dev/vdb1 2048 1048575999 524286976 83 Linux Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@ecs-201809-0002 ~]# [root@ecs-201809-0002 ~]# fdisk -l Disk /dev/vda: 42.9 GB, 42949672960 bytes 16 heads, 63 sectors/track, 83220 cylinders Units = cylinders of 1008 * 512 = 516096 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00011386 Device Boot Start End Blocks Id System /dev/vda1 3 8325 4194304 82 Linux swap / Solaris Partition 1 does not end on cylinder boundary. /dev/vda2 * 8325 83221 37747712 83 Linux Partition 2 does not end on cylinder boundary. Disk /dev/vdb: 536.9 GB, 536870912000 bytes 16 heads, 31 sectors/track, 2114064 cylinders Units = cylinders of 496 * 512 = 253952 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xd3f341c4 Device Boot Start End Blocks Id System /dev/vdb1 5 2114065 524286976 83 Linux [root@ecs-201809-0002 ~]# [root@ecs-201809-0002 ~]# mkf mkfifo mkfs mkfs.cramfs mkfs.ext2 mkfs.ext3 mkfs.ext4 mkfs.ext4dev mkfs.xfs [root@ecs-201809-0002 ~]# mkfs.ext4 /dev/vdb1 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 32768000 inodes, 131071744 blocks 6553587 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 4000 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 102400000 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 32 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@ecs-201809-0002 ~]# [root@ecs-201809-0002 ~]# tune2fs -c 0 -i 0 /dev/vdb1 tune2fs 1.41.12 (17-May-2010) Setting maximal mount count to -1 Setting interval between checks to 0 seconds [root@ecs-201809-0002 ~]# mkdir /data [root@ecs-201809-0002 ~]# [root@ecs-201809-0002 ~]# mount /dev/vdb1 /data/ oot@ecs-201809-0002 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/vda2 36G 1.3G 33G 4% / tmpfs 7.8G 0 7.8G 0% /dev/shm /dev/vdb1 493G 70M 467G 1% /data [root@ecs-201809-0002 ~]# vim /etc/fstab # # /etc/fstab # Created by anaconda on Thu Jan 19 18:08:11 2017 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # UUID=fa12133c-b37a-4a3b-acde-2a21f5be2342 / ext4 defaults 1 1 UUID=738a816d-dfc0-40cf-ba02-0ec56cc1dea0 swap swap defaults 0 0 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 /dev/vdb1 /data ext4 defaults 0 0 ~ ~ "/etc/fstab" 15L, 787C written [root@ecs-201809-0002 ~]# mount -a [root@ecs-201809-0002 ~]# [root@ecs-201809-0002 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/vda2 36G 1.3G 33G 4% / tmpfs 7.8G 0 7.8G 0% /dev/shm /dev/vdb1 493G 70M 467G 1% /data [root@ecs-201809-0002 ~]# mkdir /home mkdir: cannot create directory `/home': File exists [root@ecs-201809-0002 ~]# ln -s /home /data/home [root@ecs-201809-0002 ~]# ll /data/home lrwxrwxrwx 1 root root 5 Sep 19 13:32 /data/home -> /home [root@ecs-201809-0002 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/vda2 36G 1.3G 33G 4% / tmpfs 7.8G 0 7.8G 0% /dev/shm /dev/vdb1 493G 70M 467G 1% /data
4.7 企业案例:java环境内存不够用
swap在工作中,特别是java环境,程序写的有问题,会发生内存泄漏,可能会占用swap ,协调让开发改程序.运维可以临时增大swap (手动创建swap分区)
4.7.1 使用普通物理分区创建swap
fdisk /dev/sdb 分出来一个分区 /dev/sdb1
注意: 如果 /dev/sdb1 已经挂载了,需要卸载才行
[root@oldboyetu36 ~]# mkswap /dev/sdb1
Setting up swapspace version 1, size = 10236 KiB
no label, UUID=ee05177a-1ab7-4877-878f-9ca1a58465e0
[root@oldboyetu36 ~]# free -h
total used free shared buffers cached
Mem: 1.9G 327M 1.6G 248K 47M 117M
-/+ buffers/cache: 161M 1.8G
Swap: 767M 0B 767M
[root@oldboyetu36 ~]#
[root@oldboyetu36 ~]# swapon /dev/sdb1
[root@oldboyetu36 ~]# free -h
total used free shared buffers cached
Mem: 1.9G 327M 1.6G 248K 47M 117M
-/+ buffers/cache: 161M 1.8G
Swap: 777M 0B 777M
[root@oldboyetu36 ~]#
4.7.2 使用文件创建swap 临时
[root@oldboyetu36 ~]# dd if=/dev/zero of=/tmp/swap bs=1M count=128
128+0 records in
128+0 records out
134217728 bytes (134 MB) copied, 0.629637 s, 213 MB/s
[root@oldboyetu36 ~]# mkswap /tmp/swap
mkswap: /tmp/swap: warning: don't erase bootbits sectors
on whole disk. Use -f to force.
Setting up swapspace version 1, size = 131068 KiB
no label, UUID=0086ba8a-3eda-4a2d-ab80-c09154364387
[root@oldboyetu36 ~]# free -h
total used free shared buffers cached
Mem: 1.9G 459M 1.5G 248K 48M 245M
-/+ buffers/cache: 165M 1.8G
Swap: 777M 0B 777M
[root@oldboyetu36 ~]# swapon /tmp/swap
[root@oldboyetu36 ~]# free -h
total used free shared buffers cached
Mem: 1.9G 459M 1.5G 248K 48M 245M
-/+ buffers/cache: 165M 1.8G
Swap: 905M 0B 905M
[root@oldboyetu36 ~]#
- 显示磁盘swap的组成及使用情况
- [root@oldboyetu36 ~]# swapon -s
- Filename Type Size Used Priority
- /dev/sda2 partition 786428 0 -1
- /dev/sdb1 partition 10236 0 -2
- /tmp/swap file 131068 0 -3
- [root@oldboyetu36 ~]#
swapoff /dev/sdb1 不用了 关闭临时加上的swap
永久生效
添加到/etc/fstab
/tmp/100m swap swap defaults 0 0
或者swapon /tmp/100m /etc/rc.local
4.8 企业案例:java环境内存充足但是占用swap
4.8.1 让系统优先使用物理内存而不是swap
4.8.2 cat /proc/sys/vm/swappiness
默认是 60 数值越小越优先使用物理内存
man proc 搜索swappiness 看说明 根据说明改
第5章 有关磁盘命令
5.1 fdisk 格式化工具 (适用于mbr分区表) 磁盘小于2tb用
-l 查看系统中所有磁盘的信息 L
-u 以扇区的形式进行分区/查看 默认是柱面
-c 禁止的DOS兼容模式
5.1.1 fdisk分区工具介绍
- fdisk -Partition table manipulator for linux
- Linux下最常用的分区工具,一般是装完系统后进行分区. 装系统之前的分区
- 多数都是系统ISO里面的工具分,或者raid里分小磁盘
- fdisk只能root权限用户使用
- fdisk适合对装系统后的剩余空间进行分区.例如:安装系统时没有全部分区,或者安装系统后添加新磁盘
- fdisk支持mbr分区表(2TB以内)
5.1.2 fdisk分区的实质
用fdisk分区的实质,就是修改0磁头0磁道1扇区的前446字节之后的64字节的分区表信息.
大于2T,分区工具就用parted (gpt)
[root@oldboy ~]# fdisk –l
Disk /dev/sda: 21.5 GB, 21474836480 bytes 大小
255 heads, 63 sectors/track, 2610 cylinders 255 磁头 , 63扇区/每个磁道有, 2610个柱面
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: 0x000bc2ad
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 113 694272 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 113 2611 20071424 83 Linux
5.2 parted 磁盘分区工具 大于2TB使用(用于gpt分区表)
mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
创建分区表
#创建分区 make partition mkpart
mkpart PART-TYPE [FS-TYPE] START END make a partition
#print 显示磁盘分区信息
print [devices|free|list,all|NUMBER] display the partition table, available devices, free space, all found partitions, or a particular partition
quit exit program
#删除某一个分区
rm NUMBER delete partition NUMBER
(parted) p
(parted) mklabel gpt
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 107MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
(parted) mkpart primary
(parted) mkpart primary 0 10
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? I
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 107MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 17.4kB 10.0MB 9983kB primary
(parted) mkpart primary 10 20
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 107MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 17.4kB 10.0MB 9983kB primary
2 10.5MB 19.9MB 9437kB primary
(parted) rm 1
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 107MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
2 10.5MB 19.9MB 9437kB primary
5.3 mkfs 创建文件系统(格式化工具)
-t 指定文件系统类型
mkfs.ext4 === mkfs –t ext4
5.4 tune2fs 修改调整文件系统信息 [ e2fs ext2 3 4 文件系统]
-c 40 (次数) 在40次挂载之后,该文件系统会被磁盘检查 改为0将关闭该功能
-i 文件系统检查的间隔 0就是关闭
5.5 mount 挂载
-t ext4 指定文件系统类型
mount /dev/sdb1 /mnt
5.6 umount 卸载
umount /mnt
-lf 强制卸载
5.7 dumpe2fs 显示文件系统(分区)的信息
inode size
block size
5.8 fsck 用于检查并修复文件系统中的错误
fsck [选项] [文件系统filesys]
filesys可以是一个设备名( /dev/hdc1 /dev/sdb2 ),一个挂载点( / /usr /home)或一个ext2文件系统的磁盘标签,也可以是uuid指定符
-a 自动修复文件系统,不询问任何问题
5.9 dd 转换或复制文件 具有复制,转换,和格式化文本的功能

5.10 du 显示目录/文件所占的磁盘空间
-s 显示一共多大
5.11 parted 与fdisk的区别
- 支持gpt分区表,可以对大于2T的磁盘分区
- 分区直接生效,不需要使用命令写入磁盘,最好partprobe /dev/sdb
- fdisk用于小于2TB的磁盘
- 格式化挂载和fdisk无区别
第6章 文件系统知识
6.1 分区与文件系统的关系
分区就是给房子打隔断,创建文件系统就是给房子装修,文件系统类型类似装修风格
文件在磁盘上面怎么放
文件系统就是一种存储和组织计算机数据文件的机制或方法.
我们通过fdisk命令对一个磁盘进行分区后,并不能直接挂载目录存放数据实体,还需要格式化操作才可以进行挂载并存放数据
6.2 常见的文件系统
ReiserFS 文件系统。 SUSE linux的默认文件系统
Centos7采用XFS文件系统
Centos6采用ext4文件系统
Centos5采用ext3文件系统
IBM的AIX使用的jfs日志文件系统
6.3 文件系统小结
- 文件系统是对一个存储设备上的数据和元数据进行组织的一种机制
- 分区必须格式化创建文件系统才能存放数据
- 一个分区只能有一种文件系统
- Linux下常见文件系统 ext2 ext3 ext4 zfs xfs(centos7) 和Reiserfs (单独安装) .
windows下常见文件系统NTFS FAT32 exFAT
6.4 文件系统选型简单介绍
6.4.1 SAS/SATA硬盘文件系统选择
6.4.2 SSD固态文件系统选择
ls /lib/modules/`uname -r`/kernel/fs
dumpe2fs /dev/sda1


浙公网安备 33010602011771号