LVM Basic Concepts, management

Source: Internet
Author: User

One, the traditional disk management problems

When the partition size is not enough to expand its size, only by adding disks, creating new partitions to expand space, but the newly added hard disk as a standalone file system, the original file system has not been expanded, the upper-level applications can access only one file system. You can only bring the existing disk offline, replace the new disk, and then import the raw data.

Ii. Basic concepts of LVM logical volumes

LVM (Logical Volume Manager) Logical volume management provides the ability to dynamically adjust the size of logical volumes, without losing existing data, by encapsulating the underlying physical hard disk abstraction in the form of logical volumes to the upper system. The newly added hard drive does not change the existing upper-level logical volumes.

As a dynamic disk management mechanism, logical volume technology greatly improves the flexibility of disk Management.

PE (physical extend) default to 4MB base block

PV (physical volume) hard disk or partition

VG (volume group) consists of one or more PV components.

LV (logical volume) the space cut from the VG used to create the file system

Iii. LVM Creation Process

    1. The physical disk is formatted as PV, and the space is divided into PE
    2. The non-pass PV joins the same VG, the PE of different PV all enters the PE Ikeuchi of VG
    3. LV is created based on PE, the size is an integer multiple of PE, the PE composing LV may come from different physical disks
    4. LV now directly can be formatted after mounting using the
    5. The expansion and reduction of the LV is actually the increase or decrease in the number of PE that makes up the LV. The process does not lose the original data

Iv. Creating LVM

Initializing a physical disk device to a physical volume

Pvcreate/dev/sdb/dev/sdc

Create a volume group and add PV to the volume group

Vgcreate VG0/DEV/SDB/DEV/SDC

Create a logical volume based on a volume group

Lvcreate-n lv0-l 5G vg0

Create a file system for a created logical volume

Mkfs.ext4/dev/vg0/lv0

Mount a formatted logical volume using

mount/dev/vg0/lv0/mnt/

Write mount information to/etc/fstab the restart is still in effect

echo "/dev/vg0/lv0/mnt ext4 defaults 0 0" >>/etc/fstab

V. View LVM

View physical Volume Information: PVS, Pvdisplay (verbose)

View Volume group information: VGS, Vgdisplay (verbose)

View Logical Volume Information: LVS, Lvdisplay (verbose)

Vi. Removal of LVM

Delete Lv:lvremove/dev/vg0/lv0

Delete Vg:vgremove vg0

Delete Pv:pvremove/dev/sdb

Vii. stretching a logical volume

Stretched operations on logical volumes can be performed online without the need to unload logical volumes

Ensure that there is enough free space in the VG

VGS, Vgdisplay

Expanding logical volumes

Lvextend-l +5g/dev/vg0/lv0

View extended LV Size

LVS, Lvdisplay

Update file system

Resize2fs/dev/vg0/lv0

View the updated file system

Df–h

Eight, stretch a volume group

Format the hard drive you want to add to the VG as PV

Pvcreate/dev/sdd

Add a new PV to the specified volume group

Vgextend VG0/DEV/SDD

View expanded VG size

VGS, Vgdisplay

Nine, shrink a logical volume

The reduction of logical volumes must be performed offline, to unload logical volumes

Uninstalling a logical volume that is already mounted

Umount/dev/vg0/lv0

Shrink file System (original lv0 is 10G)

E2fsck-f/dev/vg0/lv0

Resize2fs/dev/vg0/lv0 3G

Zoom Out LV

Lvreduce-l -7g/dev/vg0/lv0

View the reduced LV

LVS, Lvdisplay

Mount

Mount/dev/vg0/lv0/mnt

Ten, reduce the volume group

Remove a PV from the specified group

Vgreduce VG0/DEV/SDD

To view the reduced volume group size

VGS, Vgdisplay

Remove PV

Pvremove/dev/sdd

LVM Basic Concepts, management

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.