Basic concepts and Management of LVM and basic concepts Management of lvm

Source: Internet
Author: User

Basic concepts and Management of LVM and basic concepts Management of lvm

I. Problems with traditional disk management

When the partition size is insufficient, it cannot be expanded. You can only add a disk or create a new partition to expand the space. However, the newly added hard disk exists as an independent file system, the original file system is not extended, and upper-layer applications can only access one file system. You can only deprecate an existing disk, replace it with a new disk, and then import the original data.

Ii. Basic concepts of LVM logical volumes

The Logical volume Management of LVM (Logical volume Manager) abstracts the underlying physical hard disks and presents them to the upper-layer system as Logical volumes. The Logical volume size can be dynamically adjusted, and existing data will not be lost. The new hard disk does not change the logical volume on the upper layer.

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

 

PE (physical extend) is a basic block of 4 MB by default.

PV (physical volume) hard disk or partition

VG (volume group) is composed of one or more PVS.

The space cut by LV (logical volume) from VG is used to create a file system.

Iii. LVM creation process

4. Create LVM

Initialize a physical disk device as 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 logical volumes based on volume groups

Lvcreate-n lv0-L 5G vg0

Create a file system for the created logical volume

Mkfs. ext4/dev/vg0/lv0

Mount and use formatted logical volumes

Mount/dev/vg0/lv0/mnt/

The mounting information is written to/etc/fstab and restarted.

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

5. View LVM

View physical volume information: pvs and pvdisplay (details)

View volume group information: vgs and vgdisplay (details)

View logical volume information: lvs and lvdisplay (details)

6. Delete LVM

Delete LV: lvremove/dev/vg0/lv0

Delete VG: vgremove vg0

Delete PV: pvremove/dev/sdb

7. Stretch a logical volume

The logical volume stretching operation can be performed online without detaching the logical volume.

Ensure sufficient free space in VG

Vgs, vgdisplay

Expand logical volume

Lvextend-L + 5G/dev/vg0/lv0

View the expanded LV size

Lvs and lvdisplay

Update File System

Resize2fs/dev/vg0/lv0

View the updated File System

Df-h

8. Stretch a volume group

Format the hard disk to be added to VG as PV

Pvcreate/dev/sdd

Add a new PV to a specified volume group

Vgextend vg0/dev/sdd

View the expanded VG size

Vgs, vgdisplay

9. Narrow down a logical volume

The logical volume downgrading operation must be performed offline. You must detach the logical volume.

Detach a mounted logical volume

Umount/dev/vg0/lv0

Shrink the file system (the original lv0 is 10 Gb)

E2fsck-f/dev/vg0/lv0

Resize2fs/dev/vg0/lv0 3G

LV reduction

Lvreduce-L-7G/dev/vg0/lv0

View the resized LV

Lvs and lvdisplay

Mount

Mount/dev/vg0/lv0/mnt

10. shrink the volume group

Removes a PV from a specified group.

Vgreduce vg0/dev/sdd

View the size of the reduced volume group

Vgs, vgdisplay

Remove PV

Pvremove/dev/sdd

Related Article

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.