Linux Logical Volume Management LVM detailed

Source: Internet
Author: User

Linux Logical Volume Management LVM detailed

One of the most common and difficult questions that Linux users encounter when installing Linux operating systems is how to properly evaluate the size of each partition to allocate the appropriate hard disk space. When a partition is exhausted, the solution is usually to use symbolic links, or to use tools that resize the partition (such as Patition magic), but this is only a temporary workaround and does not solve the problem at all. With the advent of Linux logical volume management functions, these problems are solved, this article discusses the LVM technology, so that users can easily adjust the size of each partition without the need for downtime.

First, the basic terminology of LVM

LVM is a logical layer that is added between the disk partition and the file system to mask the underlying disk partition layout for the file system, providing an abstract disk volume, and creating a file system on the disk volume. First we discuss the following LVM terminology:

1. Media (the physical media)

This refers to the storage device of the system: hard disk, such as:/DEV/HDA1,/DEV/SDA1, etc., is the lowest layer of storage system storage unit.

2. Physical volume (physical volume)

A physical volume is a partition of a hard disk or a device that logically has the same function as a disk partition (for example, RAID), which is the basic storage logic block of LVM, but is compared to basic physical storage media (such as partitions, disks, etc.) and contains management parameters related to LVM.

3. Volume groups (Volume group)

Consists of one or more physical volumes, called volume groups, in which physical volumes can be dynamically added or removed, and many physical volumes can be composed of different volume groups, with the volume group name defined by the user.

4. Logical volume (logical volume)

Logical volumes are built on top of volume groups, not directly related to physical volumes, and for logical volumes, each volume group is a whole, cutting a small chunk of space from this whole, as the basis for user-created file systems, a small piece of space called a logical volume, and a file system built on a logical volume using tools such as MKFS. Can be mounted to a directory in a Linux system.

5. Physical segment (physical extent)

Each physical volume is divided into a basic unit called the PE (physical extents), with a uniquely numbered PE being the smallest unit that can be addressed by LVM. The size of the PE is configurable and defaults to 4MB.

Ii. Creating and Managing LVM

To create an LVM system, you typically need to go through the following steps:

1. Partitioning

Create 3 100G partitions;

View the Partitions sda5, Sda6, and SDA7 that were created successfully;

2. Create a physical volume

The command to create the physical volume is pvcreate, which uses this command to create all partitions or disks that you want to add to the volume group as physical volumes.

The commands to create multiple partitions as physical volumes are:

Convert the Dev/sda5, SDA6, and SDA7 partitions into physical volumes.

3. Create a volume group

The command to create a volume group is vgcreate, and the physical volume established with Pvcreate is created as a complete volume group: vgcreate ZSDATA/DEV/SDA5/DEV/SDA6/DEV/SDA7

The vgcreate command first parameter specifies the logical name of the volume group: zsdata. The following parameter specifies all partitions and disks that you want to add to the volume group.

Vgcreate in addition to creating volume group Zsdata, a PE with a size of 4 MB is also set (default is 4MB), which means that all logical volumes created on the volume group are expanded or scaled in increments of 4 MB. The PE size range is 8 KB to MB and must always be a multiple of 2 (specified with-S, refer to man vgcreate for details).

4. Activate Volume group

In order to use the volume group immediately instead of restarting the system, you can use Vgchange to activate the volume group: # vgchange-a/DEV/SDA5/DEV/SDA6/DEV/SDA7

5. Create a logical volume

The command to create the logical volume is lvcreate: #lvcreate-L 100%free-n zhmp Zsdata

The command creates a logical volume named Zsdata on the volume group ZHMP and assigns all physical volumes to it.

6. Create File system

To create a EXT4 file system in the "Zsdata" logical volume using the MKFS command: # MKFS.EXT4/DEV/MAPPER/ZSDATA-ZHMP

7. Mount to the "/home" directory.

# mount/dev/mapper/zsdata-zhmp/home/

If you want the file system to load automatically when the system starts, you also need to add content in/etc/fstab: # Vi/etc/fstab

8. Extending the logical volume size

LVM provides the ability to easily resize logical volumes, and the command to extend the size of a logical volume is lvextend:

#lvextend-L *G/DEV/MAPPER/ZSDATA-ZHMP

The above command is implemented to expand the size of the logical volume Zsdata to *g.

# lvextend–l +*G/DEV/MAPPER/ZSDATA-ZHMP

The above command implements an increase in the size of the logical volume Zsdata *g.

After you increase the capacity of the logical volume, you need to modify the file system size to make use of the expanded space.

# RESIZE2FS/DEV/MAPPER/ZSDATA-ZHMP

9. Delete a logical volume

Before deleting a logical volume, you first need to uninstall it and then delete it:

#umount/DEV/MAPPER/ZSDATA-ZHMP

#lvremove/DEV/MAPPER/ZSDATA-ZHMP

Iii. Summary

As you can see from the above discussion, LVM is very scalable and easy to use. You can easily adjust the size of the volume group, the logical volume, and further adjust the size of the file system.

Linux Logical Volume Management LVM detailed

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.