简体   繁体   中英

How can I increase the size of lvm partition?

I have a ubuntu 18 system. I have a total of 3 partitions and in my third partition, I have an LVM partition. I need to increase the size of that partition. Here is the output of lsblk I need to increase the size of ubuntu--vg-ubuntu--lv partition inside /dev/sda3

NAME                      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                         8:0    0  140G  0 disk
├─sda1                      8:1    0    1M  0 part
├─sda2                      8:2    0    1G  0 part /boot
└─sda3                      8:3    0   49G  0 part
  └─ubuntu--vg-ubuntu--lv 253:0    0 24.5G  0 lvm  /
sr0                        11:0    1  969M  0 rom

Here is the output of df-h

udev                               3.9G     0  3.9G   0% /dev
tmpfs                              789M  1.3M  787M   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv   24G   22G  1.4G  95% /
tmpfs                              3.9G     0  3.9G   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
tmpfs                              3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda2                          974M  219M  688M  25% /boot
overlay                             24G   22G  1.4G  95% /var/lib/docker/overlay2/bb5dcb08fd6998aa3e438d3f2a43aeaea79fb22964abf42b4c5a869cde848b2a/merged
overlay                             24G   22G  1.4G  95% /var/lib/docker/overlay2/55b43f1550428d3a82d2c2aebeb71bc9d53aac8185dd92644dfb27e806643b21/merged
overlay                             24G   22G  1.4G  95% /var/lib/docker/overlay2/d812b2347f599e207581e3cd6465013c5bf397aed3e4574a029f0289c42b3a4a/merged
overlay                             24G   22G  1.4G  95% /var/lib/docker/overlay2/742e299d503c794052c173e34c78c75034e96870802856cfb15475478cbc6b01/merged
shm                                 64M   28K   64M   1% /var/lib/docker/containers/551b12883006bdf12d8a7602d862639b25cefdaac1623c62a0dfbc54970e6134/mounts/shm
shm                                 64M     0   64M   0% /var/lib/docker/containers/5f0ba3554d80c9b04823d09fed7a8c07c79f0059ba53d5a302ad981c6c419f42/mounts/shm
shm                                 64M     0   64M   0% /var/lib/docker/containers/aa50634d995d73db38c109365c7a7f330d3ba3dd8adf6901ab0668536787ea21/mounts/shm
shm                                 64M     0   64M   0% /var/lib/docker/containers/058f86b327e7efb701b5741a529157fdd01cc4785f3fb71a02355f3533664b5b/mounts/shm
overlay                             24G   22G  1.4G  95% /var/lib/docker/overlay2/d59ce13ad4c6790a0870b3f493b7093173c72da454eeaf03f96a311e16287d4b/merged
overlay                             24G   22G  1.4G  95% /var/lib/docker/overlay2/474c51077a4becbc431b85ae8204648206cb3321ccf5b778882961d410ba32c2/merged
overlay                             24G   22G  1.4G  95% /var/lib/docker/overlay2/fb516c559bd0d8368215a888320ab9624f6eac47fce9536ca6c3c4eddcb98af4/merged
overlay                             24G   22G  1.4G  95% /var/lib/docker/overlay2/f4d78c070438f018f39cd7a170594c84b6d5b1983eb9240f55e3c33c131503c9/merged
shm                                 64M     0   64M   0% /var/lib/docker/containers/eea2e2895e013598106f35980d444b0b192a9ad60e8d12071edc729f1b38a9de/mounts/shm
shm                                 64M     0   64M   0% /var/lib/docker/containers/7df0cb94fb37ee61fdec8fb2db4fc4938fe56b8ac5809f109b9ed73fd6cb07d6/mounts/shm
shm                                 64M   16K   64M   1% /var/lib/docker/containers/5a1f23081c327b5e431b985f051c85c02eaf143db4bca9984cd55c5b69485e0e/mounts/shm
shm                                 64M  8.0K   64M   1% /var/lib/docker/containers/a8b8c20bdaa2ca9f934348ec9aa754399217f9e58e69e886deef5b0df3ab7074/mounts/shm
tmpfs                              789M     0  789M   0% /run/user/1000

Here is the output of lvs

LV        VG        Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  ubuntu-lv ubuntu-vg -wi-ao---- 24.50g

Here is the output of vgs

VG        #PV #LV #SN Attr   VSize   VFree
  ubuntu-vg   1   1   0 wz--n- <49.00g <24.50g

Please help me out in extending the size of my lv inside /dev/sda3 from 24.5G to 49G

You can try the following: Find the number of FREE PE available to the partition that you need to expand (in my case is 0 but you should have some FREE PE available)

vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  7
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                6
  Open LV               6
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <222.00 GiB
  PE Size               4.00 MiB
  Total PE              56831
  Alloc PE / Size       56831 / <222.00 GiB
  Free  PE / Size       0 / 0
  VG UUID               JjwxRB-Cq29-fCJW-FQJm-FLwW-UTds-iMrq2j

Expand the logical volume:

lvextend -l +<number-of-free-pe> /dev/mapper/ubuntu--vg-ubuntu--lv

Resize the partition that needs to be expanded to occupy all available space:

# if you have xfs file system
xfs_growfs  /dev/mapper/ubuntu--vg-ubuntu--lv
# if you have ext* file system
resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM