【运维知识基础篇】Linux磁盘管理(一)

简介: 【运维知识基础篇】Linux磁盘管理

磁盘是存放数据的地方,我们需要学会去管理,添加磁盘,磁盘分区,磁盘格式化,磁盘挂载等等,简单讲下。


磁盘结构(了解)

1.磁盘外部结构:

磁盘分类:
机械磁盘(机械硬盘)   像个砖头,在台式机里,3.5英寸大小,通过机械运动达到读写数据的作用
固态磁盘              是芯片式的
NVME磁盘             M.2磁盘 PCI-E 类似显卡 像内存条
接口类型及转速决定了读写速度
IDE接口   已经淘汰了 很多针,有插电源的地方
SCSI接口  笔记本 台式机 不常用
STAT接口  笔记本 台式机 左边数据线右边电源线 中间有豁口 7200转/10k转
SAS接口   多出来一块 服务器标配 7.2k 10k 15k
15k/分钟最大储存 900G(能达到15k转) 600G(用的居多,600*8或者600*4) 300G
做备份的服务器,只管空间大,2T 4T*8
磁盘大小:3.5英寸 2.5英寸(笔记本磁盘,可以多插几个)
PCI-E     白色插槽,可以插外接独立声卡

fdisk -l 可以查看磁盘扇区总扇区数乘以一个扇区磁盘大小就是磁盘大小,磁盘以1000为1个单位

与1024不一样

raid逻辑的将磁盘组合在一起,可以增加容量,也可以提高性能

注重安全速度就慢,注重速度安全性就低

常用raid级别及应用场景

服务器磁盘先连接到raid卡上,再连接主板
raid0    最高的存储性能 磁盘容量不浪费,读写很快
要制作raid0 至少需要一块磁盘
任何一块硬盘损坏,所有数据无法使用
raid1    可以损失一半的数据容量
raid只能两块磁盘
不能提示存储性能,但会更安全,理论上写性能和单盘相差不大
raid5    可以损失一块盘的容量 
安全性最多可以损坏一块磁盘,也可以用热备盘,这样可以最多坏两个了
写入性能不好,读取速度ok
raid10   先将两块盘组成raid1,再将raid1组成raid0 
可以损坏所有硬盘一半的容量,也看损失的是不是一样的数据
读写很快
raid01就反过来,raid01可以损失一边的
企业中用0和5最多

磁盘分区

MBR格式
一个磁盘最多分四个,扩展分区最多一个,基于扩展分区划分逻辑分区
三个主分区+一个扩展分区+逻辑分区第五个开始
主分区:直接对磁盘进行格式化的分区,可以直接存储进去,速度也是最快
逻辑分区:扩展分区无法使用,基于逻辑分区划分逻辑分区。正常放数据,但是速度会慢
GPT格式
最多支持128个主分区
MBR格式和GPT格式分区区别
MBR格式对于小于2T的磁盘进行分区 使用fdisk分区
GPT格式对于大于2T的磁盘进行分区 使用parted分区
磁盘分区的设备名称
第一块磁盘:sda
第二块磁盘:sdb
         ......
第一块磁盘的第一个主分区:sda1
第一块磁盘的第二个主分区:sda2
第一块磁盘的第二个主分区:sda3
第一块磁盘的第一个扩展分区:sda4
第一块磁盘的第一个逻辑分区:ada5

磁盘挂载模拟流程

Linux系统的硬件必须通过挂载的方式才可以访问

默认无法读取硬件,类似于没有窗户没有门的监狱 进不去也出不来

创建目录挂载,只是创建了目录,给硬件提供一个入口

示例1:挂载cdrom
第一步:把镜像文件插入到DVD(装系统已经插进去了)
第二步:查看dev下的cdrom
第三步:直接将cdrom挂载到临时的挂载点
[root@VMware-koten ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only #提示被保护,不能写
[root@VMware-koten ~]#
查看挂载信息
[root@VMware-koten Packages]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        980M     0  980M   0% /dev
tmpfs           991M     0  991M   0% /dev/shm
tmpfs           991M  9.5M  981M   1% /run
tmpfs           991M     0  991M   0% /sys/fs/cgroup
/dev/sda3        19G  2.0G   17G  11% /
/dev/sda1       197M  110M   88M  56% /boot
tmpfs           199M     0  199M   0% /run/user/0
/dev/sr0        4.4G  4.4G     0 100% /mnt
[root@VMware-koten Packages]# 
第四步:通过mnt进入cdrom查看里面的内容
第五步:不想用了卸载,记得先出来这个门
[root@VMware-koten Packages]# umount /mnt/
umount: /mnt: target is busy.#目标忙,因为在门里
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))
[root@VMware-koten Packages]# cd
[root@VMware-koten ~]# umount /mnt/
[root@VMware-koten ~]# ll /mnt/
total 0        #卸载成功
[root@VMware-koten ~]# 
注意:挂载的目录下面会有内容隐藏,卸载后会再显示,不影响使用,但是最好用新目录

磁盘挂载

第一步:虚拟机右键设置,添加磁盘,设置大小512MB

第二步:添加完成后重启系统

注意:

vmware添加磁盘需要重启

企业中使用硬件服务器插入磁盘不需要重启 支持热插拔

云服务器不需要重启

第三步,使用fdisk -l查看

[root@VMware-koten ~]# 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: 0x000eee9b
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      411647      204800   83  Linux
/dev/sda2          411648     2508799     1048576   82  Linux swap / Solaris
/dev/sda3         2508800    41943039    19717120   83  Linux
Disk /dev/sdb: 536 MB, 536870912 bytes, 1048576 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@VMware-koten ~]# 

第四步:对磁盘进行分区,不分区不让挂载

[root@VMware-koten ~]# 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 0x21168715.
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          #改变分区格式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): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p                       #选择创建分区 p默认位主分区
Partition number (1-4, default 1): 1        #主分区的编号
First sector (2048-1048575, default 2048):  #直接回车默认开始的扇区
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-1048575, default 1048575): +100M
Partition 1 of type Linux and of size 100 MiB is set
Command (m for help): p #查看分区表
Disk /dev/sdb: 536 MB, 536870912 bytes, 1048576 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 #MBR格式
Disk identifier: 0x21168715
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048      206847      102400   83  Linux
Command (m for help):
省略创建三个主分区
......
删除第四个主分区
Command (m for help): d
Partition number (1-4, default 4): 
Partition 4 is deleted
Command (m for help): 
给第四个创建扩展分区
Command (m for help): n
Partition type:
   p   primary (3 primary, 0 extended, 1 free)
   e   extended
Select (default e): 
Using default response e
Selected partition 4
First sector (616448-1048575, default 616448): 
Using default value 616448
Last sector, +sectors or +size{K,M,G} (616448-1048575, default 1048575): +100M
Partition 4 of type Extended and of size 100 MiB is set
Command (m for help): p
Disk /dev/sdb: 536 MB, 536870912 bytes, 1048576 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: 0x21168715
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048      206847      102400   83  Linux
/dev/sdb2          206848      411647      102400   83  Linux
/dev/sdb3          411648      616447      102400   83  Linux
/dev/sdb4          616448      821247      102400    5  Extended
Command (m for help): 
[root@VMware-koten ~]# 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: 0x000eee9b
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      411647      204800   83  Linux
/dev/sda2          411648     2508799     1048576   82  Linux swap / Solaris
/dev/sda3         2508800    41943039    19717120   83  Linux
Disk /dev/sdb: 536 MB, 536870912 bytes, 1048576 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: 0x21168715
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048      206847      102400   83  Linux
/dev/sdb2          206848      411647      102400   83  Linux
/dev/sdb3          411648      616447      102400   83  Linux
/dev/sdb4          616448      821247      102400    5  Extended
[root@VMware-koten ~]# 

第五步:格式化磁盘(相当于打扫卫生)

使用mkfs.xfs

[root@VMware-koten ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=6400 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=25600, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=855, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@VMware-koten ~]# 

第六步:挂载使用磁盘

mount /dev/sdb1 /mnt

[root@VMware-koten ~]# mount /dev/sdb1 /mnt
[root@VMware-koten mnt]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        980M     0  980M   0% /dev
tmpfs           991M     0  991M   0% /dev/shm
tmpfs           991M  9.5M  981M   1% /run
tmpfs           991M     0  991M   0% /sys/fs/cgroup
/dev/sda3        19G  2.0G   17G  11% /
/dev/sda1       197M  110M   88M  56% /boot
tmpfs           199M     0  199M   0% /run/user/0
/dev/sdb1        97M  5.3M   92M   6% /mnt
[root@VMware-koten mnt]# 
目录
相关文章
|
8月前
|
存储 监控 Linux
Linux: 检测磁盘坏块 你得会吧!
Linux: 检测磁盘坏块 你得会吧!
514 19
Linux: 检测磁盘坏块 你得会吧!
|
7月前
|
Linux
在线对Linux进行磁盘扩容的技术指南。
综上所述,Linux磁盘扩容的过程,重要的不仅是技术,更是对每一步骤的深刻理解和投入的爱心。只要手握正确的工具,我们不仅能满足"孩子"的成长需求,还能享受其中的乐趣和成就。
485 10
|
8月前
|
监控 固态存储 Linux
如何判断Linux磁盘是SSD还是HDD?
总的来说,判断磁盘是SSD还是HDD并不复杂,只需要使用正确的命令和方法,就可以轻松得到结果。希望这些信息对你有所帮助,如果你还有其他问题,欢迎随时提问。
810 15
|
8月前
|
运维 安全 Linux
试试Linux设备命令行运维工具——Wowkey
WowKey 是一款专为 Linux 设备设计的命令行运维工具,提供自动化、批量化、标准化、简单化的运维解决方案。它简单易用、高效集成且无依赖,仅需 WIS 指令剧本文件、APT 账号密码文件和 wowkey 命令即可操作。通过分离鉴权内容与执行内容,WowKey 让运维人员专注于决策,摆脱繁琐的交互与执行细节工作,大幅提升运维效率与质量。无论是健康检查、数据采集还是配置更新,WowKey 都能助您轻松应对大规模设备运维挑战。立即从官方资源了解更多信息:https://atsight.top/training。
|
8月前
|
数据采集 运维 安全
Linux设备命令行运维工具WowKey问答
WowKey 是一款用于 Linux 设备运维的工具,可通过命令行手动或自动执行指令剧本,实现批量、标准化操作,如健康检查、数据采集、配置更新等。它简单易用,只需编写 WIS 指令剧本和 APT 帐号密码表文件,学习成本极低。支持不同流派的 Linux 系统,如 RHEL、Debian、SUSE 等,只要使用通用 Shell 命令即可通吃Linux设备。
|
9月前
|
Linux
Linux系统ext4磁盘扩容实践指南
这个过程就像是给你的房子建一个新的储物间。你需要先找到空地(创建新的分区),然后建造储物间(格式化为ext4文件系统),最后将储物间添加到你的房子中(将新的分区添加到文件系统中)。完成这些步骤后,你就有了一个更大的储物空间。
871 10
|
11月前
|
Ubuntu Linux 网络安全
Linux磁盘挂接教程
Linux磁盘挂接教程
209 14
|
11月前
|
存储 运维 安全
深入解析操作系统控制台:阿里云Alibaba Cloud Linux(Alinux)的运维利器
本文将详细介绍阿里云的Alibaba Cloud Linux操作系统控制台的功能和优势。
365 6
|
12月前
|
Prometheus 运维 监控
Prometheus+Grafana+NodeExporter:构建出色的Linux监控解决方案,让你的运维更轻松
本文介绍如何使用 Prometheus + Grafana + Node Exporter 搭建 Linux 主机监控系统。Prometheus 负责收集和存储指标数据,Grafana 用于可视化展示,Node Exporter 则采集主机的性能数据。通过 Docker 容器化部署,简化安装配置过程。完成安装后,配置 Prometheus 抓取节点数据,并在 Grafana 中添加数据源及导入仪表盘模板,实现对 Linux 主机的全面监控。整个过程简单易行,帮助运维人员轻松掌握系统状态。
1889 3
|
运维 监控 网络协议

热门文章

最新文章