Does RHEL 7 support online resize of disk partitions?
Environment
- Red Hat Enterprise Linux 7
- For Red Hat Enterprise Linux 8, see solution 5808001.
Issue
- Both Xen and KVM support online resize of the virtual block devices that the virtual machines use.
- Unfortunately, since the partitions in the boot virtual block device are already in use, those can't be modified online and the virtual machine won't pick up the changes on the boot virtual block device without a reboot.
- We are looking for the ability to dynamically increase a partitioned volume, is it possible to resize the disk partitions online in RHEL 7?
- We are unable to dynamically increase a SAN attached volume without taking the volume offline. When will this feature to support online resize of disk partitions be available?
Resolution
The ability to resize a Logical Volume and filesystem has long been provided by Logical Volume Manager (LVM) by simply using the entire block device (/dev/sdx
for example) as a Physical Volume in the LVM Volume Group. There is no need for the old style of partition. This would allow the Logical Volume and filesystem to easily be expanded.
As to older style partitions, this feature has been added in RHEL 7 current release with a feature request (RFE has been filed to add support for online resizing of disk partitions to RHEL 7 in private RHBZ#853105. With this feature, it's possible to resize the disk partitions online in RHEL 7.
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.
For additional information check also How can I extend an existing file-system partition without destroying data? article.
- In order to resize online a partition which is in use observe the following steps:
# fdisk -l /dev/vda
Disk /dev/vda: 32.2 GB, 32212254720 bytes, 62914560 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: 0x000db7e6
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 1026047 512000 83 Linux
/dev/vda2 1026048 28289023 13631488 8e Linux LVM
# cat /proc/partitions
major minor #blocks name
252 0 31457280 vda
252 1 512000 vda1
252 2 13631488 vda2
11 0 1048575 sr0
253 0 10240000 dm-0
253 1 2129920 dm-1
# pvs
PV VG Fmt Attr PSize PFree
/dev/vda2 rhel_vm-205 lvm2 a-- 13.00g 1.20g
-
Modify the on-disk partition table as usual (e.g. by using
fdisk
command).-
Delete the partition:
Command (m for help): d Partition number (1,2, default 2): 2 Partition 2 is deleted
-
Re-create the partition with the new size:
Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): p Partition number (2-4, default 2): 2 First sector (1026048-62914559, default 1026048): Using default value 1026048 Last sector, +sectors or +size{K,M,G} (1026048-62914559, default 62914559): +18G Partition 2 of type Linux and of size 18 GiB is set Command (m for help): t Partition number (1,2, default 2): 2 Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM' Command (m for help): p Disk /dev/vda: 32.2 GB, 32212254720 bytes, 62914560 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: 0x000db7e6 Device Boot Start End Blocks Id System /dev/vda1 * 2048 1026047 512000 83 Linux /dev/vda2 1026048 38774783 18874368 8e Linux LVM
-
Commit changes to on-disk partition table:
Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Syncing disks.
-
While on-disk partition table has been updated, observe that on-memory kernel partition table has not:
# partprobe Error: Partition(s) 2 on /dev/vda have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use. As a result, the old partition(s) will remain in use. You should reboot now before making further changes. # cat /proc/partitions | grep vd 252 0 31457280 vda 252 1 512000 vda1 252 2 13631488 vda2
-
-
Execute
partx
(provided byutil-linux
package) with--update
option on the block device to update the in-memory kernel partition table from the on-disk partition table:# partx -u /dev/vda
-
Verify that in-memory kernel partition table has been updated with the new size:
# cat /proc/partitions | grep vd 252 0 31457280 vda 252 1 512000 vda1 252 2 18874368 vda2
-
Proceed with any further steps, in this example by extending the PV on the partition:
# pvresize /dev/vda2 Physical volume "/dev/vda2" changed 1 physical volume(s) resized / 0 physical volume(s) not resized # pvs PV VG Fmt Attr PSize PFree /dev/vda2 rhel_vm-205 lvm2 a-- 18.00g 6.20g
Root Cause
-
Changes to allow online resizing of in-use partitions are required in both kernel and userland.
- RHEL7 kernels include the required changes to BLKPG ioctl from block: add partition resize function to blkpg ioctl to support BLKPG_RESIZE_PARTITION operation.
- RHEL7
util-linux
package includespartx
andresizepart
binaries, currently the only userland commands that support BLKPG_RESIZE_PARTITION operation of BLKPG ioctl.
Diagnostic Steps
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