Kölsch, Kompjuter & Kicken - darum geht's - unter anderem - in diesem Blog. Statt buntem Schnickschnack gibt's Information und Meinung - nämlich meine. Muss nicht immer gefallen.





VMWare: Extend a Linux partition using LVM (CentOS / Red Hat)

Sometimes it happens that a partition is running out of disk space. The following article describes how to extend a LV (Logical Volume) by adding a new virtual hard disk.
Preconditions for this procedure are:
  • Filesystem in place must be XFS (works different on other filesystems, sample for EXT2/3/4 provided below)
  • LVM can only manage up to 4 partitions: As such, first check via fdisk -l that no more than 3 partitions are currently created!
  • All commands have to executed as root. Alternatively, use sudo to gain root access.
Before following the steps below, make sure that the hard disk is organized as a LV (use the command lvdisplay to check) and

BACK UP YOUR DATA / CREATE A SNAPSHOT!



Step-by-step guide

1. Open vSphere / VMWare - Client and enhance the size of the virtual disk:

2. Login to the machine as root and verify that a Logical Volume Manager
    (LVM) is in place:



    Command: lvdisplay



3. Check the overall size of the hard disk and make sure the changes you
    performed in vSphere Client are recognized by the guest-OS:

    Command: fdisk -l
    Write down (or remember) the name of the disk (in this example: /dev/sda)


4. Find out the name of the Volume Group (VG) using the

    Command: dh -h

    (as you can see, the name of the VG here is /dev/mapper/centos/root)


5. Create a new partition. To achieve this, run fdisk in the hard disk you
      identified in the previous step


      Command: fdisk /dev/sda (please change the name of the hard disk
      according to the name displayed in step 4)


6. Enter the fdisk command "p" to print the partition table:


7. Enter the fdisk command "n" to create a new partition:


8. Choose "p" to create a primary partition and enter the partition-number
    (default usually will be fine):


9. Now you're being asked to enter the number of the first sector which should be
    used for the new partition.

    Again, the default value will be fine since it usually is the first available sector:



10. Now enter the last sector for the new partition. Default usually is the last free
      sector, so just accepting the default value 
will be fine;


11. Enter the fdisk command "w" to write the changes to the partition table.
      Afterwards, you have to reboot the machine for the kernel 
being able to re-
      scan the partition table. If you don't want to reboot, the command

        partprobe 
should do the trick and re-read the partition-table.


12. After rebooting the machine / running partprobe, login again as root and
      run the


      command: fdisk -l

       to show the new partition table. The partition you created now should show
      up:


13. Now check first, that the VG is resizable. To achieve this, again run the

      commanddf -h


14. Now make the newly created partition a Physical Volume (PV) using the

        command: pvcreate [name of partition]


15. Now find out the name of the VG managed by LVM using the

      command: vgdisplay



16. Extend the VG with the PV you created in step 14 using the

      command: vgextend [name of VG] [name of LV]


17. Now we have to extend the logical volume LV (containing the physical
      volume PV we just created) with the space available on the new PV.

      Since there is a small overhead for administration-purposes needed, you can't
      dedicate the whole space which has been added to the logical volume LV.

      In our example (we added 100 GB), we're dedicating 99 GB to the LV
      running the 


      command: lvextend -L+[additional size] [name of PV]

        Hint: The command lvdisplay outputs the names of the logical volumes
       (LV), see step 2.


18. Now we have to re-grow the file-system for the mount-point which we'd like
      to enhance. Since on CentOS / Red Hat things work a bit different since
      the 
filesystem being used is XFS, the next step is figuring out the mount-
      point.
      To achieve this, run the 

      command: mount



19. Now we only have to run xfs_growfs to resize the XFS filesystem using the

      commandxfs_growfs [mountpoint]

      Hint:

      Running xfs_growfs [mountpoint] without any additional parameters will
      add all remaining space to the file-system specified by the mountpoint.


      In case your filesystem is EXT2/3/4, you'll have to use the
      command
 resize2fs instead of xfs_growfs (not covered in this post).


20. Lastly, check the new size of the mountpoint with the

      command: df - h [mountpoint]




That's it, you're all set!

Kommentare