rhel 67 – shrink expand lvm partition

the default rhel 6.7 partition, “/” partition only have 50GB and the “/home” get the rest

if you only have 90GB for rhel, it would split  / to 50GB and /home 40GB. but if you have TeraByte space / get 50GB and /home get TeraByte

problem when you use / for default database storage, which store the data in / partition, 50GB so small for database.

the advantage using lvm partition, you can shrink the partition, and give the free space for other partition

i will try reduce /home space and add it to

# test
[root@rhel67 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_rhel67-lv_root
 50G 1.9G 45G 4% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 477M 41M 411M 10% /boot
/dev/mapper/vg_rhel67-lv_home
 45G 52M 43G 1% /home

[root@rhel67 ~]# pvs
  PV         VG        Fmt  Attr PSize  PFree
  /dev/sda2  vg_rhel67 lvm2 a--  99.51g    0 

[root@rhel67 ~]# vgs
  VG        #PV #LV #SN Attr   VSize  VFree
  vg_rhel67   1   3   0 wz--n- 99.51g    0 

[root@rhel67 ~]# lvs
  LV      VG        Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv_home vg_rhel67 -wi-ao---- 45.63g                                                    
  lv_root vg_rhel67 -wi-ao---- 50.00g                                                    
  lv_swap vg_rhel67 -wi-ao----  3.88g
  
# step to reduce
[root@rhel67 ~]# umount /home

# check system error
[root@rhel67 ~]# e2fsck -ff /dev/mapper/vg_rhel67-lv_home
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/vg_rhel67-lv_home: 11/2992416 files (0.0% non-contiguous), 233857/11962368 blocks

# now cut the space
[root@rhel67 ~]# resize2fs /dev/mapper/vg_rhel67-lv_home 20G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/vg_rhel67-lv_home to 5242880 (4k) blocks.
The filesystem on /dev/mapper/vg_rhel67-lv_home is now 5242880 blocks long.

# resize authority
[root@rhel67 ~]# lvreduce -L -19G /dev/mapper/vg_rhel67-lv_home  
  WARNING: Reducing active logical volume to 26.63 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_home? [y/n]: y
  Size of logical volume vg_rhel67/lv_home changed from 45.63 GiB (11682 extents) to 26.63 GiB (6818 extents).
  Logical volume lv_home successfully resized

[root@rhel67 ~]# lvdisplay /dev/vg_rhel67/lv_home
  --- Logical volume ---
  LV Path                /dev/vg_rhel67/lv_home
  LV Name                lv_home
  VG Name                vg_rhel67
  LV UUID                TG9ipf-EeEA-jKN6-BrG2-J3Gx-mXz2-tylb4X
  LV Write Access        read/write
  LV Creation host, time rhel67, 2017-07-04 04:05:41 +0700
  LV Status              available
  # open                 0
  LV Size                26.63 GiB
  Current LE             6818
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

[root@rhel67 ~]# bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'. 
1024*20
20480
2048/4
512

[root@rhel67 ~]# lvreduce -l -512 /dev/vg_rhel67/lv_home
  WARNING: Reducing active logical volume to 24.63 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_home? [y/n]: y
  Size of logical volume vg_rhel67/lv_home changed from 26.63 GiB (6818 extents) to 24.63 GiB (6306 extents).
  Logical volume lv_home successfully resized

[root@rhel67 ~]# resize2fs /dev/vg_rhel67/lv_home
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/vg_rhel67/lv_home to 6457344 (4k) blocks.
The filesystem on /dev/vg_rhel67/lv_home is now 6457344 blocks long.

[root@rhel67 ~]# mount /dev/vg_rhel67/lv_home /home

[root@rhel67 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_rhel67-lv_root
                       50G  1.9G   45G   4% /
tmpfs                 1.9G     0  1.9G   0% /dev/shm
/dev/sda1             477M   41M  411M  10% /boot
/dev/mapper/vg_rhel67-lv_home
                       25G   44M   23G   1% /home

# now check
[root@rhel67 ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_rhel67
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  6
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               99.51 GiB
  PE Size               4.00 MiB
  Total PE              25474
  Alloc PE / Size       20098 / 78.51 GiB
  Free  PE / Size       5376 / 21.00 GiB
  VG UUID               DYk8Up-pACU-XZco-ZuEw-iXLL-G98b-gDUSyP
   
[root@rhel67 ~]# pvs
  PV         VG        Fmt  Attr PSize  PFree 
  /dev/sda2  vg_rhel67 lvm2 a--  99.51g 21.00g

[root@rhel67 ~]# lvs
  LV      VG        Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv_home vg_rhel67 -wi-ao---- 24.63g                                                    
  lv_root vg_rhel67 -wi-ao---- 50.00g                                                    
  lv_swap vg_rhel67 -wi-ao----  3.88g

# check how much freespace 
[root@rhel67 ~]# pvscan
  PV /dev/sda2   VG vg_rhel67   lvm2 [99.51 GiB / 21.00 GiB free]
  Total: 1 [99.51 GiB] / in use: 1 [99.51 GiB] / in no VG: 0 [0   ]

[root@rhel67 ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_rhel67
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  6
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               99.51 GiB
  PE Size               4.00 MiB
  Total PE              25474
  Alloc PE / Size       20098 / 78.51 GiB
  Free  PE / Size       5376 / 21.00 GiB
  VG UUID               DYk8Up-pACU-XZco-ZuEw-iXLL-G98b-gDUSyP

# check size partition
[root@rhel67 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_rhel67-lv_root
                       50G  1.9G   45G   4% /
tmpfs                 1.9G     0  1.9G   0% /dev/shm
/dev/sda1             477M   41M  411M  10% /boot
/dev/mapper/vg_rhel67-lv_home
                       25G   44M   23G   1% /home

# now expand the freespace
[root@rhel67 ~]# resize2fs /dev/vg_rhel67/lv_root 
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_rhel67/lv_root is mounted on /; on-line resizing required
old desc_blocks = 4, new_desc_blocks = 5
Performing an on-line resize of /dev/vg_rhel67/lv_root to 18612224 (4k) blocks.
The filesystem on /dev/vg_rhel67/lv_root is now 18612224 blocks long.

# check again the size
[root@rhel67 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_rhel67-lv_root
                       70G  1.9G   65G   3% /
tmpfs                 1.9G     0  1.9G   0% /dev/shm
/dev/sda1             477M   41M  411M  10% /boot
/dev/mapper/vg_rhel67-lv_home
                       25G   44M   23G   1% /home

ubuntu – increase the size of a linux lvm

create LVM partition in new hardisk
===================================

sudo fdisk /dev/sdb
'n' create new partition
'p' primary partition
'1' partition number
[enter] for first cylinder
[enter] for last cylinder(max size)
't' type for paritition
'L' for list all
'8e' for linux.lvm
'w' for write partition

increasing the logical volume
====================================
# create a physical volume for later use by the LVM.

$ sudo pvcreate /dev/sdb1

03-disk-partitioan-create
# shown the name and the current size of it

$ sudo vgdisplay

# pvscan scan all disks for physical volumes

$ sudo pvscan

# increase the logical volume with the lvextend command
# my name volume is “ubuntu-vg”

$ sudo vgextend ubuntu-vg /dev/sdb1

# pvscan scan all disks for physical volumes

$ sudo pvscan

04-vgdisplay-after-extend
#c onfirm the name of the logical volume using lvdisplay.

$ sudo lvdisplay
--- Logical volume ---
LV Path                /dev/ubuntu-vg/root
LV Name                root
VG Name                ubuntu-vg

# The logical volume is then extended using the lvextend command
# We are extending the original logical volume of

#/dev/ubuntu-vg/root over the newer /dev/sdb1

$ sudo lvextend /dev/ubuntu-vg/root /dev/sdb1
Size of logical volume ubuntu-vg/root changed from 4.83 GiB (1236 extents) to 24.82 GiB (6355 extents).
Logical volume root successfully resized

#show vgdisplay

$ sudo vgdisplay
--- Volume group ---
VG Name               ubuntu-vg
...
VG Size               29.75 GiB

# However if you run a “df” command to see available disk space it will not have changed
# yet as there is one final step, we need to resize the file system using the
# resize2fs command in order to make use of this space.

$ sudo resize2fs /dev/ubuntu-vg/root
resize2fs 1.42.12 (29-Aug-2014)
Filesystem at /dev/ubuntu-vg/root is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
The filesystem on /dev/ubuntu-vg/root is now 6507520 (4k) blocks long.

#show size with df

$ df -h

07-df-h
# Alternatively if you’re running the XFS file system (default as of RedHat/CentOS 7)
# you can grow the file system with “xfs_growfs /dev/ubuntu-vs/root”.

https://www.rootusers.com/how-to-increase-the-size-of-a-linux-lvm-by-adding-a-new-disk/