CentOS 7
Sponsored Link

Manage Logical Volumes2015/07/20

 
This is the basic operation of managing Logical Volumes.
It needs to create Volume Group first.
[1] Create Logical Volume.
# create logical volume "lv_data" in volume group "vg_dlp" with 50G

[root@dlp ~]#
lvcreate -L 50G -n lv_data vg_dlp

  Logical volume "lv_data" created
# specify like follows if you use all free area

[root@dlp ~]#
lvcreate -l 100%FREE -n lv_data vg_dlp

  Logical volume "lv_data" created
[2] Display Logical Volumes.
[root@dlp ~]#
lvdisplay /dev/vg_dlp/lv_data

  --- Logical volume ---
  LV Path                /dev/vg_dlp/lv_data
  LV Name                lv_data
  VG Name                vg_dlp
  LV UUID                nlTuzs-T9nC-hRIC-4Vgh-Bm9G-t4EI-kTu2NU
  LV Write Access        read/write
  LV Creation host, time dlp.srv.world, 2015-07-20 09:23:36 +0900
  LV Status              available
  # open                 0
  LV Size                80.00 GiB
  Current LE             20479
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2
[3] Rename Logical Volume.
# rename from lv_data to lv_storage

[root@dlp ~]#
lvrename vg_dlp lv_data lv_storage

  Renamed "lv_data" to "lv_storage" in volume group "vg_dlp"
[root@dlp ~]#
lvdisplay /dev/vg_dlp/lv_storage

  --- Logical volume ---
  LV Path                /dev/vg_dlp/lv_storage
  LV Name                lv_storage
  VG Name                vg_dlp
  LV UUID                nlTuzs-T9nC-hRIC-4Vgh-Bm9G-t4EI-kTu2NU
  LV Write Access        read/write
  LV Creation host, time dlp.srv.world, 2015-07-20 09:23:36 +0900
  LV Status              available
  # open                 0
  LV Size                80.00 GiB
  Current LE             20479
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2
[4] Display reports of Logical Volumes.
[root@dlp ~]#
lvs

  LV         VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root       centos -wi-ao---- 45.62g
  swap       centos -wi-ao----  3.89g
  lv_storage vg_dlp -wi-a----- 80.00g
[5] Scan Logical Volumes.
[root@dlp ~]#
lvscan

  ACTIVE            '/dev/centos/swap' [3.89 GiB] inherit
  ACTIVE            '/dev/centos/root' [45.62 GiB] inherit
  ACTIVE            '/dev/vg_dlp/lv_storage' [80.00 GiB] inherit
[6] Take snapshot of Logical Volume.
# create snapshot "snap-lv_storage" from "lv_storage"

[root@dlp ~]#
lvcreate -s -L 50G -n snap-lv_storage /dev/vg_dlp/lv_storage

  Logical volume "snap-lv_storage" created.
[root@dlp ~]#
lvdisplay /dev/vg_dlp/lv_storage /dev/vg_dlp/snap-lv_storage

  --- Logical volume ---
  LV Path                /dev/vg_dlp/lv_storage
  LV Name                lv_storage
  VG Name                vg_dlp
  LV UUID                M7mPAd-e2BU-XIVY-z7tN-5SBS-eEiX-biB90f
  LV Write Access        read/write
  LV Creation host, time dlp.srv.world, 2015-07-20 09:33:33 +0900
  LV snapshot status     source of
                         snap-lv_storage [active]
  LV Status              available
  # open                 0
  LV Size                30.00 GiB
  Current LE             7680
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2

  --- Logical volume ---
  LV Path                /dev/vg_dlp/snap-lv_storage
  LV Name                snap-lv_storage
  VG Name                vg_dlp
  LV UUID                YjbZR4-Snih-3KEE-O26y-vbQb-sLBq-Uv1CIJ
  LV Write Access        read/write
  LV Creation host, time dlp.srv.world, 2015-07-20 09:34:21 +0900
  LV snapshot status     active destination for lv_storage
  LV Status              available
  # open                 0
  LV Size                30.00 GiB
  Current LE             7680
  COW-table size         30.00 GiB
  COW-table LE           7680
  Allocated to snapshot  0.00%
  Snapshot chunk size    4.00 KiB
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:5
[7] Extend Logical Volume.
It's possible to do with mounted.
[root@dlp ~]#
lvextend -L 70G /dev/vg_dlp/lv_storage

  Size of logical volume vg_dlp/lv_storage changed from 30.00 GiB (7680 extents) to 50.00 GiB (12800 extents).
  Logical volume lv_storage successfully resized
[root@dlp ~]#
lvdisplay /dev/vg_dlp/lv_storage

  --- Logical volume ---
  LV Path                /dev/vg_dlp/lv_storage
  LV Name                lv_storage
  VG Name                vg_dlp
  LV UUID                M7mPAd-e2BU-XIVY-z7tN-5SBS-eEiX-biB90f
  LV Write Access        read/write
  LV Creation host, time dlp.srv.world, 2015-07-20 09:33:33 +0900
  LV Status              available
  # open                 1
  LV Size                70.00 GiB
  Current LE             17920
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2

# for the case of extending xfs filesystem (specify mount point)

[root@dlp ~]#
xfs_growfs /mnt

meta-data=/dev/mapper/vg_dlp-lv_storage isize=256    agcount=4, agsize=3276800 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=13107200, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=6400, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 13107200 to 18350080

# for the case of extending ext4 filesystem

[root@dlp ~]#
resize2fs /dev/vg_dlp/lv_storage

resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vg_dlp/lv_storage is mounted on /mnt; on-line resizing required
old_desc_blocks = 7, new_desc_blocks = 9
[ 2296.232115] EXT4-fs (dm-2): resizing filesystem from 13107200 to 18350080 blocks
[ 2296.258785] EXT4-fs (dm-2): resized filesystem to 18350080
The filesystem on /dev/vg_dlp/lv_storage is now 18350080 blocks long.
[8] Reduce Logical Volume.
Unmount target device first.
It's impossible to reduce xfs filesystem.
# for ext4, check it first

[root@dlp ~]#
e2fsck -f /dev/vg_dlp/lv_storage 50G

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/vg_dlp/lv_storage: 11/4587520 files (0.0% non-contiguous), 334056/18350080 blocks
# for ext4, reduce filesystem

[root@dlp ~]#
resize2fs /dev/vg_dlp/lv_storage 50G

resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vg_dlp/lv_storage to 13107200 (4k) blocks.
The filesystem on /dev/vg_dlp/lv_storage is now 13107200 blocks long.
# reduce logical volmue at last

[root@dlp ~]#
lvreduce -L 50G /dev/vg_dlp/lv_storage

  WARNING: Reducing active logical volume to 50.00 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
  Do you really want to reduce lv_storage? [y/n]:
y

  Size of logical volume vg_dlp/lv_storage changed from 70.00 GiB (17920 extents) to 50.00 GiB (12800 extents).
  Logical volume lv_storage successfully resized
[9] Delete Logical Volume.
unmount ⇒ stop logical volume ⇒ delete logical volume
[root@dlp ~]#
lvchange -an /dev/vg_dlp/lv_storage

[root@dlp ~]#
lvremove /dev/vg_dlp/lv_storage

  Logical volume "lv_storage" successfully removed
Matched Content