Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On Linux I used to resize MBR partitions using fdisk, even on live filesystems, and then issue a resize2fs/pvresize/... (depending on fs type) to get the new space allocated.

Lately I've been using Xen and GPT partitions, and I've noticed that unfortunately parted doesn't seem to allow on-the-fly resizing of a mounted partition, in fact it will complain:

Error: Partition XXX is being used. You must unmount it before you modify it with Parted.

I've tried both the resize command and even rm + mkpart combination, but they will both complain about the partition being mounted.

How can I do that?

share|improve this question
A way available out of the box on RHEL/CentOS would be highly appreciated – cyberz Oct 27 '13 at 9:23
up vote 5 down vote accepted

The safest way to do this is to boot using an emergency medium (a live CD or the like) and use GParted, which will resize both the partition and the filesystem it contains. This will work only if the partition is not currently being used, though.

If you can't afford any downtime, though, you could try using gdisk instead of parted. You'll need to delete the partition you want to resize and create a new one in its place with the same start point, much as you'd have done with fdisk. gdisk is willing to work on an in-use disk, although the kernel might not register any changes. In that case, you may need to use partprobe or kpartx to get the kernel to accept the new partition table, or even reboot the computer if that doesn't work. (This should all be pretty similar to using fdisk.)

share|improve this answer
Looks nice, but is not included by default on CentOS. Any more standard ways? I mean, a redhat-like system should be able to self resize without relying on external programs – cyberz Oct 19 '13 at 15:30
There is no tool that ships with CentOS that will do the job. You must go out of the CentOS repository to do what you want. Note that almost all other distributions (including Fedora) include gdisk in their repositories, and I've heard that gdisk will be included in the next version of RHEL (and therefore of CentOS). – Rod Smith Nov 3 '13 at 14:19
Thank you for the answer and the comment, it's exactly the information i was looking for – cyberz Nov 3 '13 at 14:33
gdisk is available in EPEL. – jornane Aug 27 '14 at 17:17

If your problem is to grow a partition in a VM, then the easiest solution is not to use partitions at all. Whole disks in a VM solve the problem, because for the host they are only files but for the guest they are real.

For a discussion of this approach see the following article divided into three parts :

Partitions - A Thing Of The Past (Part 1)
Examines expanding a Linux root file system the old fashioned way, using tools like parted, fdisk and a reboot.

Partitions - A Thing Of The Past (Part 2)
Examine solutions to the reboot issue by discarding the use of partitions altogether when using virtual hardware.

Partitions - A Thing Of The Past (Part 3)
Start with a standard Linux disk setup and will show the steps required to migrate to a partitionless one consisting of three disks - one for /boot, one for swap and one for /. Extending this example to add other drives for /var, /tmp and /home is left to the reader.

share|improve this answer

I'm just summarising some answers and comments here:

parted will simply refuse to change any mounted partition. gdisk will do the job for you, but it is not in the standard RHEL or CentOS repository. It is in the EPEL repository, though.

Keep in mind that changing partitions on a disk that is in use might prevent the kernel from registering the changes. If that happens, use partprobe, partx or reboot.

share|improve this answer

Are you asking about resizing a logical volume? Here is how I would do it:

vgextend vgname /dev/sdb3
lvextend -L +3T /dev/mapper/location
resize2fs /mount/point

OR (xfs):

xfs_growfs /mount/point -D <bytes>
share|improve this answer
he probably not using ext2/ext3/ext4, otherwise resize2fs should work on the fly ? – user218473 Nov 3 '13 at 3:05
@Antony Lee: if you pass -r to lvextend, then it invokes resize2fs for you. – jmtd Mar 13 '15 at 15:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .