How Create and Delete GPT Partition with LVM on CentOS Linux 8

Create and Delete GPT Partition with GDisk on Centos Linux 8

In this article we will create and delete GPT Partition (File System) on Vmware work station environment on CentOS 8 Linux operating system. GPT stands for GUID partition table, GUID is a global unique identifier. The purpose of this lab is that we cannot create partition size more then 2TB using fdisk, therefore to resolve this issue we need GNU parted command with GPT. GNU is a free software tool and it belong to the family of Linux operating system. You must know that EFI uses GPT where BIOS uses a Master Boot Record. GPT that is GUID partition table is gradually replacing MBR (Master Boot Record). By default Redhat Enterprise Linux / CentOS comes with GPT kernel support.


To check the current file systems (partitions) on CentOS linux 8 operating system, type the below mention command.

df -hT

how create and delete gpt partition with gdisk on centos 8

To check the version of CentOS 8 Linux operating system, use command  "cat" to view the complete text of file.

cat /etc/redhat-release
create and delete gpt partition with gdisk on redhat

To verify package "gdisk" is install or not, type the below mention command on CentOS 8 Linux operating system.

dnf list gdisk

To install package "gdisk" on CentOS 8 Linux operating system, type the below mention command.

dnf install gdisk

how create and delete gpt partition with gdisk on centos 8

The package "gdisk" on CentOS 8 Linux operating system has successfully installed, please have a look below given image.

how create and delete gpt partition with gdisk on centos 8

To check all the physical drives and its associated file systems (LVM and fixed size partitions), type the below mention command.

lsblk

how create and delete gpt partition with gdisk on centos 8

Here we are create and delete new file system "backup" with a size of 2GB for this lab environment. First we need to add 2GB hard drive, this is virtualization environment therefore 2GB hard drive is add with this VMware workstation virtual machine.

how create and delete gpt partition with gdisk on centos 8

To check this newly added hard drive inside CentOS Linux 8 operating system, type the below mention command. The virtual hard drive is showing on CentOS Linux 8 operating system with the name of "sdb".

lsblk


how create and delete gpt partition with gdisk on centos 7

Create GPT Partition:

To create the partition on newly added virtual hard disk on CentOS/RedHat Linux 7/8 operating system type the below mention command. Here we create only single partition "/dev/sdb1" and assign a complete size "2GB" to this partition.

gdisk /dev/sdb

then provide the below mention given details.
Command (? for help): n
Command (? for help): w
Do you want to proceed? (Y/N): Y

For command "n" means new partition, on partition number (1-128, default 1) just press enter, first sector (press enter), last sector (press enter), Hex code (press enter), w for write and y for proceed.

how create and delete gpt partition with gdisk on centos 7

To check the partition "/dev/sdb1" has been successfully created, type the below mention command.

gdisk -l /dev/sdb

how create and delete gpt partition with gdisk on centos 7

By use of command "gdisk" it is not showing that is "/dev/sdb1" but we can use command "fdisk" better representation to list the partitions.

fdisk -l /dev/sdb

how create and delete gpt partition with gdisk on centos 7

To create the physical volume of this partition "/dev/sdb1", type the below mention command.

pvcreate /dev/sdb1

how create and delete gpt partition with gdisk on centos 7

To create a volume group "backup" of this physical volume "/dev/sdb1", type the below mention command.

vgcreate backup /dev/sdb1

how create and delete gpt partition with gdisk on centos 7

To verify volume group "backup" has been successfully created, type the below mention command.

vgs

how create and delete gpt partition with gdisk on centos 7

To create a logical volume "backup" of complete size of volume group "backup", type the below mention command.

lvcreate -l 100%FREE -n logical-volume volume-group 
lvcreate -l 100%FREE -n backup backup


Create a mount point backup "backup" to mount this logical volume "backup" by use of command "mkdir".

mkdir /backup

and to verify the directory "backup" with it's permission, use command "ls -lrd".

ls -lrd /backup

how create and delete gpt partition with gdisk on redhat 8

To create a new file system with .xfs extension, type the below mention command.

mkfs.xfs /dev/volume-group/logical-volume
mkfs.xfs /dev/backup/backup

how create and delete gpt partition with gdisk on redhat 8

Now mount the newly created logical volume "/dev/backup/backup" to mount point "/backup".

mount /dev/volume-group/logical-volume /mount-point
mount /dev/backup/backup /backup 

To verify logical volume has been successfully mounted, use command df -hT.

df -hT

how create and delete gpt partition with gdisk on redhat 8

For permanent entry edit the file "fstab" by use of editor "vi".

vi /etc/fstab

how create and delete gpt partition with gdisk on redhat 7

Add the below mention line for permanent mount of logical volume "backup".

/dev/mapper/new_vol_group-newlogicalvolume /mount-point               xfs     defaults        0 0
/dev/mapper/backup-backup /backup              xfs     defaults        0 0

how create and delete gpt partition with gdisk on redhat 7


Delete GPT Partition:

To delete the GPT partition first dismount the logical volume "backup" by use of command "umount".

umount /backup

how create and delete gpt partition with gdisk on redhat 7

To remove the mount point, type the below mention command.

rm -rf /backup

create and delete gpt partition with gdisk on redhat

Then remove the logical volume "backup" by use of command "lvremove".

lvremove /dev/Volume-Group/Logical-Volume 
lvremove /dev/backup/backup

how create and delete gpt partition with gdisk on redhat 7

To verify logical volume "backup" has been successfully remove, type the below mention command.

lvs

create and delete gpt partition with gdisk on redhat

After remove the logical volume "backup" remove the volume group "backup", type the below mention command.

vgremove backup

create and delete gpt partition with gdisk on redhat

To verify the volume group "backup" has been successfully removed, type the below mention command.

vgs

create and delete gpt partition with gdisk on redhat

To check the /dev/sdb1 (origin) is completely free now, type the below mention command.

pvs -o+pv_used

create and delete gpt partition with gdisk on centos

Now it's time to remove hard drive partition "/dev/sdb1" by use of command "gdisk", but first remove its lable by use of command "pvremove"

pvremove /dev/sdb1

create and delete gpt partition with gdisk on centos

Then remove hard drive partition "/dev/sdb1"

gdisk /dev/sdb

provide below mention details to remove the hard drive partition "/dev/sdb1".

Command (? for help): d
Command (? for help): w
Do you want to proceed? (Y/N): y

create and delete gpt partition with gdisk on centos

To verify the partition "/dev/sdb1" has been completely remove, type the below mention command/

gdisk -l /dev/sdb

gpt partition with gdisk

Remove the mount point entry from file "fstab", otherwise it will create issues when machine reboot.

vi /etc/fstab

gpt partition with gdisk

Remove the below mention mount point entry from file "fstab".

/dev/mapper/backup-backup /backup              xfs     defaults        0 0

gpt partition with gdisk


Power off the CentOS/Redhat 7/8 linux operating system for remove the hard drive from virtual machine.

init 0

gpt partition with gdisk

Finally remove the hard drive of size 2GB from the Virtual Machine setting area after power off the virtual machine.

gpt partition with gdisk

This is the complete process of Create and Delete GPT Partition with LVM on CentOS/Redhat Linux 7/8.

Thanks for read this Article

Comments