Linux LVM Logical Volume management

Source: Internet
Author: User

What is LVM

LVM is the short name of Logical volume management (Logical Volume Manager), which is an abstraction layer built on top of physical storage devices, allowing you to generate logical storage volumes, providing greater flexibility than managing direct use of physical storage.

LVM stores virtualization, uses logical volumes, you are not limited to the size of the physical disk, and the hardware-related storage settings are hidden, you can adjust the volume size or data migration without stopping the application or uninstalling the file system. This reduces operating costs.

As shown in the following:

    • The bottom is the physical hard disk:/dev/sda1,/DEV/SDB1,/DEV/SDC1 ...
    • Middle tier: storage virtualization, all physical hard disks as a logical collection (volume group)
    • Top level: Divides the volume group into logical volumes, the logical volume size can be dynamically adjusted, and so on.
Basic concepts
    • Physical storage media (the physical media)
      This refers to the system's storage devices, such as:/DEV/HDA1,/DEV/SDA, etc., is the storage system at the lowest level of storage units.

    • Physical volume (PV, physical Volume)
      A physical volume refers to a disk, a disk partition, or a device (such as a raid) that has the same functionality as a logical and disk partition, which is the basic storage logic block of LVM, but is compared with basic physical storage media (such as partitions, disks, etc.) and contains management parameters related to LVM. Current LVM allows you to save 0 to 2 copies of the metadata for this physical volume on each physical volume. The default is 1, which guarantees the beginning of the device. For 2 o'clock, save the second backup at the end of the device.

    • Volume group (VG, 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 Volume (LV, 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 built on top of logical volumes.

    • Physical volume Meaning: a physical hard disk cannot be used directly, it needs to be partitioned, formatted and so on after it becomes a physical volume before it can be used.

    • There are multiple physical volumes at the bottom of 1 volume groups.
    • 1 volume groups can create multiple logical volumes, and the size of a logical volume can be dynamically adjusted.

LVM is more resilient than normal hard disk partition management:
    • Use a volume group (VG) to make many hard disk spaces look like a large hard drive.
    • With logical volumes (LV), you can create partitions that span many hard disk spaces.
    • You can create a small logical volume (LV) that dynamically adjusts its size when there is not enough space.
    • You can adjust the logical volume (LV) size without having to worry about the location of the logical volume on your hard disk, without worrying about having no contiguous space available. It does not depend on the position of the LV within VG, there are no need to ensure surrounding available space.
    • The logical volume (LV) and volume Group (VG) can be created, deleted, resized, and so on-line (online). File systems on the LVM also need to be resized, and some file systems support such online operations.
    • Instead of restarting the service, you can migrate logical volumes (LV) online/dynamic (live) used in the service to other hard drives.
From scratch, assign maximum disk space to/home

Linux system installation process omitted, now the scene is the system in the minimum mode of installation, the physical hard disk has a large amount of space is not formatted, currently intends to allocate the remaining space of the hard disk to the/home directory.

前期准备:0.1 磁盘分区情况:fdisk -l0.1 磁盘空间使用情况:df -h如果2种情况的磁盘容量不相等,则说明有磁盘未使用。可以继续后续操作1. 新增分区fdisk /dev/sdacpnp3w2.partprobe(or reboot)3. 查看逻辑卷vgdisplayfdisk -l4. 创建逻辑卷组vgcreate vg_zy /dev/sda4vgcreate -s 32M VolGroup01 /dev/sdb1vgcreate创建卷组:格式:vgcreate [-s  <8M|16M|...>] vg0 /dev/sdb{1,2,3...}                -s:指定扩展块(PE)的大小,默认为4MB;(相当与磁盘上的簇,扩展逻辑卷的基本单位。后面的值可以是8M 16M 32M 64M .....最多65532个扩展块。                vg0:新创建的卷组的名字。                /dev/sdb{1,2,3...}:需要的物理卷可以写多个;5. 创建逻辑卷vgs lvcreate -L800g -n home vg_zy6. 建立文件系统mkfs -t ext4 /dev/vg_zy/home7. 查看/home目录挂载点  df -h /home8. 挂载存储mount /dev/vg_zy/home /home9. 修改fstab配置文件实现自动挂载df -h /home 查看vim /etc/fstab/dev/mapper/vg_zy-home  /home  ext4  defaults  1  2第五列是dump备份设置。当其值设置为1时,将允许dump备份程序备份;设置为0时,忽略备份操作;第六列是fsck磁盘检查设置。其值是一个顺序。当其值为0时,永远不检查;而 / 根目录分区永远都为1。其它分区从2开始,数字越小越先检查,如果两个分区的数字相同,则同时检查。
Expansion of new hard disk space to/ddhome

In this example, the/ddhome directory is also the new directory.

1.==不重启显示新增的磁盘信息==ls /sys/class/scsi_host/echo "- - -" > /sys/class/scsi_host/host0/scanecho "- - -" > /sys/class/scsi_host/host1/scanecho "- - -" > /sys/class/scsi_host/host2/scan查看卷组:vgs显示逻辑卷:lvs查看物理卷信息: pvdisplaydf -T  #查看分区格式2.将新增的磁盘(硬件)添加到卷组#vgextend centos /dev/sdbvgextend vgname /dev/sdc3.新建逻辑卷:在卷组centos创建名为"/dev/mapper/centos-ddhome"的逻辑卷lvcreate -L 1300G -n ddhome centos4.格式化逻辑卷mke2fs -t ext4 /dev/mapper/centos-ddhome5.挂载目录rm -rf /ddhome && mkdir /ddhomemount /dev/mapper/centos-ddhome /ddhomedf -h
Logical Volume expansion
1.不重启显示新增的磁盘信息ls /sys/class/scsi_host/echo "- - -" > /sys/class/scsi_host/host0/scanecho "- - -" > /sys/class/scsi_host/host1/scanecho "- - -" > /sys/class/scsi_host/host2/scanfdisk -l 查看新增磁盘是否已经显示2.将新增的磁盘添加到卷组vgextend vg_ddz /dev/sdc3.新增500Glvextend -L +500G /dev/mapper/vg_ddz-lv_ddhomelvextend -l +100%FREE /dev/mapper/vg_ddz-lv_ddhome4.同步文件系统resize2fs /dev/mapper/vg_ddz-lv_ddhomeorxfs_growfs /dev/mapper/centos-root
    • Reference: http://dreamfire.blog.51cto.com/418026/1084729
Free logical Volume A disk space, assigned to logical Volume B
1.查看正在使用/home的进程fuser -l /homeps -ef|grep xxxkill -9 pid2.卸载挂载目录umount /home3.检查vg_ddz-lv_home文件的错误性e2fsck -f /dev/mapper/vg_ddz-lv_home4.调整/home为100Gresize2fs -p /dev/mapper/vg_ddz-lv_home 80G5.缩减物理边界lvreduce -L 80G /dev/mapper/vg_ddz-lv_home输入y6.重新挂载/homemount /home7.查看卷组vg可用空间vgs8.新增逻辑卷lvcreate -L 150G -n lv_ddhome vg_ddz9.格式化逻辑卷mke2fs -t ext4 /dev/mapper/vg_ddz-lv_ddhome10.挂载目录rm -rf /ddhome && mkdir /ddhomemount /dev/mapper/vg_ddz-lv_ddhome /ddhome11.查看结果df -h
Ext3 upgrade to Ext4
umount /ddhomee2fsck -f /dev/mapper/vg_ddz-lv_ddhome #可能要执行2遍tune2fs -O extents,uninit_bg,dir_index /dev/mapper/vg_ddz-lv_ddhomefsck -pf /dev/mapper/vg_ddz-lv_ddhomemount -t ext4 /dev/mapper/vg_ddz-lv_ddhome /ddhome
Summarize

Through the above practice, can be further based on, deepen the understanding of LVM.

Reference documents
    • Linux disks, partitions, mounts and mount points, logical volume management (Logical Volume manager), etc.

Tips: This article belongs to their own study and practice of the process of recording, many pictures and text are pasted from the online article, no reference please forgive! If you have any questions please leave a message or e-mail notification, I will promptly reply.

Linux LVM Logical Volume management

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.