Extend LVM partition for GPT disk tables on Centos 7

GPT is a standard for formatting partition tables on a physical hard disk. It is part of the Extensible Firmware Interface (EFI), a standard proposed by Intel to replace the BIOS. EFI uses GPT where the BIOS uses the Master Boot Record (MBR).

A series of articles on working with a hard drive

  • Mount a new disk in CentOS
  • How to grow LVM partition on CentOS 7
  • Add new disk to Centos 7
  • How to delete / home partition and expand root partition in Centos 7
  • Mount LVM partition on Ubuntu 18.04 / 18.10
  • Extend LVM partition for GPT disk tables on Centos 7

On one of the servers, when executing the command fdisk -l a warning came out:

[[email protected] ~]# fdisk -l
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: gpt
Disk identifier: B0305913-98D6-4029-B711-1361097B7404

#         Start          End    Size  Type            Name
 1         2048       411647    200M  EFI System      EFI System Partition
 2       411648      2508799      1G  Microsoft basic
 3      2508800     35649535   15,8G  Linux LVM

Disk /dev/mapper/centos-root: 14.8 GB, 14814281728 bytes, 28934144 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Google translator tells us the following: Support for fdisk GPT is currently new and therefore in experimental stage. Use as you see fit.

Installing the gdisk utility

[[email protected] ~]# yum -y install gdisk

Let’s see information about the disk through this utility

[[email protected] ~]# gdisk -l /dev/sda
GPT fdisk (gdisk) version 0.8.10

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

Found valid GPT with protective MBR; using GPT.
Disk /dev/sda: 209715200 sectors, 100.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): B0305913-98D6-4029-B711-1361097B7404
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 209715166
Partitions will be aligned on 2048-sector boundaries
Total free space is 174067645 sectors (83.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048          411647   200.0 MiB   EF00  EFI System Partition
   2          411648         2508799   1024.0 MiB  0700
   3         2508800        35649535   15.8 GiB    8E00

Here you should pay attention to the last line, the value of the column End (sector) = 35649535, we will need this value in the future

Let’s start creating a new section

[[email protected] ~]# gdisk /dev/sda
GPT fdisk (gdisk) version 0.8.10

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

Found valid GPT with protective MBR; using GPT.

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 (4-128, default 4): 4
First sector (34-209715166, default = 35649536) or {+-}size{KMGTP}: 35649536
Last sector (35649536-209715166, default = 209715166) or {+-}size{KMGTP}: 209715166
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): L
0700 Microsoft basic data  0c01 Microsoft reserved    2700 Windows RE
3000 ONIE boot             3001 ONIE config           4100 PowerPC PReP boot
4200 Windows LDM data      4201 Windows LDM metadata  7501 IBM GPFS
7f00 ChromeOS kernel       7f01 ChromeOS root         7f02 ChromeOS reserved
8200 Linux swap            8300 Linux filesystem      8301 Linux reserved
8302 Linux /home           8400 Intel Rapid Start     8e00 Linux LVM
a500 FreeBSD disklabel     a501 FreeBSD boot          a502 FreeBSD swap
a503 FreeBSD UFS           a504 FreeBSD ZFS           a505 FreeBSD Vinum/RAID
a580 Midnight BSD data     a581 Midnight BSD boot     a582 Midnight BSD swap
a583 Midnight BSD UFS      a584 Midnight BSD ZFS      a585 Midnight BSD Vinum
a800 Apple UFS             a901 NetBSD swap           a902 NetBSD FFS
a903 NetBSD LFS            a904 NetBSD concatenated   a905 NetBSD encrypted
a906 NetBSD RAID           ab00 Apple boot            af00 Apple HFS/HFS+
af01 Apple RAID            af02 Apple RAID offline    af03 Apple label
af04 AppleTV recovery      af05 Apple Core Storage    be00 Solaris boot
bf00 Solaris root          bf01 Solaris /usr & Mac Z  bf02 Solaris swap
bf03 Solaris backup        bf04 Solaris /var          bf05 Solaris /home
bf06 Solaris alternate se  bf07 Solaris Reserved 1    bf08 Solaris Reserved 2
bf09 Solaris Reserved 3    bf0a Solaris Reserved 4    bf0b Solaris Reserved 5
c001 HP-UX data            c002 HP-UX service         ea00 Freedesktop $BOOT
eb00 Haiku BFS             ed00 Sony system partitio  ed01 Lenovo system partit
Press the <Enter> key to see more codes:
ef00 EFI System            ef01 MBR partition scheme  ef02 BIOS boot partition
fb00 VMWare VMFS           fb01 VMWare reserved       fc00 VMWare kcore crash p
fd00 Linux RAID
Hex code or GUID (L to show codes, Enter = 8300): 8e00
Changed type of partition to 'Linux LVM'

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/sda.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
The operation has completed successfully.

Where we used the following values:

  • Command (? For help): n – Create a new section
  • Partition number (4-128, default 4): 4 – Section number
  • First sector (34-209715166, default = 35649536) or {+ -} size {KMGTP}: 35649536 – First sector (I spoke about this parameter above, highlighted)
  • Last sector (35649536-209715166, default = 209715166) or {+ -} size {KMGTP}: 209715166 – Last sector
  • Hex code or GUID (L to show codes, Enter = 8300): 8e00 – Code for LVM
  • Command (? For help): w – Record changes
  • Do you want to proceed? (Y / N): Y – Confirm

Let us inform the operating system about the change in the partition table

[[email protected] ~]# partprobe

Let’s see what happened

[[email protected] ~]# gdisk -l /dev/sda
GPT fdisk (gdisk) version 0.8.10

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

Found valid GPT with protective MBR; using GPT.
Disk /dev/sda: 209715200 sectors, 100.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): B0305913-98D6-4029-B711-1361097B7404
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 209715166
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048          411647   200.0 MiB   EF00  EFI System Partition
   2          411648         2508799   1024.0 MiB  0700
   3         2508800        35649535   15.8 GiB    8E00
   4        35649536       209715166   83.0 GiB    8E00  Linux LVM

As you can see, a new section will appear / dev / sda4

Create a physical volume / dev / sda4 using the command

[[email protected] ~]# pvcreate /dev/sda4
  Physical volume "/dev/sda4" successfully created.

We are looking for our VG Name:

[[email protected] ~]# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               15,80 GiB
  PE Size               4,00 MiB
  Total PE              4045
  Alloc PE / Size       4044 / <15,80 GiB
  Free  PE / Size       1 / 4,00 MiB
  VG UUID               h1fisC-E0Jq-y0hg-CNsK-tbEp-FlCx-we4kc0

Expanding the volume centos

[[email protected] ~]# vgextend centos /dev/sda4
  Volume group "centos" successfully extended

Checking what happened

[[email protected] ~]# pvscan
  PV /dev/sda3   VG centos          lvm2 [15,80 GiB / 4,00 MiB free]
  PV /dev/sda4   VG centos          lvm2 [<83,00 GiB / <83,00 GiB free]
  Total: 2 [<98,80 GiB] / in use: 2 [<98,80 GiB] / in no VG: 0 [0   ]

We are looking for our LV Path:

[[email protected] ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                2Js7Fd-vndx-X1e8-mOGt-EgX6-CRn3-jrBeMB
  LV Write Access        read/write
  LV Creation host, time localhost, 2019-07-10 10:32:35 +0300
  LV Status              available
  # open                 1
  LV Size                <13,80 GiB
  Current LE             3532
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                hGtREN-VZpe-djLb-rT7g-drKz-64E5-mh4Dtd
  LV Write Access        read/write
  LV Creation host, time tocalhost, 2019-07-10 10:32:36 +0300
  LV Status              available
  # open                 2
  LV Size                2,00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1

Expanding a logical volume / dev / centos / root and activate it

[[email protected] ~]# lvextend -l +100%FREE /dev/centos/root -r
  Size of logical volume centos/root changed from <13,80 GiB (3532 extents) to <96,80 GiB (24780 extents).
  Logical volume centos/root successfully resized.
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=904192 blks
         =                       sectsz=4096  attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=3616768, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 3616768 to 25374720

Checking through the command gdisk -l / dev / sda

[[email protected] ~]# gdisk -l /dev/sda
GPT fdisk (gdisk) version 0.8.10

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

Found valid GPT with protective MBR; using GPT.
Disk /dev/sda: 209715200 sectors, 100.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): B0305913-98D6-4029-B711-1361097B7404
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 209715166
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048          411647   200.0 MiB   EF00  EFI System Partition
   2          411648         2508799   1024.0 MiB  0700
   3         2508800        35649535   15.8 GiB    8E00
   4        35649536       209715166   83.0 GiB    8E00  Linux LVM

Checking through the command df -h

[[email protected] ~]# df -h
Файловая система        Размер Использовано  Дост Использовано% Cмонтировано в
/dev/mapper/centos-root    97G         1,3G   96G            2% /
devtmpfs                  858M            0  858M            0% /dev
tmpfs                     870M            0  870M            0% /dev/shm
tmpfs                     870M         9,3M  860M            2% /run
tmpfs                     870M            0  870M            0% /sys/fs/cgroup
/dev/sda2                1014M         176M  839M           18% /boot
/dev/sda1                 200M          12M  189M            6% /boot/efi
tmpfs                     174M            0  174M            0% /run/user/0
Sidebar