Tested to work on an Ubuntu 14.04.4 LTS VM on VMWare ESXi 5.5, and CentOS 8 on VMware ESXi 6.7.
Scenario: the ext4 partition on the LVM logical volume on the LVM physical volume on partition sdb1 of sdb needs to be expanded. If you are using a physical volume directly on a disk without a partition in between, skip the fdisk steps.
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 16G 0 disk +-sda1 8:1 0 285M 0 part /boot +-sda2 8:2 0 15.7G 0 part +-vg_root-lv_root (dm-0) 252:0 0 15.3G 0 lvm / +-vg_root-lv_swap (dm-1) 252:1 0 480M 0 lvm [SWAP] sdb 8:16 0 600G 0 disk +-sdb1 8:17 0 600G 0 part +-vg_root-lv_data (dm-2) 252:2 0 600G 0 lvm /data sr0 11:0 1 1024M 0 rom
ls -l /sys/class/scsi_disk/
total 0 lrwxrwxrwx 1 root root 0 Nov 1 08:27 2:0:0:0 -> ../../devices/pci0000:00/0000:00:15.0/0000:03:00.0/host2/target2:0:0/2:0:0:0/scsi_disk/2:0:0:0 lrwxrwxrwx 1 root root 0 Nov 1 08:27 2:0:1:0 -> ../../devices/pci0000:00/0000:00:15.0/0000:03:00.0/host2/target2:0:1/2:0:1:0/scsi_disk/2:0:1:0
sudo sh -c 'echo 1 > /sys/class/scsi_disk/2\:0\:1\:0/device/rescan'
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 16G 0 disk +-sda1 8:1 0 285M 0 part /boot +-sda2 8:2 0 15.7G 0 part +-vg_root-lv_root (dm-0) 252:0 0 15.3G 0 lvm / +-vg_root-lv_swap (dm-1) 252:1 0 480M 0 lvm [SWAP] sdb 8:16 0 700G 0 disk +-sdb1 8:17 0 600G 0 part +-vg_root-lv_data (dm-2) 252:2 0 600G 0 lvm /data sr0 11:0 1 1024M 0 rom
sudo fdisk /dev/sdb
Command (m for help):
Command (m for help): p
Disk /dev/sdb: 644.2 GB, 644245094400 bytes 12 heads, 25 sectors/track, 4194304 cylinders, total 1258291200 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: 0x6d1297f2 Device Boot Start End Blocks Id System /dev/sdb1 2048 1258291199 629144576 83 Linux Command (m for help):
# Delete the partition d # If there is only one partition on the disk, as in this example, # it will be deleted. If there are more specify the partition number to delete: 1 # Create a new partition n # Choose a primary partition p # Assign a number to the partition 1 # # Press Enter twice to accept the default values for the starting and ending of the partition. # # Print the partition table, it should now list the new partition p # Set partition type t # Select partition number to set type on 2 # Set it to LVM (8e) or Linux (83) # On CentOS 8: LVM (31) or Linux (20) 8e # Write the new partition table to disk w # Exit fdisk q
partprobe
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 16G 0 disk +-sda1 8:1 0 285M 0 part /boot +-sda2 8:2 0 15.7G 0 part +-vg_root-lv_root (dm-0) 252:0 0 15.3G 0 lvm / +-vg_root-lv_swap (dm-1) 252:1 0 480M 0 lvm [SWAP] sdb 8:16 0 700G 0 disk +-sdb1 8:17 0 700G 0 part +-vg_root-lv_data (dm-2) 252:2 0 600G 0 lvm /data sr0 11:0 1 1024M 0 rom
sudo pvresize /dev/sdb1
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 16G 0 disk ├─sda1 8:1 0 285M 0 part /boot └─sda2 8:2 0 15.7G 0 part ├─vg_root-lv_root (dm-0) 252:0 0 15.3G 0 lvm / └─vg_root-lv_swap (dm-1) 252:1 0 480M 0 lvm [SWAP] sdb 8:16 0 700G 0 disk └─sdb1 8:17 0 700G 0 part └─vg_root-lv_data (dm-2) 252:2 0 700G 0 lvm /data sr0 11:0 1 1024M 0 rom
sudo lvextend -l +100%FREE /dev/vg_root/lv_data
sudo lvs
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert lv_data vg_root -wi-ao--- 700.00g lv_root vg_root -wi-ao--- 15.25g lv_swap vg_root -wi-ao--- 480.00m
sudo resize2fs /dev/mapper/vg_root-lv_data
sudo xfs_growfs /dev/mapper/vg_root-lv_data
df -h
Filesystem Size Used Avail Use% Mounted on udev 5.9G 4.0K 5.9G 1% /dev tmpfs 1.2G 836K 1.2G 1% /run /dev/dm-0 15G 5.6G 8.6G 40% / none 4.0K 0 4.0K 0% /sys/fs/cgroup none 5.0M 0 5.0M 0% /run/lock none 5.9G 12K 5.9G 1% /run/shm none 100M 0 100M 0% /run/user /dev/mapper/vg_root-lv_data 689G 517G 142G 79% /data /dev/sda1 276M 69M 194M 26% /boot