linux 磁盘基础知识学习
linux磁盘知识学习
一、磁盘的发展历史
硬盘和磁盘是对磁盘存储系同一个称呼。从1956年9月IBN向世界展示了第一台磁盘存储系统IBM 350 RAMAC至今,磁盘存储系统已经历了半个多世界的发展,经历了这么多年,磁盘的变化非常巨大。虽然最早的RAMAC容量只有5MB,然而却需要使用50个直径为24英寸的磁盘。而我们现在一块容量高达1000GB的磁盘,仅仅只需要3张盘片(还是一块3.5寸盘)即可。我们现在使用的现代硬盘样式是1980年出现的。
1.1.1 磁盘的发展趋势和实现措施
发展趋势 | 实现措施 |
---|---|
体积更小 | 存储密度更高 |
速度更快 | 读写更灵敏的磁头,主轴转数更高,接口更先进 |
容量更大 | 存储密度更高、介质更好 |
使用更安全 | 数据保持保护技术更先进安全 |
1.1.2 机械磁盘的内部介绍 | |
磁盘的内部结构主要包括:磁头、盘片、盘片主轴、控制电机、磁头控制器、数据转换器、接口、缓存等几个部分。所有的盘片都固定在一个旋转轴上,这个轴即盘片主轴。而所有的盘片之间是平行的,在每个盘片(一个盘片两个面)的每一个存储面上都有一个磁头,磁头与盘片之间距离比头发丝的直径还小很多倍。所有的磁头(一个有效盘面就有一个磁头)连在一个磁头控制器上,由磁头控制器负责各个磁头的运动。磁头可沿盘片 | |
的半径方向做径向运动,盘片以每分钟数千转的熟读告诉旋转,这样磁头就能对盘片上指定位置进行数据的读写操作。 | |
二、企业级磁盘的应用
1)企业级SAS硬盘(默认)
企业里常见的SAS的磁盘是15000转/分(主轴的转数)。当前主流300G、600G、1000G,从具体的业务需求及性价比考虑,工作中多用146G、300-600G的磁盘,在工作中一般不要选单盘容量太大的磁盘(多块盘做raid,可以提高磁盘性能),除非你是纯备份。
2)企业级SATA硬盘
企业级SATA硬盘,7200-10000转/分。常见的容量为1T、2T、4T、6T。优点是经济实惠,容量大,从具体的业务需求及性价比考虑。在工作中线下不提供服务的数据存储或者并发业务访问不是很大的义务应用,比如站点程序及数据库、图片的线下备份等。
特性: 容量性比价高,一般2T的SATA硬盘最佳。
3)磁盘选购的小结
1.线上业务,用SAS硬盘。
2.线下的业务,用SATA硬盘,磁带库。
3.线上高并发,小容量业务,SSD磁盘。
4.成本思想:根据数据访问的热度,智能分析分层存储。SATA+SSD
企业案列:不要用SATA硬盘来做在线高并发服务的数据存储或数据库业务,某公司采用SATA做数据库的存储盘,结果导致数据连续宕机一个月。
原因:5台SATA盘做RAID5。
解决:重新买5台,把硬盘SATA(RAID55)换成SAS(RAID10)。6个月内没事。
三、磁盘的核心知识原理与读写原理
磁盘的相关名词:
英文 | 中文 |
---|---|
Disk | 磁盘 |
Head | 磁头 |
Sector | 扇区 |
Track | 磁道 |
Cylinder | 柱面 |
Units | 单元块(一个柱面大小) |
Block | 数据块 |
inode | 索引节点 |
3.1.1 磁道:磁道就是每个盘面上相同圆心不同半径的同心圆轨迹,这个同心圆轨迹就是磁道,磁道有盘面从外向内依次从0开始顺序编号。
3.1.2 柱面:柱面就是不同盘面相同半径的磁道组成的圆柱体,就是柱面。 3.1.2 扇区:扇区就是磁道上的弧形扇面。,一般情况下,每个扇区的大小是512字节。一个扇区主要有两部分:存储数据地点的标识符和存储数据的数据段。
3.1.4 磁盘容量的计算
1、512字节x每个磁道扇区数=磁道大小
磁道大小x磁道数=盘面大小
盘面大小x磁头数=磁盘容量
2、磁盘容量=512字节x每个磁道扇区数x磁道数x磁头数
磁盘容量=柱面大小x柱面数(磁道数)x磁头数
柱面大小=磁道大小x磁头数
磁道大小=512字节x每个磁道扇区数
[root@node ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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 label type: dos
Disk identifier: 0x000b574f
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 41943039 20458496 8e Linux LVM
Disk /dev/mapper/centos_node-root: 19.9 GB, 19872612352 bytes, 38813696 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 /dev/mapper/centos_node-swap: 1073 MB, 1073741824 bytes, 2097152 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
计算结果:
[root@node ~]# echo "41943040 512" |awk '{print $1*$2/1000000000}'
21.4748
#centos6可能计算方式不一样,但结果一样。因为c6会列出磁头数,每个磁道有多少扇区。但是c7直接把整个磁盘的扇区都列出来了,所以计算会简单一些,但万变不离其中。
3.1.5 磁盘的读写原理
磁盘的读写是按住面来读写的。系统将文件存储到磁盘上时,按柱面、磁头、扇区的方式进行,即最先是第1磁道的第一磁头下(也就是第1盘面的第一磁道)的所有扇区,然后,是同一柱面的下一磁头,……,一个柱面存储满后就推进到下一个柱面,直到把文件内容全部写入磁盘。
(文件的记录在同一盘组上存放是,应先集中放在一个柱面上,然后再顺序存放在相邻的柱面上,对应同一柱面,则应该按盘面的次序顺序存放。)
(从上到下,然后从外到内。数据的读/写按柱面进行,而不按盘面进行,先)
系统也以相同的顺序读出数据。读出数据时通过告诉磁盘控制器要读出扇区所在的柱面号、磁头号和扇区号(物理地址的三个组成部分)进行。磁盘控制器则 直接使磁头部件步进到相应的柱面,选通相应的磁头,等待要求的扇区移动到磁头下。在扇区到来时,磁盘控制器读出每个扇区的头标,把这些头标中的地址信息与期待检出的磁头和柱面号做比较(即寻道),然后,寻找要求的扇区号。待磁盘控制器找到该扇区头标时,根据其任务是写扇区还是读扇区,来决定是转换写电路, 还是读出数据和尾部记录。找到扇区后,磁盘控制器必须在继续寻找下一个扇区之前对该扇区的信息进行后处理。如果是读数据,控制器计算此数据的ECC码,然 后,把ECC码与已记录的ECC码相比较。如果是写数据,控制器计算出此数据的ECC码,与数据一起存储。在控制器对此扇区中的数据进行必要处理期间,磁 盘继续旋转。
机器磁盘读写原理小结:
1、磁盘是按照柱面为单位读写数据的,即先读取同一盘面的某一个磁道,读完之后,如果数据没有读完,磁头也不会切换到其它的磁道,而是选择切换磁头,读取下一个盘面相同半径的磁道,直到所有盘面的相同半径的磁道读取完成之后,数据还是没有读完,才会切换到其它不同半径的磁道,这个切换磁道的过程称为寻道。
2、不同磁头间的切换是电子切换,而不同磁道间的切换需要磁头做径向运动,这个径向运动需要步进电机调节,这个动作是机械的切换。
数据在磁盘的位置:0磁头 0磁道 1扇区
四、RAID 技术的学习
RAID是廉价冗余磁盘阵列(Reaundant Array of Inexpensive Disk)的简称,有时候我们也简称磁盘整列(Disk array)。
RAid 技术是一种把多块独立的物理盘按不同的技术组合起来形成一个磁盘组,在逻辑上(做完RAID,装完系统后)看起来就是一块大的磁盘,可以可以提供比单个物理磁盘更大的存储容量或更高的存储性能,同时又能提供不同级别数据冗余备份的一种技术。 把多个物理磁盘通过你不同的技术方式组成磁盘阵列,这个技术方式被称为RAID级别,RAID的级别一般有(RAID 0 ,RAID 1,RAID 2 ,RAID 3, RAID 4, RAID 5, RAID 6, RAID7 , RAID10, RAID53),我们生产中常用的有RAID 0 RIAD 1 RAID 5 RAID 10 其它大型存储用。
4.1.1 生产环境中RAID 0 RIAD 1 RAID 5 RAID 10 的优缺点。
RAID级别 | 优点 | 缺点 | 实际场景应用 |
---|---|---|---|
RAID 0 | 读写速度最快 | 没有任何冗余 | mysql slave集群的节点RS |
RAID 1 | 100%冗余,镜像 | 读写性能一般,成本高 | 单独的,数据重要,且不能宕机的业务。监控,系统盘。 |
RAID 5(采用奇偶检验) | 具备一定性能和冗余,可以怀一块磁盘。读性能不错。 | 写入性能不高。 | 一般的业务都可以。 |
RAID 10 | 读写速度很快,100%冗余 | 成本高 | 性能和冗余要求都要好的业务。数据库主库和存储节点。 |
4.1.2 RAID的技术有两种
1、软RAID技术:
在Linux下在安装系统的过程中或者安装系统后通过自带的软件就能实现软RAID功能,使用软RAID可以省去购买的硬件RAID控制器和附件就能极大地增强磁盘IO性能和可靠性。由于是用软件功能实现的RAID功能,所以它配置灵活,方便管理,同时使用软件RAID,还可以实现将几个物理磁盘合并成一个更大的虚拟设备,从而达到性能改进和数据冗余的目的。
2、硬RAID技术:
基于硬件的RAID解决方比基于软件RAID技术在使用性能和服务性能上会更胜一筹,具体表现在检测和修复多位错误的能力,错误磁盘自动检测和阵列重建等方面。从安全性上考虑,基于硬件的RAID解决方案也是更安全,因此,在实际的生产场景工作中。基于硬件的RAID解决方案应该是我们的首选。互联网公司常用的生产DELL服务器,默认的就会支持RAID 0,1 如果RAID 5, RAID 10 就需要买RAID卡。
4.1.3 用RAID 的好处
1、提升数据的读写性能。
2、提升数据安全性。
3、提供更大的单一逻辑磁盘数据容量存储。
五、磁盘分区以及分区类型介绍
磁盘分区就是把一个分割成相互独立又有联系的单元,就相当于我们买的一个房子(磁盘),房子内部分割开了客厅(分区),卧室(分区),厨房(分区)等单个房间。
5.1.1 磁盘的分去类型
1)主分区(primary)
- 系统中必须存在的分区,系统盘选择主分区安装。
- 主分区的数字编号只能是1-4,即sda1,sda2,sda3,sda4
- 主分区最多四个,最少一个。
2)扩展分区(extend)
- 相当于一个独立的小磁盘,有独立的分区表。
- 不能独立存在,即不能直接存放数据。
- 必须在扩展分区上建立逻辑分区才能存放数据
- 扩展分区占用主分区的编号(主分区+扩展分区)之和最多4个。
- 扩展分区可以没有,最多只能有一个。
3)逻辑分区(logic) - 逻辑分区的数字编号只能从5开始。
- 存放在扩展分区之上。
- 存放任意普通数据。
5.1.2 分区的工作原理
磁盘是按柱面分区的。磁盘分区的结果信息都存放在磁盘分区边里面,磁盘分区表的位置在0磁道0磁头(柱面)1扇区(512字节)占用1扇区的前446字节的是系统引导信息,后面的64字节才是分区表,剩下的2个字节是分区结束标志。为什么我们分区只能分4个分区(主分区+扩展分区)吗,因为磁盘分区表的容量是有限的,等于64字节,而一个分区固定占16字节。所以64/4=4分区(主+扩)。
5.1.3 磁盘分区实战
磁盘分区关键就是修改64字节的分区表信息而已。
分区的两个命令:fdisk(磁盘容量小于等于2T)时使用,parted(磁盘容量大于2T)是使用。
1)fdisk分区实战
准备工作
[root@node ~]# uname -r
3.10.0-1062.18.1.el7.x86_64
[root@node ~]# uname -a
Linux node 3.10.0-1062.18.1.el7.x86_64 #1 SMP Tue Mar 17 23:49:17 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
手动给虚拟系统添加一块磁盘(大小为1G)
查看是否添加成功:
[root@node ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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 label type: dos
Disk identifier: 0x000b574f
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 41943039 20458496 8e Linux LVM
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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
开始分区:
[root@node ~]# 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 0xeeb688bd.
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 #删除一个分区
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
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)
创一个3P+1E(3L)的分区模式
[root@node ~]# 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 0xeeb688bd.
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
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
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)
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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 label type: dos
Disk identifier: 0xeeb688bd
Device Boot Start End Blocks Id System
Command (m for help): 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-2097151, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151): +150M
Partition 1 of type Linux and of size 150 MiB is set
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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 label type: dos
Disk identifier: 0xeeb688bd
Device Boot Start End Blocks Id System
/dev/sdb1 2048 309247 153600 83 Linux
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2):
First sector (309248-2097151, default 309248):
Using default value 309248
Last sector, +sectors or +size{K,M,G} (309248-2097151, default 2097151): +150M
Partition 2 of type Linux and of size 150 MiB is set
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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 label type: dos
Disk identifier: 0xeeb688bd
Device Boot Start End Blocks Id System
/dev/sdb1 2048 309247 153600 83 Linux
/dev/sdb2 309248 616447 153600 83 Linux
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
Partition number (3,4, default 3):
First sector (616448-2097151, default 616448):
Using default value 616448
Last sector, +sectors or +size{K,M,G} (616448-2097151, default 2097151): +150M
Partition 3 of type Linux and of size 150 MiB is set
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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 label type: dos
Disk identifier: 0xeeb688bd
Device Boot Start End Blocks Id System
/dev/sdb1 2048 309247 153600 83 Linux
/dev/sdb2 309248 616447 153600 83 Linux
/dev/sdb3 616448 923647 153600 83 Linux
Command (m for help): n
Partition type:
p primary (3 primary, 0 extended, 1 free)
e extended
Select (default e): e
Selected partition 4
First sector (923648-2097151, default 923648):
Using default value 923648
Last sector, +sectors or +size{K,M,G} (923648-2097151, default 2097151):
Using default value 2097151
Partition 4 of type Extended and of size 573 MiB is set
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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 label type: dos
Disk identifier: 0xeeb688bd
Device Boot Start End Blocks Id System
/dev/sdb1 2048 309247 153600 83 Linux
/dev/sdb2 309248 616447 153600 83 Linux
/dev/sdb3 616448 923647 153600 83 Linux
/dev/sdb4 923648 2097151 586752 5 Extended
Command (m for help): n
All primary partitions are in use
Adding logical partition 5
First sector (925696-2097151, default 925696):
Using default value 925696
Last sector, +sectors or +size{K,M,G} (925696-2097151, default 2097151): +150M
Partition 5 of type Linux and of size 150 MiB is set
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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 label type: dos
Disk identifier: 0xeeb688bd
Device Boot Start End Blocks Id System
/dev/sdb1 2048 309247 153600 83 Linux
/dev/sdb2 309248 616447 153600 83 Linux
/dev/sdb3 616448 923647 153600 83 Linux
/dev/sdb4 923648 2097151 586752 5 Extended
/dev/sdb5 925696 1232895 153600 83 Linux
Command (m for help): n
All primary partitions are in use
Adding logical partition 6
First sector (1234944-2097151, default 1234944):
Using default value 1234944
Last sector, +sectors or +size{K,M,G} (1234944-2097151, default 2097151): +150M
Partition 6 of type Linux and of size 150 MiB is set
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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 label type: dos
Disk identifier: 0xeeb688bd
Device Boot Start End Blocks Id System
/dev/sdb1 2048 309247 153600 83 Linux
/dev/sdb2 309248 616447 153600 83 Linux
/dev/sdb3 616448 923647 153600 83 Linux
/dev/sdb4 923648 2097151 586752 5 Extended
/dev/sdb5 925696 1232895 153600 83 Linux
/dev/sdb6 1234944 1542143 153600 83 Linux
Command (m for help): n
All primary partitions are in use
Adding logical partition 7
First sector (1544192-2097151, default 1544192):
Using default value 1544192
Last sector, +sectors or +size{K,M,G} (1544192-2097151, default 2097151):
Using default value 2097151
Partition 7 of type Linux and of size 270 MiB is set
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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 label type: dos
Disk identifier: 0xeeb688bd
Device Boot Start End Blocks Id System
/dev/sdb1 2048 309247 153600 83 Linux
/dev/sdb2 309248 616447 153600 83 Linux
/dev/sdb3 616448 923647 153600 83 Linux
/dev/sdb4 923648 2097151 586752 5 Extended
/dev/sdb5 925696 1232895 153600 83 Linux
/dev/sdb6 1234944 1542143 153600 83 Linux
/dev/sdb7 1544192 2097151 276480 83 Linux
Command (m for help):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
查看是否创建成功
[root@node ~]# ll /dev/sdb*
brw-rw---- 1 root disk 8, 16 Apr 19 12:03 /dev/sdb
brw-rw---- 1 root disk 8, 17 Apr 19 12:03 /dev/sdb1
brw-rw---- 1 root disk 8, 18 Apr 19 12:03 /dev/sdb2
brw-rw---- 1 root disk 8, 19 Apr 19 12:03 /dev/sdb3
brw-rw---- 1 root disk 8, 20 Apr 19 12:03 /dev/sdb4
brw-rw---- 1 root disk 8, 21 Apr 19 12:03 /dev/sdb5
brw-rw---- 1 root disk 8, 22 Apr 19 12:03 /dev/sdb6
brw-rw---- 1 root disk 8, 23 Apr 19 12:03 /dev/sdb7
2)更改分区的类型
列如把标准分区修改LVM动态扩容分区
分区类型
[root@node ~]# 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): l
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx
5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary
16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT
1e Hidden W95 FAT1 80 Old Minix
Command (m for help): t
Partition number (1-7, default 7): 7
Hex code (type L to list all codes): l
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx
5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary
16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT
1e Hidden W95 FAT1 80 Old Minix
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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 label type: dos
Disk identifier: 0xeeb688bd
Device Boot Start End Blocks Id System
/dev/sdb1 2048 309247 153600 83 Linux
/dev/sdb2 309248 616447 153600 83 Linux
/dev/sdb3 616448 923647 153600 83 Linux
/dev/sdb4 923648 2097151 586752 5 Extended
/dev/sdb5 925696 1232895 153600 83 Linux
/dev/sdb6 1234944 1542143 153600 83 Linux
/dev/sdb7 1544192 2097151 276480 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
检查是否修改成功
[root@node ~]# 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): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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 label type: dos
Disk identifier: 0xeeb688bd
Device Boot Start End Blocks Id System
/dev/sdb1 2048 309247 153600 83 Linux
/dev/sdb2 309248 616447 153600 83 Linux
/dev/sdb3 616448 923647 153600 83 Linux
/dev/sdb4 923648 2097151 586752 5 Extended
/dev/sdb5 925696 1232895 153600 83 Linux
/dev/sdb6 1234944 1542143 153600 83 Linux
/dev/sdb7 1544192 2097151 276480 8e Linux LVM
如果分区成功了,一定要将分区信息通知到内核,要不然会报错。
[root@node ~]# partprobe /dev/sdb
#注意这一步一定要做
知识小扩展
dd命令创建一个虚拟的文件系统
[root@node ~]# dd if=/dev/sda of=/dev/sdc bs=512 count=10240
10240+0 records in
10240+0 records out
5242880 bytes (5.2 MB) copied, 0.396542 s, 13.2 MB/s
# dd if=/dev/sda of=/dev/sdc bs=512 count=10240
if=/dev/sda | of=/dev/sdc|bs=512|count=10240
---|---|---|---|---
文件系统来源 | 生成的文件系统|block大小|块个数
参考博客:https://www.cnblogs.com/ginvip/p/6370836.html
查看分区表信息也可以这样查看。
[root@node ~]# cat /proc/partitions
major minor #blocks name
8 0 20971520 sda
8 1 512000 sda1
8 2 20458496 sda2
8 16 1048576 sdb
8 17 153600 sdb1
8 18 153600 sdb2
8 19 153600 sdb3
8 20 1 sdb4
8 21 153600 sdb5
8 22 153600 sdb6
8 23 276480 sdb7
11 0 4481024 sr0
253 0 19406848 dm-0
253 1 1048576 dm-1
3)parted分区实战
首先删除我们用fdisk创建的分区
[root@node ~]# 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): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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 label type: dos
Disk identifier: 0xeeb688bd
Device Boot Start End Blocks Id System
/dev/sdb1 2048 309247 153600 83 Linux
/dev/sdb2 309248 616447 153600 83 Linux
/dev/sdb3 616448 923647 153600 83 Linux
/dev/sdb4 923648 2097151 586752 5 Extended
/dev/sdb5 925696 1232895 153600 83 Linux
/dev/sdb6 1234944 1542143 153600 83 Linux
/dev/sdb7 1544192 2097151 276480 83 Linux
Command (m for help): d
Partition number (1-7, default 7): 4
Partition 4 is deleted
Command (m for help): d
Partition number (1-3, default 3): 1
Partition 1 is deleted
Command (m for help): d
Partition number (2,3, default 3): 2
Partition 2 is deleted
Command (m for help): d
Selected partition 3
Partition 3 is deleted
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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 label type: dos
Disk identifier: 0xeeb688bd
Device Boot Start End Blocks Id System
Command (m for help): d
No partition is defined yet!
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@node ~]# partprobe /dev/sdb
#注意删除分区后也要这样做通知内核。
查看分区是否还存在
[root@node ~]# ll /dev/sdb*
brw-rw---- 1 root disk 8, 16 Apr 19 13:46 /dev/sdb
parted 开始分区
[root@node ~]# parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) help
align-check TYPE N check partition N for TYPE(min|opt) alignment
help [COMMAND] print general help, or help on COMMAND
mklabel,mktable LABEL-TYPE create a new disklabel #创建分区格式(常用gpt) (partition table)
mkpart PART-TYPE [FS-TYPE] START END make a partition #创建一个分区
name NUMBER NAME name partition NUMBER as NAME
print [devices|free|list,all|NUMBER] display the partition table, available devices, free space, all found partitions, or a
particular partition
quit exit program #退出
rescue START END rescue a lost partition near START and END
resizepart NUMBER END resize partition NUMBER
rm NUMBER delete partition NUMBER #删除分区
select DEVICE choose the device to edit
disk_set FLAG STATE change the FLAG on selected device
disk_toggle [FLAG] toggle the state of FLAG on selected device
set NUMBER FLAG STATE change the FLAG on partition NUMBER
toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER
unit UNIT set the default unit to UNIT
version display the version number and copyright information of GNU Parted
(parted) mklabel gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
(parted) mkpart primary 0 150
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? i
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 150MB 150MB primary
(parted) mkpart primary 150 300
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? i
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 150MB 150MB primary
2 150MB 300MB 150MB primary
(parted) mkpart primary 300 450
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? i
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 150MB 150MB primary
2 150MB 300MB 150MB primary
3 300MB 450MB 150MB primary
(parted) mkpart logic 451
End? 600
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 150MB 150MB primary
2 150MB 300MB 150MB primary
3 300MB 450MB 150MB primary
4 451MB 600MB 149MB logic
#parted不用创建扩展分区,就可以直接创建逻辑分区( fdisk不行)
(parted) mkpart logic 601 1000
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 150MB 150MB primary
2 150MB 300MB 150MB primary
3 300MB 450MB 150MB primary
4 451MB 600MB 149MB logic
5 601MB 1000MB 400MB logic
(parted) quit
#parted不用创建扩展分区,就可以直接创建逻辑分区( fdisk不行)
查看分区
[root@node ~]# ll /dev/sdb*
brw-rw---- 1 root disk 8, 16 Apr 19 14:52 /dev/sdb
brw-rw---- 1 root disk 8, 17 Apr 19 14:52 /dev/sdb1
brw-rw---- 1 root disk 8, 18 Apr 19 14:52 /dev/sdb2
brw-rw---- 1 root disk 8, 19 Apr 19 14:52 /dev/sdb3
brw-rw---- 1 root disk 8, 20 Apr 19 14:52 /dev/sdb4
brw-rw---- 1 root disk 8, 21 Apr 19 14:52 /dev/sdb5
上面的分区方式也可以直接命令行创建(便于写脚本)
[root@node ~]# parted /dev/sdb mklable gpt
[root@node ~]# parted /dev/sdb mklable primary 0 150 I
[root@node ~]# parted /dev/sdb mklable primary 150 300 I
[root@node ~]# parted /dev/sdb mklable primary 300 450 I
[root@node ~]# parted /dev/sdb mklable logic 451 600 I
[root@node ~]# parted /dev/sdb mklable logic 601 1000 I
[root@node ~]# parted /dev/sdb p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 150MB 150MB primary
2 150MB 300MB 150MB primary
3 300MB 450MB 150MB primary
4 451MB 600MB 149MB logic
5 601MB 1000MB 400MB logic
分区创建小结:
1、fdisk
1)fdisk分区对磁盘的容量是有要求的不能大于2个T,是修改MRB分区信息。
2)用fdisk分逻辑分区,必须先分一个扩展分区。
3)fdisk分区的信息是保存在内存当中的,没保存退出就会消失,W就会写入到硬盘。
4)分区完成记得 partprobe /dev/sdb 通知系统内核已修改的分区信息
2、parted
1)parted是GUN的一个分区工具,小于2T大于2T容量的磁盘都可以使用它来分区,是修改gpt分区信息。
2)parted分逻辑分区不像fdisk一样需要分区一个扩展分区,parted直接就可以分逻辑分区。
3)parted分区是直接写入到磁盘里的,所以要当心。
4)分区完成记得 partprobe /dev/sdb 通知系统内核已修改的分区信息
问题需求:
刚买来的服务器,4块2T磁盘,要做RAID5 安装系统怎么搞定?
1)服务器自带硬件raid里可以支持做完raid5之后,6T,允许你把6T分成虚拟磁盘。虚拟出一个200G的磁盘出来装系统,剩下的留着装完系统之后在用,(parted)。
2)装系统时,系统镜像支持GPT格式在分区界面选择GPT分区方式。很隐蔽
参考博文:https://blog.csdn.net/qq_38228830/article/details/88049801?depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-1&utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-1
3)引导工具,进入然后用parted分区
六、文件系统讲解及格式化分区挂载分区
文件系统是计算机存储和组织数据的方法或者机制。磁盘是物理介质,没有文件系统,无法存储数据。 磁盘需要文件系统来驱动,文件系统通过磁盘管理规划、存储数据。
6.1.1 文件系统的种类
Windows: NTFS、FAT32、MSDOS
Linux: ext2 ext3(C5) ext4(C6) xfs(C7)
6.1.2 格式化分区并挂载
格式化分区的本质就是创建文件系统
[root@node ~]# mkfs -t ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
51200 inodes, 204800 blocks
10240 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=33816576
25 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
也可以这么写
[root@node ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
51200 inodes, 204800 blocks
10240 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=33816576
25 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
挂载格式化好的文件系统
[root@node /]# mkdir /mnt/data -p
[root@node /]# ls -l /mnt/data
total 0
[root@node /]# mount /dev/sdb1 /mnt/data/
[root@node /]# ls -l /mnt/data/
total 12
drwx------ 2 root root 12288 Apr 19 17:07 lost+found
[root@node /]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 979M 5.0M 974M 1% /dev
tmpfs 991M 0 991M 0% /dev/shm
tmpfs 991M 9.6M 981M 1% /run
tmpfs 991M 0 991M 0% /sys/fs/cgroup
/dev/mapper/centos_node-root 19G 2.1G 17G 12% /
/dev/sda1 497M 156M 342M 32% /boot
tmpfs 199M 0 199M 0% /run/user/0
/dev/sdb1 190M 1.6M 175M 1% /mnt/data
[root@node /]# cat /proc/mounts
rootfs / rootfs rw 0 0
sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
devtmpfs /dev devtmpfs rw,nosuid,size=1002068k,nr_inodes=250517,mode=755 0 0
securityfs /sys/kernel/security securityfs rw,nosuid,nodev,noexec,relatime 0 0
tmpfs /dev/shm tmpfs rw,nosuid,nodev 0 0
devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
tmpfs /run tmpfs rw,nosuid,nodev,mode=755 0 0
tmpfs /sys/fs/cgroup tmpfs ro,nosuid,nodev,noexec,mode=755 0 0
cgroup /sys/fs/cgroup/systemd cgroup rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd 0 0
pstore /sys/fs/pstore pstore rw,nosuid,nodev,noexec,relatime 0 0
cgroup /sys/fs/cgroup/cpu,cpuacct cgroup rw,nosuid,nodev,noexec,relatime,cpuacct,cpu 0 0
cgroup /sys/fs/cgroup/net_cls,net_prio cgroup rw,nosuid,nodev,noexec,relatime,net_prio,net_cls 0 0
cgroup /sys/fs/cgroup/perf_event cgroup rw,nosuid,nodev,noexec,relatime,perf_event 0 0
cgroup /sys/fs/cgroup/cpuset cgroup rw,nosuid,nodev,noexec,relatime,cpuset 0 0
cgroup /sys/fs/cgroup/freezer cgroup rw,nosuid,nodev,noexec,relatime,freezer 0 0
cgroup /sys/fs/cgroup/memory cgroup rw,nosuid,nodev,noexec,relatime,memory 0 0
cgroup /sys/fs/cgroup/blkio cgroup rw,nosuid,nodev,noexec,relatime,blkio 0 0
cgroup /sys/fs/cgroup/devices cgroup rw,nosuid,nodev,noexec,relatime,devices 0 0
cgroup /sys/fs/cgroup/pids cgroup rw,nosuid,nodev,noexec,relatime,pids 0 0
cgroup /sys/fs/cgroup/hugetlb cgroup rw,nosuid,nodev,noexec,relatime,hugetlb 0 0
configfs /sys/kernel/config configfs rw,relatime 0 0
/dev/mapper/centos_node-root / xfs rw,relatime,attr2,inode64,noquota 0 0
systemd-1 /proc/sys/fs/binfmt_misc autofs rw,relatime,fd=33,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=13878 0 0
hugetlbfs /dev/hugepages hugetlbfs rw,relatime 0 0
mqueue /dev/mqueue mqueue rw,relatime 0 0
debugfs /sys/kernel/debug debugfs rw,relatime 0 0
/dev/sda1 /boot xfs rw,relatime,attr2,inode64,noquota 0 0
tmpfs /run/user/0 tmpfs rw,nosuid,nodev,relatime,size=202796k,mode=700 0 0
/dev/sdb1 /mnt/data ext4 rw,relatime,data=ordered 0 0
开机自动挂载磁盘
[root@node /]# echo "/dev/sdb1 /mnt/data ext4 defaults 0 0" >>/etc/fstab
强制卸载命令
[root@node /mnt/data]# umount -lf /mnt/data/
[root@node /mnt/data]# ls -l /mnt/data/
total 0
#在挂载目录下使用此命令
[root@node /]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 979M 5.0M 974M 1% /dev
tmpfs 991M 0 991M 0% /dev/shm
tmpfs 991M 9.6M 981M 1% /run
tmpfs 991M 0 991M 0% /sys/fs/cgroup
/dev/mapper/centos_node-root 19G 2.1G 17G 12% /
/dev/sda1 497M 156M 342M 32% /boot
tmpfs 199M 0 199M 0% /run/user/0
现在我们可以使用这个分区了,创建一个文件
[root@node /]# touch /mnt/data/linux.log
[root@node /]# ls -l /mnt/data/linux.log
-rw-r--r-- 1 root root 0 Apr 19 17:22 /mnt/data/linux.log
[root@node /]# mount /dev/sdb2 /mnt/data/
[root@node /]# ls -l /mnt/data/
total 0
[root@node /]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 979M 5.0M 974M 1% /dev
tmpfs 991M 0 991M 0% /dev/shm
tmpfs 991M 9.6M 981M 1% /run
tmpfs 991M 0 991M 0% /sys/fs/cgroup
/dev/mapper/centos_node-root 19G 2.1G 17G 12% /
/dev/sda1 497M 156M 342M 32% /boot
tmpfs 199M 0 199M 0% /run/user/0
/dev/sdb2 197M 11M 187M 6% /mnt/data
[root@node /]# cat /proc/mounts
rootfs / rootfs rw 0 0
sysfs /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
devtmpfs /dev devtmpfs rw,nosuid,size=1002068k,nr_inodes=250517,mode=755 0 0
securityfs /sys/kernel/security securityfs rw,nosuid,nodev,noexec,relatime 0 0
tmpfs /dev/shm tmpfs rw,nosuid,nodev 0 0
devpts /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
tmpfs /run tmpfs rw,nosuid,nodev,mode=755 0 0
tmpfs /sys/fs/cgroup tmpfs ro,nosuid,nodev,noexec,mode=755 0 0
cgroup /sys/fs/cgroup/systemd cgroup rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd 0 0
pstore /sys/fs/pstore pstore rw,nosuid,nodev,noexec,relatime 0 0
cgroup /sys/fs/cgroup/cpu,cpuacct cgroup rw,nosuid,nodev,noexec,relatime,cpuacct,cpu 0 0
cgroup /sys/fs/cgroup/net_cls,net_prio cgroup rw,nosuid,nodev,noexec,relatime,net_prio,net_cls 0 0
cgroup /sys/fs/cgroup/perf_event cgroup rw,nosuid,nodev,noexec,relatime,perf_event 0 0
cgroup /sys/fs/cgroup/cpuset cgroup rw,nosuid,nodev,noexec,relatime,cpuset 0 0
cgroup /sys/fs/cgroup/freezer cgroup rw,nosuid,nodev,noexec,relatime,freezer 0 0
cgroup /sys/fs/cgroup/memory cgroup rw,nosuid,nodev,noexec,relatime,memory 0 0
cgroup /sys/fs/cgroup/blkio cgroup rw,nosuid,nodev,noexec,relatime,blkio 0 0
cgroup /sys/fs/cgroup/devices cgroup rw,nosuid,nodev,noexec,relatime,devices 0 0
cgroup /sys/fs/cgroup/pids cgroup rw,nosuid,nodev,noexec,relatime,pids 0 0
cgroup /sys/fs/cgroup/hugetlb cgroup rw,nosuid,nodev,noexec,relatime,hugetlb 0 0
configfs /sys/kernel/config configfs rw,relatime 0 0
/dev/mapper/centos_node-root / xfs rw,relatime,attr2,inode64,noquota 0 0
systemd-1 /proc/sys/fs/binfmt_misc autofs rw,relatime,fd=33,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=13878 0 0
hugetlbfs /dev/hugepages hugetlbfs rw,relatime 0 0
mqueue /dev/mqueue mqueue rw,relatime 0 0
debugfs /sys/kernel/debug debugfs rw,relatime 0 0
/dev/sda1 /boot xfs rw,relatime,attr2,inode64,noquota 0 0
tmpfs /run/user/0 tmpfs rw,nosuid,nodev,relatime,size=202796k,mode=700 0 0
/dev/sdb2 /mnt/data xfs rw,relatime,attr2,inode64,noquota 0 0
创建一个文件
[root@node /]# touch /mnt/data/centos.log
[root@node /]# ls -l /mnt/data/centos.log
-rw-r--r-- 1 root root 0 Apr 19 18:29 /mnt/data/centos.log
我们在格式分区的时候还可以指定block和inode大小。
[root@node /]# mkfs -t ext4 -b 4096 -I 512 /dev/sdb3
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
5120 inodes, 5120 blocks
256 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=6291456
1 block group
32768 blocks per group, 32768 fragments per group
5120 inodes per group
Allocating group tables: done
Writing inode tables: done
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done
查看格式化后的信息
[root@node /]# dumpe2fs /dev/sdb3 | egrep -i "size"
dumpe2fs 1.42.9 (28-Dec-2013)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Block size: 4096
Fragment size: 4096
Group descriptor size: 64
Flex block group size: 16
Inode size: 512
Required extra isize: 28
Desired extra isize: 28
Journal size: 4096k
查看设备id
[root@node /]# blkid
/dev/sda1: UUID="c436d5ae-9e2b-4212-b5d8-5028b8920ebe" TYPE="xfs"
/dev/sda2: UUID="rWdTZp-7OuX-j3KT-EEP5-Q8ip-qZHm-chpR3L" TYPE="LVM2_member"
/dev/sdb1: UUID="3e7066e3-75bf-45d2-b5bd-8934cadfa729" TYPE="ext4"
/dev/sdb2: UUID="62eaa0ca-27c9-4a97-a035-17e41c2f55a9" TYPE="xfs"
/dev/sr0: UUID="2018-11-25-23-54-16-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
/dev/mapper/centos_node-root: UUID="ca17e9a2-3496-40d8-9e9b-29b6917330f5" TYPE="xfs"
/dev/mapper/centos_node-swap: UUID="2890e826-8abe-43ac-88f5-d4e089338894" TYPE="swap"
磁盘检查和修复命令fsck
不能对好的磁盘使用该命令,防止磁盘损坏。操作的时候要卸载挂载点在操作。
1、针对ext文件系统的修复
[root@node /]# fsck -a /dev/sdb1
e2fsck 1.42.9 (28-Dec-2013)
/dev/sdb1: clean, 12/51200 files, 12115/204800 blocks
2、针对xfs文件系统的修复
xfs_repair命令是xfs文件系统检查和修复命令。
[root@node /]# xfs_repair /dev/sdb2
Phase 1 - find and verify superblock...
Phase 2 - using internal log
- zero log...
- scan filesystem freespace and inode maps...
- found root inode chunk
Phase 3 - for each AG...
- scan and clear agi unlinked lists...
- process known inodes and perform inode discovery...
- agno = 0
- agno = 1
- agno = 2
- agno = 3
- process newly discovered inodes...
Phase 4 - check for duplicate blocks...
- setting up duplicate extent list...
- check for inodes claiming duplicate blocks...
- agno = 0
- agno = 1
- agno = 2
- agno = 3
Phase 5 - rebuild AG headers and trees...
- reset superblock...
Phase 6 - check inode connectivity...
- resetting contents of realtime bitmap and summary inodes
- traversing filesystem ...
- traversal finished ...
- moving disconnected inodes to lost+found ...
Phase 7 - verify and correct link counts...
done
swap分区扩展
swap的作用是当内存不够的时候,用来冲当内存,一般为内存的1.5倍。内存大于8G就给8G。
[root@node /]# free -m
total used free shared buff/cache available
Mem: 1980 195 1619 14 165 1622
Swap: 1023 0 1023
[root@node /]# ls -l /dev/sdb*
brw-rw---- 1 root disk 8, 16 Apr 19 16:57 /dev/sdb
brw-rw---- 1 root disk 8, 17 Apr 19 19:43 /dev/sdb1
brw-rw---- 1 root disk 8, 18 Apr 19 19:45 /dev/sdb2
brw-rw---- 1 root disk 8, 19 Apr 19 20:02 /dev/sdb3
brw-rw---- 1 root disk 8, 20 Apr 19 16:57 /dev/sdb4
brw-rw---- 1 root disk 8, 21 Apr 19 20:10 /dev/sdb5
brw-rw---- 1 root disk 8, 22 Apr 19 16:57 /dev/sdb6
[root@node /]# mkswap /dev/sdb6
Setting up swapspace version 1, size = 410620 KiB
no label, UUID=929a819b-95af-4f51-bc62-a3814b043d84
#格式化成swap格式
[root@node /]# swapon /dev/sdb6
#挂载swap分区
[root@node /]# free -m
total used free shared buff/cache available
Mem: 1980 196 1618 14 165 1621
Swap: 1424 0 1424
#结果多了400m的容量
第二种方法:
[root@node /]# dd if=/dev/zero of=/swapfile bs=512 count=204800
204800+0 records in
204800+0 records out
104857600 bytes (105 MB) copied, 2.30139 s, 45.6 MB/s
[root@node ~]# mkswap /swapfile
[root@node ~]# chmod 0600 /swapfile
[root@node ~]# swapon /swapfile
[root@node ~]# free -m
total used free shared buff/cache available
Mem: 1980 160 1711 9 108 1687
Swap: 1123 0 1123