Lvm – extend sda partition under LVM

lvm

My server has 4 primary partitions with data I can't delete but I need to extend the hdd as it is running out of space.
I already increased the size of the vmdk file but when I try to create a partition I get the message You must delete some partition and add an extended partition first but that is the point, I can't delete a partition…

root@webhost [~]# lsblk
NAME                                  MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
loop0                                   7:0    0  2.4G  0 loop /tmp
sda                                     8:0    0  200G  0 disk
├─sda1                                  8:1    0  500M  0 part /boot
├─sda2                                  8:2    0 24.5G  0 part
│ ├─vg_linuxwebserver2-lv_root (dm-0) 253:0    0 97.5G  0 lvm  /
│ └─vg_linuxwebserver2-lv_swap (dm-1) 253:1    0    2G  0 lvm  [SWAP]
├─sda3                                  8:3    0   25G  0 part
│ ├─vg_linuxwebserver2-lv_root (dm-0) 253:0    0 97.5G  0 lvm  /
│ └─vg_linuxwebserver2-lv_swap (dm-1) 253:1    0    2G  0 lvm  [SWAP]
└─sda4                                  8:4    0   50G  0 part
  └─vg_linuxwebserver2-lv_root (dm-0) 253:0    0 97.5G  0 lvm  /
sr0                                    11:0    1 1024M  0 rom

root@webhost [~]# fdisk -l

Disk /dev/sda: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000969eb

    Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        3264    25701376   8e  Linux LVM
/dev/sda3            3264        6527    26213727+  83  Linux
/dev/sda4            6528       13054    52428127+  8e  Linux LVM

Disk /dev/mapper/vg_linuxwebserver2-lv_root: 104.7 GB, 104689827840 bytes
255 heads, 63 sectors/track, 12727 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/vg_linuxwebserver2-lv_swap: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Can I extend for instance /dev/sda4 using gparted keeping in mind that it is part of a LVM (I am trying to avoid partitions to be deleted)?

thanks

Best Answer

Yes, you can use gparted to extend partition n.4 and then (assuming you want to extend your logical volume using all free space) issue the following commands:

  1. pvresize
  2. lvresize /dev/mapper/vg_linuxwebserver2-lv_root -l+100%FREE

Anyway, I suggest you to print a sector-addressed partition table (you can switch to sector-based size using fdisk -u, so that if gparted fails to resize your partition, you can easily reconstruct it via fdisk

You can also do a binary backup of your partition table using the command

dd if=/dev/sda of=ptable.bin bs=512 count=1

Related Topic