文章目录

  • 1 磁盘要做什么操作后才能存放数据
  • 2 查看Linux系统下识别到了哪些磁盘
  • 3 MBR类型的分区表介绍和fdisk的实践
    • 3.1 一块磁盘最多可以分几个主分区
    • 3.2 一块磁盘最多可分几个扩展分区
    • 3.3 一块磁盘可分为多少个逻辑分区
    • 3.4 fdisk工具对磁盘进行分区(交互式)实践
      • 3.4.1 将磁盘分成--4个主分区--格式化--临时挂载和永久挂载
      • 3.4.2 检查磁盘是否有数据,并删除磁盘存在的分区
      • 3.4.3 将磁盘分成–1个主分区|1个扩展分区|1个逻辑分区--格式化--临时挂载和永久挂载
      • 3.4.4 检查磁盘是否有数据,并删除磁盘存在的分区
      • 3.4.5 将磁盘分成–3个主分区|1个扩展分区|1个逻辑分区--格式化--临时挂载和永久挂载
      • 3.4.6 检查磁盘是否有数据,并删除磁盘存在的分区
      • 3.4.7 将磁盘分成–1个主分区--格式化--临时挂载和永久挂载
      • 3.4.8 检查磁盘是否有数据,并删除磁盘存在的分区
      • 3.4.9 格式化磁盘--不分区---直接挂载使用【注意哈】
      • 3.4.10 检查磁盘是否有数据,并删除磁盘存在的分区
      • 3.4.11 fdisk非交互工下进行分区
    • 4 GPT类型的分区表介绍和parted的实践
    • 5 fdisk和parted工具分区的总结

1 磁盘要做什么操作后才能存放数据

第一种

01:确认磁盘是否有数据(即使他人告诉你没有数据,你也得检查,自己维护的服务器在操作前也得检查)02:格式化磁盘(就是将磁盘格式化成什么文件系统,例:NTFS,ext3,ext4,xfs等)# 不同的操作系统支持的文件系统不一样;例:NTFS是用于windows;ext3、ext4、xfs是用于linux;# 不同的文件系统是有区别的,对分区和存放数据是有限制的;# 例:FAT32文件系统:单个分区大小最大支持32GB,存放的单个文件也只支持最大4GB03:确认或调整磁盘的分区表格式(是MBR呢还是GPT呢),然后根据不同的分区表类型使用不同的工具进行分区;# MBR分区表支持:主分区、扩展分区、逻辑分区 这样的分区方式# GPT分区表:没有主分区、扩展分区、逻辑分区 之样的分区概念了,你直接分就行了;04:对磁盘的分区进行格式化(格式化成什么文件系统),然后进行磁盘分区的挂载(临时挂载加永久挂载都要做)

第二种

01:确认磁盘是否有数据(即使他人告诉你没有数据,你也得检查,自己维护的服务器在操作前也得检查)02:格式化磁盘(就是将磁盘格式化成什么文件系统,例:NTFS,ext3,ext4,xfs等)03:不对磁盘进行分区,直接挂载(临时挂载和永久挂载都要做)后就存放数据;

2 查看Linux系统下识别到了哪些磁盘

我在Vmware Workstation在创建的虚拟机上加载的磁盘


看一看在操作系统下加载的磁盘,磁盘的名称是以 /dev/sda、/dev/sdb 这样来进行命名的。

我在阿里云上选购的ECS云服务器

操作系统: CentOS 7.5(公共镜像)
系 统 盘: 40G 高效云盘
数 据 盘1:40G ESSD云盘
数 据 盘2:40G SSD云盘

看一看在操作系统下加载的磁盘,磁盘的名称是以 /dev/vda、/dev/vdb、/dev/vdc 这样来进行命名的。

3 MBR类型的分区表介绍和fdisk的实践

3.1 一块磁盘最多可以分几个主分区

一块MBR格式的磁盘最多只能分4个主分区,这是由磁盘的 0磁头0磁道0扇区 中的分区表决定的;

3.2 一块磁盘最多可分几个扩展分区

一块MBR磁盘最多只能有一个扩展分区,且主分区加扩展分区的数量不能超过4个,如下面的图所示:


3.3 一块磁盘可分为多少个逻辑分区

一块MBR分区表的磁盘只能分一个“扩展分区”,在"扩展分区"上可以分N个逻辑分区(只要不超过扩展分区的大小就好),这是因为每个"逻辑分区"都有一个”独立的扩展分区表“。如下图所示:下图是分 1个主分区,1个扩展分区(只能分1个),在扩展分区上又分了 2个逻辑分区。

3.4 fdisk工具对磁盘进行分区(交互式)实践

fdisk命令是Linux下最常用的分区工具,fdisk命令默认只能linux的超级用户root可以使用;
fdisk命令只能针对整体容量小于2T的磁盘进行分区,这个和你把磁盘格式化成什么样的文件系统没有关哈;
fdisk命令进行分区的实质就是修改磁盘的0磁头0磁道0扇区的前446字节后的64字节(分区表,分区表类型得是MBR)

3.4.1 将磁盘分成–4个主分区–格式化–临时挂载和永久挂载

我当前的虚拟机有一块100G的磁盘/dev/sdb,我要将其分成4个主分区;
是没有数据的,我自己添加的磁盘我知道,但是你的脑袋里面一定要考虑到数据(要确认);

检查磁盘/dev/sdb是否有被分区、是否被挂载、是否有数据、是否被格式化

#### 查看/dev/sdb磁盘是否被分区 和 是否被挂载使用
[root@localhost ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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# 这里用fdisk -l 看到的结果是没有被分过区,不准确;# 因为我可以将整个磁盘格式化成文件系统后,进行挂载使用;[root@localhost etc]# lsblk /dev/sdb
NAME MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdb    8:16   0  100G  0 disk # 磁盘没有被挂载使用,因为mountpoint没有值;# 磁盘没有被分区,因为没有/dev/sdb1 /dev/sdb2这样子的;#### 查看整个磁盘是否有被格式化
-- 第一种方法:
[root@localhost ~]# mount /dev/sdb /mnt/
mount: /dev/sdb is write-protected, mounting read-only   <== /dev/sdb是写保护的,安装时是只读的
mount: unknown filesystem type '(null)'                  <== 未知的文件系统(可以得出磁盘没有被格式化文件系统) # 这里是将/dev/sdb磁盘临时挂载到/mnt目录下,看能不能够成功# 结果是不成功(因为磁盘没有被格式化成文件系统,)# 若成功的话(表示磁盘有被格式化成文件系统,此时你要看有没有数据)[root@localhost ~]# parted /dev/sdb print
Error: /dev/sdb: unrecognised disk label                <== unrecognised disk label(无法识别的磁盘标签)
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:

将整个磁盘格式化成你想要的文件系统,且确认磁盘的分区表是不是MBR类型

前面已经确认磁盘/dev/sdb是没有被格式化、没有被分区、没有数据的

####  将/dev/sdb磁盘格式化成xfs文件系统(前面我确认了没有数据)mkfs.xfs  /dev/sdb # 因为/dev/sdb没有被格式化过,所以我这里没有加-f参数#### 检查/dev/sdb磁盘是否被格式化成了xfs文件系统,且查看分区表的类型
[root@localhost ~]# parted /dev/sdb print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: loop                <== 分区表:loop,这要不是GPT哈
Disk Flags: Number  Start  End    Size   File system  Flags1      0.00B  107GB  107GB  xfs    <== 可以看到"文件系统"是xfs,因为前面我将其格式化成了xfs文件系统

用fdisk工具对/dev/sdb磁盘进行分区(分4个主分区)

####  用fdisk命令对/dev/sdb进行分区(前面的需求是分4个主分区)
[root@localhost ~]# 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.# 更改只会保留在内存中,直到您决定编写它们。# 在使用write命令之前要小心。Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xfa1816a9.# 设备不包含可识别的分区表# 用磁盘标识符0xfa1816a9构建一个新的DOS磁盘标签。Command (m for help):
Command (m for help):
Command (m for help):
Command (m for help):
Command (m for help): n     <== 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                <== 分区的编号,输入的是1,不输入默认也是1
First sector (2048-209715199, default 2048):        <== 没有输入,让其默认2048M
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199): +25G   <== 主分区的大小
Partition 1 of type Linux and of size 25 GiB is set
Command (m for help):
Command (m for help):
Command (m for help):
Command (m for help):
Command (m for help): n      <== n表示创建
Partition type:p   primary (1 primary, 0 extended, 3 free)        <== 表示主分区e   extended                                       <== 表示扩展分区
Select (default p): p                                 <== 这是我输入的,p表示主分区
Partition number (2-4, default 2): 2                  <== 分区的编号,输入的是2,不输入默认也是2
First sector (52430848-209715199, default 52430848):  <==  没有输入,让其默认2048M
Using default value 52430848
Last sector, +sectors or +size{K,M,G} (52430848-209715199, default 209715199): +25G  <== 主分区的大小
Partition 2 of type Linux and of size 25 GiB is set
Command (m for help):
Command (m for help):
Command (m for help):
Command (m for help):
Command (m for help):
Command (m for help): n      <== n表示创建
Partition type:p   primary (2 primary, 0 extended, 2 free)         <== 表示主分区e   extended                                        <== 表示扩展分区
Select (default p): p                                  <== 这是我输入的,p表示主分区
Partition number (3,4, default 3): 3                   <== 分区的编号,输入的是3,不输入默认也是3
First sector (104859648-209715199, default 104859648): <==  没有输入,让其默认2048M
Using default value 104859648
Last sector, +sectors or +size{K,M,G} (104859648-209715199, default 209715199): +25G <== 主分区的大小
Partition 3 of type Linux and of size 25 GiB is set
Command (m for help):
Command (m for help):
Command (m for help):
Command (m for help):
Command (m for help):
Command (m for help): n      <== n表示创建
Partition type:p   primary (3 primary, 0 extended, 1 free)         <== 表示主分区e   extended                                        <== 表示扩展分区
Select (default e): p                                  <== 这是我输入的,p表示主分区
Selected partition 4                                   <== 这不是我输入的,是它自己先的,因为MBR磁盘只能分4个主分区
First sector (157288448-209715199, default 157288448): <==  没有输入,让其默认2048M
Using default value 157288448
Last sector, +sectors or +size{K,M,G} (157288448-209715199, default 209715199): <== 没指定大小,使用剩余所有空间
Using default value 209715199
Partition 4 of type Linux and of size 25 GiB is set
Command (m for help):
Command (m for help):
Command (m for help):
Command (m for help):
Command (m for help):
Command (m for help): p  <== 这个p不是主分区的p,这是fdisk的命令Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0xfa1816a9Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    52430847    26214400   83  Linux
/dev/sdb2        52430848   104859647    26214400   83  Linux
/dev/sdb3       104859648   157288447    26214400   83  Linux
/dev/sdb4       157288448   209715199    26213376   83  Linux^== 83表示标准分区(不是指主分区的哈)
Command (m for help):
Command (m for help):
Command (m for help):
Command (m for help):
Command (m for help):
Command (m for help): w    <== 保存分区信息并退出
The partition table has been altered!Calling ioctl() to re-read partition table.
Syncing disks.#### 看一看操作系统有没有识别到磁盘的分区信息(可以看到操作系统已识别到分区)
[root@localhost ~]# ll /dev/sdb*
brw-rw----. 1 root disk 8, 16 Jun  1 08:09 /dev/sdb
brw-rw----. 1 root disk 8, 17 Jun  1 08:09 /dev/sdb1
brw-rw----. 1 root disk 8, 18 Jun  1 08:09 /dev/sdb2
brw-rw----. 1 root disk 8, 19 Jun  1 08:09 /dev/sdb3
brw-rw----. 1 root disk 8, 20 Jun  1 08:09 /dev/sdb4#### 让操作系统的内核知道/dev/sdb的分区表已改变
[root@localhost ~]# partprobe /dev/sdb
[root@localhost ~]#
[root@localhost ~]# ll /dev/sdb*
brw-rw----. 1 root disk 8, 16 Jun  1 08:11 /dev/sdb
brw-rw----. 1 root disk 8, 17 Jun  1 08:11 /dev/sdb1
brw-rw----. 1 root disk 8, 18 Jun  1 08:11 /dev/sdb2
brw-rw----. 1 root disk 8, 19 Jun  1 08:11 /dev/sdb3
brw-rw----. 1 root disk 8, 20 Jun  1 08:11 /dev/sdb4

格式化/dev/sdb的每个分区,然后对其进行临时挂载和永久挂载

####   对/dev/sdb1磁盘的4个主分区/dev/sdb{1..4}进行格式化(前面已核对是没有数据的)
mkfs.xfs  /dev/sdb1
mkfs.xfs  /dev/sdb2
mkfs.xfs  /dev/sdb3
mkfs.xfs  /dev/sdb4####  查看磁盘/dev/sdb的每个分区是否被格式化成xfs文件系统了
[root@localhost ~]# parted /dev/sdb print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: Number  Start   End     Size    Type     File system  Flags1      1049kB  26.8GB  26.8GB  primary  xfs2      26.8GB  53.7GB  26.8GB  primary  xfs3      53.7GB  80.5GB  26.8GB  primary  xfs4      80.5GB  107GB   26.8GB  primary  xfs####  创建/tmp/d{1..4}目录
[root@localhost ~]# mkdir /tmp/d{1..4}
[root@localhost ~]# ls -ld /tmp/d{1..4}
drwxr-xr-x. 2 root root 6 Jun  1 08:22 /tmp/d1
drwxr-xr-x. 2 root root 6 Jun  1 08:22 /tmp/d2
drwxr-xr-x. 2 root root 6 Jun  1 08:22 /tmp/d3
drwxr-xr-x. 2 root root 6 Jun  1 08:22 /tmp/d4####  将磁盘/dev/sdb的4个主分区临时挂载到/tmp/d{1..4}上
mount /dev/sdb1 /tmp/d1
mount /dev/sdb2 /tmp/d2
mount /dev/sdb3 /tmp/d3
mount /dev/sdb4 /tmp/d4####  查看/dev/sdb磁盘各分区的挂载情况
[root@localhost ~]# df -h|grep "/dev/sdb"
/dev/sdb1        25G   33M   25G   1% /tmp/d1
/dev/sdb2        25G   33M   25G   1% /tmp/d2
/dev/sdb3        25G   33M   25G   1% /tmp/d3
/dev/sdb4        25G   33M   25G   1% /tmp/d4#### 将磁盘/dev/sdb的4个主分区让其永久挂载
-- 对/etc/fstab文件做备份
cp -a /etc/fstab /tmp/fstab_bak
ll /tmp/fstab_bak -- 对/etc/fstab文件进行解锁
chattr -i /etc/fstab
lsattr /etc/fstab -- 将/dev/sdb的4个主分区的挂载写到/etc/fstab文件中
echo "$(blkid|grep "/dev/sdb1"|awk -F "[: ]+" '{print $2}'|sed 's#"##g')  /tmp/d1   xfs  defaults  0 0" >>/etc/fstab
echo "$(blkid|grep "/dev/sdb2"|awk -F "[: ]+" '{print $2}'|sed 's#"##g')  /tmp/d2   xfs  defaults  0 0" >>/etc/fstab
echo "$(blkid|grep "/dev/sdb3"|awk -F "[: ]+" '{print $2}'|sed 's#"##g')  /tmp/d3   xfs  defaults  0 0" >>/etc/fstab
echo "$(blkid|grep "/dev/sdb4"|awk -F "[: ]+" '{print $2}'|sed 's#"##g')  /tmp/d4   xfs  defaults  0 0" >>/etc/fstab[root@localhost ~]# tail -4 /etc/fstab
UUID=40ab3272-dcc1-4c54-a36e-51712faa1bde  /tmp/d1   xfs  defaults  0 0
UUID=8b249fc0-395f-420a-bc19-6c762589209b  /tmp/d2   xfs  defaults  0 0
UUID=9f2156cd-8f0e-4e37-84e1-4884d0038028  /tmp/d3   xfs  defaults  0 0
UUID=76ee7b11-010a-4c9f-9294-84aedb3330e9  /tmp/d4   xfs  defaults  0 0-- 对/etc/fstab文件加锁
[root@localhost ~]# chattr +i /etc/fstab
[root@localhost ~]# lsattr /etc/fstab
----i----------- /etc/fstab

3.4.2 检查磁盘是否有数据,并删除磁盘存在的分区

3.4.1章节将/dev/sdb磁盘分了4个主分区,且进行了临时和永久挂载,我是没有存放数据的。该章节要将其/dev/sdb磁盘中的分区删除掉,方便3.4.3章节的实践(1个主分区+1个扩展分区+1个逻辑分区)。

对/dev/sdb磁盘每个分区的挂载进行卸载

### 检查/dev/sdb磁盘每个分区的挂载情况
[root@localhost ~]# df -h|grep /dev/sdb|sort
/dev/sdb1        25G   33M   25G   1% /tmp/d1
/dev/sdb2        25G   33M   25G   1% /tmp/d2
/dev/sdb3        25G   33M   25G   1% /tmp/d3
/dev/sdb4        25G   33M   25G   1% /tmp/d4[root@localhost ~]# grep -i "/tmp/d" /etc/fstab
UUID=41b7ea7c-4b78-4df5-891b-7735b84d598b  /tmp/d1   xfs  defaults  0 0
UUID=e9b8593d-f706-4cf3-969c-1b24c28ffebf  /tmp/d2   xfs  defaults  0 0
UUID=113509d7-3bf6-412c-ac5c-31682ab54e0e  /tmp/d3   xfs  defaults  0 0
UUID=1bcdc548-de43-4573-b8cf-ccd7dc0856b1  /tmp/d4   xfs  defaults  0 0### 检查/dev/sdb磁盘每个分区中是否有数据(若有数据,你得备份并哈)
[root@localhost ~]# ls /tmp/d1/|wc -l
0
[root@localhost ~]# ls /tmp/d2/|wc -l
0
[root@localhost ~]# ls /tmp/d3/|wc -l
0
[root@localhost ~]# ls /tmp/d4/|wc -l
0### 对/dev/sdb磁盘每个分区的挂载进行卸载
-- 取消相关分区的临时挂载
umount /tmp/d1
umount /tmp/d2
umount /tmp/d3
umount /tmp/d4-- 备份/etc/fstab文件并进行修改
[root@localhost ~]# cp -a /etc/fstab{,.bak}
[root@localhost ~]# ll /etc/fstab.bak
-rw-r--r--. 1 root root 789 Jun  2 23:53 /etc/fstab.bak[root@localhost ~]# chattr -i /etc/fstab
[root@localhost ~]# lsattr /etc/fstab
---------------- /etc/fstab[root@localhost ~]# sed -n '/\/tmp\/d/'p /etc/fstab
UUID=41b7ea7c-4b78-4df5-891b-7735b84d598b  /tmp/d1   xfs  defaults  0 0
UUID=e9b8593d-f706-4cf3-969c-1b24c28ffebf  /tmp/d2   xfs  defaults  0 0
UUID=113509d7-3bf6-412c-ac5c-31682ab54e0e  /tmp/d3   xfs  defaults  0 0
UUID=1bcdc548-de43-4573-b8cf-ccd7dc0856b1  /tmp/d4   xfs  defaults  0 0[root@localhost ~]# sed -i '/\/tmp\/d/'d /etc/fstab
[root@localhost ~]# grep -i "/tmp/d" /etc/fstab-- 给/etc/fstab加锁
[root@localhost ~]# chattr +i /etc/fstab
[root@localhost ~]# lsattr /etc/fstab
----i----------- /etc/fstab

删除/dev/sdb磁盘现有的分区并告知操作系统内核

####  检查磁盘/dev/sdb的分区情况
[root@localhost ~]# fdisk -l /dev/sdb
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xfa1816a9Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    52430847    26214400   83  Linux
/dev/sdb2        52430848   104859647    26214400   83  Linux
/dev/sdb3       104859648   157288447    26214400   83  Linux
/dev/sdb4       157288448   209715199    26213376   83  Linux  # 前面我已确认这些分区里面是没有数据的# 这些分区没有被挂载(临时和永久都没有了)[root@localhost ~]# lsblk /dev/sdb
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdb      8:16   0  100G  0 disk
├─sdb1   8:17   0   25G  0 part
├─sdb2   8:18   0   25G  0 part
├─sdb3   8:19   0   25G  0 part
└─sdb4   8:20   0   25G  0 part ####  用fdisk命令删除/dev/sdb的4个主分区
[root@localhost ~]# 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):
Command (m for help):
Command (m for help):
Command (m for help):
Command (m for help): p    <== 打印有哪些分区
Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0xfa1816a9Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    52430847    26214400   83  Linux
/dev/sdb2        52430848   104859647    26214400   83  Linux
/dev/sdb3       104859648   157288447    26214400   83  Linux
/dev/sdb4       157288448   209715199    26213376   83  LinuxCommand (m for help):
Command (m for help):
Command (m for help):
Command (m for help):
Command (m for help): d             <== 表示删除分区
Partition number (1-4, default 4):  <== 指定分区号,不指定默认是4,当然你也可以指定删除哪一个
Partition 4 is deletedCommand (m for help):
Command (m for help):
Command (m for help):
Command (m for help): d             <== 表示删除分区
Partition number (1-3, default 3):  <== 指定分区号,不指定默认是3,当然你也可以指定删除哪一个
Partition 3 is deletedCommand (m for help):
Command (m for help):
Command (m for help):
Command (m for help): d             <== 表示删除分区
Partition number (1,2, default 2):  <== 指定分区号,不指定默认是2,当然你也可以指定删除哪一个
Partition 2 is deletedCommand (m for help):
Command (m for help):
Command (m for help):
Command (m for help): d             <== 表示删除分区
Selected partition 1                <== 这不是我指定的哈,它自己选的,因为就剩最后一个了分区了
Partition 1 is deletedCommand (m for help):
Command (m for help):
Command (m for help):
Command (m for help): p             <== 查看分区是否被删除,但你在退出前若不保存则还是没有删除成功Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0xfa1816a9Device Boot      Start         End      Blocks   Id  SystemCommand (m for help):
Command (m for help):
Command (m for help):
Command (m for help): w             <== 将表写入磁盘并退出
The partition table has been altered!Calling ioctl() to re-read partition table.
Syncing disks.####  查看系统是否知道磁盘/dev/sdb的分区是否有变化
[root@localhost ~]# ll /dev/sdb*
brw-rw----. 1 root disk 8, 16 Jun  1 08:50 /dev/sdb####  让系统内核知道/dev/sdb的分区已经发生改变
[root@localhost ~]# partprobe /dev/sdb
[root@localhost ~]#

3.4.3 将磁盘分成–1个主分区|1个扩展分区|1个逻辑分区–格式化–临时挂载和永久挂载

在3.4.2章节已将/dev/sdb磁盘的各个分区给删除掉了,在删除前已确认是没有数据的。

*格式化/dev/sdb磁盘

####  格式化/dev/sdb磁盘
mkfs.xfs -f /dev/sdb####  检查/dev/sdb磁盘是否被格式化成xfs文件系统了,分区表的模式是否为MBR
[root@localhost ~]# parted /dev/sdb print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 107GB              <== 磁盘的容量
Sector size (logical/physical): 512B/512B
Partition Table: loop             <== 只要不是GPT
Disk Flags: Number  Start  End    Size   File system  Flags1      0.00B  107GB  107GB  xfs  <== 表示是xfs文件系统

用fdisk工具对/dev/sdb磁盘进行分区(1个主分区、1个扩展分区、1个逻辑分区)

[root@localhost ~]# 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 0xe4d88c29.Command (m for help):
Command (m for help):
Command (m for help):
Command (m for help): p    <== 查看当前有哪些分区(前面已将分区删除掉了的哈)Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0xe4d88c29Device Boot      Start         End      Blocks   Id  SystemCommand (m for help):
Command (m for help):
Command (m for help):
Command (m for help): n                         <== n表示创建分区
Partition type:p   primary (0 primary, 0 extended, 4 free)  <== p表示主分区e   extended                                 <== e表示扩展分区
Select (default p): p                           <== 输入p,表示创建主分区
Partition number (1-4, default 1): 1            <== 指定主分区的编号为1,不指定也是1
First sector (2048-209715199, default 2048):    <== 不指定
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199): +25G  <== 指定主分区的大小
Partition 1 of type Linux and of size 25 GiB is setCommand (m for help):
Command (m for help):
Command (m for help):
Command (m for help): n                         <== n表示创建分区
Partition type:p   primary (1 primary, 0 extended, 3 free)  <== p表示主分区e   extended                                 <== e表示扩展分区
Select (default p): e                           <== 输入e,表示创建扩展分区
Partition number (2-4, default 2): 2            <== 指定扩展分区的编号为2,不指定也是2
First sector (52430848-209715199, default 52430848):     <== 不指定
Using default value 52430848
Last sector, +sectors or +size{K,M,G} (52430848-209715199, default 209715199):   <== 不指定扩展分区的大小
Using default value 209715199
Partition 2 of type Extended and of size 75 GiB is setCommand (m for help):
Command (m for help):
Command (m for help):
Command (m for help): n                         <== n表示创建分区
Partition type:p   primary (1 primary, 1 extended, 2 free)  <== p表示主分区l   logical (numbered from 5)                <== l表示逻辑分区
Select (default p): l                           <== 输入l,表示创建逻辑分区
Adding logical partition 5                      <== 指定逻辑分区的编号为5,不指定也是5
First sector (52432896-209715199, default 52432896):      <== 不指定
Using default value 52432896
Last sector, +sectors or +size{K,M,G} (52432896-209715199, default 209715199):    <== 不指定逻辑分区的大小,让其使用扩展分区的所有容量
Using default value 209715199
Partition 5 of type Linux and of size 75 GiB is setCommand (m for help):
Command (m for help):
Command (m for help):
Command (m for help): p                       <== 打印磁盘的分区情况
Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0xcc587a28Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    52430847    26214400   83  Linux
/dev/sdb2        52430848   209715199    78642176    5  Extended   <== 扩展分区,/dev/sdb2不用格式化,不用挂载
/dev/sdb5        52432896   209715199    78641152   83  LinuxCommand (m for help):
Command (m for help):
Command (m for help):
Command (m for help): w                       <== 保存分区信息到磁盘的分区表,并退出
The partition table has been altered!Calling ioctl() to re-read partition table.
Syncing disks####  查看系统是否识别到了/dev/sdb磁盘的分区信息
[root@localhost ~]# ll /dev/sdb*
brw-rw----. 1 root disk 8, 16 Jun  3 00:49 /dev/sdb
brw-rw----. 1 root disk 8, 17 Jun  3 00:49 /dev/sdb1
brw-rw----. 1 root disk 8, 18 Jun  3 00:49 /dev/sdb2
brw-rw----. 1 root disk 8, 21 Jun  3 00:49 /dev/sdb5####  让操作系统的内核知道/dev/sdb磁盘的分区表已更改
[root@localhost ~]# partprobe /dev/sdb
[root@localhost ~]#

对/dev/sdb磁盘的分区进行格式化

####  查看/dev/sdb磁盘的分区情况
[root@localhost ~]# fdisk -l /dev/sdbDisk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0xcc587a28Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    52430847    26214400   83  Linux
/dev/sdb2        52430848   209715199    78642176    5  Extended  <== 这是扩展分区,不用格式化,不用挂载
/dev/sdb5        52432896   209715199    78641152   83  Linux####  格式化磁盘的主分区、逻辑分区
mkfs.xfs -f /dev/sdb1
mkfs.xfs -f /dev/sdb5####  检查是否格式化成为xfs文件系统
[root@localhost ~]# parted /dev/sdb print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: Number  Start   End     Size    Type      File system  Flags1      1049kB  26.8GB  26.8GB  primary   xfs2      26.8GB  107GB   80.5GB  extended5      26.8GB  107GB   80.5GB  logical   xfs

对磁盘各分区进行挂载

####  创建/d{1..2}目录
mkdir /d{1..2}
ls -ld /d{1..2}####  备份/etc/fstab文件
cp -a /etc/fstab{,.bak1}
ll /etc/fstab.bak1####  对/etc/fstab文件进行解锁
chattr -i /etc/fstab
lsattr /etc/fstab####  进行永久的挂载(这里挂载后不能马上使用)
echo "$(blkid|grep -i "/dev/sdb1"|awk -F "[: ]+" '{print $2}'|sed 's#"##g')  /d1  xfs  defaults 0 0" >>/etc/fstab
echo "$(blkid|grep -i "/dev/sdb5"|awk -F "[: ]+" '{print $2}'|sed 's#"##g')  /d2  xfs  defaults 0 0" >>/etc/fstab[root@localhost ~]# tail -2 /etc/fstab
UUID=923cc280-12b5-4f63-bbbc-a146ccf29492  /d1  xfs  defaults 0 0
UUID=176463e8-ad7f-452c-a138-3872f273e6e4  /d2  xfs  defaults 0 0####  对/etc/fstab文件进行加锁
chattr +i /etc/fstab
lsattr /etc/fstab####  进行挂载,让其马上可以使用
[root@localhost ~]# mount -a
[root@localhost ~]# df -h|grep "/dev/sdb"
/dev/sdb1        25G   33M   25G   1% /d1
/dev/sdb5        75G   33M   75G   1% /d2

3.4.4 检查磁盘是否有数据,并删除磁盘存在的分区

3.4.3章节将/dev/sdb磁盘分了1个主分区–1个扩展分区–1个逻辑分区,且进行了临时和永久挂载,我是没有存放数据的。该章节要将其/dev/sdb磁盘中的分区删除掉,方便3.4.5章节的实践(3个主分区+1个扩展分区+1个逻辑分区)。

对/dev/sdb磁盘每个分区的挂载进行卸载

####  检查/dev/sdb磁盘每个分区的挂载情况
[root@localhost ~]# df -h|grep "/dev/sdb"
/dev/sdb1        25G   33M   25G   1% /d1
/dev/sdb5        75G   33M   75G   1% /d2[root@localhost ~]# grep -i "/d" /etc/fstab
# Accessible filesystems, by reference, are maintained under '/dev/disk'
UUID=923cc280-12b5-4f63-bbbc-a146ccf29492  /d1  xfs  defaults 0 0
UUID=176463e8-ad7f-452c-a138-3872f273e6e4  /d2  xfs  defaults 0 0####  检查/dev/sdb磁盘每个分区中是否有数据(若有数据,你得备份并哈)
[root@localhost ~]# ls /d1|wc -l
0
[root@localhost ~]# ls /d2|wc -l
0####  对/dev/sdb磁盘每个分区的挂载进行卸载
-- 取消相关分区的临时挂载
umount /d1
umount /d2-- 备份/etc/fstab文件并进行修改
cp -a /etc/fstab{,.bak3}
ll /etc/fstab.bak3chattr -i /etc/fstab
lsattr /etc/fstabsed  -i '/\/d1/'d /etc/fstab
sed  -i '/\/d2/'d /etc/fstab-- 对/etc/fstab文件进行加锁
chattr +i /etc/fstab
lsattr /etc/fstab

删除/dev/sdb磁盘现有的分区并告知操作系统内核

####  检查磁盘/dev/sdb的分区情况
[root@localhost ~]# fdisk -l /dev/sdbDisk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0xcc587a28Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    52430847    26214400   83  Linux
/dev/sdb2        52430848   209715199    78642176    5  Extended
/dev/sdb5        52432896   209715199    78641152   83  Linux# 前面我已确认这些分区里面是没有数据的# 这些分区没有被挂载(临时和永久都没有了)[root@localhost ~]# lsblk /dev/sdb
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdb      8:16   0  100G  0 disk
├─sdb1   8:17   0   25G  0 part
├─sdb2   8:18   0    1K  0 part
└─sdb5   8:21   0   75G  0 part ####  用fdisk命令删除/dev/sdb的相关分区
[root@localhost ~]# 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):
Command (m for help):
Command (m for help):
Command (m for help): p      <== 打印有哪些分区
Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0xcc587a28Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    52430847    26214400   83  Linux
/dev/sdb2        52430848   209715199    78642176    5  Extended
/dev/sdb5        52432896   209715199    78641152   83  LinuxCommand (m for help):
Command (m for help):
Command (m for help):
Command (m for help):
Command (m for help): d   <== 表示删除分区
Partition number (1,2,5, default 5):     <== 让你输入要删除的分区编号,不指定默认5,5就是第1个逻辑分区的编号
Partition 5 is deletedCommand (m for help):
Command (m for help):
Command (m for help):
Command (m for help):
Command (m for help): d   <== 表示删除分区
Partition number (1,2, default 2):    <== 让你输入要删除的分区编号,不指定默认2,2有可能是主分区,有可能是扩展分区
Partition 2 is deleted                    Command (m for help):
Command (m for help):
Command (m for help):
Command (m for help):
Command (m for help): d  <== 表示删除分区
Selected partition 1                 <== 只乘最后一个分区了,它自己就选择了
Partition 1 is deletedCommand (m for help):
Command (m for help):
Command (m for help):
Command (m for help):
Command (m for help): p              <== 查看分区是否删除,若你发现删除错了,你再输入q(不保存并退出,之前的分区还在)Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0xcc587a28Device Boot      Start         End      Blocks   Id  SystemCommand (m for help):
Command (m for help):
Command (m for help):
Command (m for help): w           <== 输入w(写入磁盘分区,并退出)
The partition table has been altered!Calling ioctl() to re-read partition table.
Syncing disks.####  查看系统是否知道/dev/sdb的分区已改变
[root@localhost ~]# ll /dev/sdb*
brw-rw----. 1 root disk 8, 16 Jun  3 01:16 /dev/sdb####  让系统内核知道/dev/sdb的分区已改变
[root@localhost ~]# partprobe /dev/sdb
[root@localhost ~]#

3.4.5 将磁盘分成–3个主分区|1个扩展分区|1个逻辑分区–格式化–临时挂载和永久挂载

在3.4.4章节已将/dev/sdb磁盘的各个分区给删除掉了,在删除前已确认是没有数据的。

格式化/dev/sdb磁盘

### 格式化/dev/sdb磁盘
mkfs.xfs -f /dev/sdb### 检查/dev/sdb磁盘是否被格式化成xfs文件系统了,分区表的模式是否为MBR
[root@localhost ~]# parted /dev/sdb print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 107GB              <== 磁盘的容量
Sector size (logical/physical): 512B/512B
Partition Table: loop             <== 只要不是GPT
Disk Flags: Number  Start  End    Size   File system  Flags1      0.00B  107GB  107GB  xfs   <== 表示是xfs文件系统

用fdisk工具对/dev/sdb磁盘进行分区(3个主分区、1个扩展分区、1个逻辑分区)

[root@localhost ~]# 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 0x30c9f934.Command (m for help):
Command (m for help):
Command (m for help):
Command (m for help): p     <== 这是fdisk的命令,查看有哪些分区(前面我已检查是否有数据,最后删除了分区)
Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x30c9f934Device Boot      Start         End      Blocks   Id  SystemCommand (m for help):
Command (m for help):
Command (m for help):
Command (m for help):
Command (m for help): n     <== 输入命令n,表示创建分区
Partition type: p   primary (0 primary, 0 extended, 4 free)   <== p表示主分区e   extended                                  <== e表示扩展分区
Select (default p): p                            <== 输入p,表示创建主分区
Partition number (1-4, default 1): 1             <== 输入1,设置主分区的编号,默认也是1
First sector (2048-209715199, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199): +25G  <== 指定大小25G
Partition 1 of type Linux and of size 25 GiB is setCommand (m for help):
Command (m for help):
Command (m for help):
Command (m for help): n     <== 输入命令n,表示创建分区
Partition type:p   primary (1 primary, 0 extended, 3 free)   <== p表示主分区e   extended                                  <== e表示扩展分区
Select (default p): p                            <== 输入p,表示创建主分区
Partition number (2-4, default 2): 2             <== 输入2,设置主分区的编号,默认也是2
First sector (52430848-209715199, default 52430848):
Using default value 52430848
Last sector, +sectors or +size{K,M,G} (52430848-209715199, default 209715199): +25G <== 指定大小25G
Partition 2 of type Linux and of size 25 GiB is setCommand (m for help):
Command (m for help):
Command (m for help):
Command (m for help): n     <== 输入命令n,表示创建分区
Partition type:p   primary (2 primary, 0 extended, 2 free)   <== p表示主分区e   extended                                  <== e表示扩展分区
Select (default p): p                            <== 输入p,表示创建主分区
Partition number (3,4, default 3): 3             <== 输入3,设置主分区的编号,默认也是3
First sector (104859648-209715199, default 104859648):
Using default value 104859648
Last sector, +sectors or +size{K,M,G} (104859648-209715199, default 209715199): +25G <== 指定大小25G
Partition 3 of type Linux and of size 25 GiB is setCommand (m for help):
Command (m for help):
Command (m for help):
Command (m for help): n     <== 输入命令n,表示创建分区
Partition type:p   primary (3 primary, 0 extended, 1 free)   <== p表示主分区e   extended                                  <== e表示扩展分区
Select (default e): e                            <== 输入e,表示创建扩展分区
Selected partition 4                             <== 输入4,设置主分区的编号,默认也是4
First sector (157288448-209715199, default 157288448):
Using default value 157288448
Last sector, +sectors or +size{K,M,G} (157288448-209715199, default 209715199):    <== 使用剩余的所有空间
Using default value 209715199
Partition 4 of type Extended and of size 25 GiB is setCommand (m for help):
Command (m for help):
Command (m for help):
Command (m for help): n
All primary partitions are in use    # 所有主分区都在使用中
Adding logical partition 5           # 添加逻辑分区
First sector (157290496-209715199, default 157290496):
Using default value 157290496
Last sector, +sectors or +size{K,M,G} (157290496-209715199, default 209715199):  <== 不指定逻辑分区的大小,让其用扩展分区的所有容量
Using default value 209715199
Partition 5 of type Linux and of size 25 GiB is setCommand (m for help):
Command (m for help):
Command (m for help):
Command (m for help): p     <== 这是fdisk的命令,查看有哪些分区
Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x30c9f934Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    52430847    26214400   83  Linux
/dev/sdb2        52430848   104859647    26214400   83  Linux
/dev/sdb3       104859648   157288447    26214400   83  Linux
/dev/sdb4       157288448   209715199    26213376    5  Extended   <== 扩展分区,不要格式化,不要挂载
/dev/sdb5       157290496   209715199    26212352   83  LinuxCommand (m for help):
Command (m for help):
Command (m for help):
Command (m for help): w    <== 写入磁盘的分区表并退出
The partition table has been altered!Calling ioctl() to re-read partition table.
Syncing disks.####  查看系统是否识别到/dev/sdb的分区
[root@localhost ~]# ll /dev/sdb*
brw-rw----. 1 root disk 8, 16 Jun  3 01:30 /dev/sdb
brw-rw----. 1 root disk 8, 17 Jun  3 01:30 /dev/sdb1
brw-rw----. 1 root disk 8, 18 Jun  3 01:30 /dev/sdb2
brw-rw----. 1 root disk 8, 19 Jun  3 01:30 /dev/sdb3
brw-rw----. 1 root disk 8, 20 Jun  3 01:30 /dev/sdb4
brw-rw----. 1 root disk 8, 21 Jun  3 01:30 /dev/sdb5####  通知系统内核让其知道/dev/sdb的分区表发生了变化
[root@localhost ~]# partprobe /dev/sdb
[root@localhost ~]#

对/dev/sdb磁盘的分区进行格式化

####  查看/dev/sdb磁盘的分区情况
[root@localhost ~]# fdisk -l /dev/sdbDisk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x30c9f934Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    52430847    26214400   83  Linux
/dev/sdb2        52430848   104859647    26214400   83  Linux
/dev/sdb3       104859648   157288447    26214400   83  Linux
/dev/sdb4       157288448   209715199    26213376    5  Extended   <== 扩展分区,不用格式化,不用挂载
/dev/sdb5       157290496   209715199    26212352   83  Linux####  格式化磁盘的主分区、逻辑分区
mkfs.xfs -f /dev/sdb1
mkfs.xfs -f /dev/sdb2
mkfs.xfs -f /dev/sdb3
mkfs.xfs -f /dev/sdb5####  检查是否格式化成为xfs文件系统
[root@localhost ~]# parted /dev/sdb print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: Number  Start   End     Size    Type      File system  Flags1      1049kB  26.8GB  26.8GB  primary   xfs2      26.8GB  53.7GB  26.8GB  primary   xfs3      53.7GB  80.5GB  26.8GB  primary   xfs4      80.5GB  107GB   26.8GB  extended5      80.5GB  107GB   26.8GB  logical   xfs

对磁盘各分区进行挂载

####  创建/dir{1..4}目录
mkdir /dir{1..4}
ls -ld /dir{1..4}####  备份/etc/fstab文件
cp -a /etc/fstab{,.bak4}
ll /etc/fstab.bak4 ####  对/etc/fstab文件进行解锁
chattr -i /etc/fstab
lsattr /etc/fstab####  进行永久的挂载(这里挂载后不能马上使用)
echo "$(blkid|grep -i "/dev/sdb1"|awk -F "[: ]+" '{print $2}'|sed 's#"##g')  /dir1  xfs  defaults 0 0" >>/etc/fstab
echo "$(blkid|grep -i "/dev/sdb2"|awk -F "[: ]+" '{print $2}'|sed 's#"##g')  /dir2  xfs  defaults 0 0" >>/etc/fstab
echo "$(blkid|grep -i "/dev/sdb3"|awk -F "[: ]+" '{print $2}'|sed 's#"##g')  /dir3  xfs  defaults 0 0" >>/etc/fstab
echo "$(blkid|grep -i "/dev/sdb5"|awk -F "[: ]+" '{print $2}'|sed 's#"##g')  /dir4  xfs  defaults 0 0" >>/etc/fstab[root@localhost ~]# tail -4 /etc/fstab
UUID=b3619cd5-1d29-401e-8fa2-bac3ff639ff1  /dir1  xfs  defaults 0 0
UUID=ef1f52bd-e147-40a4-b556-2dd03aea2f2c  /dir2  xfs  defaults 0 0
UUID=24084557-9f04-4325-bee7-8c4d8a29d908  /dir3  xfs  defaults 0 0
UUID=cc613222-044b-401a-980f-fa0951350283  /dir4  xfs  defaults 0 0####  对/etc/fstab文件进行加锁
chattr +i /etc/fstab
lsattr /etc/fstab####  进行挂载,让其马上可以使用
[root@localhost ~]# mount -a
[root@localhost ~]# df -h|grep "/dev/sdb"
/dev/sdb1        25G   33M   25G   1% /dir1
/dev/sdb2        25G   33M   25G   1% /dir2
/dev/sdb3        25G   33M   25G   1% /dir3
/dev/sdb5        25G   33M   25G   1% /dir4

3.4.6 检查磁盘是否有数据,并删除磁盘存在的分区

3.4.5章节将/dev/sdb磁盘分了3个主分区–1个扩展分区–1个逻辑分区,且进行了临时和永久挂载,我是没有存放数据的。该章节要将其/dev/sdb磁盘中的分区删除掉,方便3.4.7章节的实践(只分一个主分区–格式化–临时挂载和永久挂载)。

对/dev/sdb磁盘每个分区的挂载进行卸载

####  检查/dev/sdb磁盘每个分区的挂载情况
[root@localhost ~]# df -h|grep "/dev/sdb"
/dev/sdb1        25G   33M   25G   1% /dir1
/dev/sdb2        25G   33M   25G   1% /dir2
/dev/sdb3        25G   33M   25G   1% /dir3
/dev/sdb5        25G   33M   25G   1% /dir4[root@localhost ~]# grep -i "/dir" /etc/fstab
UUID=b3619cd5-1d29-401e-8fa2-bac3ff639ff1  /dir1  xfs  defaults 0 0
UUID=ef1f52bd-e147-40a4-b556-2dd03aea2f2c  /dir2  xfs  defaults 0 0
UUID=24084557-9f04-4325-bee7-8c4d8a29d908  /dir3  xfs  defaults 0 0
UUID=cc613222-044b-401a-980f-fa0951350283  /dir4  xfs  defaults 0 0####  检查/dev/sdb磁盘每个分区中是否有数据(若有数据,你得备份并哈)
[root@localhost ~]# ls /dir1|wc -l
0
[root@localhost ~]# ls /dir2|wc -l
0
[root@localhost ~]# ls /dir3|wc -l
0
[root@localhost ~]# ls /dir4|wc -l
0####  对/dev/sdb磁盘每个分区的挂载进行卸载
-- 取消相关分区的临时挂载
umount /dir1
umount /dir2
umount /dir3
umount /dir4-- 备份/etc/fstab文件并进行修改
cp -a /etc/fstab{,.bak5}
ll /etc/fstab.bak5chattr -i /etc/fstab
lsattr /etc/fstab[root@localhost ~]# sed -n '/\/dir/'p /etc/fstab
UUID=b3619cd5-1d29-401e-8fa2-bac3ff639ff1  /dir1  xfs  defaults 0 0
UUID=ef1f52bd-e147-40a4-b556-2dd03aea2f2c  /dir2  xfs  defaults 0 0
UUID=24084557-9f04-4325-bee7-8c4d8a29d908  /dir3  xfs  defaults 0 0
UUID=cc613222-044b-401a-980f-fa0951350283  /dir4  xfs  defaults 0 0[root@localhost ~]# sed  -i '/\/dir/'d /etc/fstab
[root@localhost ~]# grep -i "/dir" /etc/fstab
[root@localhost ~]#

删除/dev/sdb磁盘现有的分区并告知操作系统内核

####  检查磁盘/dev/sdb的分区情况
[root@localhost ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x30c9f934Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    52430847    26214400   83  Linux
/dev/sdb2        52430848   104859647    26214400   83  Linux
/dev/sdb3       104859648   157288447    26214400   83  Linux
/dev/sdb4       157288448   209715199    26213376    5  Extended
/dev/sdb5       157290496   209715199    26212352   83  Linux# 前面我已确认这些分区里面是没有数据的# 这些分区没有被挂载(临时和永久都没有了)[root@localhost ~]# lsblk /dev/sdb
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdb      8:16   0  100G  0 disk
├─sdb1   8:17   0   25G  0 part
├─sdb2   8:18   0   25G  0 part
├─sdb3   8:19   0   25G  0 part
├─sdb4   8:20   0    1K  0 part
└─sdb5   8:21   0   25G  0 part ####  用fdisk命令删除/dev/sdb的分区
[root@localhost ~]# 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):
Command (m for help):
Command (m for help):
Command (m for help): p               <== 查看当前有哪些分区(之前确认了是没有数据的)Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x30c9f934Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    52430847    26214400   83  Linux
/dev/sdb2        52430848   104859647    26214400   83  Linux
/dev/sdb3       104859648   157288447    26214400   83  Linux
/dev/sdb4       157288448   209715199    26213376    5  Extended
/dev/sdb5       157290496   209715199    26212352   83  LinuxCommand (m for help):
Command (m for help):
Command (m for help):
Command (m for help): d               <== d表示删除分区
Partition number (1-5, default 5):    <== 指定分区的编号,不指定就是5(就是逻辑分区/dev/sdb5)
Partition 5 is deletedCommand (m for help):
Command (m for help):
Command (m for help):
Command (m for help): d              <== d表示删除分区
Partition number (1-4, default 4):   <== 指定分区的编号,不指定就是4
Partition 4 is deletedCommand (m for help):
Command (m for help):
Command (m for help): d              <== d表示删除分区
Partition number (1-3, default 3):   <== 指定分区的编号,不指定就是3
Partition 3 is deletedCommand (m for help):
Command (m for help):
Command (m for help): d              <== d表示删除分区
Partition number (1,2, default 2):   <== 指定分区的编号,不指定就是2
Partition 2 is deletedCommand (m for help):
Command (m for help):
Command (m for help):
Command (m for help): d              <== d表示删除分区,只剩余最后一个分区了,它自己就选择了
Selected partition 1
Partition 1 is deletedCommand (m for help):
Command (m for help):
Command (m for help):
Command (m for help): p             <== 检查当前磁盘是否还有分区Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x30c9f934Device Boot      Start         End      Blocks   Id  SystemCommand (m for help):
Command (m for help):
Command (m for help):
Command (m for help): w          <== 将其写入硬盘分区表,并退出
The partition table has been altered!Calling ioctl() to re-read partition table.####  查看系统是否知道/dev/sdb的分区表发生了变化
[root@localhost ~]# ll /dev/sdb*
brw-rw----. 1 root disk 8, 16 Jun  3 02:53 /dev/sdb####  让系统的内核知道/dev/sdb磁盘的分区已变化了
[root@localhost ~]# partprobe /dev/sdb
[root@localhost ~]#

3.4.7 将磁盘分成–1个主分区–格式化–临时挂载和永久挂载

在3.4.6章节已将/dev/sdb磁盘的各个分区给删除掉了,在删除前已确认是没有数据的。

格式化/dev/sdb磁盘

####  格式化/dev/sdb磁盘
mkfs.xfs -f /dev/sdb####  检查/dev/sdb磁盘是否被格式化成xfs文件系统了,分区表的模式是否为MBR
[root@localhost ~]# parted /dev/sdb print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 107GB              <== 磁盘的容量
Sector size (logical/physical): 512B/512B
Partition Table: loop             <== 只要不是GPT
Disk Flags: Number  Start  End    Size   File system  Flags1      0.00B  107GB  107GB  xfs   <== 表示是xfs文件系统

用fdisk工具对/dev/sdb磁盘进行分区(1个主分区)

[root@localhost ~]# 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 0x04517af4.Command (m for help):
Command (m for help):
Command (m for help):
Command (m for help): p           <== 查看当前磁盘有哪些分区(前面已经删除掉了的)
Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x04517af4Device Boot      Start         End      Blocks   Id  SystemCommand (m for help):
Command (m for help):
Command (m for help):
Command (m for help): n                          <== n表示创建分区
Partition type:p   primary (0 primary, 0 extended, 4 free)   <== p表示主分区e   extended                                  <== e表示扩展分区
Select (default p): p
Partition number (1-4, default 1): 1             <== 指定主分区的编号,这里指定的是1,不指定也是1
First sector (2048-209715199, default 2048):     <== 不指定
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199):  <== 让其使用磁盘的所有容量
Using default value 209715199
Partition 1 of type Linux and of size 100 GiB is setCommand (m for help):
Command (m for help):
Command (m for help):
Command (m for help): p                          <== 查看当前磁盘有哪些分区Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x04517af4Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   209715199   104856576   83  LinuxCommand (m for help):
Command (m for help):
Command (m for help):
Command (m for help): w                          <== 将分区写入磁盘的分区表,并退出
The partition table has been altered!Calling ioctl() to re-read partition table.
Syncing disks.#### 查看系统是否识别到/dev/sdb磁盘的分区信息
[root@localhost ~]# ll /dev/sdb*
brw-rw----. 1 root disk 8, 16 Jun  3 03:05 /dev/sdb
brw-rw----. 1 root disk 8, 17 Jun  3 03:05 /dev/sdb1#### 通知系统内核,让其知道磁盘的分区已改变
[root@localhost ~]# partprobe /dev/sdb
[root@localhost ~]#

对/dev/sdb磁盘的分区进行格式化

####  查看/dev/sdb磁盘的分区情况
[root@localhost ~]# fdisk -l /dev/sdbDisk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x04517af4Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   209715199   104856576   83  Linux[root@localhost ~]# lsblk /dev/sdb
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdb      8:16   0  100G  0 disk
└─sdb1   8:17   0  100G  0 part ####  格式化磁盘的主分区/dev/sdb1
mkfs.xfs -f /dev/sdb1####  检查是否格式化成为xfs文件系统
[root@localhost ~]# parted /dev/sdb
sdb   sdb1
[root@localhost ~]# parted /dev/sdb print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: Number  Start   End    Size   Type     File system  Flags1      1049kB  107GB  107GB  primary  xfs

对磁盘各分区进行挂载

####  创建/data目录
mkdir /data
ls -ld /data####  备份/etc/fstab文件
cp -a /etc/fstab{,.bak6}
ll /etc/fstab.bak6#### 对/etc/fstab文件进行解锁
chattr -i /etc/fstab
lsattr /etc/fstab####  进行永久的挂载(这里挂载后不能马上使用)
echo "$(blkid|grep -i "/dev/sdb1"|awk -F "[: ]+" '{print $2}'|sed 's#"##g')  /data   xfs  defaults  0 0" >>/etc/fstab[root@localhost ~]# tail -1 /etc/fstab
UUID=d5570a6d-7b9a-4244-8d89-f88d9e17db0c  /data   xfs  defaults  0 0####  对/etc/fstab文件进行加锁
chattr +i /etc/fstab
lsattr /etc/fstab####  进行挂载,让其马上可以使用
[root@localhost ~]# mount -a
[root@localhost ~]# df -h|grep "/dev/sdb"
/dev/sdb1       100G   33M  100G   1% /data

3.4.8 检查磁盘是否有数据,并删除磁盘存在的分区

在3.4.7章节中将/dev/sdb磁盘分成了一个主分区–格式化–临时挂载和永久挂载,在这章节要将其分区信息进行删除,方便在3.4.9章节的实践(不对磁盘进行分区—格式化—挂载)

对/dev/sdb磁盘每个分区的挂载进行卸载

####  查看/dev/sdb磁盘各分区的挂载情况
[root@localhost ~]# df -h|grep "/dev/sdb"
/dev/sdb1       100G   33M  100G   1% /data[root@localhost ~]# grep -i "/data" /etc/fstab
UUID=d5570a6d-7b9a-4244-8d89-f88d9e17db0c  /data   xfs  defaults  0 0####  检查/dev/sdb磁盘每个分区中是否有数据(若有数据,你得备份并哈)
[root@localhost ~]# ls /data|wc -l
0#### 对/dev/sdb磁盘每个分区的挂载进行卸载
-- 取消相关分区的临时挂载
umount /data-- 备份/etc/fstab文件并进行修改
cp -a /etc/fstab{,.bak7}
ll /etc/fstab.bak7chattr -i /etc/fstab
lsattr /etc/fstab[root@localhost ~]# sed -n '/\/data/'p /etc/fstab
UUID=d5570a6d-7b9a-4244-8d89-f88d9e17db0c  /data   xfs  defaults  0 0[root@localhost ~]# sed -i '/\/data/'d /etc/fstab
[root@localhost ~]# grep -i "/data" /etc/fstab
[root@localhost ~]#

删除/dev/sdb磁盘现有的分区并告知操作系统内核

[root@localhost ~]# 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):
Command (m for help):
Command (m for help):
Command (m for help): p      <== 查看磁盘当前有哪些分区
Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x04517af4Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   209715199   104856576   83  LinuxCommand (m for help):
Command (m for help):
Command (m for help):
Command (m for help): d      <== 删除分区
Selected partition 1
Partition 1 is deletedCommand (m for help):
Command (m for help):
Command (m for help):
Command (m for help): p      <== 查看磁盘当前有哪些分区Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x04517af4Device Boot      Start         End      Blocks   Id  SystemCommand (m for help):
Command (m for help):
Command (m for help):
Command (m for help): w      <== 将分区信息写入磁盘的分区表并退出
The partition table has been altered!Calling ioctl() to re-read partition table.
Syncing disks.####  查看系统是否知道磁盘/dev/sdb的分区信息是知改变
[root@localhost ~]# ll /dev/sdb*
brw-rw----. 1 root disk 8, 16 Jun  3 03:47 /dev/sdb####  让系统内核知道/dev/sdb磁盘的分区信息已改变
[root@localhost ~]# partprobe /dev/sdb
[root@localhost ~]#

3.4.9 格式化磁盘–不分区—直接挂载使用【注意哈】

在3.4.8章节中已将/dev/sdb磁盘的分区删除掉了,在删除前已确认是没有数据的。

格式化磁盘

####  将磁盘/dev/sdb格式化成xfs文件系统
mkfs.xfs -f /dev/sdb####  检查磁盘/dev/sdb是否被格式化成xfs文件系统
[root@localhost ~]# parted /dev/sdb print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags: Number  Start  End    Size   File system  Flags1      0.00B  107GB  107GB  xfs

对磁盘进行挂载

####  创建/mysql目录,用于挂载
mkdir /mysql
ls -ld /mysql####  备份/etc/fstab文件并进行解锁
cp -a /etc/fstab{,.bak8}
ll /etc/fstab.bak8chattr -i /etc/fstab
lsattr /etc/fstab####  让其永久挂载(不能马上使用)并对/etc/fstab文件加锁
echo "$(blkid|grep "/dev/sdb"|awk -F "[: ]+" '{print $2}'|sed 's#"##g')  /mysql  xfs  defaults  0 0" >>/etc/fstab[root@localhost ~]# tail -1 /etc/fstab
UUID=dbead2b5-10f5-41b1-ba02-8553e577c120  /mysql  xfs  defaults  0 0chattr +i /etc/fstab
lsattr /etc/fstab####  让其挂载(让其可以马上使用)
[root@localhost ~]# mount -a
[root@localhost ~]#
[root@localhost ~]# df -h|grep "/dev/sdb"
/dev/sdb        100G   33M  100G   1% /mysql

注意

####  用fdisk -l查看/dev/sdb的分区信息
[root@localhost ~]# fdisk -l /dev/sdb Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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@localhost ~]# lsblk /dev/sdb
NAME MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdb    8:16   0  100G  0 disk /mysql# 可以看出是挂载到/mysql目录下的

3.4.10 检查磁盘是否有数据,并删除磁盘存在的分区

在3.4.9章节是将/dev/sdb格式化成文件系统–临时挂载和永久挂载(没有分区)的操作。这时要取消其临时挂载和永久挂载,并将其磁盘重新格式化一下。方便后面章节的实践。

检查磁盘是否有数据,并进行挂载的卸载

#### 检查磁盘是否分区、是否挂载
[root@localhost ~]# fdisk -l /dev/sdb Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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@localhost ~]# lsblk /dev/sdb
NAME MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdb    8:16   0  100G  0 disk /mysql
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# df -h|grep "/dev/sdb"
/dev/sdb        100G   33M  100G   1% /mysql
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# grep -i "/mysql" /etc/fstab
UUID=33d70562-c800-41f1-88fb-feb64e8eeb4b  /mysql  xfs  defaults  0 0#### 检查是否有数据
[root@localhost ~]# ls /mysql|wc -l
0#### 进行磁盘挂载的卸载
-- 进行临时的卸载
[root@localhost ~]# umount /mysql/
[root@localhost ~]# df -h|grep "/dev/sdb"-- 进行永久的卸载
[root@localhost ~]# cp -a /etc/fstab{,.bak9}      # 对/etc/fstab文件做备份
[root@localhost ~]# ll /etc/fstab.bak9
-rw-r--r--. 1 root root 571 Jun  4 06:33 /etc/fstab.bak9[root@localhost ~]# chattr -i /etc/fstab          # 解锁/etc/fstab
[root@localhost ~]# lsattr /etc/fstab
---------------- /etc/fstab[root@localhost ~]# sed -n '/\/mysql/'p /etc/fstab   # 检查
UUID=33d70562-c800-41f1-88fb-feb64e8eeb4b  /mysql  xfs  defaults  0 0[root@localhost ~]# sed -i '/\/mysql/'d /etc/fstab   # 修改/etc/fstab文件
[root@localhost ~]# grep -i "/mysql" /etc/fstab[root@localhost ~]# chattr +i /etc/fstab             # 对/etc/fstab文件加锁
[root@localhost ~]# lsattr /etc/fstab
----i----------- /etc/fstab

将/dev/sdb磁盘重新格式化一次
前面将/dev/sdb的临时挂载和永久挂载都卸载了,且检查了是没有数据的。

## 将磁盘/dev/sdb格式化成文件系统
mkfs.xfs -f /dev/sdb## 检查磁盘/dev/sdb是否被格式化成了xfs文件系统
[root@localhost ~]# parted /dev/sdb print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags: Number  Start  End    Size   File system  Flags1      0.00B  107GB  107GB  xfs

3.4.11 fdisk非交互工下进行分区

4 GPT类型的分区表介绍和parted的实践

5 fdisk和parted工具分区的总结

fdisk和parted对磁盘的分区总结相关推荐

  1. linux使用parted分区报错,使用parted对硬盘进行分区

    使用parted对硬盘进行分区 在linux系统中,分区通常可以使用fdisk和parted工具,分区表通常有MBR分区表和GPT分区表.对于磁盘大小小于2T的磁盘,我们可以使用fdisk和parte ...

  2. 【linux磁盘分区--格式化】fdisk,parted,mkfs.ext3

    磁盘分区完成后,一般就需要对分区进行格式化 磁盘分区命令主要有两个: fdisk :最大支持不超过2T分区: parted :支持GPT,适用于大容量分区: 分区指令的选择: 在RHEL系统上,用fd ...

  3. 磁盘分区命令fdisk、parted和gdisk

    Linux给新加磁盘进行分区有三个常用命令: fdisk.parted.gdisk fdisk最多只能有4个主分区,或3个主分区加1个扩展分区.fdisk最大只能管理2T大小的分区. 当想要用fdis ...

  4. fdisk和parted磁盘分区工具命令

    本文转载自:点击打开链接(http://blog.163.com/nancainvmao_bq/blog/static/106573742013101253730555/) 补充:parted支持2T ...

  5. 如何使用fdisk与parted对不同容量硬盘分区

    一.简介 通常我们用的比较多的一般都是fdisk工具来进行分区,但是现在由于磁盘越来越廉价,而且磁盘空间越来越大;而fdisk工具他对分区是有大小限制的,它只能划分小于2T的磁盘.如果使用fdisk对 ...

  6. 8.4 parted:磁盘分区工具

    parted 对于小于2TB的磁盘可以用fdisk和parted命令进行分区,这种情况一般采用flisk命令,但对于大于2TB的磁盘则只能用parted分区,且需要将磁盘转换为GPT格式. parte ...

  7. [CentOS7] parted用于磁盘分区(同时支持GPT和MBR分区表)

    声明:本文主要总结自:鸟哥的Linux私房菜-第七章.Linux 磁碟與檔案系統管理,如有侵权,请通知博主 fdisk支持MBR分区表,gdisk支持GPT分区表,而parted支持两者 不知道为什么 ...

  8. fdisk、parted无损调整普通分区大小

    2019独角兽企业重金招聘Python工程师标准>>> 环境:oracle linux 6.4 #fdisk -v fdisk (util-linux-ng 2.17.2) #par ...

  9. Linux笔记 No.17---(磁盘分区fdisk,gdisk,parted、格式化mkfs,mke2fs、挂载mount、卸载umount、df、du、lsof命令)

    文章目录 一.磁盘 (一)机械硬盘(HDD) 1.基本组成 2.逻辑结构 (二)固态硬盘(SSD) 二.硬盘分区 (一)基本概念 1. MBR(MS-DOS 主引导记录区)方案 2.GPT(GUID ...

最新文章

  1. 测试工程师工作流程概论
  2. html class 位置,HTML class 属性 | 菜鸟教程
  3. ffmpeg图片压缩为视频
  4. PHP之SQL防注入代码(360提供)
  5. kafka配置参数详解
  6. 禁止复制的网页怎么复制
  7. 企业微信万亿级日志检索系统
  8. why is pricing callback CRM_PRIDOC_UPDATE_EC called
  9. 金蝶二次开发好跳槽吗_金蝶财务软件不会操作怎么办?
  10. 计算机及服务器硬件组成结合企业运维场景知识
  11. mysql case循环_php一次操作多个数据是循环更新好还是使用mysql里带的casewhen?性能方面哪个更有优势?...
  12. CTF —— 网络安全大赛
  13. 职场Word使用技巧大全,太实用了
  14. TFN DG15M 高抗干扰电缆故障测试仪评测
  15. 局域网内建网站教程,如何零成本搭建自己的网站?
  16. 1.8w 字 | 初中级前端 JavaScript 自测清单 - 2
  17. 如果你看见这个舞女是顺时针转,说明你用的是右脑;耶鲁大学耗时5年的研究成果。左脑?右脑?
  18. 后台UI框架开发(一)
  19. ubuntu无线网卡安装指南
  20. 笔记本宏碁 4750G加装固态硬盘小计

热门文章

  1. PDF在线编辑器的实现
  2. 腾讯企业邮箱只能接受消息不能发送
  3. 2021年中国人工智能产业及其重点企业分析(阿里巴巴、百度、腾讯、科大讯飞)[图]
  4. Grubbs Test
  5. 丽江古城历史悠久,古朴自然
  6. CPU也能加速AlphaFold2!英特尔最新发布:23倍通量优化指南!
  7. 1905. 统计子岛屿
  8. re.search与re.findall的区别
  9. TDD双工方式保护时隙与通信距离的关系
  10. 《信息物理融合系统(CPS)设计、建模与仿真——基于 Ptolemy II 平台》——2.4 注释及参数设置...