Koozali.org formerly Contribs.org

Resize LVM Partition to max free space

Offline HACKERSOFT2011

  • *
  • 23
  • HACKERSOFT
    • Adventist International Mission School
Resize LVM Partition to max free space
« on: February 17, 2021, 09:35:24 AM »
Hi! 

My smeserver main storage running on ESXI is now at around 90% full so I've decided to increase the virtual disk size to 700G.

My question is, how can I safely resize the LVM partition to fully use the available disk space in smeserver 9?


Code: [Select]
[root@sme1 ~]# fdisk -l

Disk /dev/sda: 834.3 GB, 834297397248 bytes
255 heads, 63 sectors/track, 101430 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: 0x00058d80

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          32      256000   fd  Linux raid autodetect
Partition 1 does not end on cylinder boundary.
/dev/sda2              32       27414   219943936   8e  Linux LVM

Disk /dev/mapper/main-root: 221.1 GB, 221060792320 bytes
255 heads, 63 sectors/track, 26875 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/main-swap: 4160 MB, 4160749568 bytes
255 heads, 63 sectors/track, 505 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/md0: 262 MB, 262127616 bytes
2 heads, 4 sectors/track, 63996 cylinders
Units = cylinders of 8 * 512 = 4096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Code: [Select]
[root@sme1 ~]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/main-root
                     212359480 179197592  22367904  89% /
tmpfs                 16439996         0  16439996   0% /dev/shm
/dev/md0                243759     78959    152004  35% /boot


Code: [Select]
[root@sme1 ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/main/root
  LV Name                root
  VG Name                main
  LV UUID                gq2kwk-uImZ-q2y3-Qfcb-8Y5f-K6WI-Rdsc3H
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2015-12-17 15:10:27 +0700
  LV Status              available
  # open                 1
  LV Size                205.88 GiB
  Current LE             52705
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/main/swap
  LV Name                swap
  VG Name                main
  LV UUID                jozvKK-HOpP-OUzz-a3Vn-6Vax-khYC-VbRGBw
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2015-12-17 15:11:19 +0700
  LV Status              available
  # open                 1
  LV Size                3.88 GiB
  Current LE             992
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1



Code: [Select]
[root@sme1 ~]# vgdisplay
  --- Volume group ---
  VG Name               main
  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               209.75 GiB
  PE Size               4.00 MiB
  Total PE              53697
  Alloc PE / Size       53697 / 209.75 GiB
  Free  PE / Size       0 / 0
  VG UUID               lSFJF6-9BzE-aB8a-50yM-Jnux-0Uaj-ufIbf0



Thank you in advance for your help!

Online ReetP

  • *
  • 2,717
Re: Resize LVM Partition to max free space
« Reply #1 on: February 17, 2021, 09:43:32 AM »
Stacks of howto resize lvm around.

This was my first hit

https://www.rootusers.com/lvm-resize-how-to-increase-an-lvm-partition/

Note IIRC it is usually recommended to run "no lvm/no raid" on virtual machines.
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions of software
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation

Offline HACKERSOFT2011

  • *
  • 23
  • HACKERSOFT
    • Adventist International Mission School
Re: Resize LVM Partition to max free space
« Reply #2 on: February 18, 2021, 02:14:32 AM »
I've already tried that prior to posting a question here but it does not see the remaining free space:

Code: [Select]
[root@sme1 ~]# vgdisplay
  --- Volume group ---
  VG Name               main
  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               209.75 GiB
  PE Size               4.00 MiB
  Total PE              53697
  Alloc PE / Size       53697 / 209.75 GiB
  Free  PE / Size       0 / 0
  VG UUID               lSFJF6-9BzE-aB8a-50yM-Jnux-0Uaj-ufIbf0

Free PE/Size = 0


But as you can see from below, the drive is now 834.3GB:

Code: [Select]
[root@sme1 ~]# fdisk -l

Disk /dev/sda: 834.3 GB, 834297397248 bytes
255 heads, 63 sectors/track, 101430 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: 0x00058d80

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          32      256000   fd  Linux raid autodetect
Partition 1 does not end on cylinder boundary.
/dev/sda2              32       27414   219943936   8e  Linux LVM

Disk /dev/mapper/main-root: 221.1 GB, 221060792320 bytes
255 heads, 63 sectors/track, 26875 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/main-swap: 4160 MB, 4160749568 bytes
255 heads, 63 sectors/track, 505 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/md0: 262 MB, 262127616 bytes
2 heads, 4 sectors/track, 63996 cylinders
Units = cylinders of 8 * 512 = 4096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Re: Resize LVM Partition to max free space
« Reply #3 on: February 18, 2021, 09:49:56 AM »
lvextend -L + xG /dev/mapper/main-root
xfs_growfs /dev/mapper/main-root

« Last Edit: February 18, 2021, 03:50:49 PM by Gary Douglas »

Offline HACKERSOFT2011

  • *
  • 23
  • HACKERSOFT
    • Adventist International Mission School
Re: Resize LVM Partition to max free space
« Reply #4 on: February 19, 2021, 02:33:30 AM »
I've done this but is still can't resize it to max free:
Code: [Select]
[root@sme1 ~]# lvextend -l +100%FREE /dev/main/root
[root@sme1 ~]# lvresize -l +100%FREE /dev/main/root
[root@sme1 ~]# resize2fs /dev/main/root
resize2fs 1.41.12 (17-May-2010)
The filesystem is already 53969920 blocks long.  Nothing to do!

Offline HACKERSOFT2011

  • *
  • 23
  • HACKERSOFT
    • Adventist International Mission School
Re: Resize LVM Partition to max free space
« Reply #5 on: February 19, 2021, 08:21:42 AM »
Okay, I ended up downloading gparted live iso and extended it from there, restarted back to smeserver then run the following commands in order:

Code: [Select]
lvextend -l +100%FREE /dev/mapper/main-root
lvresize -l +100%FREE /dev/mapper/main-root
resize2fs /dev/main/root


and voila!

Code: [Select]
[root@sme1 ~]# vgdisplay
  --- Volume group ---
  VG Name               main
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  7
  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               776.75 GiB
  PE Size               4.00 MiB
  Total PE              198849
  Alloc PE / Size       198849 / 776.75 GiB
  Free  PE / Size       0 / 0
  VG UUID               lSFJF6-9BzE-aB8a-50yM-Jnux-0Uaj-ufIbf0

Online ReetP

  • *
  • 2,717
Re: Resize LVM Partition to max free space
« Reply #6 on: February 19, 2021, 10:55:45 AM »
Cool.

I'd take a look at v10 Beta 1 and if you are on a hypervisor lose the LVM. Think it save a bit of overhead, and resize issues ;-)

Remember it isn't like running real hardware where you need to add disks and increase the LVM.

You can just increase the VM size, resize the partition table and expand the file system. It is MUCH easier without LVMs (done it loads of times on my Prox servers)
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions of software
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation

Online ReetP

  • *
  • 2,717
Re: Resize LVM Partition to max free space
« Reply #7 on: February 19, 2021, 11:44:37 AM »
FYI - v10 defaults to a LVM install. You should be able to change that if you use the manual partitioner during install.

We are looking at ways to change/disable it during install like the old no raid/no lvm options, but no guarantees on that yet.
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions of software
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation

Offline TerryF

  • grumpy old man
  • *
  • 1,263
Re: Resize LVM Partition to max free space
« Reply #8 on: February 19, 2021, 12:56:53 PM »
Yep, when installing sme10 using the graphic installer you can delete the partition scheme that kickstart has created and created a custom one with no lvm, test vm running with this now, just a basic setup

[root@smenolvm ~]# fdisk -l

Disk /dev/sda: 16.1 GB, 16106127360 bytes, 31457280 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 label type: dos
Disk identifier: 0x000e3af4

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 26367999 13182976 83 Linux
/dev/sda2 26368000 29296639 1464320 82 Linux swap / Solaris

[root@smenolvm ~]# df -T
Filesystem     Type     1K-blocks    Used Available Use% Mounted on
devtmpfs       devtmpfs   2014268       0   2014268   0% /dev
tmpfs          tmpfs      2022520      12   2022508   1% /dev/shm
tmpfs          tmpfs      2022520    8780   2013740   1% /run
tmpfs          tmpfs      2022520       0   2022520   0% /sys/fs/cgroup
/dev/sda1      xfs       13172736 2608240  10564496  20% /
tmpfs          tmpfs       404504       0    404504   0% /run/user/0
--
qui scribit bis legit

Offline TerryF

  • grumpy old man
  • *
  • 1,263
Re: Resize LVM Partition to max free space
« Reply #9 on: February 19, 2021, 12:59:48 PM »
and there are those quicker on the gun than me

just redid mine, ext2 for /boot and ext4 for /

:-)
--
qui scribit bis legit

Online ReetP

  • *
  • 2,717
Re: Resize LVM Partition to max free space
« Reply #10 on: February 20, 2021, 11:54:14 AM »
xfs_growfs /dev/mapper/main-root

That would only work on an xfs file system, but v9 is ext4.

CentOS7 defaults to xfs though there is some debate whether we use that or stick with ext4 for v10.

See the bug tracker for details.

...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions of software
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation