How to create, extend & remove Linux partition larger than 2TB with PARTED in Centos 7

This article cover 3 part.

1. Create  3TB disk partition and add the disk into LVM.

2.  Extend the 3TB partition by adding 1TB more in same disk.

3. Remove the disk from LVM and delete the disk.

Frankly speaking, you cannot create a Linux partition larger than 2 TB using the fdisk command

To solve this problem use, GNU parted command with GPT

You must include GPT support in the kernel to use GPT. If you don’t add GPT support in Linux kernel, after rebooting the server, the file system will no longer be mountable, or the GPT table will get corrupted. By default, Redhat Enterprise Linux / CentOS comes with GPT kernel support. However, if you are using Debian or Ubuntu Linux, you need to recompile the kernel. Set CONFIG_EFI_PARTITION to y to compile this feature.

Find Out Current Disk Size

Type the following command:

[root@centos01 ~]# fdisk /dev/sdd
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 0x37b5a96f.
WARNING: The size of this disk is 3.3 TB (3298534883328 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).

Linux Create 3TB partition size

1. To create a partition start GNU parted as follows:

[root@centos01 ~]# parted /dev/sdd
GNU Parted 3.1
Using /dev/sdd
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)


2. Check the label available.

#(parted) help mklabel
mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
LABEL-TYPE is one of: aix, amiga, bsd, dvh, gpt, mac, msdos, pc98, sun, loop
(parted)

3. Creates a new GPT disklabel i.e. partition table:
#(parted) mklabel gpt
Warning: The existing disk label on /dev/sdd will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes
(parted)

4. Check the free partition size 

#(parted) print free
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdd: 3299GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
17.4kB 3299GB 3299GB Free Space


5. Next, set the default unit to TB check free partition:
#(parted) unit TB
#(parted) print free

Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdd: 3.30TB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
0.00TB 3.30TB 3.30TB Free Space
(parted)

6. To create a 3TB partition size, enter:
(parted) mkpart primary
File system type? [ext2]? xfs
Start? 0
End? 3
(parted)


7. To print the current partitions, enter:
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdd: 3.30TB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 0.00TB 3.30TB 3.30TB primary
(parted)


8. Quit and save the changes, enter:
(parted) quit
Information: You may need to update /etc/fstab.
[root@centos01 ~]#

9. Check disk status of sdd1. 

[root@centos01 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 20G 0 disk
sdc 8:32 0 4T 0 disk
└─sdc1 8:33 0 4T 0 part
└─vg01-lv01 253:2 0 2T 0 lvm /data
sdd 8:48 0 3T 0 disk
└─sdd1 8:49 0 3T 0 part
sr0 11:0 1 4.3G 0 rom
[root@centos01 ~]#


10. Now add the disk into LVM.

11. Create Physical Volume(PV).

[root@centos01 ~]# pvcreate /dev/sdd1
Physical volume "/dev/sdd1" successfully created.
[root@centos01 ~]#


12. Create Volume Group(VG) on PV. 

[root@centos01 ~]# vgcreate vg-data /dev/sdd1
Volume group "vg-data" successfully created
[root@centos01 ~]#

13. Create Logical Volume(LV) on VG.

[root@centos01 ~]# lvcreate -L +2.8T -n lv-data vg-data
Rounding up size to full physical extent 2.80 TiB
Logical volume "lv-data" created.
[root@centos01 ~]#


14. Check the free space available in Volume group.

[root@centos01 ~]# vgs vg-data
VG #PV #LV #SN Attr VSize VFree
vg-data 1 1 0 wz--n- <3.00t 204.79g
[root@centos01 ~]#


15. Create file system on the partition. 

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


16. Mount disk on data1 partition and update fstab.

[root@centos01 ~]# mount /dev/vg-data/lv-data /data1/
[root@centos01 ~]# cat /etc/mtab | grep data1 >> /etc/fstab
[root@centos01 ~]# df -PTh /data1
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg--data-lv--data xfs 2.8T 33M 2.8T 1% /data1
[root@centos01 ~]#


Now we are going to Extend /dev/sdd from 3TB to 4TB


1. Increase the partition size from 3TB to 4TB & scan the disk. 

2. Check the partition size

[root@centos01 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 20G 0 disk
sdc 8:32 0 4T 0 disk
└─sdc1 8:33 0 4T 0 part
└─vg01-lv01 253:3 0 2T 0 lvm /data
sdd 8:48 0 4T 0 disk ------>
└─sdd1 8:49 0 3T 0 part
└─vg--data-lv--data 253:2 0 2.8T 0 lvm
sr0 11:0 1 4.3G 0 rom
[root@centos01 ~]#

2. Resize the /dev/sdd partition.

[root@centos01 ~]# parted /dev/sdd
GNU Parted 3.1
Using /dev/sdd
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) 
(parted) unit TB
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdd: 4.40TB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 0.00TB 3.30TB 3.30TB primary
(parted) resizepart 1 4
(parted) print

Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdd: 4.40TB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 0.00TB 4.00TB 4.00TB primary
(parted) quit
Information: You may need to update /etc/fstab.
[root@centos01 ~]#

3. Check the Physical Volume 

[root@centos01 ~]# pvs /dev/sdd1
PV VG Fmt Attr PSize PFree
/dev/sdd1 vg-data lvm2 a-- <3.00t 204.79g
[root@centos01 ~]#

4. Now resize the Physical Volume.

[root@centos01 ~]# pvresize /dev/sdd1
Physical volume "/dev/sdd1" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
[root@centos01 ~]# pvs /dev/sdd1
PV VG Fmt Attr PSize PFree
/dev/sdd1 vg-data lvm2 a-- <3.64t 858.08g
[root@centos01 ~]#

5. Check the Volume Group, you see the free space available.

[root@centos01 ~]# vgs vg-data
VG #PV #LV #SN Attr VSize VFree
vg-data 1 1 0 wz--n- <3.64t 858.08g
[root@centos01 ~]#

6. Extend the Logical Volume by 500 GB. 

[root@centos01 ~]# lvextend -L +500G /dev/vg-data/lv-data
Size of logical volume vg-data/lv-data changed from 2.80 TiB (734004 extents) to <3.29 TiB (862004 extents).
Logical volume vg-data/lv-data successfully resized.
[root@centos01 ~]#

7. Resize the File System.

[root@centos01 ~]# xfs_growfs /dev/vg-data/lv-data
meta-data=/dev/mapper/vg--data-lv--data isize=512 agcount=4, agsize=187905024 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=751620096, imaxpct=5
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=367002, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 751620096 to 882692096

8. Check the disk space.

[root@centos01 ~]# df -h /data1/
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg--data-lv--data 3.3T 33M 3.3T 1% /data1
[root@centos01 ~]#


Remove the disk from LVM.

1. Remove the entry from /etc/fstab

2. Unmount the partition

[root@centos01 ~]# umount /data1/

3. Remove disk from LV

[root@centos01 ~]# lvremove /dev/vg-data/lv-data
Do you really want to remove active logical volume vg-data/lv-data? [y/n]: y
Logical volume "lv-data" successfully removed
[root@centos01 ~]#

4. Remove the VG.

[root@centos01 ~]# vgs vg-data
VG #PV #LV #SN Attr VSize VFree
vg-data 1 0 0 wz--n- <3.64t <3.64t
[root@centos01 ~]# vgremove vg-data
Volume group "vg-data" successfully removed
[root@centos01 ~]#

5. Remove the PV from LVM

[root@centos01 ~]# pvs /dev/sdd1
PV VG Fmt Attr PSize PFree
/dev/sdd1 lvm2 --- <3.64t <3.64t
[root@centos01 ~]# pvremove /dev/sdd1
Labels on physical volume "/dev/sdd1" successfully wiped.
[root@centos01 ~]#

6. Delete the partition and remove disk

[root@centos01 ~]# parted /dev/sdd
GNU Parted 3.1
Using /dev/sdd
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdd: 4398GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 4000GB 4000GB primary
(parted) rm
Partition number? 1
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdd: 4398GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
(parted) quit
Information: You may need to update /etc/fstab.
[root@centos01 ~]#

7. Inform storage team to remove the disk in case of VMWare Shutdown the system and remove disk

8. Boot the system and check.

[root@centos01 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 20G 0 disk
sdc 8:32 0 4T 0 disk
└─sdc1 8:33 0 4T 0 part
└─vg01-lv01 253:2 0 2T 0 lvm /data
sr0 11:0 1 4.3G 0 rom
[root@centos01 ~]#

No comments:

Post a Comment