This is an old revision of lvm from 24.02.2018 12:13 edited by EvaggelosBalaskas.
lvm basics
Contents
- physical volumes
- volume groups
- logical volumes
- Create a new LVM partition
- extend an lvm partition
- reduce
physical volumes
# pvs PV VG Fmt Attr PSize PFree /dev/sda2 vg_790 lvm2 a-- 465.52g 211.52g
list physical volumes
# pvdisplay # pvdisplay -C
volume groups
# vgs VG #PV #LV #SN Attr VSize VFree vg_790 1 10 0 wz--n- 465.52g 211.52g
list all volume groups
# vgscan # vgdisplay # vgdisplay -C
activate all
# vgchange -ay
deactivate a specific volume group
# vgchange -an vol_group_1
activate all logical volumes on a volume group, only
# vgchange -ay vol_group_1
logical volumes
list logical volumes
# lvs # lvdisplay -C
Create a new LVM partition
# lvcreate -L 10G -n /dev/vg_group01/lv_vol01 # mkfs.ext4 -L lv_vol01 /dev/vg_group01/lv_vol01 # mount /dev/vg_group01/lv_vol01 /media/
extend an lvm partition
How to extend an lvm partition:
umount /opt/dnl lvextend -L +5G /dev/vg01/dnl e2fsck -f /dev/vg01/dnl resize2fs /dev/vg01/dnl mount /opt/dnl/
reduce
# df -h /opt/ Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_xps-lv_optfs 69G 44G 23G 66% /opt
The goal is to reduce from 70G to 50G
umount
# umount /opt/
check filesystem
check a Linux ext2/ext3/ext4 file system
# e2fsck -ff /dev/mapper/vg_xps-lv_optfs e2fsck 1.43.9 (8-Feb-2018) 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 optfs: 117811/4587520 files (0.4% non-contiguous), 11609065/18350080 blocks
resize2fs filesystem
resize2fs – ext2/ext3/ext4 file system resizer
# resize2fs /dev/mapper/vg_xps-lv_optfs 50G resize2fs 1.43.9 (8-Feb-2018) Resizing the filesystem on /dev/mapper/vg_xps-lv_optfs to 13107200 (4k) blocks. The filesystem on /dev/mapper/vg_xps-lv_optfs is now 13107200 (4k) blocks long.
LVM reduce
# lvreduce -L -20G /dev/mapper/vg_xps-lv_optfs WARNING: Reducing active logical volume to 50.00 GiB. THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce vg_xps/lv_optfs? [y/n]: y Size of logical volume vg_xps/lv_optfs changed from 70.00 GiB (17920 extents) to 50.00 GiB (12800 extents). Logical volume vg_xps/lv_optfs successfully resized.
verify
# mount /opt/ # df -h /opt/ Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_xps-lv_optfs 50G 44G 3.6G 93% /opt
resize to 100%
# lvresize -l +100%FREE -n /dev/vg01/backup
resize xfs
LVM resize
# lvresize -l +100%FREE -n /dev/vg_xps/lv_Breach Size of logical volume vg_xps/lv_Breach changed from 5.00 GiB (1280 extents) to <6.97 GiB (1784 extents). Logical volume vg_xps/lv_Breach successfully resized.
xfs grow
# xfs_growfs /opt/Breach