Extend LVM Partition in ubuntu

علی ذوالفقار
1402/12/14 08:56:29 (146)
Extend LVM Partition in ubuntu : 


[ CHECK BLOCK DEVICES with lsblk or lsblk /dev/sda or ... ]
root@agw:~# lsblk /dev/vda
NAME                 MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
vda                  252:0    0   20G  0 disk 
├─vda1               252:1    0    1M  0 part 
├─vda2               252:2    0  513M  0 part /boot/efi
└─vda3               252:3    0 19.5G  0 part 
  ├─vgxubuntu-root   253:0    0 18.5G  0 lvm  /
  └─vgxubuntu-swap_1 253:1    0  976M  0 lvm  [SWAP]


[ USE vgs to check the virtual disk groups ]  
root@agw:~# vgs
  VG        #PV #LV #SN Attr   VSize  VFree
  vgxubuntu   1   2   0 wz--n- 19.49g    0  


[ after adding more space to disk (example 20GB) , recheck the block size again ( old : 20G , now : 40G ) ]
root@agw:~# lsblk /dev/vda
NAME                 MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
vda                  252:0    0   40G  0 disk 
├─vda1               252:1    0    1M  0 part 
├─vda2               252:2    0  513M  0 part /boot/efi
└─vda3               252:3    0 19.5G  0 part 
  ├─vgxubuntu-root   253:0    0 18.5G  0 lvm  /
  └─vgxubuntu-swap_1 253:1    0  976M  0 lvm  [SWAP]


[ check vg again and see it does not change yet ]   
root@agw:~# vgs
  VG        #PV #LV #SN Attr   VSize  VFree
  vgxubuntu   1   2   0 wz--n- 39.49g    0  


[ use growpart to append aditional space on disk to partition ]
root@agw:~# growpart /dev/vda 3
CHANGED: partition=3 start=1054720 old: size=40888287 end=41943007 new: size=45082591 end=46137311


[ use pvs to check the partiton status ]
root@agw:~# pvs
PV         VG        Fmt  Attr PSize  PFree
/dev/vda3  vgxubuntu lvm2 a--  19.49g 20.00g


[ use lvextend to extend the logical volume space ]
root@agw:~# lvextend -l+100%FREE /dev/vgxubuntu/root
  Size of logical volume vgxubuntu/root changed from <18.54 GiB (4746 extents) to <39.54 GiB (5258 extents).
  Logical volume vgxubuntu/root successfully resized.


[ check result and see the space does not change yet ]  
root@agw:~# df -hPT /
Filesystem                 Type  Size  Used Avail Use% Mounted on
/dev/mapper/vgxubuntu-root ext4   19G   11G  7.2G  59% /


[ use resize2fs to resize the root partition ]
root@agw:~# resize2fs /dev/mapper/vgxubuntu-root
resize2fs 1.46.5 (30-Dec-2021)
Filesystem at /dev/mapper/vgxubuntu-root is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 3
The filesystem on /dev/mapper/vgxubuntu-root is now 5384192 (4k) blocks long.


[ check the partiton again and see the size change from 19 to 21 (20GB additional space) ]
root@agw:~# df -hPT /
Filesystem                 Type  Size  Used Avail Use% Mounted on
/dev/mapper/vgxubuntu-root ext4   39G   11G  19.1G  53% / 
        
Back