当前位置: 首页 > news >正文

第八章 磁盘管理未完待续

1.磁盘管理

磁盘简介

名词:磁盘/硬盘/disk

存储设备类型从工作原理区分

  • 机械
    机械硬盘即是传统普通硬盘,主要由:盘片,磁头,盘片转轴及
    控制电机,磁头控制器,数据转换器,接口,缓存等几个部分组
    成。
    磁道大小4K

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

  • 固态
    固态驱动器(Solid State Disk或Solid State Drive,简称SSD),
    俗称固态硬盘,固态硬盘是用固态电子存储芯片阵列而制成的硬

    在这里插入图片描述
    尺寸 3.5 、2.5 、1.8英寸
    磁盘接口类型
    (1) SATA(Serial ATA)
    类型:串行接口(替代旧式并行IDE接口)
    在这里插入图片描述

(2) SAS(Serial Attached SCSI)
类型:企业级串行接口(兼容SATA设备)
在这里插入图片描述

(3) NVMe(Non-Volatile Memory Express)
类型:基于PCIe通道的协议(非物理接口)
在这里插入图片描述

(4) IDE(PATA,已淘汰)
类型:并行接口(旧式)
在这里插入图片描述

(5) SCSI(Small Computer System Interface,逐渐淘汰)
类型:并行/串行接口(企业级)
在这里插入图片描述

转速 5400/7200/10000/15000rpm

厂商: 西部数据/希捷(美国) 三星(韩国) 日立/金士顿(日本)

术语

  • 盘片
    一块硬盘有若干盘片,每个盘片有可以存储数据的上、下两盘面
    (Side)。这些盘面堆叠在主轴上高速旋转,它们从上至下从“0”开
    始依次编号。

  • 磁道
    每个盘面被划分成许多同心圆,这些同心圆轨迹叫做磁道;磁道从
    外向内从0开始顺序编号。

  • 扇区
    将一个盘面划分为若干内角相同的扇形,这样盘面上的每个磁道就
    被分为若干段圆弧,每段圆弧叫做一个扇区。每个扇区中的数据作
    为一个单元同时读出或写入。硬盘的第一个扇区,叫做引导扇区。

  • 扇面
    同一角度的扇区被叫扇面

  • 柱面
    所有盘面上的同一磁道构成一个圆柱,称作柱面


  • 块(簇)是 操作系统与磁盘(硬盘)交互的最小数据单元(在linux系统中称为块,在windows系统中称为簇)。操作系统从硬盘中拿一块数据,即完成一次磁盘IO。
    在这里插入图片描述
    kernel对不同接口硬盘命名方式
    RHEL9/centos9

  • IDE(并口)
    /dev/hda
    /dev/hdb

  • SATA(串口)
    /dev/sda
    /dev设备文件目录
    sda是一个文件
    s代表sata就是串口
    d代表磁盘
    a第一块
    /dev/sdb 表示第二块

磁盘分区类型
MBR
主引导记录(MBR,Master Boot Record)是位于磁盘最前边的
一段引导
MBR支持最大的磁盘容量是 <2TB。设计时分配4个分区
如果希望超过4个分区,需放弃主分区,改为扩展分区和逻辑分
区。
fdisk命令

GPT
全局唯一标识分区表(GUIDPartition Table,缩写:GPT)是一
个实体硬盘的分区表的结构布局的标准。
GPT 支持大于2T的硬盘,支持128个分区
gdisk命令

添加磁盘
VMWARE增加磁盘
先关闭虚拟机电源
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
管理磁盘流程三部曲
新硬盘
分区(MBR或者GPT) ---->格式化/文件系统 Filesystem ----> 挂载
mount
毛坯房
隔间-----------> 放家具/打造格子柜----------------> 加个门/目录

1.查看磁盘信息
方法1

[root@station ~]# ll /dev/sd*
brw-rw----. 1 root disk 8,  0 Apr 29 23:11 /dev/sda
brw-rw----. 1 root disk 8, 16 Apr 29 23:11 /dev/sdb
[root@station ~]# ll /dev/nvme0*
crw-------. 1 root root 241, 0 Apr 29 23:11 /dev/nvme0
brw-rw----. 1 root disk 259, 0 Apr 29 23:11 /dev/nvme0n1
brw-rw----. 1 root disk 259, 1 Apr 29 23:11 /dev/nvme0n1p1
brw-rw----. 1 root disk 259, 2 Apr 29 23:11 /dev/nvme0n1p2
brw-rw----. 1 root disk 259, 3 Apr 29 23:11 /dev/nvme0n1p3

c(字符设备,Character Device)
b(块设备,Block Device)

方法2

[root@station ~]# lsblk
NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda             8:0    0    5G  0 disk 
sdb             8:16   0    5G  0 disk 
sr0            11:0    1 1024M  0 rom  
nvme0n1       259:0    0  100G  0 disk 
├─nvme0n1p1   259:1    0  600M  0 part /boot/efi
├─nvme0n1p2   259:2    0    1G  0 part /boot
└─nvme0n1p3   259:3    0 98.4G  0 part └─rhel-root 253:0    0 98.4G  0 lvm  /

名称 设备类型 序号 是否可移动设备 大小 是否只读 磁盘或分区
挂载点

[root@station ~]# fdisk /dev/sdaWelcome to fdisk (util-linux 2.37.4).
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.
Created a new DOS disklabel with disk identifier 0x258c5ad5.Command (m for help): mHelp:DOS (MBR)a   toggle a bootable flagb   edit nested BSD disklabelc   toggle the dos compatibility flagGenericd   delete a partitionF   list free unpartitioned spacel   list known partition typesn   add a new partitionp   print the partition tablet   change a partition typev   verify the partition tablei   print information about a partitionMiscm   print this menuu   change display/entry unitsx   extra functionality (experts only)ScriptI   load disk layout from sfdisk script fileO   dump disk layout to sfdisk script fileSave & Exitw   write table to disk and exitq   quit without saving changesCreate a new labelg   create a new empty GPT partition tableG   create a new empty SGI (IRIX) partition tableo   create a new empty DOS partition tables   create a new empty Sun partition tableCommand (m for help): n
Partition typep   primary (0 primary, 0 extended, 4 free)e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-10485759, default 2048): ## 一个扇区 = 512KB
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-10485759, default 10485759): +1GCreated a new partition 1 of type 'Linux' and of size 1 GiB.Command (m for help): P
P: unknown commandCommand (m for help): pDisk /dev/sda: 5 GiB, 5368709120 bytes, 10485760 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x258c5ad5Device     Boot Start     End Sectors Size Id Type
/dev/sda1        2048 2099199 2097152   1G 83 LinuxCommand (m for help): n
Partition typep   primary (1 primary, 0 extended, 3 free)e   extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (2099200-10485759, default 2099200): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2099200-10485759, default 10485759): +1GCreated a new partition 2 of type 'Linux' and of size 1 GiB.Command (m for help): p
Disk /dev/sda: 5 GiB, 5368709120 bytes, 10485760 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x258c5ad5Device     Boot   Start     End Sectors Size Id Type
/dev/sda1          2048 2099199 2097152   1G 83 Linux
/dev/sda2       2099200 4196351 2097152   1G 83 LinuxCommand (m for help): n
Partition typep   primary (2 primary, 0 extended, 2 free)e   extended (container for logical partitions)
Select (default p): Using default response p.
Partition number (3,4, default 3): 
First sector (4196352-10485759, default 4196352): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (4196352-10485759, default 10485759): +1GCreated a new partition 3 of type 'Linux' and of size 1 GiB.Command (m for help): p
Disk /dev/sda: 5 GiB, 5368709120 bytes, 10485760 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x258c5ad5Device     Boot   Start     End Sectors Size Id Type
/dev/sda1          2048 2099199 2097152   1G 83 Linux
/dev/sda2       2099200 4196351 2097152   1G 83 Linux
/dev/sda3       4196352 6293503 2097152   1G 83 LinuxCommand (m for help): n # 新建分区
Partition typep   primary (3 primary, 0 extended, 1 free)e   extended (container for logical partitions)
Select (default e): p #p主分区  e扩展分区Selected partition 4
First sector (6293504-10485759, default 6293504): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (6293504-10485759, default 10485759): +1GCreated a new partition 4 of type 'Linux' and of size 1 GiB.Command (m for help): p # 打印分区信息
Disk /dev/sda: 5 GiB, 5368709120 bytes, 10485760 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x258c5ad5Device     Boot   Start     End Sectors Size Id Type
/dev/sda1          2048 2099199 2097152   1G 83 Linux
/dev/sda2       2099200 4196351 2097152   1G 83 Linux
/dev/sda3       4196352 6293503 2097152   1G 83 Linux
/dev/sda4       6293504 8390655 2097152   1G 83 LinuxCommand (m for help): w # w保存分区信息,自动退出分区工具
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.# 刷新分区表
[root@station ~]# partprobe /dev/sda
# 查看分区结果
[root@station ~]# fdisk -l /dev/sda
Disk /dev/sda: 5 GiB, 5368709120 bytes, 10485760 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x258c5ad5Device     Boot   Start     End Sectors Size Id Type
/dev/sda1          2048 2099199 2097152   1G 83 Linux
/dev/sda2       2099200 4196351 2097152   1G 83 Linux
/dev/sda3       4196352 6293503 2097152   1G 83 Linux
/dev/sda4       6293504 8390655 2097152   1G 83 Linux[root@station ~]# lsblk
NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda             8:0    0    5G  0 disk 
├─sda1          8:1    0    1G  0 part 
├─sda2          8:2    0    1G  0 part 
├─sda3          8:3    0    1G  0 part 
└─sda4          8:4    0    1G  0 part 
sdb             8:16   0    5G  0 disk 
sr0            11:0    1 1024M  0 rom  
nvme0n1       259:0    0  100G  0 disk 
├─nvme0n1p1   259:1    0  600M  0 part /boot/efi
├─nvme0n1p2   259:2    0    1G  0 part /boot
└─nvme0n1p3   259:3    0 98.4G  0 part └─rhel-root 253:0    0 98.4G  0 lvm  /# 创建文件系统
[root@station ~]# mkfs.ext4 /dev/sda1
mke2fs 1.46.5 (30-Dec-2021)
Creating filesystem with 262144 4k blocks and 65536 inodes
Filesystem UUID: f47827c9-7275-4a9d-bf7b-6a567a8c96ba
Superblock backups stored on blocks: 32768, 98304, 163840, 229376Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
[root@station ~]# mkfs.ext4 /dev/sda2
[root@station ~]# mkfs.ext4 /dev/sda3
[root@station ~]# mkfs.ext4 /dev/sda4# 挂载mount 
## 手动挂载
## 创建挂载点,一个分区一个挂载点
[root@station ~]# mkdir /mnt/disk1
# -t ext4指定文件系统类型,最好加上,增强可读性
[root@station ~]# mount -t ext4 /dev/sda1 /mnt/disk1# 查看挂载信息
## 方法1 df -hT
[root@station ~]# df -Th
Filesystem            Type      Size  Used Avail Use% Mounted on
/dev/sda1             ext4      974M   24K  907M   1% /mnt/disk1## 方法2 mount
[root@station ~]#  mount
/dev/sda1 on /mnt/disk1 type ext4 (rw,relatime,seclabel)
# mount 看的是磁盘有没有特殊属性,具体属性在后续讲解。

相关文章:

  • 数据库中常用的窗口函数
  • neo4j基础操作:命令行增删改查
  • 从SOA到微服务:架构演进之路与实践示例
  • 外部存储器接口:EMIF总线
  • 中国人工智能发展战略与个体发展机遇研究
  • 分词概念,中英文不同语言分词原理,以及中文分词的所有方法(基于词典匹配的分词方法、 基于语义理解的分词方法、 基于词频统计的分词方法)
  • CentOS上搭建 Python 运行环境并使用第三方库
  • Qt5与现代OpenGL学习(三)纹理
  • Android 实现一个隐私弹窗
  • c网络库libevent的http常用函数的使用(附带源码)
  • 打造惊艳的渐变色下划线动画:CSS实现详解
  • Kotlin -> lateinit 和 lazy 详解
  • 聚焦智能体未来,领驭科技在微软创想未来峰会大放异彩
  • 按键精灵安卓ios辅助工具脚本:实用的文件插件(lua开源)
  • 私有知识库 Coco AI 实战(四):打造 ES 索引参数小助手
  • 前端漏洞不扫描理由
  • Linux systemd 从理论到实践:现代系统管理的核心工具
  • C++ 单例对象自动释放(保姆级讲解)
  • Hearts of Iron IV 钢铁雄心 4 [DLC 解锁] [Windows SteamOS macOS]
  • 机器学习-入门-决策树(1)
  • 马上评丨准入壁垒越少,市场活力越足
  • 中方发布《不跪!》视频传递何种信息?外交部回应
  • “85后”潘欢欢已任河南中豫融资担保有限公司总经理
  • 北上广深还是小城之春?“五一”想好去哪玩了吗
  • 女乘客遭顺风车甩客、深夜丢高速服务区,滴滴霸道回应:赔五百元
  • 孟泽:我们简化了历史,因此也简化了人性