0

I have some free space unallocated and this problem affects more instances.

Number  Start   End     Size    Type     File system  Flags
        32.3kB  1049kB  1016kB           Free Space
 1      1049kB  1075MB  1074MB  primary  xfs          boot
 2      1075MB  34.4GB  33.3GB  primary               lvm
        34.4GB  53.7GB  19.3GB           Free Space

How can I fix this issue using shell scripting? It is impossible to do the operations using cfdisk on every instance.

enter image description here

sfdisk -l

[root@test ~]# sfdisk -l

Disk /dev/sda: 6527 cylinders, 255 heads, 63 sectors/track
Units: cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/sda1   *      0+    130-    131-   1048576   83  Linux
/dev/sda2        130+   4177-   4047-  32504832   8e  Linux LVM
/dev/sda3          0       -       0          0    0  Empty
/dev/sda4          0       -       0          0    0  Empty

Disk /dev/mapper/centos_template--centos7-root: 3758 cylinders, 255 heads, 63 sectors/track

Disk /dev/mapper/centos_template--centos7-swap: 417 cylinders, 255 heads, 63 sectors/track

pvs

[root@test ~]# pvs
  PV         VG                      Fmt  Attr PSize    PFree
  /dev/sda1  centos_template-centos7 lvm2 a--  1020.00m    0
  /dev/sda2  centos_template-centos7 lvm2 a--   <31.00g    0

[root@test ~]# vgdisplay
  --- Volume group ---
  VG Name               centos_template-centos7
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  6
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               31.99 GiB
  PE Size               4.00 MiB
  Total PE              8190
  Alloc PE / Size       8190 / 31.99 GiB
  Free  PE / Size       0 / 0
  VG UUID               OtZy5d-vzvd-ojJw-247H-Bzd7-Xezz-QCFFIu
7
  • Use parted, depending what you mean by "fix".
    – tater
    Jan 13, 2021 at 12:07
  • To extend this logical volumes with the maximum unallocated space. Jan 13, 2021 at 12:44
  • Usually you need to use use lvresize, but in this case you will probably need to add the space to a physical volume first. Can you add the output of the following commands sfdisk -l, pvs and vgdisplay Jan 13, 2021 at 13:06
  • it's LVM, so you need to use lvextend, use lvdisplay to check your logical volume path mapping, and then use lvextend -l +100%FREE /dev/mapper/path/to/your/mapping to extend it.
    – mforsetti
    Jan 13, 2021 at 13:27
  • lvextend -l +100%FREE /dev/mapper/path/to/your/mapping is not usefull in my case due to PE. I need to extend with the whole free space Jan 13, 2021 at 13:40

0

You must log in to answer this question.

Browse other questions tagged .