Extending an LVM partition inside an Extended one

shape
shape
shape
shape
shape
shape
shape
shape

Let’s see in the example below how to increase an LVM partition, which is inside an Extended partition. In the example below, we will recreate the LVM partition, which must start from the same old sector, i.e. in our example the starting sector of our LVM is 501760, so the new resized partition must also start at sector 501760.

root@masterdaweb:~# fdisk -l
Disk /dev/sda: 800 GiB, 858993459200 bytes, 1677721600 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
Disklabel type: dos
Disk identifier: 0xac7783f0

Device     Boot  Start      End  Sectors  Size Id Type
/dev/sda1  *      2048   499711   497664  243M 83 Linux
/dev/sda2       501758 83884031 83382274 39,8G  5 Extended
/dev/sda5       501760 83884031 83382272 39,8G 8e Linux LVM


Disk /dev/mapper/debian--vg-root: 38,1 GiB, 40907046912 bytes, 79896576 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 /dev/mapper/debian--vg-swap_1: 1,7 GiB, 1782579200 bytes, 3481600 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
root@masterdaweb:~# fdisk /dev/sda

Welcome to fdisk (util-linux 2.29.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): d
Partition number (1,2,5, default 5): 2

Partition 2 has been deleted.

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (2-4, default 2): 2
First sector (499712-1677721599, default 499712): 501760
Last sector, +sectors or +size{K,M,G,T,P} (501760-1677721599, default 1677721599): 

Created a new partition 2 of type 'Linux' and of size 799,8 GiB.
Partition #2 contains a LVM2_member signature.

Do you want to remove the signature? [Y]es/[N]o: N

Command (m for help): t
Partition number (1,2, default 2): 2
Partition type (type L to list all types): 8e

Changed type of partition 'Linux' to 'Linux LVM'.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: 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).

root@masterdaweb:~# fdisk -l
Disk /dev/sda: 800 GiB, 858993459200 bytes, 1677721600 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
Disklabel type: dos
Disk identifier: 0xac7783f0

Device     Boot  Start        End    Sectors   Size Id Type
/dev/sda1  *      2048     499711     497664   243M 83 Linux
/dev/sda2       501760 1677721599 1677219840 799,8G 8e Linux LVM


Disk /dev/mapper/debian--vg-root: 38,1 GiB, 40907046912 bytes, 79896576 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

Then simply restart the machine so that the changes are applied, and then resize the Physical Volume of our LVM:

shutdown -r now
pvresize /dev/sda2
root@masterdaweb:~# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               debian-vg
  PV Size               799,76 GiB / not usable 2,00 MiB
  Allocatable           yes 
  PE Size               4,00 MiB
  Total PE              204738
  Free PE               194560
  Allocated PE          10178
  PV UUID               k7gcJz-tKRI-WZb2-Dmdo-BpMn-qANT-y7PMYY
root@masterdaweb:~# vgdisplay
  --- Volume group ---
  VG Name               debian-vg
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               799,76 GiB
  PE Size               4,00 MiB
  Total PE              204738
  Alloc PE / Size       10178 / 39,76 GiB
  Free  PE / Size       194560 / 760,00 GiB
  VG UUID               kXiqf9-oqdT-szRX-fNd9-utWC-ZncD-DwDooI

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Latest news

Latest news directly from our blog.