Header Shadow Image


Linux LVM: Adding Disk Space to Virtual of Physical Drives

Linux LVM: Adding Disk Space to Virtual of Physical Drives

In this writeup, we will aim to increase the size of the root drive that has:

1) Standard drive partitioning using fdisk and no LVM: /dev/sda1
2) Has LVM for the OS and files: /dev/sda2

This procedure will help to avoid the can't find the centos-root logical volume.

Virtual Drive: 

The first thing we'll do is to increase the physical size of the disk.  To do that, login to whatever hypervisor you have available and increase the drive.  For VMware for example, edit the VM properties and increase the size of the drive.  

While doing so, also add a secondary drive.  We will need this to effectively transition the partition while maintaining the correct labeling.  Failing to ensure correct labeling will result with an unmountable drive.

1) Check your mounts:

[root@srv01 ~]# lsblk -f
NAME            FSTYPE      LABEL           UUID                                   MOUNTPOINT
fd0
sda
??sda1          xfs                         42343696-5957-46e3-9f28-863b2778a7df   /boot
??sda2          LVM2_member                 owcjYz-ohz3-3obA-KaL0-wcyn-ayc5-EG1Fgc
  ??centos-root xfs                         729d6ef5-37ec-40c4-a728-3a27120b029c   /
  ??centos-swap swap                        11193f5e-498f-4e05-9f2c-e42c4d15ec06   [SWAP]
  ??centos-home xfs                         dfdc00f0-bc2e-4406-9c0a-900ed9f864c3   /home
sr0             iso9660     CentOS 7 x86_64 2015-12-09-23-03-16-00
[root@srv01 ~]#

2) Add a second drive, increase the size of the primary one ( /dev/sda above ) and recheck.  Use a separate SCSI controller if possible for the second drive.  Once done, issue the following from the OS side:

  • echo 1 > /sys/block/sda/device/rescan
  • lsblk -f
  • fdisk -l /dev/sda
  • fdisk -l /dev/sdb

3) Create a standard partition and PV ID's:  

  • fdisk /dev/sdb, followed by options n, (default for all questions) then w to write the partition to the disk.
  • lsblk -f to verify
  • pvcreate /dev/sdb1
  • pvs  # (verify)
  • vgs  # (verify)

4) Verify correct labeling exists for FSTYPE and UUID.  This is important.  The server won't boot if these are not present on the partition.  ( fdisk does not create these instead it sets it to PTTYPE="dos" causing boot failures. )

  • lsblk -f
    [root@cm-r01en01 ~]# lsblk -f /dev/sdb
    NAME   FSTYPE      LABEL UUID                                   MOUNTPOINT
    sdb
    – sdb1 LVM2_member       yudPwG-BCwa-cRL1-8sk8-4ins-Ncth-5CaXUr
    [root@cm-r01en01 ~]#

5) Extend the volume and pvmove data from /dev/sda2 to /dev/sdb1 :

  • vgextend centos /dev/sdb1
  • pvmove /dev/sda2 /dev/sdb1
  • vgreduce centos /dev/sda2

6) Remove the old partition using fdisk and verify the new partition matches the size of the disk.

  • fdisk /dev/sda
  • d, 2, w   # d = delete, 2 = partition, w = write to disk.
  • (You may need to reboot at this point.)
  • fdisk /dev/sda
  • n, 2, (default for the rest), w
  • fdisk -l /dev/sda
  • (You may need to reboot at this point.)

7) Reverse the steps of the VG / LV migration above.

  • vgextend centos /dev/sda2
  • pvmove /dev/sdb1 /dev/sda2
  • vgreduce centos /dev/sdb1
  • Remove the temporary disk /dev/sdb1 from the system. 

8) You may need to run pvresize:

  • pvresize /dev/sda2
    [root@srv01 ~]# pvresize /dev/sda2
      Physical volume "/dev/sda2" changed
      1 physical volume(s) resized or updated / 0 physical volume(s) not resized
    [root@cm-r01en01 ~]# pvs
      PV         VG     Fmt  Attr PSize    PFree
      /dev/sda2  centos lvm2 a–  <255.51g 192.06g
    [root@srv01 ~]#

At this point, you're done.  The newly extended drive is in effect.

 

Physical Drives: 

If you're stuck with a physical here, you don't have much of a choice.  The only and safest thing you can do here is to buy a new larger one and skip to the part where we extend the volume.  One option is to use the dd command to transfer both the /boot partition and the OS partition to the new disk.

The process for the VG / LV move for physical is identical to that of the VM's with the exception of course that you can't extend the size of the physical disk.     

Cheers,
TK

 

Leave a Reply

You must be logged in to post a comment.


     
  Copyright © 2003 - 2013 Tom Kacperski (microdevsys.com). All rights reserved.

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License