cmdref.net - Cheat Sheet and Example

cmdref.net is command references/cheat sheets/examples for system engineers.

User Tools

Site Tools


Sidebar








Cloud



Etc


Reference














.

os:linux:disk:lvm.html



LVM - How to Use LVM in Linux

References

Basic

Example

How to create LVM

# fdisk /dev/mapper/mpath0
# fdisk /dev/mapper/mpath1         #if you use over 2TB disk, you have to use parted insted of fdisk.

    m <- help
    p <- print the partition table
    n <- add a new partition
      p <- primary partition
      1 <- Partition number
    t <- change a partition''s system id
      L  <- List
      8e <- LVM
    p <- print the partition table
    w <- write table to disk and exit

# kpartx -a /dev/mapper/mpath0      <- RHEL6 kpartx -a -p p /dev/mapper/mpath0 , created mpath0p1
# kpartx -a /dev/mapper/mpath1

# ls /dev/mapper

# pvcreate /dev/mapper/mpath0p1
# pvcreate /dev/mapper/mpath1p1
# pvs
# pvdisplay |more

# vgcreate VG_DATA /dev/mapper/mpath0p1
# vgcreate VG_REDO /dev/mapper/mpath1p1
# vgs
# vgdisplay

# vgdisplay  |grep "VG Name"
# vgdisplay  |grep "Free"   <- Check Free PE Number


# lvcreate -l 127998  VG_DATA   <- 127998 is PE Number   or '-l 100%FREE'
# lvcreate -l 5118  VG_REDO
# lvs
# lvdisplay

# mkfs -t ext4 /dev/VG_DATA/lvol0
# mkfs -t ext4 /dev/VG_REDO/lvol0

# mount /dev/VG_DATA/lvol0 /mnt
# umount /mnt


How to create LV

# lvcreate -l 100%FREE -n yourlv testvg

# lvcreate -L 50G -n gfslv vg0

# vgdisplay testvg | grep "Total PE"
Total PE              10230
# lvcreate -l 10230 testvg -n mylv


How to recognize the LVM with the other server

server1 # vgchange -an
server2 # kpartx -a /dev/mapper/mpathN

server2 # pvscan
server2 # vgscan
server2 # lvscan

server2 # vgdisplay  |grep "Open"
server2 # vgchange -a y


How to remove the LVM

# lvremove /dev/vgtest/lvol0
# vgremove vgtest
# pvremove /dev/mapper/mpath0p1


How to expand Volume

# lvextend -l +100%FREE /dev/testvg/lvol0

# resize2fs /dev/testvg/lvol0   <- ext3, ext4
 or
# mount /dev/testvg/lvol0 /mount
# xfs_growfs  /mount             <- xfs




TIPS

making partition over 2TB DISK

The fdisk cann't make over 2TB Disk.

# parted /dev/mapper/mpath0
(parted) mklabel gpt
(parted) print
(parted) mkpart primary 0 100%
(parted) print
(parted) set 1 lvm on
(parted) print
(parted) quit


How to use Tag

# vgs -o +vg_tags   <- check tag
# vgchange --addtag $(uname -n) vgtest
# vgs -o +vg_tags   <- check tag
# vgchange -a y vgtest

# mount /dev/vgtest/lvol1 /mnt
# umount /mnt

# vgchange -a n vgtest
# vgchange --deltag $(uname -n) vgtest
# vgs -o +vg_tags   <- check tag







os/linux/disk/lvm.html.txt ยท Last modified: 2021/03/09 by admin

Page Tools