16 LVM shrinking lvreduce resize2fs umount/nount

[root@localhost /]# df -h
Filesystem                 Size  Used Avail Use% Mounted on
/dev/mapper/cl-root         17G  4.7G   13G  28% /
devtmpfs                   480M     0  480M   0% /dev
tmpfs                      493M   96K  493M   1% /dev/shm
tmpfs                      493M   20M  473M   4% /run
tmpfs                      493M     0  493M   0% /sys/fs/cgroup
/dev/sda1                 1014M  188M  827M  19% /boot
tmpfs                       99M   48K   99M   1% /run/user/1000
/dev/mapper/vgmyvg-lvmylv  186M  1.6M  176M   1% /mnt
tmpfs                       99M     0   99M   0% /run/user/0
[root@localhost /]#

root@localhost /]# mount | grep lvm
/dev/mapper/vgmyvg-lvmylv on /mnt type ext2 (rw,relatime)
[root@localhost /]# 

we cannot online shrink filesystem, it needs to be unmounted first.

[root@localhost /]# umount /mnt/
[root@localhost /]# df -k
Filesystem          1K-blocks    Used Available Use% Mounted on
/dev/mapper/cl-root  17811456 4827440  12984016  28% /
devtmpfs               491296       0    491296   0% /dev
tmpfs                  504192      96    504096   1% /dev/shm
tmpfs                  504192   19884    484308   4% /run
tmpfs                  504192       0    504192   0% /sys/fs/cgroup
/dev/sda1             1038336  192076    846260  19% /boot
tmpfs                  100840      48    100792   1% /run/user/1000
tmpfs                  100840       0    100840   0% /run/user/0
[root@localhost /]# 

The first step for shrinking would be filesystem itself
The next step - logical volume


[root@localhost /]# man -k resize
fsadm (8)            - utility to resize or check filesystem on a device
lvresize (8)         - resize a logical volume
probe::tty.resize (3stap) - Called when a terminal resize happens
probe::vm.brk (3stap) - Fires when a brk is requested (i.e. the heap will be resized)
pvresize (8)         - resize a disk or partition in use by LVM2
resize (1)           - set environment and terminal settings to current xterm window size
resize2fs (8)        - ext2/ext3/ext4 file system resizer
resizecons (8)       - change kernel idea of the console size
resizepart (8)       - simple wrapper around the "resize partition" ioctl
[root@localhost /]


1) OPTION without lvreduce -r
[root@localhost /]# resize2fs /dev/vgmyvg/lvmylv 100M
resize2fs 1.42.9 (28-Dec-2013)
Please run 'e2fsck -f /dev/vgmyvg/lvmylv' first.

[root@localhost /]# 


[root@localhost /]# e2fsck -f /dev/vgmyvg/lvmylv
e2fsck 1.42.9 (28-Dec-2013)
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/vgmyvg/lvmylv: 11/49152 files (0.0% non-contiguous), 7755/196608 blocks
[root@localhost /]# resize2fs /dev/vgmyvg/lvmylv 100M
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vgmyvg/lvmylv to 102400 (1k) blocks.
The filesystem on /dev/vgmyvg/lvmylv is now 102400 blocks long.

[root@localhost /]# 

Next step we resize the size of volume

[root@localhost /]# lvreduce --help
File descriptor 22 (socket:[27108]) leaked on lvreduce invocation. Parent PID 3225: -bash
  lvreduce: Reduce the size of a logical volume

lvreduce
        [-A|--autobackup y|n]
        [--commandprofile ProfileName]
        [-d|--debug]
        [-f|--force]
        [-h|--help]
        {-l|--extents [-]LogicalExtentsNumber[%{VG|LV|FREE|ORIGIN}] |
         -L|--size [-]LogicalVolumeSize[bBsSkKmMgGtTpPeE]}
        [-n|--nofsck]
        [--noudevsync]
        [-r|--resizefs]
        [--reportformat {basic|json}]
        [-t|--test]
        [-v|--verbose]
        [--version]
        [-y|--yes]
        LogicalVolume[Path]

[root@localhost /]# 


[root@localhost /]# lvreduce -L 102400K /dev/vgmyvg/lvmylv 
File descriptor 22 (socket:[27108]) leaked on lvreduce invocation. Parent PID 3225: -bash
  WARNING: Reducing active logical volume to 100.00 MiB.
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vgmyvg/lvmylv? [y/n]: y
  Size of logical volume vgmyvg/lvmylv changed from 192.00 MiB (48 extents) to 100.00 MiB (25 extents).
  Logical volume vgmyvg/lvmylv successfully resized.
[root@localhost /]# 

[root@localhost /]# mount /dev/vgmyvg/lvmylv /mnt

[root@localhost /]# df -h
Filesystem                 Size  Used Avail Use% Mounted on
/dev/mapper/cl-root         17G  4.7G   13G  28% /
devtmpfs                   480M     0  480M   0% /dev
tmpfs                      493M   96K  493M   1% /dev/shm
tmpfs                      493M   20M  473M   4% /run
tmpfs                      493M     0  493M   0% /sys/fs/cgroup
/dev/sda1                 1014M  188M  827M  19% /boot
tmpfs                       99M   48K   99M   1% /run/user/1000
tmpfs                       99M     0   99M   0% /run/user/0
/dev/mapper/vgmyvg-lvmylv   97M  1.6M   91M   2% /mnt
[root@localhost /]# 

2) OPTION - without e2fsck 
[root@localhost /]# lvreduce -L 50M -r /dev/vgmyvg/lvmylv 
File descriptor 22 (socket:[27108]) leaked on lvreduce invocation. Parent PID 3225: -bash
  Rounding size to boundary between physical extents: 52.00 MiB.
fsck from util-linux 2.23.2
/dev/mapper/vgmyvg-lvmylv: 11/26624 files (0.0% non-contiguous), 4917/102400 blocks
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/mapper/vgmyvg-lvmylv to 53248 (1k) blocks.
The filesystem on /dev/mapper/vgmyvg-lvmylv is now 53248 blocks long.

  Size of logical volume vgmyvg/lvmylv changed from 100.00 MiB (25 extents) to 52.00 MiB (13 extents).
  Logical volume vgmyvg/lvmylv successfully resized.
[root@localhost /]# mount /dev/vgmyvg/lvmylv /mnt
[root@localhost /]# df -h
Filesystem                 Size  Used Avail Use% Mounted on
/dev/mapper/cl-root         17G  4.7G   13G  28% /
devtmpfs                   480M     0  480M   0% /dev
tmpfs                      493M   96K  493M   1% /dev/shm
tmpfs                      493M   20M  473M   4% /run
tmpfs                      493M     0  493M   0% /sys/fs/cgroup
/dev/sda1                 1014M  188M  827M  19% /boot
tmpfs                       99M   48K   99M   1% /run/user/1000
tmpfs                       99M     0   99M   0% /run/user/0
/dev/mapper/vgmyvg-lvmylv   51M  1.1M   47M   3% /mnt
[root@localhost /]# 





Comments

Popular posts from this blog

HAproxy logging

teamcity Automatic Agent Start under Linux

NFS mount add in fstab _netdev instead of default | firewall-cmd --list-all