Linux LVM HDD Management and LVM expansion

Source: Internet
Author: User
Tags hex code

I. Introduction of LVM

LVM is shorthand for Logical Volume Manager (Logical Volume management), which is implemented by Heinz Mauelshagen on the Linux 2.4 kernel. LVM sets the partition of one or more hard disks logically, equivalent to a large hard disk to use, when the hard disk space is not enough to use, you can continue to add the partitions of other hard disks, so that the dynamic management of disk space, relative to the normal disk partition has a lot of flexibility.

LVM provides a higher level of disk storage for computers than traditional disks and partitions. It makes it easier for system administrators to allocate storage space for apps and users. Storage volumes under LVM management can be resized and removed as needed at any time (file system tools may need to be upgraded). LVM also allows storage volumes to be managed by user groups, allowing administrators to identify storage volumes with more intuitive names (such as "Sales", "development") instead of physical disk names (such as ' SDA ', ' SDB ').

LVM Model:

A large amount of space can be composed of four partitions, and then some logical partitions are partitioned, and when there is not enough space for a logical partition, some space can be allocated from the remaining space to the partition where space is not available.

Ii. Basic terminology of LVM

As mentioned earlier, LVM is a logical layer that is added between the disk partition and the file system to mask the underlying disk partition layout for the file system, providing an abstract disk volume, and creating a file system on the disk volume. First we discuss the following LVM terminology:

Physical storage media (the physical media): This refers to the system's storage device: The hard disk, such as:/DEV/HDA1,/DEV/SDA, etc., is the lowest layer of storage system storage unit.

Physical volume (physical volume): a physical volume refers to a hard disk partition or a device (such as RAID) that logically has the same function as a disk partition, which is the basic storage logic block of LVM, but is compared to basic physical storage media (such as partitions, disks, etc.) and contains management parameters related to LVM.

Volume group (Volume Group): LVM volume groups are similar to physical hard disks in non-LVM systems, which consist of physical volumes. You can create one or more LVM partitions (logical volumes) on a volume group, and an LVM volume group consists of one or more physical volumes.

Logical volumes (logical volume): LVM logical volumes are similar to hard disk partitions in non-LVM systems, and file systems (such as/home or/usr) can be created on top of logical volumes.

PE (physical extent): each physical volume is divided into a basic unit called PE (physical extents), with a uniquely numbered PE being the smallest unit that can be addressed by LVM. The size of the PE is configurable and defaults to 4MB.

Le (logical extent): Logical volumes are also divided into addressable basic units called LE (logical extents). In the same volume group, the size of Le is the same as the PE, and one by one corresponds.

In simple terms:

PV: is a physical partition of the disk

The physical disk partition in VG:LVM, which is PV, must be added to the VG, which can be understood as a warehouse or a few large hard disks.

LV: The logical partition from the VG

As shown in PV, VG, LV three relations:

Iii. installation of LVM
First determine if the LVM tool is installed in the system:
[Root@www root]# Rpm–qa|grep LVM
Lvm-1.0.3-4
If the command result input is similar to the previous example, the system already has the LVM management tool installed, and if the command does not have output, then the LVM management tool is not installed, you need to download from the network or install the LVM RPM Toolkit from the CD.

Iv. Creating and Managing LVM

1. Physical Volume PV
Pvcreate Create PV Example: PVCREATE/DEV/SDA1
PVS View PV Information Example: Enter PVS directly on the command line
Pvdisplay View PV Details Example: pvdisplay/dev/sda1
Pvmove moving PV data to other PV example: PVMOVE/DEV/SDA1/DEV/SDA4
Pvremove PV Removal Example: pvremove/dev/sda1
2, Volume Group VG
2.1 Create, view, delete VG
Vgcreate Create VG Example: Vgcreate myvg/dev/sda{m,n}
VGS View VG Information example: Enter VGS directly on the command line
Vgdisplay View VG Details Example: Vgdisplay MYVG
Vgremove The VG Deletion example: Vgremove MYVG
2.2 Extended VG
First, prepare a PV;
You can then use the Vgextend command to complete the extension;
Format: Vgextend VG_NAME/PATH/TO/PV
Vgextend MYVG/DEV/SDB2 Expand the MYVG volume group and add the/DEV/SDB2
2.3 Reduced VG
1) Determine the PV to be removed;
2) Transfer the data on this PV to other PV;
Pvmove/path/to/pv
3) Remove this PV from the volume group;
Format: Vgreduce VG_NAME/PATH/TO/PV
Vgreduce MYVG/DEV/SDB2 Reduce the MYVG volume group and remove the/dev/sda2
3 Logical Volume LV
3.1 Create, view, delete LV
Lvcreate Create LV Example: Lvcreate LV1/DEV/MYVG
LVS View LV Information example: Enter LVS directly on the command line
Lvdisplay View LV Details Example: Vgdisplay lv1
Lvremove to remove the LV removal example: LVREMOVE/DEV/MYVG/LV1
3.2 Extended LV

Determine how large the extension

Determine if the volume group on which the current logical volume is located has enough free space;

Extended:
1. Physical boundaries
Lvextend-l [+]SIZE/PATH/TO/LV
2. Logical boundary
Resize2fs/path/to/device
3.3 Reduced LV
Determine the size of the reduction, but only if you can accommodate at least all of the original data.
Reduce:
1) Uninstall and forcibly detect the file system;
E2fsck-f
2) Logical Boundary
Resize2fs/path/to/device SIZE
3) Physical boundaries
Lvreduce-l [-]SIZE/PATH/TO/LV
4. Snapshot volume
1) The lifetime of the entire data length, in this time period, 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 Specifies the size of the snapshot volume
-S Create snapshot volume
-P R Creates a snapshot volume for read-only access
Format:
Lvcreate-l size-s-P r-n lv_name/path/to/lv

Third, the example of LV

1. Create a partition

The code is as follows:
[Root@stau11 ~]# fdisk-l//view partition condition
[Root@stau11 ~]# FDISK/DEV/SDA//partition
Command (M for help): N//n to add a partition, p to view the partition
First cylinder (2898-10443, default 2898)://Press "enter" key to determine
Using Default value 2898//Start cylinder Select defaults
Last cylinder or +size or +sizem or +sizek (289810443, default 10443): +2g//to 2G size
Command (M for help): t//change partition type
Partition number (1-5): 5//select partition
Hex code (Type L to list codes): L//partition Type list
Hex code (type L to list codes): 8e//Annotate newly added partitions as LVM
Command (M for help): P//view partition table
/dev/sda5 2756 2999 1959898+ 8e Linux LVM
Command (M for help): w//Save
[Root@localhost ~]# PARTPROBE/DEV/SDA//Is System-aware partition (instead of restart)
[Root@localhost ~]# mkfs.ext3/dev/sda5//Formatting a newly added partition

2, the creation of PV

The code is as follows:
[Root@localhost ~]# Pvcreate/dev/sda5//Create PV
Writing physical volume data to disk "/dev/sda5"
Physical volume "/DEV/SDA5" successfully created
[Root@localhost ~]# PVs//view current PV information
PV VG Fmt Attr PSize pfree
/dev/sda5 lvm2 a--1.87G 1.87G

3, the creation of VG

The code is as follows:
[Root@localhost ~]# vgcreate vg0/dev/sda5//vg0 is the name of the current VG
Volume Group "VG0" successfully created
[Root@localhost ~]# VGS//view VG Information
VG #PV #LV #SN Attr vsize vfree
Vg0 1 0 0 wz--n-1.87g 1.87G

4, the creation of LV

The code is as follows:
[Root@localhost ~]# lvcreate-l 500m-n lv01 vg0
Logical volume "LV01" created
[Root@localhost ~]# LVS//view LV Information
LV VG Attr lsize Origin snap% Move Log copy% Convert
LV01 vg0-wi-a-500.00M
You have mail in/var/spool/mail/root
[Root@localhost ~]# MKFS.EXT3/DEV/VG0/LV01//format

Use of LVM

5, the increase of LV

The code is as follows:
[Root@localhost ~]# lvextend-l +300m/dev/vg0/lv01//(Original LV size 500M, stretched partition to 800M) extending logical Volume LV01 to 800.00 MB
Logical Volume LV01 successfully resized
[Root@localhost ~]# resize2fs/dev/vg0/lv01//Stretched file system
[Root@localhost ~]# LVs
LV VG Attr lsize Origin snap% Move Log copy% Convert
LV01 Vg0-wi-ao 800.00M//size becomes 800M

6, the reduction of LV

The code is as follows:
# UMOUNT/DEV/VG0/LV01//Unload Logical Volume/DEV/VG0/LV01
# Df-h//view
# e2fsck-f/DEV/VG0/LV01//disk checksum
# RESIZE2FS/DEV/VG0/LV01 500M//Retraction file system to 500M
# lvreduce-l 500M/DEV/VG0/LV01//retraction partition to 500M
Warning:reducing active Logical Volume to 500.00 MB
This May DESTROY YOUR DATA (filesystem etc)
Does really want to reduce lv01? [y/n]: Y
# LVS
LV VG Attr lsize Origin snap% Move Log copy% Convert
LV01 vg0-wi-a-500.00M//At this time it has become 500M size
# MOUNT/DEV/VG0/LV01/MNT/LV01//re-mount Partition
# Df-h//view
# LS/MNT/LV01//view files

Iv. system Snapshots of LVM

1. Mount LVM

The code is as follows:
[Root@localhost ~] # MOUNT/DEV/VG0/LV01/MNT/LV01
[Root@localhost ~]# CD/MNT/LV01
[Root@localhost lv01]# Touch {a,b,c}{a,b,c}
[Root@localhost lv01]# ls
aa ab ac ba bb BC CA CB CC Lost+found lv.file restoresymtable

2. Create a snapshot for LVM

The code is as follows:
[Root@localhost lv01]# lvcreate-l 64m-s-N lv-backup/dev/vg0/lv01
Logical volume "Lv-backup" created

3. Mount a Snapshot

The code is as follows:
[Root@localhost lv01]# Mkdir/mnt/lv-backup
[Root@localhost mnt]# Mount-o ro/dev/vg0/lv-backup/mnt/lv-backup/

4. Backup Snapshots

The code is as follows:
[Root@localhost tmp]# dump-0u-f/tmp/lv-backup.dump/mnt/lv-backup///Backup
Dump:date of this level 0 Dump:sun Nov 11 14:53:31 2012
Dump:dumping/dev/mapper/vg0-lv--backup (/mnt/lv-backup) to/tmp/lv-backup.dump

5. Deleting snapshots

The code is as follows:
[Root@localhost tmp]# umount/mnt/lv-backup/
[Root@localhost tmp]# Lvremove/dev/vg0/lv-backup
Do you really want to remove active logical volume Lv-backup? [y/n]: Y
Logical volume "lv-backup" successfully removed

6. Empty the contents of/DEV/VG0/LV01

The code is as follows:
[Root@localhost tmp]# UMOUNT/MNT/LV01
[Root@localhost tmp]# MKFS.EXT3/DEV/VG0/LV01
MKE2FS 1.39 (29-may-2006)
Filesystem label=
OS Type:linux

7, the LVM shutdown

The code is as follows:
[Root@localhost ~]# UMOUNT/MNT/LV01
[Root@localhost ~]# lvremove/dev/vg0/lv01//delete LV
Do you really want to remove active logical volume LV01? [y/n]: Y
Logical volume "LV01" successfully removed
[Root@localhost ~]# vgchange-a n vg0//Make vg0 do not have an active flag
0 Logical Volume (s) in volume group ' vg0 ' now active
[Root@localhost ~]# vgremove vg0//delete VG
Volume Group "vg0" successfully removed
[Root@localhost ~]# Pvremove/dev/sda5//Remove PV
Labels on physical volume "/DEV/SDA5" successfully wiped

Linux LVM HDD Management and LVM expansion

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.