Difference between revisions for lvm





Next edit →


Hits : 6,709

lvm basics


physical volumes


# pvs
  PV         VG     Fmt  Attr PSize   PFree  
  /dev/sda2  vg_79 lvm2 a--  465.52g 211.52g		


list physical volumes

# pvdisplay 

# pvdisplay  -C		

volume groups


# vgs
  VG     #PV #LV #SN Attr   VSize   VFree  
  vg_79   1  1    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 1G -n /dev/vg_group1/lv_vol1 

# mkfs.ext4 -L lv_vol1 /dev/vg_group1/lv_vol1 

# mount /dev/vg_group1/lv_vol1 /media/		

extend an lvm partition


How to extend an lvm partition:

umount /opt/dnl

lvextend -L +5G /dev/vg1/dnl

e2fsck -f /dev/vg1/dnl

resize2fs /dev/vg1/dnl 

mount /opt/dnl/
<!--markup:2:begin-->		

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 7G to 5G

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-218)
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/458752 files (.4% non-contiguous), 116965/18358 blocks		

resize2fs filesystem


resize2fs – ext2/ext3/ext4 file system resizer

# resize2fs /dev/mapper/vg_xps-lv_optfs 5G 

resize2fs 1.43.9 (8-Feb-218)
Resizing the filesystem on /dev/mapper/vg_xps-lv_optfs to 13172 (4k) blocks.
The filesystem on /dev/mapper/vg_xps-lv_optfs is now 13172 (4k) blocks long.		

LVM reduce



# lvreduce -L -2G /dev/mapper/vg_xps-lv_optfs 
  WARNING: Reducing active logical volume to 5. 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 7. GiB (1792 extents) to 5. GiB (128 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   5G   44G  3.6G  93% /opt<!--markup:2:end-->		

resize to 1%


BASH
# lvresize -l +1%FREE -n /dev/vg1/backup 
<!--markup:2:begin-->


resize xfs 

LVM resize




# lvresize -l +1%FREE -n /dev/vg_xps/lv_Breach

  Size of logical volume vg_xps/lv_Breach changed from 5. GiB (128 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.G  7.G   15M 1% /opt/Breach		


# xfs_growfs /opt/Breach

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


# df -h /opt/Breach
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/vg_xps-lv_Breach   27G  7.G   2G  26% /opt/Breach<!--markup:2:end-->