Linux lvm usage

Source: Internet
Author: User


Linux (centos) System Configuration logic disk Volume management Logical Volume Manager each Linux user will encounter this problem when installing Linux: When partitioning the system, how to accurately assess and allocate the capacity of each hard disk partition, because the system administrator must not only consider the capacity required by a partition, but also anticipate the maximum capacity that may be required by the partition in the future. If the estimation is inaccurate, the Administrator may even need to back up the entire system, clear the hard disk, re-partition the hard disk, and restore the data to the new partition when a partition is insufficient. Lvm makes an intermediate adaptation layer between physical devices and the available disk space of users. users do not need to worry about the partitions at the bottom layer, or they only have one partition when they see several hard disks. in this way, the storage limit of a single hard disk is exceeded. this is the advantage of lvm. What is PV, PE, VG, and LV? PV (physical volume): physical volumes are at the bottom of the logical volume management system, it can be used to partition the entire physical hard disk or the actual physical hard disk. VG (volume group): A volume is created on a physical volume. A volume group must contain at least one physical volume. After a volume group is created, it can be dynamically added to the volume group, A logical volume Management System project can contain multiple volume groups. LV (logical volume): A logical volume is created on the basis of a volume group. unallocated space in the volume group can be used to create new logical volumes. After a logical volume is created, the space can be dynamically expanded and reduced. PE (physical extent): The physical area is the smallest storage unit that can be allocated in the physical volume. The size of the physical area is specified when the volume group is created. It cannot be changed once determined, the physical regions of all physical volumes in the same volume group must be the same. After a new pv is added to the vg, the pe size is automatically changed to the pe size defined in the vg. LE (logical extent): the logical region is the smallest storage unit that can be allocated in a logical volume. The size of the logical region depends on the size of the physical region in the volume group where the logical volume is located. Volume group description area: the volume group description area exists in each physical volume, describes all information about the physical volume itself, the volume group to which the physical volume belongs, the logical volume in the volume group, and the allocation of Physical Areas in the logical volume. It is created when a physical volume is created using pvcreate. Www.2cto.com 1. Creation steps: 1. Use the fdisk tool to convert the disk to partition 2 in linux, and use the pvcreate command to convert the linux partition to a physical volume (pv) 3, use the vgcreate command to process the created physical volume into a volume (vg) 4, use the lvcreate command to group the volume into several logical volume (lv) 5, format and mount the logical volume, dynamic Adjustment of the logical volume size does not affect the PV phase of the logical volume data. It is actually very easy to create a PV, as long as you directly use pvcreate! Let's talk about the commands related to PV! Pvcreate: Create the object partition as PV; pvscan: search for any disk with PV in the current system; pvdisplay: displays the PV status on the current system; pvremove: removes the PV attribute, make the partition do not have the PV attribute. There are also a lot of commands for creating VG and VG In the VG stage. Let's take a look at: vgcreate: the command for creating VG! There are many parameters. Let's take a look. Vgscan: Does VG exist in the search system? Vgdisplay: displays the VG status on the current system. vgextend: adds an additional PV to the VG. vgreduce: removes the PV from the VG. vgchange: configures whether the VG is started (active). vgremove: delete a VG! Logical volume of LVM in www.2cto.com LV stage lvcreate: Create LV! Lvscan: query the LV on the system; lvdisplay: displays the LV status on the system! Lvextend: add capacity in LV! Lvreduce: reduce the capacity in the LV; lvremove: delete a LV! Lvresize: Adjust the LV capacity! Fdisk partitions are repeated 5 times to create 5 partitions when the hard disk is an sdb extended partition [root @ bogon ~] # Fdisk/dev/sdb WARNING: DOS-compatible mode is deprecated. it's stronugly recommended to switch off the mode (command 'C') and change display units to sectors (command 'U '). command (m for help): c DOS Compatibility flag is not set Command (m for help): n Command action e extended p primary partition (1-4) p create a primary Partition multiple logical partitions () Partition number (1-4): 1 First cylinder (1-1044, default 1): Using default v Alue 1 Last cylinder, + cylinders or + size {K, M, G} (1-1044, default 1044): + 1000 M reads the new partition table into the memory, format the new partition [root @ bogon ~]. # Partprobe write the allocated partitions to the memory-bash: partprobe: command not found [root @ bogon ~] # Yum-y install parted [root @ bogon ~] # Partprobe write the allocated partition to the memory [root @ bogon ~] # Fdisk-l view partition information Device Boot Start End Blocks Id System/dev/sdb1 1 128 1028128 + 83 Linux LVM/dev/sdb2 129 256 1028160 83 Linux LVM/dev/sdb3 257 894 5124735 5 Extended/dev/sdb5 257 384 1028128 + 83 Linux LVM/dev/sdb6 385 512 1028128 + 83 Linux LVM/dev/sdb7 513 640 1028128 + 83 Linux LVM creation and management LVM www.2cto.com pv stage [root @ bogon ~] # Pvcreate/dev/sdb {1, 2, 5, 6}-bash: partprobe: command not found [root @ bogon ~] # Yum install lvm2 install lvm support [root @ bogon ~] # Pvcreate/dev/sdb {1, 2, 5, 6} the pv sdb (1.2.5.6) partition must exist [root @ bogon ~] # Pvscan display pv details PV/dev/sdb1 VG VolGroup lvm2 [992.00 MiB/0 free] PV/dev/sdb2 VG VolGroup lvm2 [992.00 MiB/0 free] PV/dev/ sdb5 VG VolGroup lvm2 [992.00 MiB/0 free] PV/dev/sdb6 VG VolGroup lvm2 [992.00 MiB/0 free] Total: 5 [4.84 GiB]/in use: 5 [3.84 GiB]/in no VG: 0 [0] vg stage [root @ bogon ~] # Vgcreate-s 16 M VolGroup/dev/sdb {1, 2, 5, 6} create vg [root @ bogon ~] # Vgdisplay vg details --- Volume group --- VG Name VolGroup System ID Format lvm2 Metadata Areas 4 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 4 Act PV 4 VG Size 3.84 GiB PE Size 16.00 MiB Total PE 248 Alloc PE/Size 0/0 Free PE/Size 248/3 .88 GiB vg uuid yGy2H6-dNUv-aVZS-R5si-OvN3-qN7n-CQpfSAlv phase [root @ bogon ~] # Lvcreate-l 248-n alinelv VolGroup distribute vg to alinelv. A total of 248 PES are displayed above [root @ bogon ~] # Ls/dev/VolGroup/view the generated alinelv [root @ bogon ~] # Mkfs. ext4/dev/VolGroup/alinelv format alinelv [root @ bogon ~] # Mkdir/mnt/lvm1 create a directory to prepare for mounting [root @ bogon ~] # Mount/dev/VolGroup/alinelv/mnt/lvm1 mount directory can store things in www.2cto.com/dev/sdb {1, 2, 5, 6} most of the hard drive's lvm directories can store relatively large and small data [root @ bogon ~] # Lvscan displays lv details in "ACTIVE"/dev/VolGroup/alinelv "[3.84 GiB] inherit [root @ bogon ~] # Cp-r/boot/mnt/lvm1 test copy data into [root @ bogon ~] # Df-hT display system mount information Filesystem Type Size Used Avail Use % Mounted on/dev/sda2 ext4 3.9G 590 M 3.1G 16%/tmpfs 514 M 0 514 M 0%/dev /shm/dev/sda1 ext4 194 M 22 M 163 M 12%/boot/dev/sda3 ext4 2.0G 35 M 1.8G 2%/home/dev/mapper/VolGroup-alinelv ext4 3.84G 143 M 3.8G 5%/mnt/lvm1 enlarge lvm capacity [root @ bogon ~] # Pvcreate/dev/sdb7 pv add partitions already divided by fdisk [root @ bogon ~] # Pvscan display pv details PV/dev/sdb1 VG VolGroup lvm2 [992.00 MiB/0 free] PV/dev/sdb2 VG VolGroup lvm2 [992.00 MiB/0 free] PV/dev/ sdb5 VG VolGroup lvm2 [992.00 MiB/0 free] PV/dev/sdb6 VG VolGroup lvm2 [992.00 MiB/0 free] PV/dev/sdb7 VG VolGroup lvm2 [992.00 MiB/0 free total: 5 [4.84 GiB]/in use: 5 [4.84 GiB]/in no VG: 0 [0] www.2cto.com [root @ bogon ~] # Add vgextend VolGroup/dev/sdb7 vg to the new pv [root @ bogon ~] # Vgdisplay vg details --- Volume group --- VG Name VolGroup System ID Format lvm2 Metadata Areas 5 Metadata Sequence No 3 VG Access read/write VG Status resizable max lv 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 5 Act PV 5 VG Size 4.84 GiB PE Size 16.00 MiB Total PE 310 Alloc PE/Size 248/3 .88 GiB Free PE/Size 62/992 .00 MiB focus on this information pe vg uuid yGy2H6-dNUv-aVZS-R5si-OvN3-qN7n-CQpfSA not used just added [root @ Bogon ~] # Lvresize-l + 62/dev/VolGroup/alinelv add lv [root @ bogon ~] # Dumpe2fs/dev/VolGroup/alinelv view the File status [root @ bogon ~] # Resize2fs/dev/VolGroup/alinelv the newly added e2fsck-f/dev/VolGroup/alinelv on the lv server prompts [root @ bogon ~] # E2fsck-f/dev/VolGroup/alinelv run [root @ bogon ~] # Lvscan displays lv details in ACTIVE '/dev/VolGroup/alinelv' [4.84 GiB] inherit www.2cto.com uninstalling LVM [root @ bogon ~] # Unmount umount/mnt/lvm1 [root @ bogon ~] # Lvremove/dev/VolGroup/alinelv lv remove [root @ bogon ~] # Vgremove VolGroup vg also removes [root @ bogon ~] # Pvremove/dev/sdb1/dev/sdb2/dev/sdb5/dev/sdb6/dev/sdb7 pv remove [root @ bogon ~] # Check whether the LVM has been deleted by pvdisplay. We can see that LVM has good scalability and is very convenient to use. You can easily adjust the volume group and logical volume size to further adjust the file system size by zhouxingfu520

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.