Home >Operation and Maintenance >Linux Operation and Maintenance >How to use LVM disk operation commands in Linux disk management
LVM, Logical Volume Manger, is a logical volume management function provided by the Linux kernel. It is composed of kernel drivers and application layer tools. It creates a logical layer based on the hard disk partition, which can be very flexible and very Conveniently manage storage devices.
LVM uses the device-mapper function of the Linux kernel to implement virtualization of the storage system (the system partition is independent of the underlying hardware). Through LVM, storage space can be abstracted and virtual partitions can be created on it. Partitions can be expanded and reduced more easily. When adding or deleting partitions, there is no need to worry about not having enough contiguous space on a certain hard disk to avoid being in use. It eliminates the trouble of disk repartitioning and the inconvenience of having to move other partitions to adjust partitions. It can manage disks more flexibly than traditional partitioning systems.
A block device that can store LVM. Such as hard disk partition (MBR or GPT Partition), SAN hard disk, RAID or LUN, a loopback file, a kernel-mapped device (such as dm-crypt), which contains a special LVM header, which is the actual hardware or storage system built by LVM.
A volume group is a collection of one or more physical volumes and is displayed as /dev/VG_NAME in the device file system.
Logical volumes are the final meta-devices available for use by the system. They are created and managed in volume groups and are composed of physical blocks. In fact It is a virtual partition and appears as /dev/VG_NAME/LV_NAME, on which file systems can usually be created.
If a logical volume needs to allocate multiple physical blocks, they will become the smallest contiguous area in a volume group (default is 4 MiB ). You can think of it as part of a physical volume that can be assigned to a logical volume.
Below I drew a picture of the location of lvm in Linux disk management:
## The order is: disk -> partition -> PV - > VG -> LV -> fs, that is, disk->partition->physical volume->volume group->logical volume->file system. The creation is also in this order, which will be introduced in detail below. 2. Advantages and Disadvantages of LVM1. AdvantagesCompared with the traditional hard disk partition management method, LVM is more flexible:
Note: If the system boot program does not support LVM, /boot
cannot be placed in LVM. At this moment, an independent /boot
partition must be created and directly formatted and mounted to /boot. The only known bootloader that supports LVM is GRUB.
As you can see from the above figure, //dev/sda2 is already a PV, so only dev/sda1, /dev/sdb1, and /dev/sdb2 can be used to create PV, and because /dev/sda1 is boot boot area, so below we can create PV
root# pvcreate device1 device2 ...
You can view PV information through the three commands pvs, pvscan, and pvdisplay
Note: If you are using an SSD that has not been formatted and the erase block size is less than 1M, please use the following command
pvcreate --dataalignment 1m /dev/sda
to set the alignment. .
Use the command vgcreate to create a volume group
root# vgcreate vg_name pv1 pv2 ...
Create the volume group vg_fedora_yg and add pv /dev/sdb1 to the volume group.
At this time, you can also view the volume group where each physical volume is located through pvs:
Use the lvcreate command
root# lvcreate -L <lv_size> <vg_name> -n <lv_name> # 将卷组vg_name下所有剩余空间给创建的lv_name逻辑卷 root# lvcreate -l +100%FREE <vg_name> -n <lv_name>
root# lvcreate -L <lv_size> <vg_name> -n <lv_name>
After the logical volume is created, you can access it through /dev/mapper/vg_fedora_yg-lv_yg01
or /dev/vg_fedora_yg/lv_yg01
:
Command lvs, lvscan, lvdisplay to view
##③、Expand logical volumeBy command lvextend:root# lvextend -L <extend_size> <lv_path>
Note: If the expanded logical volume has been mounted to a specific file system, you need to execute resize2fs or xfs_growfs (for xfs files System) command to make the modification effective, You can use df -Th or blkid to check the file system type mounted by lv.
5. Format and mount LV (logical volume) After the above logical volume LV is created, it can usually be found under /dev/mapper/ or /dev/vg_name/ If the logical volume cannot be found, you can execute the following command:# modprobe dm-mod # vgscan # vgchange -ayFinally, you can see the following: ①. Format the logical volume Now you can create a file system on this logical volume:
# mkfs.<filesystem_type> /dev/mapper/<vg_name>-<lv_name> # # mkfs.xfs /dev/mapper/vg_fedora_yg-lv_yg01②, mount
# mount /dev/mapper/<vg_name>-<lv_name> <mount_point>
Note: Please select the new logical volume you created for the mount point (for example:
/dev/mapper/vg_fedora_yg-lv_yg01),
Do not use the actual partition device where the logical volume is located (That is, do not use: /dev/sdb1)
illustrate:① In the picture, /dev/sda1 is the boot boot area and cannot be managed by lvm, so it is directly formatted and mounted to the directory /boot. In addition, /dev/sdb2 is also mounted to the directory without being directly formatted by lvm. directory.
②. The capacity of volume group vg_fedora1 is 139G, from which 40 5 45 = 90G is allocated, and there is still 49G free. These free capacities can be lvextended to the following lv; you can also create another lv and allocate go out.
③. Disk settings /dev/sdc still has 50G free space that is not partitioned and can be used after partitioning.
The above is the detailed content of How to use LVM disk operation commands in Linux disk management. For more information, please follow other related articles on the PHP Chinese website!