

服务器类型

https://it.sohu.com/a/548478491_121124371







# 1、SAS-SATA-SSD-SCSI-IDE硬盘讲解

**一般磁盘类型：**

- **SAS硬盘**
- **SATA硬盘**
- **SSD硬盘**
- **SCSI硬盘**
- **IDE硬盘**



== **SAS硬盘**：==

- **SAS（串行连接SCSI接口）**
- **SAS（SerialAttachedSCSI），串行连接SCSI接口，串行连接小型计算机系统接口。**
- **SAS是新一代的SCSI技术，和现在流行的SerialATA(SATA)硬盘相同，都是采用串行技术以获得更高的传输速度，并通过缩短连结线改善内部空间等。**
- **SAS的接口技术可以向下兼容SATA。**
![sas1.png](https://s2.loli.net/2022/01/29/56jLKZlVYkQWRFh.png)
![sas2.png](https://s2.loli.net/2022/01/29/jdkFgBqpJfEu9TD.png)

**SAS和SATA接口对比**
![sas3.png](https://s2.loli.net/2022/01/29/y6iJwkdFR9H3UQ7.png)

---
==**磁盘尺寸**：==
- **3.5英寸设计**
- **2.5英寸设计**
- **此前主流的桌面磁盘和服务器磁盘都是采用3.5英寸设计，而SAS硬盘除了具有传统的3.5英寸规格之外，还采用了2.5英寸的缩小版，这样可以在机架式服务器有限的空间内安装更多的磁盘以扩充存储系统的容量，也能够为其他配件腾出更大的空间，以便通风散热，在2U高度内使用8个2.5英寸的SAS硬盘位已经成为大多数服务器厂商的选择。**

<font color='red'>**已经被淘汰的硬盘：**</font>
![tao.png](https://s2.loli.net/2022/01/29/3B9pnxKaePNRf7h.png)
![tao2.png](https://s2.loli.net/2022/01/29/3HojuYgCUV7FEpk.png)

---
**互动：数据线和电源接口，串型和并型哪个快?**

![image-20220725005136822](https://note-1308251438.cos.ap-guangzhou.myqcloud.com/typora/202207250051928.png)

**并口为什么没有串口快？**

- **串口形容一下就是一条车道，而并口就是有8个车道。同一时刻能传送8位（一个字节）数据。**
- **但是并不是并口快，由于8位通道之间的互相干扰。传输受速度就受到了限制。当传输出错时，要同时重新传8个位的数据，<font color='red'>而且传输速度越快，干扰越严重。这是硬伤</font>，这样速度就无法提升上来。**
- **串口没有干扰，传输出错后重发一位就可以了。而且串口传输的时钟频率要比并口高。**

**1956年，一台5mb的IBM硬盘被装上飞机，重量超过一吨**
![IBM.png](https://s2.loli.net/2022/01/29/CHRDdtZSzV3lUXM.png)

# 2.当下流行的磁盘种类
**常见硬盘品牌：<font color='red'>希捷</font>&nbsp; &nbsp;西数&nbsp; &nbsp;<font color='red'>日立</font>&nbsp; &nbsp;HP&nbsp; &nbsp;DELL&nbsp; &nbsp;<font color='red'>EMC</font>&nbsp; &nbsp;IBM**

---
**硬盘分几种？**

**A.从工作原理来说：**
**&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 固态：价格相对贵，寿命长，读取速度快，但不适合频繁读写**
**&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 机械：怕摔、怕磁，（单位换下来的坏盘会做消磁处理），读取速度 ===> 磁道寻址时间  ， &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;潜伏时间&nbsp;&nbsp;**
**B.从硬盘的接口来说**
**&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; STAT：用在低端服务器多**
**&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; SAS、SCSI：用在中高服务器**
**&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; PCIE(固态)&nbsp; &nbsp;STAT接口&nbsp; &nbsp; M.2接口**

硬盘性能指标

| 指标 | 家用                        | 企业                 |
| ---- | --------------------------- | -------------------- |
| 容量 | 1TB   2TB...                | 5T   10T   15T   20T |
| 转速 | 4.5K或7.2K rpm 每分钟多少转 | 7.2K    10K      15k |
|      |                             |                      |



**例子1：**

**戴尔（Dell）服务器硬盘<font color='red'> SAS 300G 15K （15K表示转速 1500转速）</font>3.5英寸 缓存：128MB（128M代表缓存，硬盘也有缓存，缓存越大越好）  6Gbp/S（传输速率6GB每秒，实际上可能达不到6GB）**
**http://item.jd.com/10437410142.html  支持热插拔**

**￥1330.00**

---
**SAS磁盘容量一般：300G 、600G**
**有SAS 2T、4T的硬盘？**
**希捷(SEAGATE)ES.3系列 2TB 7200转 128M SAS企业级硬盘6Gbp/s(ST2000NM0023)**
**http://item.jd.com/1093052.html 京东价：￥999.00**

---
**假SAS=SATA盘身+SAS接口（热插拔）**
**硬盘：容量大+便宜符合市场需求！**
**提速度：假SAS做raid5、raid10，做分布式存储MFS，HDFS，GFS,swift,ceph**

---
**例子2**

**存储设备：阵列柜**
![cun.png](https://s2.loli.net/2022/01/29/qLulKvy9hbxpfGT.png)

---

**互动：存储会放到机柜的上面还是下面？**
![cun2.png](https://s2.loli.net/2022/01/29/uYqt2c8NiyzW3nO.png)
**答：下面：稳，换硬盘方便，机柜不容已倒，布线容易，太沉**

---
**例子3**

**以西部数据为例，了解一下SATA盘。你看过什么颜色的盘？蓝、黑、绿红，黄盘？**
![xi.png](https://s2.loli.net/2022/01/29/f7hsdGu9vOWpYSe.png)

**西部数据(WD)黑盘2TBSATA6Gb/s64MB台式机硬盘￥999.00**


**西部数据(WD)红盘西部数据(WD)紫盘西部数据(WD)绿盘西部数据(WD)蓝盘**


**2TBSATA6Gb/s64M2TBSATA6Gb/s64M2TBSATA6Gb/s64M2TBSATA6Gb/s64M**


**台式机硬盘监控硬盘台式机硬盘台式机硬盘**


**￥849.00￥589.00￥499.00￥459.90**

**西部数据(WD) 金盘 2TB 7200转 128M 企业级硬盘(WD2005FBYZ）￥1099 http://item.jd.com/4360258.html#crumb-wrap**

![xi2.png](https://s2.loli.net/2022/01/29/KzuWXPLbOZhMCno.png)

**西部数据(WD) 蓝盘 2TB SATA 6Gb/s 64M台式机硬盘(WD20EZRZ) http://item.jd.com/2054175.html**
![xi3.png](https://s2.loli.net/2022/01/29/jscq7BP6LtHo4OI.png)

---
**<font color='red'>中关村技巧：要4块黑块，把蓝盘上的标签一撕，然后花两元买4个黑盘的标签一贴。4块硬盘挣500*4=2000元
如何无痕撕标签？使用吹风机
如何防？
硬件大师鲁大师可以检测，或上官网查看序列号</font>**

---
**大容量磁盘价格**

**西部数据(WD) 绿盘 6TB SATA 6Gb/s 64MB台式机硬盘 ￥1899.00**

**昱科/HGST Ultrastar He10 10T 企业级服务器磁盘阵列硬盘 10TB 现货**
![da.png](https://s2.loli.net/2022/01/29/R2o4wJ5j6uQznvO.png)

**注：昱科 ==> 前日立硬盘业务**

---
**查看存储上的磁盘：**
![da2.png](https://s2.loli.net/2022/01/29/G3SdI2ktmufQlqh.png)
**注：ST希捷WD西数**

**例子4**

**游戏服务器上的固态磁盘：数据不多，但要延迟小，随机读写能力强！**
![da3.png](https://s2.loli.net/2022/01/29/frp6MnNOqGlxbtC.png)
**接口：**
![da4.png](https://s2.loli.net/2022/01/29/7UNxODBVCATgKIP.png)

**http://item.jd.com/10427653932.html
三星/SAMSUNG750EVOSSD固态硬盘120G/250G/500G支架+螺丝刀+SATA线+螺丝500G京东价￥899.00
http://item.jd.com/10427653932.html**

---
**<font color='red'>互动：有SAS接口的SSD硬盘？</font>**

**联想（Lenovo）IBM存储 V3500/V3700系列 2.5英寸 存储硬盘200G SAS SSD http://item.jd.com/10184874758.html ￥9999.00
戴尔（DELL）400GB SAS接口 2.5英寸 SSD固态硬盘服务器硬盘 ￥6900.00
http://item.jd.com/1578475963.html**



总结：https://www.bilibili.com/video/BV1Qv411t7ZL?spm_id_from=333.999.0.0&vd_source=7dbd3ff3b59f8ee7e600b6e2a47731e0



# 2、磁盘分区工具和挂载

## 2.1、硬盘分区符认识

![image-20220725081503910](https://note-1308251438.cos.ap-guangzhou.myqcloud.com/typora/202207250815240.png)

**1.MBR概述：全称为MasterBootRecord，即硬盘的主引导记录。
硬盘的0柱面、0磁头、1扇区称为主引导扇区（也叫主引导记录MBR）。它由三个部分组成，主引导程序、硬盘分区表DPT（DiskPartitiontable）和分区有效标志（55AA）。在总共512字节的主引导扇区里主引导程序（bootloader）占446个字节，第二部分是Partitiontable区（分区表），即DPT，占64个字节，硬盘中分区有多少以及每一分区的大小都记在其中。第三部分是magicnumber，占2个字节，固定为55AA。**

**分区编号：主分区1-4，逻辑分区5……**

**LINUX规定：逻辑分区必须建立在扩展分区之上，而不是建立在主分区上**

**分区作用：**

**&nbsp; &nbsp;&nbsp; &nbsp; 主分区：主要是用来启动操作系统的，它主要放的是操作系统的启动或引导程序，/boot分区&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 最好放在主分区上**

**扩展分区不能使用的，它只是做为逻辑分区的容器存在的；我们真正存放数据的是主分区和逻辑分区，大量数据都放在逻辑分区中**

**<font color='red'>注意：</font>
主分区+扩展分区&nbsp; &nbsp;&nbsp; &nbsp;最多只能有4个&nbsp; &nbsp;&nbsp; &nbsp;可以理解为扩展分区属于一个主分区
扩展分区可以是0个，最多是1个
扩展分区不能直接使用，扩展分区必须首先创建成逻辑分区才能使用
逻辑分区可以是0个 1个 多个**

---
**2.GPT概述：MBR升级版**

**如果你用的是GPT的分区方式，那么它没有限制主分区个数**

**<font color='red'>两种类型的分区表：GPT和MBR；MBR不支持2T以上</font>**

**<font color='red'>GPT分区：</font><font color='blue'>GPT，全局唯一标识分区表(GUIDPartitionTable)，它使用128位GUID来唯一标识每个磁盘和分区，与MBR存在单一故障点不同，GPT提供分区表信息的冗余，一个在磁盘头部一个在磁盘尾部；它通过CRC校验和来检测GPT头和分区表中的错误与损坏；默认一个硬盘支持128个分区</font>**




## 2.2、查看磁盘

    [root@exercise1 ~]# ls /dev/sda*   #查看磁盘
    /dev/sda  /dev/sda1  /dev/sda2  /dev/sda3   #颜色呈现黄色，代表块设备
    [root@exercise1 ~]# 
![dev.png](https://s2.loli.net/2022/01/29/mzZiIfUONe9KEyX.png)

**命名方式：/dev/sd[a-z]n**

**其中：a-z表示设备的序号，如sda表示第一块scsi硬盘，sdb就是第二块......
&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; n表示每块磁盘上划分的磁盘分区编号**
![dev2.png](https://s2.loli.net/2022/01/29/lR9sgB1wPZoGCO5.png)



* 常见硬盘命名：

​        o sata/sas/scsi		/dev/sd开头

​       o 云服务器-kvm		/dev/vd开头

* /dev/sd[a-z]

* /dev/vd[a-z]

  

* 第1块sata硬盘/dev/sda

* 第3块sas硬盘/dev/sdc

* 硬盘分区命名：

* 主分区和扩展分区/dev/sda11-4

* 逻辑分区(mbr规则)/dev/sda5从5开始

* 第3块硬盘的第1个主分区/dev/sdc1

* 第6块硬盘的第1个逻辑分区/dev/sdf5





**查看磁盘命令(查看系统的磁盘)**

**lsblk命令的英文是“list block”，即用于列出所有可用块设备的信息，而且还能显示他们之间的依赖关系，但是它不会列出RAM盘的信息**

    [root@exercise1 ~]# lsblk   #默认情况下将以树状列出所有块设备
    NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda      8:0    0   20G  0 disk 
    ├─sda1   8:1    0  200M  0 part /boot
    ├─sda2   8:2    0    2G  0 part [SWAP]
    └─sda3   8:3    0 17.8G  0 part /
    sr0     11:0    1  4.2G  0 rom  /mnt




显示当前磁盘读取速度

iotop 

-o 只显示进行读写的进程信息

```
yum install -y iotop    #需安装
```





**<font color='red'>注意：使用分区工具fdisk对磁盘进行操作，分区，格式化(重点)</font>**

# 3、使用fdisk管理分区

**fdisk：磁盘分区，是Linux发行版本中最常用的分区工具**

**用法：fdisk [选项] device(设备)**

**常用的选项：<font color='red'>-l &nbsp; &nbsp;&nbsp; &nbsp;查看硬盘分区表</font>**

    [root@exercise1 ~]# fdisk -l
    
    磁盘 /dev/sda：21.5 GB, 21474836480 字节，41943040 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理)：512 字节 / 512 字节
    I/O 大小(最小/最佳)：512 字节 / 512 字节
    磁盘标签类型：dos
    磁盘标识符：0x000a9b62
    
       设备 Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048      411647      204800   83  Linux
    /dev/sda2          411648     4605951     2097152   82  Linux swap / Solaris
    /dev/sda3         4605952    41943039    18668544   83  Linux

---
**<font color='red'>添加硬盘，不关机重启识别新硬盘方法：</font>**

    [root@exercise1 ~]# echo "- - -" > /sys/class/scsi_host/host0/scan
    [root@exercise1 ~]# echo "- - -" > /sys/class/scsi_host/host1/scan
    [root@exercise1 ~]# echo "- - -" > /sys/class/scsi_host/host2/scan


---
**案例：在sdb盘上建一个分区，大小为100M**

**<font color='red'>在虚拟机上添加一块硬盘</font>**

![da6.png](https://s2.loli.net/2022/01/30/CIpkGHoncbRA3ev.png)

    #热插拔，如何让机子识别新添加进来的磁盘。重启或者使用不重启识别新磁盘命令
    
    [root@exercise1 ~]# echo "- - -" > /sys/class/scsi_host/host0/scan
    [root@exercise1 ~]# echo "- - -" > /sys/class/scsi_host/host1/scan
    [root@exercise1 ~]# echo "- - -" > /sys/class/scsi_host/host2/scan


​    
​    
​    #此时使用fdisk命令查询会有一个新磁盘，但还不能使用
​    
​    [root@exercise1 ~]# fdisk -l
​    
​    磁盘 /dev/sda：21.5 GB, 21474836480 字节，41943040 个扇区
​    Units = 扇区 of 1 * 512 = 512 bytes
​    扇区大小(逻辑/物理)：512 字节 / 512 字节
​    I/O 大小(最小/最佳)：512 字节 / 512 字节
​    磁盘标签类型：dos
​    磁盘标识符：0x000a9b62
​    
​       设备 Boot      Start         End      Blocks   Id  System
​    /dev/sda1   *        2048      411647      204800   83  Linux
​    /dev/sda2          411648     4605951     2097152   82  Linux swap / Solaris
​    /dev/sda3         4605952    41943039    18668544   83  Linux
​    
    磁盘 /dev/sdb：21.5 GB, 21474836480 字节，41943040 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理)：512 字节 / 512 字节
    I/O 大小(最小/最佳)：512 字节 / 512 字节
    [root@exercise1 ~]#


​    
​    
​    #开始分区，使用fdisk命令(fdisk 设备)
​    [root@exercise1 ~]# fdisk /dev/sdb
​    欢迎使用 fdisk (util-linux 2.23.2)。
​    
​    更改将停留在内存中，直到您决定将更改写入磁盘。
​    使用写入命令前请三思。
​    
​    Device does not contain a recognized partition table
​    使用磁盘标识符 0xacf16e11 创建新的 DOS 磁盘标签。
​    
​    命令(输入 m 获取帮助)：m
​    命令操作
​       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)
​    
    命令(输入 m 获取帮助)：p
    
    磁盘 /dev/sdb：21.5 GB, 21474836480 字节，41943040 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理)：512 字节 / 512 字节
    I/O 大小(最小/最佳)：512 字节 / 512 字节
    磁盘标签类型：dos
    磁盘标识符：0xacf16e11
    
       设备 Boot      Start         End      Blocks   Id  System
    
    命令(输入 m 获取帮助)：n
    Partition type:
       p   primary (0 primary, 0 extended, 4 free)
       e   extended
    Select (default p):    #默认选择(p)
    Using default response p
    分区号 (1-4，默认 1)：   #默认选择
    起始 扇区 (2048-41943039，默认为 2048)：   #默认选择
    将使用默认值 2048
    Last 扇区, +扇区 or +size{K,M,G} (2048-41943039，默认为 41943039)：+100M   #设定大小，否则是全给
    分区 1 已设置为 Linux 类型，大小设为 100 MiB
    
    命令(输入 m 获取帮助)：p
    
    磁盘 /dev/sdb：21.5 GB, 21474836480 字节，41943040 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理)：512 字节 / 512 字节
    I/O 大小(最小/最佳)：512 字节 / 512 字节
    磁盘标签类型：dos
    磁盘标识符：0xacf16e11
    
       设备 Boot      Start         End      Blocks   Id  System
    /dev/sdb1            2048      206847      102400   83  Linux
    
    命令(输入 m 获取帮助)：w   #保存退出
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    正在同步磁盘。
    [root@exercise1 ~]# fdisk -l
    
    磁盘 /dev/sda：21.5 GB, 21474836480 字节，41943040 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理)：512 字节 / 512 字节
    I/O 大小(最小/最佳)：512 字节 / 512 字节
    磁盘标签类型：dos
    磁盘标识符：0x000a9b62
    
       设备 Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048      411647      204800   83  Linux
    /dev/sda2          411648     4605951     2097152   82  Linux swap / Solaris
    /dev/sda3         4605952    41943039    18668544   83  Linux
    
    磁盘 /dev/sdb：21.5 GB, 21474836480 字节，41943040 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理)：512 字节 / 512 字节
    I/O 大小(最小/最佳)：512 字节 / 512 字节
    磁盘标签类型：dos
    磁盘标识符：0xacf16e11
    
       设备 Boot      Start         End      Blocks   Id  System
    /dev/sdb1            2048      206847      102400   83  Linux

**查询是否有了分区**
![ls.png](https://s2.loli.net/2022/01/30/O9GD7StsHurnjTQ.png)

---
**[root@exercise1 ~] fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。**

**更改将停留在内存中，直到您决定将更改写入磁盘。**
**使用写入命令前请三思。**

**Device does not contain a recognized partition table
使用磁盘标识符 0x4fa41385 创建新的 DOS 磁盘标签。**

**命令(输入 m 获取帮助)：m
命令操作
   a&nbsp; &nbsp;&nbsp; &nbsp;toggle a bootable flag
   b&nbsp; &nbsp;&nbsp; &nbsp;edit bsd disklabel
   c&nbsp; &nbsp;&nbsp; &nbsp;toggle the dos compatibility flag
   d&nbsp; &nbsp;&nbsp; &nbsp;delete a partition&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<font color='red'>删除分区</font>
   g&nbsp; &nbsp;&nbsp; &nbsp;create a new empty GPT partition table
   G&nbsp; &nbsp;&nbsp; &nbsp;create an IRIX (SGI) partition table
   l&nbsp; &nbsp;&nbsp; &nbsp;list known partition types&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<font color='red'>显示分区类型</font>
   m&nbsp; &nbsp;&nbsp; &nbsp;print this menu&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<font color='red'>打印帮助菜单</font>
   n&nbsp; &nbsp;&nbsp; &nbsp;add a new partition&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<font color='red'>添加新的分区</font>
   o&nbsp; &nbsp;&nbsp; &nbsp;create a new empty DOS partition table
   p&nbsp; &nbsp;&nbsp; &nbsp;print the partition table&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<font color='red'>显示分区表</font>
   q&nbsp; &nbsp;&nbsp; &nbsp;quit without saving changes&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<font color='red'>不保存，退出</font>
   s&nbsp; &nbsp;&nbsp; &nbsp;create a new empty Sun disklabel
   t&nbsp; &nbsp;&nbsp; &nbsp;change a partition's system id&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<font color='red'>改变分区类型</font>
   u&nbsp; &nbsp;&nbsp; &nbsp;change display/entry units
   v&nbsp; &nbsp;&nbsp; &nbsp;verify the partition table
   w&nbsp; &nbsp;&nbsp; &nbsp;write table to disk and exit&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<font color='red'>写分区表信息到硬盘，保存操作并退出</font>
   x&nbsp; &nbsp;&nbsp; &nbsp;extra functionality (experts only)**

**命令(输入 m 获取帮助)：p &nbsp; &nbsp;&nbsp; &nbsp;<font color='red'>-----打印分区表</font> 
Command (m for help): n &nbsp; &nbsp;&nbsp; &nbsp;<font color='red'>----新建一个分区</font> 
Partition type: 
p primary (2 primary, 0 extended, 2 free) &nbsp; &nbsp;&nbsp; &nbsp;<font color='red'>p:主分区</font> 
e extended &nbsp; &nbsp;&nbsp; &nbsp;<font color='red'>e:扩展分区</font> 
Select (default p): &nbsp; &nbsp;&nbsp; &nbsp;<font color='red'>--直接默认</font> 
Using default response p 
Partition number (1,4, default 1): &nbsp; &nbsp;&nbsp; &nbsp;<font color='red'>---直接默认</font> 
First sector (1230848-41943039, default 1230848): &nbsp; &nbsp;&nbsp; &nbsp;<font color='red'>---直接默认</font> 
Using default value 1230848 
Last sector, +sectors or +size{K,M,G} (1230848-41943039, default 41943039): +1G &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<font color='red'>输入分区大小</font> 
Partition 3 of type Linux and of size 1 GiB is set 
Command (m for help): w &nbsp; &nbsp;&nbsp; &nbsp;<font color='red'>保存退出</font>**

---
**例2：对已经在使用的磁盘进行分区，分区让新生成的分区生效。如果对sda再做一个sda4主分区**

**但是本机子无法再创建，会有提示。因为在一开始创建虚拟机的时候就选择标准分区，分了三个区，最后分剩下的内存全给了根分区**

![da7.png](https://s2.loli.net/2022/01/30/4fB1eRhrcimxlLA.png)

**no free sectors available：白话文翻译过来大概是：你的磁盘空间不足了，没有多余的空间给你去分配；有时候用各种翻译工具不一定准确；白话文大家都能听得懂；**

**Liunx 分区也是需要空间的，如果你连多余的磁盘空间都没有，当然是分不了区**


    #现在用新添加的磁盘分区操作案列，先挂上去使用
    
    [root@exercise1 ~]# mount /dev/sdb1 /opt/
    [root@exercise1 ~]# df -h
    文件系统        容量  已用  可用 已用% 挂载点
    /dev/sda3        18G  2.2G   16G   13% /
    devtmpfs        479M     0  479M    0% /dev
    tmpfs           489M     0  489M    0% /dev/shm
    tmpfs           489M  6.7M  482M    2% /run
    tmpfs           489M     0  489M    0% /sys/fs/cgroup
    /dev/sr0        4.3G  4.3G     0  100% /mnt
    /dev/sda1       197M   97M  100M   50% /boot
    tmpfs            98M     0   98M    0% /run/user/0
    /dev/sdb1        97M  5.2M   92M    6% /opt
    [root@exercise1 ~]# fdisk /dev/sdb
    欢迎使用 fdisk (util-linux 2.23.2)。
    
    更改将停留在内存中，直到您决定将更改写入磁盘。
    使用写入命令前请三思。


​    
​    命令(输入 m 获取帮助)：n
​    Partition type:
​       p   primary (2 primary, 0 extended, 2 free)
​       e   extended
​    Select (default p): p
​    分区号 (3,4，默认 3)：
​    起始 扇区 (2304000-41943039，默认为 2304000)：
​    将使用默认值 2304000
​    Last 扇区, +扇区 or +size{K,M,G} (2304000-41943039，默认为 41943039)：+1G
​    分区 3 已设置为 Linux 类型，大小设为 1 GiB
​    
​    命令(输入 m 获取帮助)：w
​    The partition table has been altered!
​    
​    Calling ioctl() to re-read partition table.
​    
​    WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
​    The kernel still uses the old table. The new table will be used at
​    the next reboot or after you run partprobe(8) or kpartx(8)
​    正在同步磁盘。
​    [root@exercise1 ~]# partprobe
​    Warning: 无法以读写方式打开 /dev/sr0 (只读文件系统)。/dev/sr0 已按照只读方式打开。

---
**<font color='red'>解决：让新生成的分区生效</font>**

    [root@exercise1 ~]# reboot   #这个是最好的方法
    
    或
    
    [root@exercise1 ~]# partprobe   #获得新分区表


---
**<font color='red'>注意</font>：分区好的不能直接使用，还不能用，相当于一张白纸，没有文件系统，要有文件系统类型才行**

    [root@exercise1 ~]# mount /dev/sdb3 /opt/   #sdb3是已经分好区还没有给格式化选择文件系统
    mount: /dev/sdb3 写保护，将以只读方式挂载
    mount: 未知的文件系统类型“(null)”
    [root@exercise1 ~]# mkfs.xfs /dev/sdb1


---
**使用sdb3新分区**

    [root@exercise1 ~]# mkfs.ext4 /dev/sdb3   #将sda3分区格式化为ext4格式
    mke2fs 1.42.9 (28-Dec-2013)
    文件系统标签=
    OS type: Linux
    块大小=4096 (log=2)
    分块大小=4096 (log=2)
    Stride=0 blocks, Stripe width=0 blocks
    65536 inodes, 262144 blocks
    13107 blocks (5.00%) reserved for the super user
    第一个数据块=0
    Maximum filesystem blocks=268435456
    8 block groups
    32768 blocks per group, 32768 fragments per group
    8192 inodes per group
    Superblock backups stored on blocks: 
    	32768, 98304, 163840, 229376
    
    Allocating group tables: 完成                            
    正在写入inode表: 完成                            
    Creating journal (8192 blocks): 完成
    Writing superblocks and filesystem accounting information: 完成


​    [root@exercise1 ~]# mkfs.xfs -f /dev/sdb3   <font color='red'>#格式化，-f对已经存在文件系统的分区，强制格式化 </font >

   meta-data=/dev/sdb3              isize=512    agcount=4, agsize=65536 blks
             =                       sectsz=512   attr=2, projid32bit=1
             =                       crc=1        finobt=0, sparse=0
    data     =                       bsize=4096   blocks=262144, imaxpct=25
             =                       sunit=0      swidth=0 blks
    naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
    log      =internal log           bsize=4096   blocks=2560, version=2
             =                       sectsz=512   sunit=0 blks, lazy-count=1
    realtime =none                   extsz=4096   blocks=0, rtextents=0


​    
​    [root@exercise1 ~]# mkdir /opt/test   #创建挂载点


​    
​    [root@exercise1 ~]# mount /dev/sdb3 /opt/test/   #挂载


​    
​    [root@exercise1 ~]# df -h   #查看
​    文件系统        容量  已用  可用 已用% 挂载点
​    /dev/sda3        18G  2.2G   16G   13% /
​    devtmpfs        479M     0  479M    0% /dev
​    tmpfs           489M     0  489M    0% /dev/shm
​    tmpfs           489M   13M  476M    3% /run
​    tmpfs           489M     0  489M    0% /sys/fs/cgroup
​    /dev/sr0        4.3G  4.3G     0  100% /mnt
​    /dev/sda1       197M   97M  100M   50% /boot
​    tmpfs            98M     0   98M    0% /run/user/0
​    /dev/sdb3      1014M   33M  982M    4% /opt/test


​    [root@exercise1 ~]# cd /opt/test/   #使用新分区
​    [root@exercise1 test]# ls
​    [root@exercise1 test]# cp /etc/passwd ./
​    [root@exercise1 test]# ls
​    passwd
​    [root@exercise1 test]# 

---
**<font color='red'>注意：两个分区，一个先挂载到/opt里面写入了东西，但是卸载原有分区或者是直接用另外一个分区挂载上去会发现没有东西，但是换回第一个（原先的分区）会发现东西回来了，因为是写入的磁盘分区不一样，虽挂载点一样，但要看挂载源里是否有东西</font>**

---
**例3：解决卸载不了的问题**    

    [root@exercise1 ~]# cd /opt/test/
    [root@exercise1 test]# umount /dev/sdb3
    umount: /opt/test：目标忙。
            (有些情况下通过 lsof(8) 或 fuser(1) 可以
             找到有关使用该设备的进程的有用信息)
             
    或者
    
    [root@exercise1 test]# umount /opt/test


​    
​    [root@exercise1 test]# lsof /dev/sdb3   #此命令需要安转
​    -bash: lsof: 未找到命令
​    [root@exercise1 test]# yum search lsof   #yum命令查找包
​    [root@exercise1 test]# yum -y install lsof.x86_64   #yum安装


​    
​    [root@exercise1 test]# lsof /dev/sdb3
​    COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
​    bash     998 root  cwd    DIR   8,19       20   64 /opt/test
​    lsof    3102 root  cwd    DIR   8,19       20   64 /opt/test
​    lsof    3103 root  cwd    DIR   8,19       20   64 /opt/test
​    [root@exercise1 test]# 


​    #方法一
​    [root@exercise1 test]# kill -9 998   #这样子在xshell会直接断掉链接


​    
​    #方法二
​    [root@exercise1 test]# cd   #退出目录，这个最合适


​    
​    #卸载挂载
​    [root@exercise1 ~]# umount /dev/sdb3   #卸载挂载源
​    
​    或者
​    
​    [root@exercise1 ~]# umount /opt/test/  #卸载挂载点

---

**<font color='red'>注：</font>**

**<font color='red'>umount    挂载点     //卸载方式1</font>**  

**<font color='red'>或 </font>**  

**<font color='red'>umount     设备路径          //卸载方式2</font>**



**例4：写入磁盘挂载配置文件，让它开机自动挂载**

    [root@exercise1 ~]# vim /etc/fstab   #在文件最后写入
    /dev/sdb3   /opt/test   xfs defaults    0   0


​    [root@exercise1 ~]# mount -a   #自动挂载/etc/fstab中没有挂载上的文件

​    [root@exercise1 ~]# df -h
​    文件系统        容量  已用  可用 已用% 挂载点
​    /dev/sda3        18G  2.3G   16G   13% /
​    devtmpfs        479M     0  479M    0% /dev
​    tmpfs           489M     0  489M    0% /dev/shm
​    tmpfs           489M   13M  476M    3% /run
​    tmpfs           489M     0  489M    0% /sys/fs/cgroup
​    /dev/sr0        4.3G  4.3G     0  100% /mnt
​    /dev/sda1       197M   97M  100M   50% /boot
​    /dev/sdb1        97M  5.2M   92M    6% /opt/test
​    tmpfs            98M     0   98M    0% /run/user/0


​    
​    [root@exercise1 ~]# 
![mount3.png](https://s2.loli.net/2022/01/30/c8CHFsBLtE5UX3M.png)
**发现已经挂载上，说明配置没有问题。然后再重启，看看挂载**
![mount3.png](https://s2.loli.net/2022/01/30/c8CHFsBLtE5UX3M.png)
**可以看出重启过后一样挂载上去了，证明成功**

**<font color='red'>注释：</font>**


| /dev/sdb3 | /opt/test | xfs | defaults | 0 | 0 |
| --- | --- | --- | --- | --- | --- |
| 要挂载的分区设备 | 挂载点 | 文件系统类型 | 挂载选项 | 是否备份 | 是否检测 |

---
**方法2：使用UUID挂载**

    [root@exercise1 ~]# blkid
    /dev/sda1: UUID="7d95eb01-b37e-4430-b021-a0fdaa96e782" TYPE="xfs" 
    /dev/sda2: UUID="487a8924-8901-498d-a2af-ff81970e5157" TYPE="swap" 
    /dev/sda3: UUID="c14ecb64-e445-457e-a838-04314faa45bf" TYPE="xfs" 
    /dev/sdb1: UUID="d8bcad4e-c5de-409c-bfe2-5fd75aa9f4d8" TYPE="xfs" 
    /dev/sdb3: UUID="37a54df4-22fe-4b38-a8d2-3424301a4b07" TYPE="xfs" 
    /dev/sr0: UUID="2017-09-06-10-51-00-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos" 


​    
​    [root@exercise1 ~]# echo "UUID=37a54df4-22fe-4b38-a8d2-3424301a4b07/sdb3xfsdefaults00" >> /etc/fstab

---
**<font color='red'>扩展：了解</font>**

| /dev/sdb3 | /opt/test | xfs | defaults | 0 | 0 |
| --- | --- | --- | --- | --- | --- |
| 要挂载的分区设备 | 挂载点 | 文件系统类型 | 挂载选项 | 是否备份 | 是否检测 |

**其中第四列：parameters-文件系统的参数**

| Async/sync | 设置是否为同步方式运行，默认为async |
| --- | --- |
| auto/noauto | 当执行mount -a的命令时，此文件系统是否被主动挂载。默认为auto |
| rw/ro | 是否以以只读或者读写模式挂载 |
| exec/noexe | 限制此文件系统内是否能够进行"执行"的操作 |
| user/nouser | 是否允许用户使用mount命令挂载 |
| suid/nosuid | 是否允许SUID的存在 |
|  Usrquota | 启动文件系统支持磁盘配额模式 |
| Grpquota | 启动文件系统对群组磁盘配额模式的支持 |
| Defaults | 同时具有rw,suid,dev,exec,auto,nouser,async等默认参数的设置sambanfs |

**第五列：是否进行备份。通常这个参数的值为0或者1**


| 0 | 代表不要做备份 |
| --- | --- |
| 1 | 代表要每天进行操作 |
| 2 | 代表不定日期的进行操作 |

**第六列：是否检验扇区：开机的过程中，系统默认会以fsck检验我们系统是否为完整**

| 0 | 不要检验 |
| --- | --- |
| 1 | 最早检验（一般根目录会选择） |
| 2 | 1级别检验完成之后进行检验 |

---
**例5：设置开机执行挂载命令（重点）**

    [root@exercise1 ~]# ll /etc/rc.local 
    lrwxrwxrwx. 1 root root 13 1月   9 09:29 /etc/rc.local -> rc.d/rc.local


​    [root@exercise1 ~]# ll /etc/rc.d/rc.local 
​    -rw-r--r--. 1 root root 473 8月   5 2017 /etc/rc.d/rc.local


​    [root@exercise1 ~]# vim /etc/rc.d/rc.local   #往rc.local里添加挂载命令
**mount  -o ro /dev/sdb1 /opt/test&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='red'>#-o 指定参数来挂载</font>**
**注：**
**centos6可以直接使用该文件**
**<font color='red'>但centos7需要手动添加执行权限</font>**

    [root@exercise1 ~]# chmod +x /etc/rc.d/rc.local
    
    [root@home abc]# touch a.txt
    touch: 无法创建"a.txt": 只读文件系统			#出现这种错，优先考虑文件系统层面

---

---
# 4.gdisk磁盘分区工具
**<font color='red'>gdisk主要是用来划分容量大于2T的硬盘,大于2T fdisk搞不定</font>**

**<font color='red'>gdisk使用GPT分区表</font>**

**<font color='red'>两种类型的分区表：GPT和MBR；MBR不支持2T以上</font>**

**<font color='red'>GPT分区：</font><font color='blue'>GPT，全局唯一标识分区表(GUIDPartitionTable)，它使用128位GUID来唯一标识每个磁盘和分区，与MBR存在单一故障点不同，GPT提供分区表信息的冗余，一个在磁盘头部一个在磁盘尾部；它通过CRC校验和来检测GPT头和分区表中的错误与损坏；默认一个硬盘支持128个分区</font>**

**案例**

    [root@exercise1 ~]# yum search gdisk   #需要安转gdisk，利用yum来搜查包


​    [root@exercise1 ~]# yum -y install gdisk.x86_64   #安装


​    [root@exercise1 ~]# gdisk /dev/sdb
​    GPT fdisk (gdisk) version 0.8.10
​    

    Partition table scan:
      MBR: not present
      BSD: not present
      APM: not present
      GPT: not present
    
    Creating new GPT entries.
    
    Command (? for help): ?
    b	back up GPT data to a file
    c	change a partition's name
    d	delete a partition
    i	show detailed information on a partition
    l	list known partition types
    n	add a new partition
    o	create a new empty GUID partition table (GPT)
    p	print the partition table
    q	quit without saving changes
    r	recovery and transformation options (experts only)
    s	sort partitions
    t	change a partition's type code
    v	verify disk
    w	write table to disk and exit
    x	extra functionality (experts only)
    ?	print this menu
    
    Command (? for help): n
    Partition number (1-128, default 1): 
    First sector (34-41943006, default = 2048) or {+-}size{KMGTP}: 
    Last sector (2048-41943006, default = 41943006) or {+-}size{KMGTP}: +1G
    Current type is 'Linux filesystem'
    Hex code or GUID (L to show codes, Enter = 8300): 
    Changed type of partition to 'Linux filesystem'
    
    Command (? for help): p
    Disk /dev/sdb: 41943040 sectors, 20.0 GiB
    Logical sector size: 512 bytes
    Disk identifier (GUID): CC561CA3-746A-4C27-AB4F-5EC4F0B958CB
    Partition table holds up to 128 entries
    First usable sector is 34, last usable sector is 41943006
    Partitions will be aligned on 2048-sector boundaries
    Total free space is 39845821 sectors (19.0 GiB)
    
    Number  Start (sector)    End (sector)  Size       Code  Name
       1            2048         2099199   1024.0 MiB  8300  Linux filesystem
    
    Command (? for help): w
    
    Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
    PARTITIONS!!
    
    Do you want to proceed? (Y/N): y
    OK; writing new GUID partition table (GPT) to /dev/sdb.
    The operation has completed successfully.


​    
​    [root@exercise1 ~]# mkfs.xfs /dev/sdb1   #格式化成xfs
​    meta-data=/dev/sdb1              isize=512    agcount=4, agsize=65536 blks
​             =                       sectsz=512   attr=2, projid32bit=1
​             =                       crc=1        finobt=0, sparse=0
​    data     =                       bsize=4096   blocks=262144, imaxpct=25
​             =                       sunit=0      swidth=0 blks
​    naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
​    log      =internal log           bsize=4096   blocks=2560, version=2
​             =                       sectsz=512   sunit=0 blks, lazy-count=1
​    realtime =none                   extsz=4096   blocks=0, rtextents=0


​    
​    [root@exercise1 ~]# fdisk -l
​    
​    磁盘 /dev/sda：21.5 GB, 21474836480 字节，41943040 个扇区
​    Units = 扇区 of 1 * 512 = 512 bytes
​    扇区大小(逻辑/物理)：512 字节 / 512 字节
​    I/O 大小(最小/最佳)：512 字节 / 512 字节
​    磁盘标签类型：dos
​    磁盘标识符：0x000a9b62
​    
​       设备 Boot      Start         End      Blocks   Id  System
​    /dev/sda1   *        2048      411647      204800   83  Linux
​    /dev/sda2          411648     4605951     2097152   82  Linux swap / Solaris
​    /dev/sda3         4605952    41943039    18668544   83  Linux
​    WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
​    
​    磁盘 /dev/sdb：21.5 GB, 21474836480 字节，41943040 个扇区
​    Units = 扇区 of 1 * 512 = 512 bytes
​    扇区大小(逻辑/物理)：512 字节 / 512 字节
​    I/O 大小(最小/最佳)：512 字节 / 512 字节
​    磁盘标签类型：gpt
​    Disk identifier: CC561CA3-746A-4C27-AB4F-5EC4F0B958CB


​    
​    #         Start          End    Size  Type            Name
​     1         2048      2099199      1G  Linux filesyste Linux filesystem
​    [root@exercise1 ~]# 

**说明**

[root@exercise1 ~]# gdisk /dev/sdb
GPT fdisk (gdisk) version 0.8.10

Partition table scan:
  MBR: not present
  BSD: not present
  APM: not present
  GPT: not present

Creating new GPT entries.

Command (? for help): ?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='red'>#相当于fdisk的m选项</font>
b	back up GPT data to a file
c	change a partition's name
d	delete a partition&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='red'>#删除分区</font>
i	show detailed information on a partition
l	list known partition types
n	add a new partition&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='red'>#添加一个分区</font>
o	create a new empty GUID partition table (GPT)
p	print the partition table&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='red'>#打印分区表</font>
q	quit without saving changes&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='red'>#退出不保存</font>
r	recovery and transformation options (experts only)
s	sort partitions
t	change a partition's type code
v	verify disk
w	write table to disk and exit&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='red'>#写入分区表并退出</font>
x	extra functionality (experts only)
?	print this menu

Command (? for help): n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='red'>#新建分区表</font>
Partition number (1-128, default 1): &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='red'>#直接回车</font>
First sector (34-41943006, default = 2048) or {+-}size{KMGTP}: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='red'>#直接回车， 从头开始划分空间</font>
Last sector (2048-41943006, default = 41943006) or {+-}size{KMGTP}: +1G&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='red'>#给 1G 空间</font>
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='red'>#分区类型直接回车</font>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='red'>注：8300 Linux filesystem ；8e00 Linux LVM 想查看，可以按 L 来显示</font>
Changed type of partition to 'Linux filesystem'

Command (? for help): p&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='red'>#查看</font>
Disk /dev/sdb: 41943040 sectors, 20.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): CC561CA3-746A-4C27-AB4F-5EC4F0B958CB
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 41943006
Partitions will be aligned on 2048-sector boundaries
Total free space is 39845821 sectors (19.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         2099199   1024.0 MiB  8300  Linux filesystem

Command (? for help): w&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='red'>#保存</font>

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='red'>#确定写入</font>
OK; writing new GUID partition table (GPT) to /dev/sdb.
The operation has completed successfully.


---
**实战：修改fstab重启系统后，系统报错**

**重启后报错：**
![fstab.png](https://s2.loli.net/2022/01/30/qMjv3hwZzJl2kFa.png)

**输入root密码：123456**

**把fstab中新添加开机自动加载项目删除**

![fstab2.png](https://s2.loli.net/2022/01/30/JDTkzKxiEyIFZLY.png)

**然后reboot**

---
**新磁盘不分区直接使用**

**假设新硬盘是 /dev/sdc
fdisk操作的是/dev/sdc ，分区后才会有/dev/sdc1 /dev/sdc2 之类
一般mkfs.ext4 /dev/sdc1 来格式化一个分区，再mount /dev/sdc1
不过你也可以不分区，直接mkfs.ext4 /dev/sdc ，然后mount /dev/sdc**

