3

I VM Player running a linux guest and I was wanting to know how do I expand the disk? In the VM player I gave more disk space but I am not sure how to mount/expand/connect the new disk space to the system.

My old disk space was 14GB

[root@localhost ~]# df -h /
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       14G  4.5G  8.2G  36% /

Then I expanded it and now I see sda2 which is the new space?

[root@localhost ~]# fdisk -l

Disk /dev/sda: 128.8 GB, 128849018880 bytes
255 heads, 63 sectors/track, 15665 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000cd44d

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        2611    20458496   8e  Linux LVM

Disk /dev/mapper/VolGroup-lv_root: 14.5 GB, 14537457664 bytes
255 heads, 63 sectors/track, 1767 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/VolGroup-lv_swap: 6408 MB, 6408896512 bytes
255 heads, 63 sectors/track, 779 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Do I need to mount the new space first?

resize2fs -p /dev/mapper/VolGroup-lv_root 108849018880
resize2fs 1.41.12 (17-May-2010)
The containing partition (or device) is only 3549184 (4k) blocks.
You requested a new size of 1474836480 blocks.

 resize2fs -p /dev/mapper/VolGroup-lv_root 128849018880
resize2fs 1.41.12 (17-May-2010)
resize2fs: Invalid new size: 128849018880

[root@localhost ~]# lvextend -L+90GB /dev/mapper/VolGroup-lv_root
  Extending logical volume lv_root to 103.54 GiB
  Insufficient free space: 23040 extents needed, but only 0 available

[root@localhost ~]# lvextend -L90GB /dev/mapper/VolGroup-lv_root
  Extending logical volume lv_root to 90.00 GiB
  Insufficient free space: 19574 extents needed, but only 0 available

EDIT: So after trying pvcreate/vgextend nothing has so far worked. I'm guessing the new disk space added from VM Player is not showing up?

pvscan
  PV /dev/sda2   VG VolGroup   lvm2 [19.51 GiB / 0    free]
  Total: 1 [19.51 GiB] / in use: 1 [19.51 GiB] / in no VG: 0 [0   ]
1
  • Could you please close this question in case one of the answers was ok? If something was wrong with them please let the people know.
    – Marki
    Aug 10, 2014 at 17:28

5 Answers 5

3

As already stated, you had first to resize the partition containing the logical volume, than you can proceed with LVM resize. Follow these steps:

  1. with fdisk -l -u /dev/sda take note of the current partition setting (especially the start sector)
  2. delete partition sda2 and recreate it. Use the very same start sector, or you will lose your data! Obviously, the end sector should be higher that before (fdisk will suggest to use the last available sector by default, so you can simply press ENTER here)
  3. now run partprobe /dev/sda or reboot the system. This will inform the kernel that partition size has changed
  4. run pvresize /dev/sda2. This will resize the physical volume structures
  5. execute pvs and vgs to check that the new size is correctly identified by LVM
  6. you can now resize your LVM volume with lvresize -l +100%FREE /dev/mapper/VolGroup-lv_root
  7. finally, resize the filesystem itself with resize2fs /dev/mapper/VolGroup-lv_root

These instruction are valid for increasing disk space (extending the volume)

Shrinking a volume is conceptually similar but you had to follow the steps backward, starting with filesystem shrink. As a side note, if you use XFS or other filesystems that can not be shrunk, you can not resize your LVM volume without a backup/restore process.

0

Since your underlying device is already extended, you should be able to see the available space in the output of vgdisplay. Look for the line that says Free PE / Size. If this is the case, you can simply extend the logical volume via lvextend and then grow the filesystem via resize2fs.

0

I did a guide how to do this a while back, hope this helps.

https://serverfault.com/a/422972/1435

0
0

I always have this guide on the side for live expanding LVM

http://www.scribd.com/doc/39997149/Live-Expand-RedHat-based-Linux-LVM-Volume-and-Filesystem-on-VMWare-Virtual-Machines

0

The problem here is you put the LVM (physical volume) into a partition.

If it were on the device directly, you could simply do

* pvextend
* lvextend
* resize2fs

In your case you will have to boot using a live-cd or such delete the /dev/sda2 partition and recreate with a bigger size then proceed as outlined above

The safer way would however be to

create a new volume for your VM which would then be /dev/sdb for example initialize it as a PV using pvcreate add the new PV to the existing volume group

vgextend my_volume_group /dev/sdb

now you can extend the logical volume

lvextend -v -l +100%FREE /dev/mapper/VolGroup-lv_root

and finally the filesystem

resize2fs /dev/mapper/VolGroup-lv_root

Once you aware of the all the layers (physical disk, partition, physical volume, volume group, logical volume) it will be a piece of cake.

You must log in to answer this question.

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