Enlarge LVM Partition

First I went to fdisk and identify the LVM partition:

# fdisk /dev/sda

Command (m for help): p 
Disk /dev/sda: 268.4 GB, 268435456000 bytes
16 heads, 63 sectors/track, 520126 cylinders, total 524288000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000873eb  
  Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048   419430399   209202176   8e  Linux LVM

Very carefully, delete the partition, and re-create it with an ending point the same or greater unit.

Command (m for help): d
Partition number (1-4): 2 
Command (m for help): p 

Disk /dev/sda: 268.4 GB, 268435456000 bytes
16 heads, 63 sectors/track, 520126 cylinders, total 524288000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000873eb  
  Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First sector (1026048-524287999, default 1026048): 1026048
Last sector, +sectors or +size{K,M,G} (1026048-524287999, default 524287999):
Using default value 524287999 

Command (m for help): p 

Disk /dev/sda: 268.4 GB, 268435456000 bytes
16 heads, 63 sectors/track, 520126 cylinders, total 524288000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000873eb  
  Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048   524287999   261630976   83  Linux

Change the partition type to 8e (Linux LVM) and write changes on disk:

Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 8e
Changed system type of partition 2 to 8e (Linux LVM)

Command (m for help): p 

Disk /dev/sda: 268.4 GB, 268435456000 bytes
16 heads, 63 sectors/track, 520126 cylinders, total 524288000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000873eb  
  Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048   524287999   261630976   8e  Linux LVM

Command (m for help): w

The partition table has been altered! 

Calling ioctl() to re-read partition table. 

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks. 
[root@mysqlrep1 ~]# reboot

After the reboot there are 4 more commands to run, and we are done.

# pvresize /dev/sda2
# pvdisplay
# lvextend -l +100%FREE /dev/mapper/ol_pxe-root
# xfs_growfs /

Related Posts