Sing Xing organizes lvm in Linux

Source: Internet
Author: User

Sing Xing organizes lvm in Linux

First, what is LVM?

Traditionally, if the size of a partition is static. If the user has no space in the partition, he or she will either re-partition (may need to reinstall the system) or use the assembly machine like a symbolic connection.

A partition is a series of continuous data blocks on a physical disk. Most Unix-like systems now have the ability to break down physical disks into many units. The storage units on multiple drives can converge into a logical volume that can be allocated to the partition. In addition, the Unit can be added and deleted from the partition as the space requirement changes.

For example, if we have a 1 GB hard disk and it takes 600 MB to create a/home partition, we suppose we have no space, so we decided that/home would need 1 GB. So with the concept of traditional partitioning, we need another 1 GB drive, and then we can add this disk, create a new/home, and copy the existing data.

However, to use lvm, we only need to add a disk of MB and add its storage unit to the/home partition. Other tools can let us adjust the size of the original file system, we only need to adjust the/home size to use a larger partition, and then we can return to the business.

Of course, lvm can also take snapshots of itself, which enables us to back up some unmovable targets.

Second, basic components of LVM

Physical Media ----- The Physical Media, which indicates that it is only a hard disk or a partition, such as/dev/hda,/dev/sda,/dev/sda4, and so on.

Physical Volume ----- Physical Volume (PV) a pv is only a Physical medium with a lot of management data added to it. Once we add it, lvm can think of it as the holder of the hard disk.

Physical partition ---- Physical Extents (PE) the Physical partition here is similar to some data blocks. The default value is 4 MB.

Volume Group -------- Volume Group (VG) a VG has many physical partitions (may come from multiple physical volumes or hard disks ), although this may make a VG composed of several hard disks, such as/dev/hda and/dev/sda, it contains many PES provided by these hard disks.

Logical Volume ----- Logic Volume (LV) a logical Volume is usually the final result of our work, where we store information, which is equivalent to our traditional partition.

Logical partition ---- Logical Extents (LE). In the same volume group, the size of the LE and the PE are the same and one-to-one correspondence.

Third, the basic steps for creating LVM

Step 1: implement the partitioning phase. Our common command is fdisk. Our goal is to change the System ID to 8e. We can get some partitions, such as/dev/hda1, /dev/hda5,/dev/hb1, etc.

Step 2: In the PV stage, our common commands are pvcreate and pvscan. Our goal is to establish and observe pv. We can get some PVS, such as/dev/hda1, /dev/hda5,/dev/hb1, etc.

Step 3: In the VG stage, our main Commands are vgcreate and vgdisplay. Our goal is to use pv to create the vg. We can get a corresponding vg, which can contain several PEs.

Step 4: In the LV stage, our main Commands are lvcreate and lvdisplay. We split the lv from vg and we can get several lv.

Step 5: In the use phase of the file system, mkfs and mount are the main Commands. We format the system and mount it directly to the Linux File System.

Fourth, some instructions

Starting from Linux Kernel 2.6.9, the device-mapper module is included. You only need to load it. To load the mapper module, run the modprobe dm_mod command to check whether the mapper module is loaded. We use lsmod | grep dm_mod. If our kernel is higher than 2.6.9 but does not have this module, we can use the yum install device-mapper command to install it. If our kernel is lower than 2.6.9, compile and install the device-mapper module.

Fifth, Common commands

Common commands for creating a PV:

(1) pvcreate refers to object partion creation as pv

(2) search for any disk or partition with pv in the current system by pvscan

(3) pvdisplay displays the current pv status on the system.

(4) pvremove removes the pv attribute so that the partition does not have the pv attribute.

Example of creating a PV command:

(1) Create PV on the disk: pvcreate/dev/hdb

(2) create a PV on the partition (first use fdisk to set the partition type to 8e): pvcreate/dev/dhb1

Common commands for creating VG:

(1) Create the vg command in vgcreate

(2) Whether vg exists in the vgscan Search System

(3) vgdisplay displays the vg status on the current system.

(4) add an additional pv to the vg.

(5) vgreduce remove pv in vg

(6) vgchange: Configure whether vg is qidong (active)

(7) vgremove deletes a vg.

Create an VG example:

(1) For example, we add/dev/hda1 and/dev/hdb1 to the xin volume group: vgcreate xin/dev/hda1/dev/hdb1

Create LV command:

(1) Create lv in lvcreate

(2) lv scan Query System

(3) lvdisplay displays the lv status on the system.

(4) add lvextend capacity in lv

(5) lvreduce reduces the capacity in lv

(6) lvremove

(7) lvresize adjusts the lv capacity

LV creation example:

(1) Create an lv: lvcreate-L 1500 M-n star xin named star in MB.

(2) create an lv: lvcreate-l 100-n star xin named star with 100 PES

Format mounting command:

(1) create a directory using mkdir

(2) create a file system using mkfs

(3) mount

Example of formatting and attaching:

(1) Example of creating a file system: mkfs-t ext3/dev/xin/star

Sixth, other functions

Stop vg: vgchange-a n xin

Delete vg: vgremove xin

Add pv to vg: vgextend xin/dev/hdc1

Delete pv from vg: vgreduce xin/dev/hda1

Delete an lv: umount/dev/xin/star

Lvremove/dev/xin/star

Extend lv to 12G: lvextend-L 12G/dev/xin/star

Add lv to 1G: lvextend-L + 1G/dev/xin/star

7. One Parameter explanation

Lvcreate is usually used in the following two formats:

(1) lvcreate [-l n [mgt] [-n LV name] VG name

(2) lvcreate [-l n] [-n LV name] VG name

Parameter options:

(1)-L: backend capacity. The unit of capacity can be M, G, T, etc. Note that the minimum unit is PE, therefore, the number must be a multiple of PES. If the number does not match, the system automatically calculates the nearest capacity.

(2)-l: the number of PES followed, rather than the capacity. If you want to do this, calculate the number of PES on your own.

(3)-n: Follow the name of LV

Eighth, note

I have also written an article about lvm before, but it seems that it is not summative. If you are interested, you can read it. This article is more summative.

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.