LVM creation under Linux and Linux snapshot volumes

Source: Internet
Author: User
Tags extend

through the most learning, I deepened the understanding of LVM, here, I write it blog, one is to facilitate their own memory, and the second is to let the Linux beginners learn together.

First we introduce the concept of LVM, and expand the detailed description, mainly the recent study of the view, we first look at a figure

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/3E/0A/wKioL1PGBRrTXGPIAAIcOi_5TiM515.jpg "title=" 22.jpg "alt=" Wkiol1pgbrrtxgpiaaicoi_5tim515.jpg "/>

The nouns we will refer to are: PV, VG, LV, PE


In the diagram, the bottom, we can understand as physical storage media , hard disk or partition

PV: Called physical Volume , is the basic storage block of LVM.

VG: Called a volume group , we can see that the volume group is composed of physical volumes.

LV: Called a Logical volume , is divided from the volume group.

PE:physical extent, I'm called a physical block , which is the smallest unit in LVM.


Principle: LVM technology, is to be a physical storage medium, generate a physical volume, and then a number of physical volumes to form one or more volume groups, and finally, from the volume group of a logical volume, after formatting, mount use.

Popular Explanation: If everyone has not contacted, I explain that, PV is a bucket of water, VG is a large reservoir, LV is the need to get the water from the reservoir, means that everyone put their own water in a reservoir, and then, everyone on demand to obtain, But also can be added from the outside into the reservoir, the key is the PE, quite a drop of water, it is the key to the whole division, so to speak, do not know if you have some understanding of it


below, I'll go through some examples to further illustrate the principles of LVM, before we take a look at some of the commands. 650) this.width=650; "Src=" http://s3.51cto.com/wyfs02/M00/3E/0D/wKiom1PGEwHgSeXBAAENcav2FPA976.jpg " title= "Picture 1.jpg" alt= "Wkiom1pgewhgsexbaaencav2fpa976.jpg"/>

Next, we will explain the meaning of these commands in an experiment step-by-step, and let the reader understand the LVM creation process

The experimental environment is in the virtual machine, we have a 20G hard disk, next, we divide it into 3 5G partitions (finally left, we will first ignore), partition with the Fdisk command, the hard disk is/dev/sdb, the result is as follows:

Note, to change the system format of the partition to LVM (by changing the T in Fdisk)

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/3E/0D/wKiom1PGFs2SV6iJAACcYKO8nQQ406.jpg "title=" 12.JPG "alt=" Wkiom1pgfs2sv6ijaaccyko8nqq406.jpg "/>


Start the experiment:

Create physical volume (PV)

1. Create/DEV/SDB1,/DEV/SDB2, and/dev/sdb into physical volumes (PV) first

PV: command to create a physical volume

Usage of PV: pvcreate DEVICE

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/3E/0D/wKiom1PGGC6x28HXAABRRJqHgJ0657.jpg "title=" 13.JPG "alt=" Wkiom1pggc6x28hxaabrrjqhgj0657.jpg "/>

2 , view our physical volumes (PV)

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/3E/0D/wKiom1PGGJbgUgeQAABEaMbQAhc512.jpg "title=" 14.JPG "alt=" Wkiom1pggjbgugeqaabeambqahc512.jpg "/>

from that, we can see that just three partitions have been successfully created into physical volumes.

3. Remove any of our partitions from the physical volume and add it back (add the pvcreate above)

Pvremove: Removing partitions or physical media

Usage of pvremove: Pvremove DEVICE

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/3E/0E/wKioL1PGGsOxjRaqAACki54UH2M703.jpg "title=" 15.JPG "alt=" Wkiol1pggsoxjraqaacki54uh2m703.jpg "/>

4. Our readers may refer to our pvdisplay, which is also the view of the physical volume, but the information it returns is more detailed

(The following results are similar and are not explained.)

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/3E/0E/wKiom1PGGiDTYf2XAABZaR_fRXc622.jpg "title=" 16.JPG "alt=" Wkiom1pggidtyf2xaabzar_frxc622.jpg "/>


Create a volume group (VG)

1, next, is to put the newly created PV together into a volume group (VG) to go

Vgcreate: Is the command used to create a volume group

Usage of vgcreate: vgcreate vg_name DEVICE

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/3E/0E/wKiom1PGG4PzmlCjAAAxvUdQm9Q685.jpg "title=" 17.JPG "alt=" Wkiom1pgg4pzmlcjaaaxvudqm9q685.jpg "/>

2. View our VG and use the VGS command

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/3E/0E/wKioL1PGHQ7TjSrXAABAHTqzDv4694.jpg "title=" 18.JPG "alt=" Wkiol1pghq7tjsrxaabahtqzdv4694.jpg "/>

3, so that our volume group was created successfully, the volume group is like a PV container, since it is a container, it should be able to change its capacity, below, we say how to expand and remove the volume group of physical volumes

Vgextend: The command to extend the VG

Usage of vgextend: Vgextend vg_name DEVICE

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/3E/0E/wKiom1PGHNuAazEVAAA3hsOZ5eg619.jpg "title=" 19.JPG "alt=" Wkiom1pghnuaazevaaa3hsoz5eg619.jpg "/>

Vgreduce: Removing a volume Group (PV) from a VG

Usage of vgreduce: Vgreduce vg_name DEVICE

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/3E/0E/wKiom1PGHUfToGSoAAA3OQOZlXY244.jpg "title=" 20.JPG "alt=" Wkiom1pghuftogsoaaa3oqozlxy244.jpg "/>


Create a logical volume (LV)

1, LV is like the water removed from the container, it can make a cup of capacity, can also make a bowl of capacity, but it must not exceed the capacity of the VG container, that is, the logical boundary can not be greater than the physical boundary, the method of LV creation is as follows:

Lvcreate: Is this command similar to the two create above, yes, it's the one that created the LV

Lvcreate usage: lvcreate-l #UNIT-N lv_name vg_name

Let's say we're going to create a 6G logical volume and look at it after it's created with the LVS command

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/3E/0F/wKioL1PGIFfApNjDAABpJfX8JjE583.jpg "title=" 21.JPG "alt=" Wkiol1pgiffapnjdaabpjfx8jje583.jpg "/>

2, then, how do we use this logical volume, we first format it, and then mount the use of

The steps are as follows:

#mkdir/mylv#mke2fs-t ext4/dev/cshangvg/cshanglv #mount/dev/cshangvg/shanglv/mylv

In this way, our LV (logical volume) can be used

3, Volume group can be extended and removed, then our logical volume is OK? The answer is yes.

Note: When you extend a logical volume, its logical boundaries cannot be greater than the physical boundary

Lvextend: Size of the extended logical volume

Usage of lvextend: lvextend-l #UNIT device_lv

Let's take a look at the size of the/MYLV mount when it is mounted:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/3E/18/wKioL1PGJeuQHd3_AABr_LuYWW4867.jpg "title=" 31.JPG "alt=" Wkiol1pgjeuqhd3_aabr_luyww4867.jpg "/>

then expand it to 7G size, as shown in the following steps:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/3E/1A/wKiom1PGJWfRPORgAACSSgjNbeo581.jpg "title=" 32.JPG "alt=" Wkiom1pgjwfrporgaacssgjnbeo581.jpg "/>

then, look at the size of the/MYLV mount again

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/3E/1A/wKiom1PGJb3wmapYAABw7uJGkUQ692.jpg "title=" 33.JPG "alt=" Wkiom1pgjb3wmapyaabw7ujgkuq692.jpg "/>

From the DF command above two times, we can see that the size of the logical volume does extend


Because the reduction of logical volume is a very dangerous thing, so we must be very cautious when we operate.

4. Unmount the logical volume first, then, to force the detection

#umount/mylv#e2fsck-f/dev/cshangvg/cshanglv #resize/dev/cshangvg/cshanglv #UNIT

5. Lvreduce: The command to reduce the logical volume

Usage of lvreduce: lvreduce-l #UNIT/DEV/CSHANGVG/CSHANGLV

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/3E/1C/wKioL1PGKT6iXDLEAAC4-f3ThzE774.jpg "title=" 34.JPG "alt=" Wkiol1pgkt6ixdleaac4-f3thze774.jpg "/>

6, finally put the logical volume mounted up, we look at the size

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/3E/1B/wKiom1PGKHOQ9KstAABqZYff4EY865.jpg "title=" 35.JPG "alt=" Wkiom1pgkhoq9kstaabqzyff4ey865.jpg "/>

As can be seen in this process, our logical volumes extend from the process of scaling to shrinking


To create a snapshot volume

A snapshot volume refers to a snapshot of a logical volume that must be in the same volume group as the directory logical volume, without specifying a volume group.

1. We want to see if the logical volume is being used, and if so, let its program process end

#fuser-V/mylv# If there are processes in use, kill #fuser-km/mylv

2, in order to verify, we can copy a file to/mylv, such as/etc/issue

3. Create a Snapshot volume

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/3E/1C/wKioL1PGK5nSQWxqAAA6ZUzaDC0279.jpg "title=" 41.JPG "alt=" Wkiol1pgk5nsqwxqaaa6zuzadc0279.jpg "/>

Some of the parameters to explain

-L: Specifies the size of the snapshot volume

-N: The name of the snapshot volume

-P R: indicates only Read permission

-S: Specifies that the logical volume is a snapshot volume

4. Then, create a directory and mount it.

#mkdir/mysnap#mount/dev/cshangvg/cshang-snap

5, then we change the/MYLV in the issue,/mysnap in the issue does not change , copy the file in, is the same effect, the snapshot volume is a good backup role.


Summary: The content of LVM is much more, need everybody to practice more, this is more to myself say; for a server storage size extension has a good application, the final snapshot volume for backup is also a good choice.






This article is from the "Child Naked Fart" blog, please be sure to keep this source http://cshang.blog.51cto.com/6143980/1438982

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.