51

I recently resized the hard drive of a VM from 150 GB to 500 GB in VMWare ESXi. After doing this, I used Gparted to effectively resize the partition of this image. Now all I have to do is to resize the file system, since it still shows the old value (as you can see from the output of df -h):

Filesystem                     Size  Used Avail Use% Mounted on
/dev/mapper/owncloud--vg-root  157G   37G  112G  25% /
udev                           488M  4.0K  488M   1% /dev
tmpfs                          100M  240K  100M   1% /run
none                           5.0M     0  5.0M   0% /run/lock
none                           497M     0  497M   0% /run/shm
/dev/sda1                      236M   32M  192M  14% /boot

However, running sudo resize2fs /dev/mapper/owncloud--vg-root returns this:

resize2fs 1.42 (29-Nov-2011)
The filesystem is already 41608192 blocks long.  Nothing to do!

Since Gparted says that my partition is /dev/sda5, I also tried running sudo resize2fs /dev/sda5, but in this case I got this:

resize2fs 1.42 (29-Nov-2011)
resize2fs: Device or resource busy while trying to open /dev/sda5
Couldn't find valid filesystem superblock.

Finally, this is the output of pvs:

PV         VG          Fmt  Attr PSize   PFree
/dev/sda5  owncloud-vg lvm2 a-   499.76g 340.04g

fdisk -l /dev/sda shows the correct amount of space.

How can I resize the partition so that I can finally make the OS see 500 GB of hard drive?

3
  • pvs should show where your vg is located. Where is that?
    – Nils
    Commented Jun 19, 2014 at 19:37
  • @Nils added to the question :) Commented Jun 19, 2014 at 21:06
  • Joel gave the right answer. Your question contains now the complete picture of your - quite common - problem.
    – Nils
    Commented Jun 20, 2014 at 21:07

5 Answers 5

94

Thanks a lot for @Bratchley answer and the comments. It helped me :)

My environment: Ubuntu 18.04 in VirtualBox 6.1

My case: I created 10GB fixed VDI disk and increased to 30GB dynamic using VirtualBox GUI. But still the increased space is not available to filesystem. Then came across @Bratchley answer.

Steps I ran:

  1. Run below command to get PV (Physical Volume) name (Ex: /dev/sda1)
sudo pvs
  1. Resize the PV (Ex: sudo pvresize /dev/sda1)
sudo pvresize <PV name from above step>   
  1. Run below command to get root logical volume name (Filesystem value of / row; ex: /dev/mapper/ubuntu--vg-root)
df -h
  1. Expand logical volume (ex : sudo lvextend -r -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv):
sudo lvextend -r -l +100%FREE <root logical volume name from above step>   
11
  • 7
    Best answer of all!
    – SHM
    Commented Dec 4, 2020 at 10:48
  • Step 3: what does this mean? I have no idea what I'm looking for or how to get that information. Commented Jun 7, 2021 at 15:03
  • 1
    Run df -h command, and look for the Filesystem value of / mount path. (it will be something like /dev/xxxxx)
    – manikanta
    Commented Jun 9, 2021 at 9:42
  • Note: Doesn't work with gfs2 filesystem. Commented Aug 23, 2022 at 2:59
  • 1
    I am only joining this stack exchange to upvote you! solved, thanks
    – sekomer
    Commented Oct 24, 2023 at 11:11
32

If you only changed the partition size, you're not ready to resize the logical volume yet. Once the partition is the new size, you need to do a pvresize on the PV so the volume group sees the new space. After that you can use lvextend to expand the logical volume into the volume group's new space. You can pass -r to the lvextend command so that it automatically kicks off the resize2fs for you.

Personally, I would have just made a new partition and used vgextend on it since I've had mixed results with pvresize.

6
  • I have run pvresize followed by lvextend -r -L 500G /dev/sda2, and this is what I get: Path required for Logical Volume "sda2" Please provide a volume group name Run 'lvextend --help' for more information. Commented Jun 19, 2014 at 21:20
  • 8
    Once you do the pvresize you're done dealing with regular partitions. You need to specify the path of the logical volume which in this case is /dev/mapper/owncloud--vg-root Personally I'd run lvextend -r -l +100%FREE /dev/mapper/owncloud--vg-root
    – Bratchley
    Commented Jun 19, 2014 at 21:23
  • After you run the pvresize command, you can verify the space is in the volume group by running the vgs command.
    – Bratchley
    Commented Jun 19, 2014 at 21:24
  • Also, you didn't mention it in your question but does fdisk -l /dev/sda show the correct hard drive size? If not you may have to reboot or rescan the SCSI bus.
    – Bratchley
    Commented Jun 19, 2014 at 21:26
  • That worked, thanks! For some reason it did not autocomplete /dev/mapper/owncloud--vg-root and so I kept trying /sda5 XD Commented Jun 20, 2014 at 17:59
3

sudo btrfs filesystem resize max / should be able to resize the partition.

Extended virtual disk size up to 100GB but command df -h said old spase size after resizing with fdisk.

btrfs simply resolves the resize2fs: Device or resource busy issue.

3
  • 3
    That assumes that the file system is Btrfs, not Ext4 (which is apparently what the OP was using). Commented Aug 10, 2022 at 16:52
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Aug 20, 2022 at 9:29
  • Does not answers the question! Commented Apr 16 at 9:01
1

This happened to me too, I have checked /etc/fstab and than I realized that I have renamed the VG and this did not change everywhere that rename, I was able to solve this by renaming back my VG!

-1

First of all, you must extend your drive size to get all the free space. Then resize your drive to use all the space.

  1. Extend drive space

    lvextend -l +100%FREE /dev/mapper/owncloud--vg-root

  2. Resize drive size

    resize2fs /dev/mapper/owncloud--vg-root

1
  • Same error message. Commented Apr 16 at 8:53

You must log in to answer this question.

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