Hits : 2828


lvm basics


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


# mount /opt/Breach 

# df -h /opt/Breach

Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/vg_xps-lv_Breach  7.0G  7.0G   15M 100% /opt/Breach


# xfs_growfs /opt/Breach


meta-data=/dev/mapper/vg_xps-lv_Breach isize=512    agcount=6, agsize=327680 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1 spinodes=0 rmapbt=0
         =                       reflink=0
data     =                       bsize=4096   blocks=1826816, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 1826816 to 7069696


# df -h /opt/Breach
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/vg_xps-lv_Breach   27G  7.0G   20G  26% /opt/Breach