Extend/resize LVM partition on RedHat/CentOS
Brief commands to extend Linux LVM partition.
Increase disk size in VSphere and reboot Linux first.
Sample session. Typed commands are bolded.
# parted /dev/sda (parted) p Model: VMware Virtual disk (scsi) Disk /dev/sda: 53.7GB Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 1049kB 525MB 524MB primary ext4 boot 2 525MB 26.8GB 26.3GB primary lvm (parted) u s (parted) p Model: VMware Virtual disk (scsi) Disk /dev/sda: 104857600s Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 2048s 1026047s 1024000s primary ext4 boot 2 1026048s 52428799s 51402752s primary lvm (parted) rm 2 Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot. (parted) mkpart Partition type? primary/extended? primary File system type? [ext2]? Start? 1026048s End? -1s Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot. (parted) tog 2 lvm Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot. (parted) p Model: VMware Virtual disk (scsi) Disk /dev/sda: 104857600s Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File system Flags 1 2048s 1026047s 1024000s primary ext4 boot 2 1026048s 104857599s 103831552s primary lvm (parted) q # reboot # pvresize -v /dev/sda2 Using physical volume(s) on command line Archiving volume group "vg_sys" metadata (seqno 3). Resizing volume "/dev/sda2" to 51402752 sectors. Resizing physical volume /dev/sda2 from 0 to 12674 extents. Updating physical volume "/dev/sda2" Creating volume group backup "/etc/lvm/backup/vg_sys" (seqno 4). Physical volume "/dev/sda2" changed 1 physical volume(s) resized / 0 physical volume(s) not resized # lvextend -v -l +100%FREE /dev/vg_sys/lv_root Finding volume group vg_sys Archiving volume group "vg_sys" metadata (seqno 4). Extending logical volume lv_root to 47.54 GiB Found volume group "vg_sys" Found volume group "vg_sys" Loading vg_sys-lv_root table (253:0) Suspending vg_sys-lv_root (253:0) with device flush Found volume group "vg_sys" Resuming vg_sys-lv_root (253:0) Creating volume group backup "/etc/lvm/backup/vg_sys" (seqno 5). Logical volume lv_root successfully resized # resize2fs /dev/vg_sys/lv_root resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/vg_sys/lv_root is mounted on /; on-line resizing required old desc_blocks = 2, new_desc_blocks = 3 Performing an on-line resize of /dev/vg_sys/lv_root to 12462080 (4k) blocks. The filesystem on /dev/vg_sys/lv_root is now 12462080 blocks long. # df -k -t ext4 Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/vg_sys-lv_root 49066300 22052540 24526168 48% /