LVM2 Logical Volume management tool for Linux

Source: Internet
Author: User


650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>

Sometimes we do not think about the planning of the main machine or other reasons can cause our disk partition is not enough. At this point we can only re-expand the capacity of the disk, if you add a hard disk, and then re-partition format, the original partition data is completely copied to the new hard disk, and finally the original partition to unmount the new partition on the mount. In this way, things will become very cumbersome. And sometimes if we give too much, the disk space will be wasted. Oh, is there a better way? The answer is yes. LVM is there to solve this problem.

What is LVM?

The full name of LVM is logical Volume Manager, the logical volume Manager. It can consolidate multiple physical partitions or disks. To make them look like a large disk, and in the future we can delete or add the physical partitions or disks as we need them. That is, we can arbitrarily adjust the file system capacity.

LVM Mechanism Implementation

Combine several physical partitions or disks into a large, seemingly separate, disk by software. The large disk is then divided into usable partitions (LVS), which are eventually mounted for use. Essentially it is the exchange of data through PE. Transfer the original LV PE to other devices to reduce the LV capacity, and add PE from other devices to the existing LV in order to increase the disk capacity.

Physical volume (physical Volume)

Our actual partition needs to use Fdisk to adjust the system identifier (systems ID) to become an LVM identifier (8e), which can then be exploited by Pvcreate's command to convert it into the lowest physical volume (PV).

Volume groups (Volume group)

The so-called LVM large disk is to combine a lot of PV into a VG, and the size of this disk is related to the inside of the PE.

Physical expansion block (PE)

PE is generated using the Vgcreate tool. It is the smallest storage block in LVM. The writing of our files and data is handled by it. LVM default PE size is 4MB, we can take a look into the file system in the Fast (block).

Logical volumes (Logical Volume)

The VG will be cut into LV,LV and the last one can be formatted as the partition we use MKE2FS (MKFS). The size of the LV is related to the total number of PE in VG. At the same time, in order to facilitate user management of LVM system, LV device files are usually specified with the format

/dev/vg_name/lv_name

Specific implementation flowchart

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>

1. Use the Fsck tool to separate four extents, and modify their partition identifier (System ID) to be a logical absolute identifier (8e).

~]# FDISK/DEV/SDA

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>

Where/dev/sda3,/dev/sda5,/dev/sda6 just added the partition, their size is 10G, 5G, 8G

Forcing the kernel to read partitions

~]# partx-a/DEV/SDA

~]# cat/proc/partitions

2. PV Phase

First we use PV to look at the number of PV on the system.

~]# Pvdisplay or PVs view.

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>

Use the Pvcreate tool to generate PV.

~]# pvcreate/dev/sda{3,5}

~]# Pvdisplay

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>

Note that the size of PE here equals 0.

3.VG Stage

Use the Vgcreate tool to generate the VG.

First we use VGS to look at the existing VG.

~]# VGS

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>

~]# vgcreate-s 16M myvg/dev/sda{3,5}

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>

-s Specifies the size of the PE here is 16M.

5.lv Stage

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>

Here the VG originally had 15G, and we now only give 10G the remainder we can extend back again.

6. File system phase.

~]# mke2fs-t ext3-b 1024-l lablel/dev/myvg/mylv

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>

7. Mount the Use

~]# mount/dev/myvg/mylv/mnt

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>

There are two types of extended logical volumes

One is the direct expansion of the logical volume on the line with the original VG inside the original PE to enlarge the capacity of the LV can be completed.

~]# lvextend-l 15g/dev/myvg/mylv

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>

# resize2fs-f/dev/myvg/mylv

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>

One is the need to first expand the physical boundary and then expand the logical boundary. The situation is more complex and more common.

Here we use the original thousand/dev/sda6l to expand.

First use Pvcreate to build PV.

~]# Pvcreate/dev/sda6

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>

Using VG

~]# Vgextend Myvg/dev/sda6

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>

~]# Lvextend/dev/myvg/mylv/dev/sda6

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>

By resize2fs the file system????? Increase in total capacity

~]# df-h

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>

~]# resize2fs-f/dev/myvg/mylv

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>

Note that the expansion file system does not need to be uninstalled, can be executed online, and the reduced file system must be uninstalled, i.e. offline.

Shrink File System

Uninstalling the file system must be uninstalled first

~]# umount/mnt

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>

The/DEV/SDA6 is drawn out here.

Force detection and repair of partitions.

~]# fsck-f/dev/myvg/mylv

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>

Reducing logical partitions

~]# lvresize-l -8g/dev/myvg/mylv

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>

Shrink physical partitions

~]# Vgreduce/myvg/dev/sda6

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>

Remove PV

~]# Pvremove/dev/sda6

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>


This article is from the "11284919" blog, please be sure to keep this source http://11294919.blog.51cto.com/11284919/1783183

LVM2 Logical Volume management tool for Linux

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.