How to use LVM (LogicalVolumeManager) partitioning in Linux

Source: Internet
Author: User
LVM is short for LogicalVolumeManager (logical volume management). It is a mechanism for managing disk partitions in Linux. it is implemented by HeinzMauelshagen on the Linux2.4 kernel. I. general idea: partition into LVM format (8e) -- create PV -- create VG -- create LV -- Format partition -- MOUNT partition -- e2fsad

LVM is short for Logical VolumeManager (Logical volume management). it manages disk partitions in Linux. it is implemented by HeinzMauelshagen in Linux 2.4 kernel.

I. overall thinking:

Partition into LVM format (8e) --> create PV --> create VG --> create LV --> format partition --> MOUNT partition --> e2fsadm adjust LV size

Several keywords:

PV (Physical Volumn); -- Physical volume

LV (Logical Volumn); -- Logical Volume

VG (Volumn Group); -- Volume Group

PE (Physical Extend -- Physical block default 4 M );

LE (Logical Extend -- Logical Block)

PE: LE = 1:1 (Normal)

II. the summary of LVM is as follows:

Hda1 hdb1 sdc (PV: s physical volume, usually partition or entire hard disk)

\ |/

Diskvg (VG volume group consists of physical volumes)

/| \

Usrlv rootlv varlv (LV: s logical volume created on the volume group)

|

Ext2 reiserfs xfs (a document system built on a logical volume)

Instance description:

PV: Partition/dev/had...

VG: virtual hard disk/dev/vg_name

LV: virtual partition/dev/vg_name/lv_name

III. detailed LVM creation process:

If there are three hard disks, hda2 (3G), hdb2 (3G), hdc2 (3G), hdd2 (3G), and hda1 (100Mboot partition)

1. create a partition:

# Fdisk/dev/hda (... hdb... hdc... hdd) ----- p --- n -- t -- 8e --- p -- w --- reboot

(Separate 3g lvm partitions of hda2/hdb2/hdc2/hdd2 in the format of 8e .)

2. create a physical volume (PV ):

# Pvcreate [-v]/dev/hda2/dev/hdb2/dev/hdc2/dev/hdd2

(You can use# PvscanCheck whether there is a physical volume and its information. for example, if pvscan shows that the current PV (such as/dev/hdb1,/dev/hdc1) belongs to VG (such as VG0), you can use# Pvdisplay/dev/hdb1View the status of the existing LVM. Here, the parameter-v is used to display all the creation processes, which can be omitted .)

3. create a volume Group (VG ):

# Vgcreate [-v] [-s 8 M] vg01/dev/hda2/dev/hdb2/dev/hdc2/dev/hdd2

[You can use# VgdisplayView information about an existing volume group ;]

[After the VG is created, it is automatically Active (Active). if it is not automatically Active# Vgchange-a y vg01

Activate VG.# Vgchange-a n vg01Disable the VG of Actice to Deactive ;]

[Only the Deactive VG can be changed or deleted ;]

[Deactive is not required for renaming VG, as shown in figure# Vgrename old_vg_namenew_vg_name;]

[Vgremove deletes an existing VG, as shown in figure# Vgremovevg_name, Must be Deactive VG ;]

[If the hard disk space is insufficient after the LVM is created, you can create an LVM partition, activate the partition through pvcreate, and then use

Add vgextend to the existing VG to expand the space,# Pvcreate/dev/hde2;

# Vgextend-v vg01/dev/hde2Add hde2 to the existing vg01 to expand the space ;]

[To delete the PV in VG, make sure that the PV is not used by VG, for example,/dev/hdd2. check the PV first.# Pvdisplay/dev/hdd2

If PV Status is Not Availiable, it can be deleted,# Vgreduce-v vg01/dev/hdd2 .]

Parameter: the PE size (such as 8 M) of the VG created by-s. it is omitted by default and is not written to 4 M. It must be an integer multiple of 4.

4. create a logical volume (LVM ):

Common lvcreate commands:

Lvcreate [options]-n logical volume name Volume group name

Common options include:

"-I Stripes: Create an LV in a staggered manner, where Stripes refers to the number of PVS in the volume group.

"-I Stripe_size: The block size used in the staggered mode (unit: KB). The Stripe_size must be 2 exponent: 2N, N = 2, 3... 9.

"-L LEs: number of logical LV blocks.

"-L size: specify the LV size. then, K, M, and G can be used to represent KB, MB, and GB.

"-S: create a snapshot volume with an existing LV.

"-N name: specifies the name of the LV.

1) create a common LV:

# Lvcreate-L 5G-n lv01 vg01

--> Create a 5G virtual partition named lv01 on the virtual hard disk vg01/dev/vg01/lv01

# Lvcreate-I-I-L 4G-n lv02 vg01

--> Where-I is the number of PVS in VG,-I block size, and-L LV size.

2) create a snapshot LV:

# Lvcreate-s-I-I-L 2G-n lv03_snapshot vg01
5. create a document system:
# Mke2fs-j/dev/vg01/lv01 (mkfs. ext3/dev/vg01/lv02; mkfs. ext3/dev/vg01/lv_snapshot)
6. Mount:
# Mkdir/mnt/lv01;
# Mount-t ext3/dev/vg01/lv01/mnt/lv01;
7. increase or decrease the LV size:
# Umount/lv01;
# E2fsadm-L 100 M (-100 M)/dev/vg01/lv01

________________________________________________________

IV. Summary:

1) fdisk/dev/hd? -- 8e (/dev/hda2;/dev/hdb2;/dev/hdc2/; dev/hdd2)

2) pvcreate/dev/hda2/dev/hdb2/dev/hdc2

3) vgcreate vg01/dev/hd2/dev/hdb2/dev/hdc2

4) lvcreate [-s] [-I pv_pation_count] [-I n * 2 k]-L partition size [-nlv_name] vg01

5) mke2fs [-j]/vg01/lv_name

6) mkdir/mnt/mnt_point; mount-t ext3/dev/vg01/lv_name/mnt/mnt_point;

Increase the partition capacity of the hard disk:

1) pvcreate/dev/hdd2;

2) vgextend vg01/dev/hdd2;

3) lvextend-L 100 M/dev/vg01/lv_name; (online expansion partition size) lvreduce-L-100 M/dev/vg01/lv_name (online expansion partition size)

If the capacity in VG is not allocated, you can increase or decrease the partition capacity:

1) umount/mnt/mnt_point;

2) e2fsadm-L 100 M/dev/vg01/lv_name

-- The above expansion must be the last LV in the LV (for example,/dev/vg01/lv01;/dev/vg01/lv02;/dev/vg01/lv03)

Only the last LV: lv03 can be properly and correctly expanded. problems may occur if lv01 and lv02 are expanded!

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.