CentOS中管理大于2T的磁盘分区

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS中管理大于2T的磁盘分区相关的知识,希望对你有一定的参考价值。

参考技术A

常见磁盘分区存储形式类型有两种: MBR(MSDOS) GPT

MBR(Master Boot Record,主引导记录)。
MBR是存在于驱动器最开始部分的一个特殊的启动扇区,一般叫它0扇区。它由446B的启动加载器(Windows和Linux的不同),64B的分区表,和2B用来存放区域的有效性标识55AA,共512B。

GPT(GUID Partition Table),这是最近几年逐渐流行起来的一种分区形式,如果要将使用GPT分区格式的磁盘作为系统盘,需要UEFI Bios的支持,它才可以引导系统启动。UEFI一种称为Unified Extensible Firmware Interface(统一的可扩展的固件接口,它最终是为了取代BIOS,目前市面上的BIOS大多已支持UEFI。GPT也是为了最终取代MBR的。
GPT相比MBR的优点:

因为传统的MBR分区,支持的最大分区为2T,也可以一定程度上等同于磁盘大小,必定2T以上的硬盘不是非常普及。在CentOS中可以使用 fdisk 指令进行管理。详细过程不在赘述。

当CentOS中识别到有磁盘容量超过2T时,如果试图使用 fdisk 指令对其分区会有相应的警告提示,大致如下:

明确提示需要使用 parted 进行管理,如果系统中没有这一指令,使用 yum install -y parted 进行安装即可。

4K对齐
在磁盘中的扇区只有排列整齐才有利于发挥磁盘的最佳读写性能。这里的对齐即常听说的4K对齐。可以简单的理解4K对齐的作用:当在磁盘中存取小于4K的数据时,如果没有4K对齐这时候很可能需要将这份数据放到两个4K块中,会出现多次读写不同的块的情况,明显没有4K对齐只在一个块中去存取数据高效。
如果系统进行了磁盘内核参数的调整,可以使用以下公式计算出合适的磁盘第一分区的start值,单位为s,s表示扇区,如果没有调整start可以使用2048s或0%表示。end值可以使用百分比的形式,也可以使用数字加单位的形式,如50%,3T。

然后将optimal_io_size的值加上alignment_offset的值,再除以physical_block_size的值,得到这块盘分区的起始位置扇区编号。

注意 :parted指令做的磁盘设置立即生效,不需要和fdisk一样使用w才会生效。

当完成对超过2T的磁盘分区以后,可以查看系统内核( cat /proc/partition )是否已成功识别到相应分区。如果识别到了,按照常规方式对分区进行格式化,然后挂载即可使用新的磁盘分区了。

CentOS 7.6在线扩容xfs文件系统(创建大于2T的磁盘分区并使用LVM管理)

1. 使用parted方式格式化磁盘

1.1 查看磁盘情况

[root@jylhlog2 ~]# fdisk -l

Disk /dev/sdd: 2199.0 GB, 2199023255552 bytes, 4294967296 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 /dev/sdb: 42.9 GB, 42949672960 bytes, 83886080 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 /dev/sdc: 2199.0 GB, 2199023255552 bytes, 4294967296 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 /dev/sde: 2199.0 GB, 2199023255552 bytes, 4294967296 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 /dev/sdf: 2199.0 GB, 2199023255552 bytes, 4294967296 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 /dev/sda: 536.9 GB, 536870912000 bytes, 1048576000 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: 0x0008ce60

Device Boot Start End Blocks Id System

/dev/sda1 * 2048 2099199 1048576 83 Linux

/dev/sda2 2099200 1048567807 523234304 8e Linux LVM

Disk /dev/mapper/vg_root-lv_root: 64.4 GB, 64424509440 bytes, 125829120 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 /dev/mapper/vg_root-lv_swap: 68.7 GB, 68719476736 bytes, 134217728 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 /dev/mapper/vg_root-lv_data: 209.4 GB, 209371267072 bytes, 408928256 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 /dev/mapper/vg_root-lv_home: 64.4 GB, 64424509440 bytes, 125829120 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 /dev/mapper/vg_root-oracle: 64.4 GB, 64424509440 bytes, 125829120 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 /dev/mapper/vg_root-lv_grid: 64.4 GB, 64424509440 bytes, 125829120 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 /dev/sdg: 2199.0 GB, 2199023255552 bytes, 4294967296 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@jylhlog2 ~]#

1.2 使用parted格式化/dev/sdg分区

[root@jylhlog2 ~]# parted /dev/sdg

GNU Parted 3.1

Using /dev/sdg

Welcome to GNU Parted! Type ‘help‘ to view a list of commands.

(parted) mklabel gpt ------将MBR分区形式转为GPT分区形式

(parted) mkpart primary xfs 0 -1 ------设置分区的开始位置和结束位置

Warning: The resulting partition is not properly aligned for best performance.

Ignore/Cancel? Ignore

(parted) print ------查看分区

Model: VMware Virtual disk (scsi)

Disk /dev/sdg: 2199GB

Sector size (logical/physical): 512B/512B

Partition Table: gpt

Disk Flags:

Number Start End Size File system Name Flags

1 17.4kB 2199GB 2199GB primary

(parted) toggle 1 lvm ------使用toggle 更改硬盘类型

(parted) print ------查看分区

Model: VMware Virtual disk (scsi)

Disk /dev/sdg: 2199GB

Sector size (logical/physical): 512B/512B

Partition Table: gpt

Disk Flags:

Number Start End Size File system Name Flags

1 17.4kB 2199GB 2199GB primary lvm

(parted) quit

Information: You may need to update /etc/fstab.

[root@jylhlog2 ~]#

1.3 查看格式化后的分区情况

[root@jylhlog2 ~]# fdisk -l

Disk /dev/sdd: 2199.0 GB, 2199023255552 bytes, 4294967296 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 /dev/sdb: 42.9 GB, 42949672960 bytes, 83886080 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 /dev/sdc: 2199.0 GB, 2199023255552 bytes, 4294967296 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 /dev/sde: 2199.0 GB, 2199023255552 bytes, 4294967296 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 /dev/sdf: 2199.0 GB, 2199023255552 bytes, 4294967296 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 /dev/sda: 536.9 GB, 536870912000 bytes, 1048576000 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: 0x0008ce60

Device Boot Start End Blocks Id System

/dev/sda1 * 2048 2099199 1048576 83 Linux

/dev/sda2 2099200 1048567807 523234304 8e Linux LVM

Disk /dev/mapper/vg_root-lv_root: 64.4 GB, 64424509440 bytes, 125829120 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 /dev/mapper/vg_root-lv_swap: 68.7 GB, 68719476736 bytes, 134217728 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 /dev/mapper/vg_root-lv_data: 209.4 GB, 209371267072 bytes, 408928256 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 /dev/mapper/vg_root-lv_home: 64.4 GB, 64424509440 bytes, 125829120 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 /dev/mapper/vg_root-oracle: 64.4 GB, 64424509440 bytes, 125829120 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 /dev/mapper/vg_root-lv_grid: 64.4 GB, 64424509440 bytes, 125829120 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

WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

Disk /dev/sdg: 2199.0 GB, 2199023255552 bytes, 4294967296 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: 9C5E039C-2C6C-4585-8EAB-7B2DBA949516

# Start End Size Type Name

1 34 4294965343 2T Linux LVM primary

[root@jylhlog2 ~]#

1.4 使系统重读分区表

[root@jylhlog2 ~]# partprobe

Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.

[root@jylhlog2 ~]#

[root@jylhlog2 ~]# fdisk -l

Disk /dev/sdd: 2199.0 GB, 2199023255552 bytes, 4294967296 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 /dev/sdb: 42.9 GB, 42949672960 bytes, 83886080 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 /dev/sdc: 2199.0 GB, 2199023255552 bytes, 4294967296 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 /dev/sde: 2199.0 GB, 2199023255552 bytes, 4294967296 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 /dev/sdf: 2199.0 GB, 2199023255552 bytes, 4294967296 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 /dev/sda: 536.9 GB, 536870912000 bytes, 1048576000 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: 0x0008ce60

Device Boot Start End Blocks Id System

/dev/sda1 * 2048 2099199 1048576 83 Linux

/dev/sda2 2099200 1048567807 523234304 8e Linux LVM

Disk /dev/mapper/vg_root-lv_root: 64.4 GB, 64424509440 bytes, 125829120 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 /dev/mapper/vg_root-lv_swap: 68.7 GB, 68719476736 bytes, 134217728 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 /dev/mapper/vg_root-lv_data: 209.4 GB, 209371267072 bytes, 408928256 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 /dev/mapper/vg_root-lv_home: 64.4 GB, 64424509440 bytes, 125829120 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 /dev/mapper/vg_root-oracle: 64.4 GB, 64424509440 bytes, 125829120 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 /dev/mapper/vg_root-lv_grid: 64.4 GB, 64424509440 bytes, 125829120 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

WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

Disk /dev/sdg: 2199.0 GB, 2199023255552 bytes, 4294967296 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: 9C5E039C-2C6C-4585-8EAB-7B2DBA949516

# Start End Size Type Name

1 34 4294965343 2T Linux LVM primary

[root@jylhlog2 ~]#

2 创建pv、扩容vg、扩容lv、扩容xfs分区

2.1 查看目前分区情况

[root@jylhlog2 ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/vg_root-lv_root 60G 6.2G 54G 11% /

devtmpfs 63G 0 63G 0% /dev

tmpfs 63G 640M 63G 1% /dev/shm

tmpfs 63G 32M 63G 1% /run

tmpfs 63G 0 63G 0% /sys/fs/cgroup

/dev/sda1 1014M 179M 836M 18% /boot

/dev/mapper/vg_root-lv_grid 60G 40G 21G 66% /grid

/dev/mapper/vg_root-lv_data 195G 595M 195G 1% /data

/dev/mapper/vg_root-oracle 60G 22G 38G 37% /oracle

/dev/mapper/vg_root-lv_home 60G 16G 45G 27% /home

tmpfs 13G 12K 13G 1% /run/user/42

tmpfs 13G 0 13G 0% /run/user/1000

[root@jylhlog2 ~]#

2.2 查看目前lv情况

[root@jylhlog2 ~]# lvs

LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert

lv_data vg_root -wi-ao---- 194.99g

lv_grid vg_root -wi-ao---- 60.00g

lv_home vg_root -wi-ao---- 60.00g

lv_root vg_root -wi-ao---- 60.00g

lv_swap vg_root -wi-ao---- 64.00g

oracle vg_root -wi-ao---- 60.00g

[root@jylhlog2 ~]#

2.3 查看目前vg情况

[root@jylhlog2 ~]# vgs

VG #PV #LV #SN Attr VSize VFree

vg_root 1 6 0 wz--n- 498.99g 0

[root@jylhlog2 ~]#

2.4 创建pv

[root@jylhlog2 ~]# pvcreate /dev/sdg1

Physical volume "/dev/sdg1" successfully created.

[root@jylhlog2 ~]#

2.5 扩容vg

[root@jylhlog2 ~]# vgextend vg_root /dev/sdg1

Volume group "vg_root" successfully extended

[root@jylhlog2 ~]#

2.6 查看vg扩容情况

[root@jylhlog2 ~]# vgs

VG #PV #LV #SN Attr VSize VFree

vg_root 2 6 0 wz--n- <2.49t <2.00t

[root@jylhlog2 ~]#

2.7 查看扩容后vg大小情况

[root@jylhlog2 ~]# vgdisplay

--- Volume group ---

VG Name vg_root

System ID

Format lvm2

Metadata Areas 2

Metadata Sequence No 8

VG Access read/write

VG Status resizable

MAX LV 0

Cur LV 6

Open LV 6

Max PV 0

Cur PV 2

Act PV 2

VG Size <2.49 TiB

PE Size 4.00 MiB

Total PE 652029

Alloc PE / Size 127742 / 498.99 GiB

Free PE / Size 524287 / <2.00 TiB

VG UUID bV0qQR-Vhfg-ynTF-dbza-qJD1-ao3k-l02WiP

[root@jylhlog2 ~]#

2.8 扩容lv

[root@jylhlog2 ~]# lvextend -L +2097148M /dev/mapper/vg_root-lv_data

Size of logical volume vg_root/lv_data changed from 194.99 GiB (49918 extents) to 2.19 TiB (574205 extents).

Logical volume vg_root/lv_data successfully resized.

[root@jylhlog2 ~]#

2.9 查看容量变化,发现文件系统大小没有变化

[root@jylhlog2 ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/vg_root-lv_root 60G 6.2G 54G 11% /

devtmpfs 63G 0 63G 0% /dev

tmpfs 63G 640M 63G 1% /dev/shm

tmpfs 63G 32M 63G 1% /run

tmpfs 63G 0 63G 0% /sys/fs/cgroup

/dev/sda1 1014M 179M 836M 18% /boot

/dev/mapper/vg_root-lv_grid 60G 40G 21G 66% /grid

/dev/mapper/vg_root-lv_data 195G 595M 195G 1% /data

/dev/mapper/vg_root-oracle 60G 22G 38G 37% /oracle

/dev/mapper/vg_root-lv_home 60G 16G 45G 27% /home

tmpfs 13G 12K 13G 1% /run/user/42

tmpfs 13G 0 13G 0% /run/user/1000

[root@jylhlog2 ~]#

2.10 使用xfs_growfs同步磁盘信息

[root@jylhlog2 ~]# xfs_growfs /dev/mapper/vg_root-lv_data

meta-data=/dev/mapper/vg_root-lv_data isize=512 agcount=4, agsize=12779008 blks

? = sectsz=512 attr=2, projid32bit=1

? = crc=1 finobt=0 spinodes=0

data = bsize=4096 blocks=51116032, imaxpct=25

? = sunit=0 swidth=0 blks

naming =version 2 bsize=4096 ascii-ci=0 ftype=1

log =internal bsize=4096 blocks=24959, version=2

? = sectsz=512 sunit=0 blks, lazy-count=1

realtime =none extsz=4096 blocks=0, rtextents=0

data blocks changed from 51116032 to 587985920

[root@jylhlog2 ~]#

2.11 查看容量变化,发现文件系统已扩容成功

[root@jylhlog2 ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/vg_root-lv_root 60G 6.2G 54G 11% /

devtmpfs 63G 0 63G 0% /dev

tmpfs 63G 640M 63G 1% /dev/shm

tmpfs 63G 32M 63G 1% /run

tmpfs 63G 0 63G 0% /sys/fs/cgroup

/dev/sda1 1014M 179M 836M 18% /boot

/dev/mapper/vg_root-lv_grid 60G 40G 21G 66% /grid

/dev/mapper/vg_root-lv_data 2.2T 597M 2.2T 1% /data

/dev/mapper/vg_root-oracle 60G 22G 38G 37% /oracle

/dev/mapper/vg_root-lv_home 60G 16G 45G 27% /home

tmpfs 13G 12K 13G 1% /run/user/42

tmpfs 13G 0 13G 0% /run/user/1000

[root@jylhlog2 ~]#

以上是关于CentOS中管理大于2T的磁盘分区的主要内容,如果未能解决你的问题,请参考以下文章

CentOS 7.6在线扩容xfs文件系统(创建大于2T的磁盘分区并使用LVM管理)

linux磁盘管理

Centos分区/超过2T的磁盘

Linux关于大于2T的磁盘分区格式化

磁盘超过2T无法用fdisk分区的问题

linux 分区 大于2T 磁盘