Tag: Disk partitioning

Grow (Extend) an LVM on a Linux VM

We’ve all been there, you’re running an app on a VM and you see that it is quickly running out of free space. Since we’re not constrained by any physical limitation, we can just allocate more space to the guest and grow the disk.

As with any hard drive partitioning, make sure you back up any critical data. Since this is a vm and I’m running VDR, I can run a quick backup and begin. Also, remove any snapshots if you have them.

Power down the VM. Add space to the hard disk under Edit Settings.

Edit Settings on the VM

Power the VM back up  and  run a  # df -Th  to see the current disk usage & filesystem type.

df -h output before growing the disk

Run  # ls -al /dev/sda* to view all the disks

fdisk /dev/sda

:n (new disk)

:p (create primary partition)

:3 (the partition number)

: first cylinder  (keep the defaults)

: p (print the partition table and review the new partition on /dev/sda#)

:w (write the table to disk and exit)

# reboot the server or run  # partprobe . If partprobe throws an error, just reboot. This is to make sure the partition table is actually written.

Run  # vgdisplay to view the volume group. In the FREE PE / Size section, you will see that there isn’t any free space yet. Take note of the proper name of the volume group.

Output from vgdisplay

Run a  #vgextend vg_insertyourvghere /dev/sda#

Do another #vgdisplay to confirm the free space on the volume group.

freespace

It shows you there is now 4GB free space that can be added to the volume group.  Now we extend the logical volume into that free space

Do an #lvdisplay to get the proper name of the logical volume you’re going to extend.

Now, time to extend the logical volume group.

#  lvextend -L +4G /dev/vg_kimathegreat/lv_root

lvextend

I reduced the size slightly to avoid the error about  “Insufficient free space”.

Now to resize the file system. If this is a partition that can be unmounted, run a # umount before running resize2fs.

#resize2fs /dev/vg_kimathegreat/lv_root

Run df -h to see the new size of the partition and the increased free space.

newfreespace

Now, there are a few caveats I’ve run across. Mainly when running fdisk /dev/sda. I will allow me to make a partition, but depending on where the sectors start and end, I won’t be able to run a pvextend.

If that happens, run # cfdisk and see where the partitions are and if you have any free space. If you do, that is where you create your partition.  You can make your corrections, between both fdisk and cfdisk , by deleting the small partition and creating a new one with the larger chunk of free space.  Just be careful and don’t delete anything critical.

As you can see, I’m missing sda3. That was because the 1st fdisk /dev/sda created a partition using only a few megs of space. I didn’t note the sector count and created the primary partition in the smaller block of free space. I used fdisk  (d) to delete that partition and then created a new one.

missingsda3

Adding space to a vDisk on a PERC 5/i Controller Part 2 of 3

To Grow the D:\ Drive

This is part 2 of the “Adding space to a vDisk on a PERC 5/i Controller” post.

Back to Part 1

  • Launch diskpart from the command prompt.  #diskpart (enter)
  • It opens in another window.  Enter  #LIST DISK (enter) and review the disks of the server.
  • Enter #LIST VOLUME   (enter) to view the volumes. Note the volume numbers next to the drive letter.  You will select the volume that you would like to grow.

diskpart-listvolume

  • #LIST PARTITION (to view the partitions)

diskpart-listpartition

  • Enter #SELECT DISK # (the number of the volume you’re growing). This is to bring focus on the disk that you’re working with. OR
  • Enter #SELECT VOLUME 2 (the D:\  is what we’re growing so we will have enough space to ‘give’ to C:\)
  • Decide on the size that you’d like to grow the disk by (in MB). In this example, we grew the disk by 100GB. Enter #EXTEND SIZE=100000 (100GB~)
  • You’ll see the success message immediately  following.
  • Enter #LIST VOLUME (to review the size of the new volume.  It will have an asterisk beside it)

diskpart-extend

  • Enter #LIST DISK to view the available space on the vDisk.

diskpart-listdisk-done

  • Enter #EXIT to close diskpart.
  • Go back to disk management and view the size change of D:\ and the unallocated space.

diskmgmt-unallocated2

Next Step: Growing the C:\ Drive

Social media & sharing icons powered by UltimatelySocial