Gnu/linux LVM Configuration management and the creation and deletion of snapshot volumes, physical volumes, volume groups, logical volumes

Source: Internet
Author: User

LVM is a mechanism for managing disk partitions in a Linux environment, a logical layer that is built on top of hard disks and partitions and under a file system to improve the flexibility of disk partition management. The biggest advantage is that the size of the storage space is adjusted without compromising the data.

This article focuses on the creation of LVM, the expansion and reduction of LVM, and the use of snapshot volumes three parts

Part I: Creation of LVM

The approximate steps for LVM creation are

1. Convert multiple partitions into multiple physical volumes PV (physical vomule)

A partition can create a physical volume that can be created on multiple disks. You can also do a RAID10 disk array later in the physical volume so that there is faster read-write and disk redundancy.

2. Create multiple physical volumes as volume Group VG (vomule Group)

3. Divide a volume group VG into multiple logical volume LV (Logical vomule)

Specific steps for LVM creation:

First step: Create LVM partitions and physical volumes

1. Detect a few available disks and check the total amount of free hard disk space on the drive

[Email protected] ~]# Fdisk-l | grep "Disk/dev/[sh]d[a-z]"

#检测有几块磁盘, and disk information

disk/dev/sda:21.5 GB, 21474836480 bytes

disk/dev/sdb:32.2 GB, 32212254720 bytes

[Email protected] tmp]# df-h

#查看磁盘使用情况

Filesystem Size used Avail use% mounted on

/DEV/SDB3 28G 4.0G 23G 16%/

Tmpfs 504M 0 504M 0%/dev/shm

/DEV/SDB1 194M 190M 0 100%/boot

Disk/DEV/SDA not used

2. Creating an LVM partition

There's no solution to Fdisk and the partition.

Create two partitions using FDISK/DEV/SDA

Wkiom1tpduzceqmuaahgveww7dm394.jpg

Change two block format to 8e,w exit

Wkiom1tpd7yzt7m-aactmzjaqqw225.jpg

3. Create a physical volume

Converts the newly created two partition/dev/sda1/dev/sda2 into physical volumes, primarily by adding LVM attribute information and dividing the PE storage unit

[Email protected] tmp]# pvcreate/dev/sda1/dev/sda2

Physical volume "/DEV/SDA1" successfully created

Physical volume "/dev/sda2" successfully created

[Email protected] tmp]# PVs

PV VG Fmt Attr PSize pfree

/DEV/SDA1 lvm2 a--2.01g 2.01g

/dev/sda2 lvm2 a--3.01g 3.01g

[Email protected] tmp]# Pvdisplay

"/DEV/SDA1" is a new physical volume of "2.01 GiB"

---NEW physical volume---

PV name/dev/sda1

VG Name

PV Size 2.01 GiB

Allocatable NO

PE Size 0

Total PE 0

Free PE 0

Allocated PE 0

PV UUID NHJSM3-RLXF-XTUH-VBKA-QZQA-1HQ3-FXUXS5

"/dev/sda2" is a new physical volume of "3.01 GiB"

---NEW physical volume---

PV Name/dev/sda2

VG Name

PV Size 3.01 GiB

Allocatable NO

PE Size 0

Total PE 0

Free PE 0

Allocated PE 0

PV UUID Ppfwnr-39xt-xen7-xrtt-b2g3-slio-ttcmyh

Second step: Create a volume group with two physical volumes vg01

[[email protected] tmp]# vgcreate vg01/dev/sda{1,2}

Volume Group "VG01" successfully created

[Email protected] tmp]# VGS

VG #PV #LV #SN Attr vsize vfree

VG01 2 0 0 wz--n-5.01g 5.01g

[Email protected] tmp]# Vgdisplay

---Volume Group---

VG Name vg01

System ID

Format lvm2

Metadata Areas 2

Metadata Sequence No 1

VG Access Read/write

VG Status resizable

MAX LV 0

Cur LV 0

Open LV 0

Max PV 0

Cur PV 2

ACT PV 2

VG Size 5.01 GiB

PE Size 4.00 MiB

Total PE 1283

Alloc pe/size 0/0

Free Pe/size 1283/5.01 GiB

VG UUID vam594-dxah-uch0-rgu3-eeux-ktq5-nerv31

Step three: Create a logical volume. Use the Lvcreate command to create a logical volume in the volume group LV01, size-l specifies 1G, name-n Specifies LV01

[Email protected] tmp]# lvcreate-l 1g-n lv01 vg01

Logical volume "LV01" created

[[email protected] tmp]# LVS

LV VG Attr lsize Pool Origin data% Move Log cpy%sync Convert

LV01 vg01-wi-a----1.00g

[Email protected] tmp]# Lvdisplay

---Logical volume---

LV PATH/DEV/VG01/LV01

LV Name LV01

VG Name vg01

LV UUID Tnkxzj-grqk-nake-xw6c-oycy-voep-9hknya

LV Write Access Read/write

LV Creation Host, Time WLM, 2015-02-02 21:36:40 +0800

LV Status Available

# Open 0

LV Size 1.00 GiB

Current LE 256

Segments 1

Allocation inherit

Read ahead Sectors Auto

-Currently set to 256

Block Device 253:0

[Email protected] tmp]# MKFS.EXT4/DEV/VG01/LV01

Part fourth: Mounting

[Email protected] tmp]# MKDIR/LV01

[Email protected] tmp]# mount/dev/vg01/lv01/lv01/

[Email protected] tmp]# mount-s

/DEV/SDB3 on/type ext4 (rw)

Proc On/proc type proc (rw)

Sysfs On/sys type SYSFS (rw)

Devpts on/dev/pts type devpts (rw,gid=5,mode=620)

Tmpfs ON/DEV/SHM type TMPFS (rw)

/DEV/SDB1 on/boot type EXT4 (rw)

None On/proc/sys/fs/binfmt_misc type Binfmt_misc (rw)

Vmware-vmblock on/var/run/vmblock-fuse type Fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)

Sunrpc on/var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

/DEV/MAPPER/VG01-LV01 on/lv01 type EXT4 (rw)

Easy to restart the server automatically mount, you need to add the created file system mount information to/etc/fstab inside

To see if the/etc/fstab is set correctly, you can unload the logical volume DATA1 and then use Mount–a to make the kernel reread/etc/fstab to see if it can be mounted automatically.

[Email protected] tmp]# Vim/etc/fstab

Wkiol1tpgk_sv4-zaahbejqu6xa746.jpg

[Email protected] tmp]# umount/lv01/

[Email protected] tmp]# Mount-s | grep "/LV01"

[Email protected] tmp]# mount-a

[Email protected] tmp]# Mount-s | grep "/LV01"

/DEV/MAPPER/VG01-LV01 on/lv01 type EXT4 (rw)

This concludes the creation of LVM

Part Two: the expansion and reduction of LVM

Expansion of volume groups

[Email protected] ~]# vgextend vg01/dev/sda3 #将物理卷/dev/sda3 Join volume group VG01

Volume Group "VG01" successfully extended

Expansion of logical volumes: first expanding physical boundaries ——— expanding logical boundaries

Expansion boundary

Command: Lvextend

-L [+]#/PATH/TO/LV

[[email protected] tmp]# lvextend-l 2g/dev/vg01/lv01 to expand to 2G (expanded)

Wkiol1tphynt-wxeaabeva34i9e701.jpg

Extending logical boundaries

Resize2fs

Resize2fs-p/PATH/TO/LV

[[email protected] tmp]# resize2fs-p/dev/vg01/lv01 to expand to 2G (expanded)

Wkiol1tphzjqgus3aadog55hmts773.jpg

Reduction of logical volumes, risk, first reducing logical boundaries--reducing physical boundaries

Note: 1, can not be reduced online, you have to uninstall first;

2, to ensure that the size of the reduced space can still store all the original data;

3, before the reduction should be forced to check the file, to ensure that the file system in a consistent state

Df–lh

Umount Uninstall

E2fsck-f/dev/vg01/lv01 force file system Check to see if there is a problem

Start shrinking

RESIZE2FS/PATH/TO/PV 1G

[Email protected] ~]# RESIZE2FS/DEV/VG01/LV01 1G

RESIZE2FS 1.41.12 (17-may-2010)

Resize2fs:new size smaller than minimum (275802)

Reduction (logical boundary) is 1G (reduced total size is 1G)

lvreduce-l [-]#/PATH/TO/LV

[Email protected] ~]# lvreduce-l 1G/DEV/VG01/LV01

Warning:reducing Active and open Logical volume to 1.00 GiB

This May DESTROY YOUR DATA (filesystem etc)

Does really want to reduce lv01? [y/n]: Y

Reducing logical Volume LV01 to 1.00 GiB

Logical Volume LV01 successfully resized

Reduction (physical boundary) is 1G

Mount-a

Re-hung in

Part III: Using snapshot volumes ()

1, the life cycle for the entire data length: In this period of time, the amount of data growth can not exceed the size of the snapshot volume;

2, the snapshot volume should be read-only;

3, with the original volume in the same volume group;

Lvcreate-l #-N slv_name-s-P R/PATH/TO/LV

-l Specifies the size of the –n name-S, which is represented as the snapshot volume-p read-only source volume to take the snapshot

[[email protected] ~]# lvcreate-l 100m-n lv01_snap-s-P R/DEV/VG01/LV01

Logical volume "Lv01_snap" created

[Email protected] ~]# mount/dev/vg01/lv01_snap/mnt/

Mount:block Device/dev/mapper/vg01-lv01_snap is write-protected, mounting read-only

Backups can be backed up from the snapshot volume and can be uninstalled after the backup is complete

[Email protected] ~]# Lvremove/dev/vg01/lv01_snap

Do you really want to remove active logical volume LV01_SNAP? [y/n]: Y

Logical volume "Lv01_snap" successfully removed

The commands to use to manage LVM management configuration are:

Vgextend Vg0/dev/sdaz * Add a third physical volume to the vg0 physical volume group *

Fdisk-l: Check that the physical hard disks are recognized in the system

Pvdisplay: View the physical volumes that have been created in the system

Pvcreate: Create a new physical volume

Pvremove: Deleting a physical volume (that is, removing an LVM tag from a physical volume)

Vgdisplay: Viewing volume groups in the system

Vgcreate: Create a new volume group

Vgreduce: Removing a physical volume from a volume group (that is, shrinking a volume group)

Vgremove: Deleting a volume group

Lvdisplay: View the logical volumes that have been created in the system

Lvcreate: Create a new Logical volume

Lvreduce: Shrink A logical volume (that is, reduce some le from a logical volume)

Lvremove: Deleting a logical volume from the system

MKFS: Create a file system of the appropriate type based on a logical volume

Mkdir-p $mount _piont: Create a mount Directory

The created file system is located at:

/dev/$create _vg_name/$lv _name

mount/dev/$create _vg_name/$lv _name $mount _piont: Mount file system

Lvextend-l 2g/dev/vg01/lv01 to expand to 2G (expanded physical boundary)

Resize2fs-p/dev/vg01/lv01 to expand to 2G (the logical boundary after expansion)

The following is a blog written by others as a supplement, provenance http://dreamfire.blog.51cto.com/418026/1084729

If a piece of disk or partition fails, how to quickly transfer data to the same volume group other space.

1. Transfer spatial data via Pvmove command

2, by Vgreduce command will be bad disk or partition from the volume group Vgdata inside remove removed.

3. Remove the bad disk or partition from the system by Pvremove command.

4. Manually remove the hard drive or repair the partition with some tools.

clip_image042

clip_image044

Delete the entire logical volume

1. Remove the logical volume by Umount command first lvdata1

2, modify the/etc/fstab inside the logical volume mount information, or the system may not start up.

3. Delete the logical volume by Lvremove lvdata1

4. Delete the volume group by Vgremove Vgdata

5. Convert physical volumes to normal partitions via Pvremove.

clip_image046

After the deletion, do not forget to modify the ID identifier of the partition. Modify it to a normal Linux partition.

clip_image048

Summary: LVM logical volumes are a great space-use mechanism in Linux because partitions are not available to be enlarged or smaller without formatting. With LVM, you can make your disk space flexible.

Gnu/linux LVM Configuration management and the creation and deletion of snapshot volumes, physical volumes, volume groups, logical volumes

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.