> 文章列表 > Centos7.5 使用gpt模式挂载磁盘

Centos7.5 使用gpt模式挂载磁盘

Centos7.5 使用gpt模式挂载磁盘

说明:挂载大于2T容量的磁盘时,需要要用parted分区,小于2T可以用fdisk /dev/vdc;

数据库备份服务器挂载3T磁盘;

故我用fdisk 分区会有如下告警提示,所以改用parted分区;


[root@DBbackup ~]# fdisk /dev/vdc
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 0x504fd045.WARNING: The size of this disk is 3.2 TB (3221225472000 bytes).
DOS partition table format can not be used on drives for volumes
larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID
partition table format (GPT).

首先,找到需要挂载的磁盘。

fdisk -l
[root@DBbackup ~]# fdisk -lDisk /dev/vda: 128.8 GB, 128849018880 bytes, 251658240 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: 0x000cc5f5Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     2099199     1048576   83  Linux
/dev/vda2         2099200   251658239   124779520   8e  Linux LVM
WARNING: fdisk GPT support is currently new, and therefore in an experimental ph                                          ase. Use at your own discretion.Disk /dev/vdb: 2147.5 GB, 2147483648000 bytes, 4194304000 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: gpt
Disk identifier: B0406BA1-116C-4D49-AE8C-7E427CF75FD1#         Start          End    Size  Type            Name1           34   4194302047      2T  Microsoft basic backDisk /dev/mapper/apolloos-root: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/apolloos-swap: 8455 MB, 8455716864 bytes, 16515072 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/apolloos-home: 65.6 GB, 65624080384 bytes, 128172032 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/vdc: 3221.2 GB, 3221225472000 bytes, 6291456000 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@DBbackup ~]# df -Th
Filesystem                Type      Size  Used Avail Use% Mounted on
devtmpfs                  devtmpfs   32G     0   32G   0% /dev
tmpfs                     tmpfs      32G  212K   32G   1% /dev/shm
tmpfs                     tmpfs      32G   25M   32G   1% /run
tmpfs                     tmpfs      32G     0   32G   0% /sys/fs/cgroup
/dev/mapper/apolloos-root xfs        50G   15G   36G  29% /
tmpfs                     tmpfs     2.0G     0  2.0G   0% /tmp
tmpfs                     tmpfs     2.0G     0  2.0G   0% /var/tmp
/dev/vdb1                 xfs       2.0T  1.1T  967G  52% /bakdata
/dev/vda1                 xfs      1014M  176M  839M  18% /boot
/dev/mapper/apolloos-home xfs        62G  3.4G   58G   6% /home
tmpfs                     tmpfs     6.3G     0  6.3G   0% /run/user/1000

 本文以数据库备份虚拟机服务器为例演示,故磁盘是vda、vdb、vdc一类,如果是物理服务器一般是以sda、sdb、sdc。

 可以看见我们待挂载的新磁盘为 /dev/vdc

parted /dev/vdb
mklabel

 输入磁盘标签类型

New disk labeltype? gpt

 再次列出磁盘分区

(parted) p
[root@DBbackup ~]# parted /dev/vdc
GNU Parted 3.1
Using /dev/vdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)(parted) mklabel
New disk label type? gpt
(parted) q
Information: You may need to update /etc/fstab.

使用分区

(parted) mkpart primary 0% 100%

再次查看分区

(parted) p
Model: Virtio Block Device (virtblk)
Disk /dev/vdc: 3221GB
Sector size (logical/physical): 512B/512BPartition Table: gpt
Disk Flags:Number  Start   End     Size    File system  Name     Flags1      1049kB  3221GB  3221GB               primary(parted) q
Information: You may need to update /etc/fstab.

退出

q

格式化刚刚新建好的分区

[root@DBbackup ~]# mkfs.xfs -f /dev/vdc
meta-data=/dev/vdc               isize=512    agcount=4, agsize=196608000 blks=                       sectsz=512   attr=2, projid32bit=1=                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=786432000, imaxpct=5=                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=384000, version=2=                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

创建一个/bakdatalyw文件   然后查看是否挂载成功

[root@DBbackup ~]# mkdir -p /bakdatalyw
[root@DBbackup ~]# fdisk -lDisk /dev/vda: 128.8 GB, 128849018880 bytes, 251658240 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: 0x000cc5f5Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     2099199     1048576   83  Linux
/dev/vda2         2099200   251658239   124779520   8e  Linux LVM
WARNING: fdisk GPT support is currently new, and therefore in an experimental ph                                          ase. Use at your own discretion.Disk /dev/vdb: 2147.5 GB, 2147483648000 bytes, 4194304000 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: gpt
Disk identifier: B0406BA1-116C-4D49-AE8C-7E427CF75FD1#         Start          End    Size  Type            Name1           34   4194302047      2T  Microsoft basic backDisk /dev/mapper/apolloos-root: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/apolloos-swap: 8455 MB, 8455716864 bytes, 16515072 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/apolloos-home: 65.6 GB, 65624080384 bytes, 128172032 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/vdc: 3221.2 GB, 3221225472000 bytes, 6291456000 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@DBbackup ~]# mount /dev/vdc /bakdatalyw
[root@DBbackup ~]# df -Th
Filesystem                Type      Size  Used Avail Use% Mounted on
devtmpfs                  devtmpfs   32G     0   32G   0% /dev
tmpfs                     tmpfs      32G  212K   32G   1% /dev/shm
tmpfs                     tmpfs      32G   25M   32G   1% /run
tmpfs                     tmpfs      32G     0   32G   0% /sys/fs/cgroup
/dev/mapper/apolloos-root xfs        50G   15G   36G  29% /
tmpfs                     tmpfs     2.0G     0  2.0G   0% /tmp
tmpfs                     tmpfs     2.0G     0  2.0G   0% /var/tmp
/dev/vdb1                 xfs       2.0T  1.1T  967G  52% /bakdata
/dev/vda1                 xfs      1014M  176M  839M  18% /boot
/dev/mapper/apolloos-home xfs        62G  3.4G   58G   6% /home
tmpfs                     tmpfs     6.3G     0  6.3G   0% /run/user/1000
/dev/vdc                  xfs       3.0T   33M  3.0T   1% /bakdatalyw

查看 /dev/vdb的UUID

[root@DBbackup ~]# blkid /dev/vdc
/dev/vdc: UUID="61925832-968e-4456-bc5f-a70d031840db" TYPE="xfs"

设置开机自动挂载

vim /etc/fstab
#也可以直接vi /etc/fstab

按insert键 进入编辑模式 新行写入

UUID=61925832-968e-4456-bc5f-a70d031840db /data xfs defaults 0 0

然后键入  ESC ,再键入

:wq!

保存!

重启服务器验证

reboot

自此,磁盘已成功挂载。

重启完成后再次验证

df -Th

---------------------------------------------------------------

注意:
parted命令和fdisk命令不同,fdisk命令是等到你最后执行那个w的时候才生效最终写入到分区表中的,
parted命令是实时的写入到分区表,所以在操作有数据的磁盘的时候需要格外小心,毕竟数据无价的!

------------------------------------

参考文章:
Linux主分区,扩展分区,逻辑分区的联系和区别:https://www.cnblogs.com/alexyuyu/articles/3454907.html
centos7挂载新加4T硬盘到/home目录:https://www.cnblogs.com/wq242424/p/9187285.html
CentOS7设置开机自动挂载硬盘:https://blog.csdn.net/tangjuntangjun/article/details/84635259

基本概念

MBR(Master Boot Record)

主引导记录(Master Boot Record,缩写:MBR),又叫做主引导扇区,是计算机开机后访问硬盘时所必须要读取的首个扇区,硬盘的第一个扇区也就是第0扇区是用来存放主引导记录(MBR)的,因此也称MBR扇区。

磁盘分区格式
硬盘分区有三种,主磁盘分区、扩展磁盘分区、逻辑分区。

一个硬盘主分区至少有1个,最多4个,扩展分区可以没有,最多1个。且主分区+扩展分区总共不能超过4个。逻辑分区可以有若干个。
在windows下激活的主分区是硬盘的启动分区,他是独立的,也是硬盘的第一个分区,正常分的话就是C区。 在linux下主分区和逻辑分区都可以用来放系统,引导os开机;

分出主分区后,其余的部分可以分成扩展分区,一般是剩下的部分全部分成扩展分区,也可以不全分,那剩的部分就浪费了。

但扩展分区是不能直接用的,他是以逻辑分区的方式来使用的,所以说扩展分区可分成若干逻辑分区。他们的关系是包含的关系,所有的逻辑分区都是扩展分区的一部分。

在linux中第一块硬盘分区为hda分区,主分区编号为hda1-4,逻辑分区从5开始。
硬盘的容量=主分区的容量+扩展分区的容量
扩展分区的容量=各个逻辑分区的容量之和

分区划分缘由
一个MBR扇区是512字节,其具体数据结构是:446个字节的引导代码、64个字节的分区表及2个字节的签名值"55AA"。由于MBR的分区表只有64个字节,这决定了它只能 存储4个分区记录。这就是为什么一块硬盘最多只能有4个“主分区"的原因。要划出4个以上的分区一种的思路就是把其中一个主分区再进 行细分,衍生出一个二级分区表。对的,这个被用来二次分区的主分区就是“扩展分区”,它下面的二级分区就是“逻辑分区”。

MBR 2T限制
在使用fdisk建立分区时,我们最大只能建立2TB大小的分区,如果你的磁盘(阵列)大于2TB,只能通过划分多个分区的方法才能充分利用磁盘容量。或者使用GPT分区表,可以支持2T以上的分区;

GPT(GUID Partition Table)

全局唯一标识分区表(GUID Partition Table,缩写:GPT)是一个实体硬盘的分区结构。它是EFI(可扩展固件接口标准)的一部分,用来替代BIOS中的主引导记录分区表。GPT磁盘分区支持最大卷为18 EB(Exabytes)并且每磁盘的分区数没有上限,只受到操作系统限制。

在MBR硬盘中,分区信息直接存储于主引导记录(MBR)中(主引导记录中还存储着系统的引导程序)。但在GPT硬盘中,分区表的位置信息储存在GPT头中。但出于兼容性考虑,硬盘的第一个扇区仍然用作MBR,之后才是GPT头。

EFI(Extensible Firmware Interface)

可 扩展固件接口(英文名Extensible Firmware Interface 或EFI)是一种个人电脑系统规格,用来定义操作系统与系统韧体之间的软件界面,为替代BIOS的升级方案。可扩展固件接口负责加电自检(POST)、连 系操作系统以及提供连接操作系统与硬件的接口。
EFI最初由英特尔开发,现时由UEFI论坛来推广与发展。

UEFI是由EFI1.10为基础发展起来的,它的所有者已不再是Intel,而是一个称作Unified EFI Form的国际组织,贡献者有Intel,Microsoft,AMI,等几个大厂,属于open source,目前版本为2.1。

GPT挂载超过2T的磁盘

由于fdisk仅支持2T以内的磁盘分区,大于2T的磁盘要使用parted进行GPT格式分区。分区之前要先确认磁盘其实扇区的位置;

磁盘其实扇区计算:
查看磁盘参数,根据实际参数计算起始扇区的设定值;

如果optimal_io_size为0,那么我们最好直接使用起始扇区的默认值2048。
如果optimal_io_size不为0,则可以用optimal_io_size的值加上alignment_offset的值,然后除以physical_block_size的值,就是起始扇区的位置了。计算公式:(optimal_io_size+alignment_offset)/physical_block_size

/etc/fstab 文件参数解释:

  • defaults:挂载时所要设定的参数(只读,读写,启用quota等),输入defaults包括的参数有(rw、dev、exec、auto、nouser、async)
  • 0:使用dump是否要记录,0为不需要,1为需要
  • 2:2是开机时检查的顺序,boot系统文件为1,其他文件系统都为2,如不要检查就为0

挂载小于2T的磁盘

小于2T的磁盘可以直接使用fdisk 命令进行挂载。