In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
V
Preface to the understanding and Management of LVM logical Volume in Linux disk Management
This paper extends as follows from the previous article:
Link: disk management and file system for Linux disk management
What is LVM? Why do I need LVM? How to manage LVM logical volumes specifically? What is a disk quota? Why do I need disk quotas? What are the conditions for disk quotas in Linux? How to make disk quota specifically?
The following explains the above problems one by one, and goes deep into the examples to give you an in-depth understanding of linux logical volume management in LVM disk management.
1. Overview of LVM 1. What is LVM? Why do I need LVM?
Many Linux users will encounter this dilemma when installing the operating system: how to accurately evaluate and allocate the capacity of each hard disk partition? if the initial evaluation is not accurate, once the system partition is not enough, they may have to back up and delete the relevant data, or even be forced to replan the partition and reinstall the operating system to meet the needs of the application system. The LVM technology realizes the requirement of dynamic management and allocation of disks by users.
LVM--Logical Volume Manger, logical volume management, is a logical mechanism for Linux system to manage disk partitions. It is a logical layer built on hard disks and partitions and under the file system. It shields the underlying disk partition layout when establishing the file system, and dynamically adjusts the disk capacity while keeping the existing data unchanged, so as to improve the flexibility of disk management.
Note: / boot partition is used to store boot files and cannot be created based on LVM!
Basic Concepts of 2.LVM Mechanism
PV (physical volume)
A physical volume (physical volume), which is the basic storage device of the LVM mechanism, usually corresponds to a normal partition or an entire hard disk. During creation, a reserved block is created in the head of the partition or hard disk, which is used to record the attributes of LVM, and the storage space is divided into basic units (PE) with the default size of 4MB, and multiple PE form physical volumes.
VG (volume group)
Multiple physical volumes form a volume group
LV (logical volume)
It is based on the volume group and is not directly related to the physical volume.
The schematic diagrams of the three are as follows:
3.LVM 's main management commands function physical volume management volume group management logical volume management scan scan pvscanvgscanlvscancreate establishment pvcreatevgcreatelvcreatedisplay display pvdisplayvgdisplaylvdisplayremove delete pvremovevgremovelvremoveextend extension-vgextendlvextendreduce reduction (some formats may not support)-- vgreducelvreduce
The above table mainly lists the specific operation commands for managing logical volumes, and the following demonstrates the common commands in the above table combined with the actual operation.
Second, LVM logical volume management practice operation process (can be followed) 4. How to manage LVM logical volumes specifically?
Experimental environment: operating in the virtual machine environment of Centos7 on VMware15 version
Add disks and restart the virtual machine, depending on your own needs and hardware limitations
I have added three blocks. For specific steps, please refer to: https://blog.51cto.com/14557673/2447274
Check whether the disk has been added successfully, and the partition operation will be carried out if it is successful (in which you need to change the ID tag number as the partition type to 8e to indicate that the LVM partition is supported)
[root@lokott ~] # uname-a / / shows the kernel version of Centos7 Linux lokott 3.10.0-693.el7.x86_64 # 1 SMP Tue Aug 22 21:09:27 UTC 2017 x86 "64 GNU/Linux [root@lokott ~] # fdisk-l disk / dev/sda:42.9 GB, 42949672960 bytes 83886080 sector Units = sector of 1 * 512 = 512 bytes sector size (logical / physical): 512byte / 512byte I size (min / best): 512byte / 512byte disk label type: dos disk identifier: 0x000a0791 device Boot Start End Blocks Id System/dev/sda1 * 2048 12584959 6291456 83 Linux/dev/sda2 12584960 54599920971520 83 Linux/dev/sda3 54528000 62916607 4194304 82 Linux swap / Solaris/dev/sda4 62916608 83886079 10484736 5 Extended/dev/sda5 62918656 83886079 10483712 83 Linux disk / dev/sdb:21.5 GB 21474836480 bytes 41943040 sector Units = sector of 1 * 512 = 512 bytes sector size (logical / physical): 512 bytes / 512 bytes I Zero size (min / best): 512 bytes / 512 bytes disk / dev/sdc:21.5 GB, 21474836480 bytes 41943040 sector Units = sector of 1 * 512 = 512 bytes sector size (logical / physical): 512byte / 512byte I size (min / best): 512byte / 512byte disk / dev/sdd:21.5 GB, 21474836480 bytes, 41943040 sector Units = sector of 1 * 512x bytes sector size (logical / physical): 512byte / 512byte I XO size (minimum / optimal): 512byte / 512byte
The partition operation is as follows:
[root@lokott ~] # fdisk / dev/sdb / / complete the partition and partition type settings for sdb and sdc. Welcome to fdisk (util-linux 2.23.2). . / / Interactive process is omitted. For more information, please see the above link article command (enter m for help): P disk / dev/sdb:21.5 GB, 21474836480 bytes 41943040 sector Units = sector of 1 * 512 = 512 bytes sector size (logical / physical): 512byte / 512byte size (min / best): 512byte / 512byte disk label type: dos disk identifier: 0x5e2f4ad3 device Boot Start End Blocks Id System/dev/sdb1 2048 20973567 10485760 8e Linux LVM/dev/sdb2 20973568314593275242880 83 Linux command (enter m for help): W [root@lokott ~] # fdisk / dev/sdc Welcome to fdisk (util-linux 2.23.2). The changes remain in memory until you decide to write them to disk. Think twice before using the write command. Command (enter m for help): P disk / dev/sdc:21.5 GB, 21474836480 bytes 41943040 sector Units = sector of 1 * 512 = 512 bytes sector size (logical / physical): 512byte / 512byte size (min / best): 512byte / 512byte disk label type: dos disk identifier: 0xfd710363 device Boot Start End Blocks Id System/dev/sdc1 2048 10487807 5242880 83 Linux/dev/sdc2 104878083145932710485760 8e Linux LVM
At present, sdb1 and sdc2 have been used as logical partitions, and you can use fdisk-l to view information.
[root@lokott ~] # fdisk-l / dev/sd [bMurc] / / simplified operating disk / dev/sdb:21.5 GB, 21474836480 bytes 41943040 sector Units = sector of 1 * 512 = 512 bytes sector size (logical / physical): 512byte / 512byte I size (min / best): 512byte / 512byte disk label type: dos disk identifier: 0x5e2f4ad3 device Boot Start End Blocks Id System/dev/sdb1 2048 20973567 10485760 8e Linux LVM / dev/sdb2 2097356831459327 5242880 83 Linux disk / dev/sdc:21.5 GB 21474836480 bytes 41943040 sector Units = sector of 1 * 512 = 512 bytes sector size (logical / physical): 512byte / 512byte size (min / best): 512byte / 512byte disk label type: dos disk identifier: 0xfd710363 device Boot Start End Blocks Id System/dev/sdc1 2048 10487807 5242880 83 Linux/dev/sdc2 10487808 3145932710485760 8e Linux LVM [root@lokott ~] #
After the partition is complete, use the pvcreate command to convert the desired operation partition to a physical volume
[root@lokott ~] # pvscan / / View all physical volumes of the system The result is that there is no No matching physical volumes found [root@lokott ~] # pvcreate / dev/sdb1 / dev/sdc2 / / convert partition to physical volume Physical volume "/ dev/sdb1" successfully created.Physical volume "/ dev/sdc2" successfully created. [root@lokott ~] # pvdisplay / / View physical volume details "/ dev/sdc2" is a new physical volume of "10.00 GiB"-- NEW Physical volume-PV Name / dev/sdc2VG Name PV Size 10.00 GiBAllocatable NOPE Size 0 Total PE 0Free PE 0Allocated PE 0PV UUID AzPaEA-X9Um-HPQQ-zdOg-mzVf-wXvh-QWEEXt "/ dev/sdb1" is a new physical volume of "10.00 GiB"-NEW Physical volume- -PV Name / dev/sdb1VG Name PV Size 10.00 GiBAllocatable NOPE Size 0 Total PE 0Free PE 0Allocated PE 0PV UUID 5fh4Yx-Bwlm-ym7b-Qg0P-3HRb-iKRi-lwQyG9
Use the vgcreate command to group one or more physical volumes into volume groups
[root@lokott ~] # vgscan Reading volume groups from cache. [root@lokott ~] # vgcreate vgroup / dev/sdb1 / dev/sdc2 / / vgroup is the name of the volume group Volume group "vgroup" successfully created [root@lokott ~] # vgdisplay-Volume group-- VG Name vgroupSystem ID Format lvm2Metadata Areas 2Metadata Sequence No 1VG Access read/writeVG Status resizableMAX LV 0Cur LV 0Open LV 0Max PV 0Cur PV 2Act PV 2VG Size 19.99 GiBPE Size 4.00 MiBTotal PE 5118Alloc PE / Size 0 / 0 Free PE / Size 5118 / 19.99 GiBVG UUID K2s77S-fAfb-C5V2-P7ci-m4eo-DdNh-nanIW4
Use the lvcreate command to split space from a user-specified volume group to create a logical volume.
[root@lokott ~] # lvscan / / View system built logical volume information [root@lokott ~] # lvcreate-L 10G-n vgroup1 vgroup/ / create logical volume Logical volume "vgroup1" created from volume group split space. [root@lokott ~] # ls / dev/vgroup/vgroup1 / / Link file / dev/vgroup/ showing logical volume vgroup1 Vgroup1 [root@lokott ~] # ls / dev/mapper/vgroup-vgroup1 / / display logical volume vgroup1 device file / dev/mapper/vgroup-vgroup1 [root@lokott ~] # lvdisplay / / display logical volume details-Logical volume-LV Path / dev/vgroup/vgroup1LV Name vgroup1VG Name vgroupLV UUID UcTRFz-DK1l-fVgf-Gvzr-562n-nkYS-kuRACZLV Write Access read/writeLV Creation host Time lokott, 2019-11-02 14:27:41 + 0800LV Status available# open 0LV Size 10.00 GiBCurrent LE 2560Segments 2Allocation inheritRead ahead sectors auto- currently set to 8192Block device 253purl
Format the logical volume, create a mount point (mkdir) to mount it, and view it using the df command
[root@lokott ~] # mkfs.xfs / dev/vgroup/vgroup1 meta-data=/dev/vgroup/vgroup1 isize=512 agcount=4, agsize=655360 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0data = bsize=4096 blocks=2621440 Imaxpct=25 = sunit=0 swidth=0 blksnaming = version 2 bsize=4096 ascii-ci=0 ftype=1log = internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1realtime = none extsz=4096 blocks=0 Rtextents=0 [root@lokott ~] # mkdir / mail [root@lokott ~] # mount / dev/vgroup/vgroup1 / mail/ [root@lokott ~] # df-hT File system Type capacity available available mount point / dev/sda2 xfs 20G 4.4G 16G 22% / devtmpfs devtmpfs 474M 0474M 0% / devtmpfs tmpfs 489M 0 489m 0% / dev/shmtmpfs tmpfs 489M 7.2m 482m 2% / runtmpfs tmpfs 489M 0 489m 0% / sys/fs/cgroup/dev/sda5 xfs 10G 37M 10G 1% / home/dev/sda1 xfs 6.0G 158M 5.9G 3% / boottmpfs tmpfs 98M 4.0K 98m 1% / run/user/42tmpfs tmpfs 98M 24K 98m 1% / run/user/0/dev/sr0 iso9660 4.3G 4.3G 0% / run/media/root/CentOS 7 x86_64/dev/mapper/vgroup-vgroup1 Xfs 10G 33m 10G 1% / mail use the lvextend command to expand the capacity of logical volumes Then use the resize2fs command to update the file system size recognized by the system: [root@lokott] # lvextend-L + 5G / dev/vgroup/vgroup1 / / indicates a successful expansion (provided there is free space in the volume group) Size of logical volume vgroup/vgroup1 changed from 10.00 GiB (2560 extents) to 15.00 GiB (3840 extents). Logical volume vgroup/vgroup1 successfully resized. [root@lokott ~] # df-hT / / check whether it needs to be updated to let the system recognize that the file system type capacity has been used. Used mount point / dev/sda2 xfs 20G 4.4G 16G 22% / devtmpfs Devtmpfs 474M 0 474M 0% / devtmpfs tmpfs 489M 0 489M 0% / dev/shmtmpfs tmpfs 489M 7.2m 482m 2% / runtmpfs tmpfs 489M 0 489m 0% / sys/fs/cgroup/dev/sda5 xfs 10G 37M 10G 1% / home/dev/sda1 xfs 6.0G 158M 5.9G 3% / boottmpfs tmpfs 98M 4.0K 98M 1% / run/user/42tmpfs tmpfs 98M 24K 98M 1% / run/user/0/dev/sr0 iso9660 4.3G 4.3G 0 100% / Run/media/root/CentOS 7 x86_64/dev/mapper/vgroup-vgroup1 xfs 10G 33m 10G 1% / mail [root@lokott ~] # xfs_growfs / dev/vgroup/vgroup1 / / xfs using the xfs_growfs command Ext4 uses the resize2fs command, but first unmount meta-data=/dev/mapper/vgroup-vgroup1 isize=512 agcount=4, agsize=655360 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0data = bsize=4096 blocks=2621440 Imaxpct=25 = sunit=0 swidth=0 blksnaming = version 2 bsize=4096 ascii-ci=0 ftype=1log = internal bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1realtime = none extsz=4096 blocks=0 Rtextents=0data blocks changed from 2621440 to 3932160 [root@lokott ~] # df-hT | grep / dev/mapper/vgroup-vgroup1 / / can be extended to 15G/dev/mapper/vgroup-vgroup1 xfs 15G 33m 15G 1% / mail [root@lokott ~] # 5 after update. Summary of the experiment (1)
The above is the whole process of LVM logical volume management operation, you can follow! Be sure to pay attention to the operation of logical partitions when partitioning, and later updated commands need to use the corresponding commands according to the file system type (ext4--resize2fs (unmount first), xfs--xfs_growfs)
3. Disk quota 6. What is a disk quota? Why do I need disk quotas?
Disk quota, as the name implies, is to limit the use of disk resources. Disk quota is the system's control (or restriction) that users can use disk resources. In Linux, disk quotas can limit the user's space usage, the number of files (actually the number of inode, the number of files is the result of limiting inode). If this range is exceeded, the user cannot continue to write data to disk.
It may not be easy for ordinary people to understand the explanation of this paragraph, so let's give an example to illustrate:
Suppose there is a basket of peaches, a total of 50, evenly distributed to 10 monkeys, then each monkey can get five peaches, first of all, it limits the total number of peaches and the number of peaches that each monkey can get, which is the disk quota. But the distribution in the system must not be equal, which requires a quota allocation. Some monkeys get more points, which means that some monkeys get less poop. But the total will not change. For linux systems, it means that the actual resource space of a single disk is limited, so the reasonable allocation of disks is particularly important.
Therefore, the reason for disk quota is that the disk space resources are limited, and its purpose can be understood as reasonable planning to avoid waste of resources.
7. So what are the conditions for disk quotas in Linux? First of all, the Linux kernel is required to support the installation of xfsprogs and quota8.Linux disk limits. scope of action: limit objects for specified file system (partition): user account, group account limit type: disk capacity, file number limit method: soft limit, hard limit
In which the soft limit
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.