What is growpart utility and how to use it ?
Environment
- Red Hat Enterprise Linux 7
- Red Hat Enterprise Linux 8
- Red Hat Enterprise Linux 9
- Red Hat Enterprise Linux 10
Issue
- How to extend a partition using the
growpartutility online? - Can I extend the partition which is in-between the two partitions? - A special Case
Resolution
Disclaimer: The following information has been provided by Red Hat, but is outside the scope of the posted Service Level Agreements and support procedures (Production Support - Red Hat Customer Portal). The information is provided as-is and any configuration settings or installed applications made from the information in this article could make the Operating System unsupported by Red Hat Global Support Services. The intent of this article is to provide information to accomplish the system's needs. Use of the information in this article at the user's own risk.
From a technical point of view, resizing filesystems and their underlying partitions (making changes to the existing partition table) can be very dangerous. Also, it is only possible to resize partitions from their end position on the disk. It is not possible to move partitions on the disk or resize them from their beginning. Such operations can result in a corrupted partition table, which will render all data on the disk device inaccessible, leading to data loss. While it is possible to perform online partition resize operation, it is not recommended simply from a data integrity standpoint and not because it's not possible.
- What is
growpartutility?
growpartis one of the utility to extend thelast partitionof the disk to fill the available free space on the disk. It changes thesector positionto the end sector of the disk.- It only extends the last partition. It doesn't create or delete any existing partition.
- It can be run
online. Dry run test can also be done to check the same.
- Extend the partition:
root@rhelbox ~]# growpart -v /dev/sde 1
CHANGED: partition=1 start=2048 old: size=1675264 end=1677312 new: size=4192223 end=4194271
Here growpart's first argument is disk and second argument is partition number.
- Verify the partition table:
[root@rhel7 test6]# parted /dev/sde u s p
Model: VMware Virtual disk (scsi)
Disk /dev/sde: 4194304s
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 2048s 4194270s 4192223s primary
- Once the partition has been extended,
Resizethe physical volume which is using it (Only if PV exists on top of it). -
From
cloud-utils-growpart-0.33*on-wards, Underlying physical volume automatically gets resized once the partition is increased. -
Can I extend the partition which is in-between the two partitions? - A SPECIAL CASE
- Consider the following layout, where we can delete the 2nd and 3rd partition i.e. /dev/vde2 and /dev/vde3 and extend /dev/vde1 to use free space between /dev/vde1 and /dev/vde4.
vde 252:64 0 7G 0 disk
├─vde1 252:65 0 716.8M 0 part
├─vde2 252:66 0 717M 0 part
├─vde3 252:67 0 716M 0 part
└─vde4 252:68 0 1.4G 0 part
(parted) p
Model: Virtio Block Device (virtblk)
Disk /dev/vde: 7516MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 752MB 752MB
2 752MB 1504MB 752MB ext2
3 1504MB 2254MB 751MB ext2
4 2254MB 3758MB 1504MB ext2
- Delete the partitions 2 and 3.
(parted) p
Model: Virtio Block Device (virtblk)
Disk /dev/vde: 7516MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 752MB 752MB
2 752MB 1504MB 752MB
3 1504MB 2254MB 751MB
4 2254MB 3758MB 1504MB
(parted) rm 2
(parted) rm 3
(parted) ^C
Information: You may need to update /etc/fstab.
- Now, extend the first partition /dev/vde1 upto /dev/vde4
# growpart -v /dev/vde 1
update-partition set to true
FLOCK: try exec open fd 9, on failure exec exits this program
FLOCK: /dev/vde: obtained exclusive lock
resizing 1 on /dev/vde using resize_sfdisk_gpt
14680064 sectors of 512. total size=7516192768 bytes
## sfdisk --unit=S --dump /dev/vde
label: gpt
label-id: BD1F8EAF-8A66-41D6-B544-6264F2805A3E
device: /dev/vde
unit: sectors
first-lba: 34
last-lba: 14680030
sector-size: 512
/dev/vde1 : start= 34, size= 1467973, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=0A8B9462-BB70-4A2B-99F7-2BE
40602AD9C
/dev/vde4 : start= 4403200, size= 2936832, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=4C8B160C-D5F3-409D-89F8-152
6F4FC42E3
max_end=4403199 tot=14680064 pt_end=1468006 pt_start=34 pt_size=1467973
resize of /dev/vde returned 0.
CHANGED: partition=1 start=34 old: size=1467973 end=1468006 new: size=4403166 end=4403199
FLOCK: /dev/vde: releasing exclusive lock
/dev/vde1 is not an lvm pv
- Confirm the same.
# lsblk | grep vde
vde 252:64 0 7G 0 disk
├─vde1 252:65 0 2.1G 0 part
└─vde4 252:68 0 1.4G 0 part
# parted /dev/vde
GNU Parted 3.5
Using /dev/vde
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: Virtio Block Device (virtblk)
Disk /dev/vde: 7516MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 2254MB 2254MB
4 2254MB 3758MB 1504MB
(parted)
Diagnostic Steps
- Verify
growpart packageis installed, If not then install:
[root@rhel7 ~]# rpm -qa| grep -i growpart
[root@rhel7 ~]# yum install cloud-utils-growpart -y
OR
# rpm -ivh cloud-utils-growpart/path/to/rpm
- Verify the
partitiontable using the below command before runninggrowpart:
[root@rhel7 test6]# parted /dev/sde u s p
Model: VMware Virtual disk (scsi)
Disk /dev/sde: 4194304s
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 2048s 839679s 837632s primary
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Comments