In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
LVM logical disk volume management
LVM is the abbreviation of logical disk volume management. It is a mechanism for managing disk partitions under Linux environment. LVM is a logical layer based on hard disk and partition to improve the flexibility of disk partition management. Its mechanism is to connect multiple block devices into a whole block of volume groups (volumegroup) to form a storage pool. Then, create a logical volume (logicalvolumes) on this volume group, and further create a file system on the logical volume.
When the hard disk space is not enough, you can continue to add other hard disk partitions to it, which can realize the dynamic management of disk space and has great flexibility compared with ordinary disk partitions.
Physical volume (physicalvolume): refers to a disk partition or a device (such as a RAID) that has the same function as a disk partition. The disk type needs to be 8e when creating a physical volume. For example, / dev/hda1, / dev/sda, etc., are the storage units at the lowest level of the storage system. Cannot be formatted directly when creating a physical volume!
Volume group (volumegroup): multiple physical volumes are combined to logically form a hard disk. Its size depends on the physical volume size and number, and there must be at least one physical volume.
Logical volume (logicalvolume): created on a volume group, and a file system can be established on the logical volume that is created. Similar to disk partitions. The difference is that the boundaries of logical volumes can be expanded or narrowed at will.
PE (PhysicalExtents): a storage unit specified by the underlying layer when creating a volume group, which is called physical extent (physical extension) based on the expression of Oracle, so we determine how many PE are allocated when dividing a logical volume. The size of PE is determined by the volume group, and the size of PE is also configurable (described below). The default is 4MB.
LE (LogicalExtents): when PE is assigned to a logical volume, it is called LE, that is, the logical volume is divided into addressable basic units called LE (LogicalExtents). In the same volume group, the size of LE and PE are the same and correspond one to one.
Snapshots (Snapshot): logical volumes also support snapshots, and LVM snapshots record file system changes to a snapshot partition instead of mirroring that partition (that is, preserving the state of the past moment). So when you create a snapshot partition, you don't need to use the same size as the partition you are creating the snapshot, but the size you need to change during the snapshot process. It depends on how much data is being written to the partition and how long you want to keep the LVM snapshot. The longer you keep it, the more changes you make in the file system, the more snapshot partitions will be populated with changed information. The higher the rate of change in the partition, the shorter the average lifetime of the snapshot. If the change to a LVM partition exceeds the size of the snapshot, the snapshot is released. To put it simply: there is nothing in the snapshot it is just a path to access the original file. (as shown in the figure) after we have a snapshot, our backup of the data will be very simple and convenient.
The creation process is as follows: first, physical devices are made into physical volumes, then physical volumes are combined to form volume groups, and finally logical volumes are created on the volume group. And what we use is a logical volume.
Hard disk partition type
There are four partition forms of hard disk, which are primary partition, extended partition, logical partition and active partition. They are introduced respectively below.
Primary partition
The primary partition is the partition used to install the operating system, which contains the necessary files and data for the operating system to boot.
It must be passed in order to start. To install an operating system on a hard disk, there must be at least one primary partition on the hard disk and set to
Active partition to boot the system. A hard disk can only be divided into up to 4 primary partitions.
Extended partition
Extended partition is the type of partition that users use when creating more than 4 partitions. Extended partitions cannot be used to store data directly.
And is only used to partition logical partitions An extended partition can contain multiple logical partitions, which can be high for its logical partition.
Level format and assign a drive letter to it. For example, when a user wants to create five partitions for a hard disk, if all of them are created as the primary
Partition, the system can only recognize 4, which can not meet our needs. At this point, you can create three primary partitions and another
Expand the partition, and then create 2 logical partitions under the extended partition.
Logical partition
Logical partitions are divided from extended partitions and are mainly used to store data. Up to 23 logic can be created in an extended partition
Partition, each logical partition can get a unique drive letter from D to Z.
Active partition
The active partition is the partition used to load system startup information. The primary partition needs to be activated as the active partition before the operation can be started normally.
Make a system. If none of the primary partitions on the hard drive is set as the active partition, the hard drive will not boot properly.
Hard disk partition format
The hard disk partition format is the file system format. The file system format is used by the operating system to identify files on disk or partition
Different partition formats use different file management mechanisms to store and read file data, while
Different operating systems need the support of different file system formats.
At present, there are mainly three commonly used partition formats, namely, FAT16 format, FAT32 format and NTFS format.
They are introduced.
FAT16 format
FAT16 format is the disk partition format used in MS-DOS and early Windows 95 operating systems. It uses 16-bit file division.
Matching table, also known as FAT format. FAT16 is no longer applicable to current operating systems.
FAT32 format
FAT32 format uses a 32-bit file allocation table, has a strong ability to manage disks, and supports Windows XP and its previous parts.
Windows operating system.
NTFS format
NTFS is a hard disk partition format specially designed for management security features such as disk quotas, file encryption and network applications. Its
The advantage is that the security and stability are very good, it is not easy to produce file fragments in the process of use, and can carry out the operation of the user.
Record, through very strict restrictions on user permissions, so that each user can only operate in accordance with the permissions assigned by the system
Fully protect the system and data security, if you want to install Windows 7 or Windows 8 must be in NTFS format.
Simply implement a LVM logical volume implementation process:
1. Create a partition
First create a disk partition, here using the SCSI hard drive, and the system already has three primary partitions, so we can only create an extended partition and create a logical partition on the extended partition. I use the fdisk tool for partitioning.
# fdisk / dev/sda
Note that the partition type must be 8e, otherwise the use of LVM logical volumes cannot be supported. After partitioning, it is best to enter p to view the created partition and type, and finally save and exit. Here I created / dev/sda5 and / dev/sda6 logical partitions with sizes of 7G and 3G, respectively.
2. Create a physical volume
The command is pvcreate, and we can create the two partitions created above as physical volumes, or we can first create only one partition as a physical volume.
# pvcreate / dev/sda5 / dev/sda6
3. Create a volume group
The command is vgcreate to create the two physical volumes created above as a volume group
# vgcreate myvg / dev/sda5 / dev/sda6
Note:
Myvg is the logical name of the volume group that is specified and can be set at will. The next step is to add the created physical volume to the volume group, or we can add only one physical volume to the volume group until we want to add another physical volume. Note the concept of PE (4m by default), which means that all logical volumes created on a volume group are expanded or shrunk in 4MB increments. PE size determines the maximum size of logical volumes. 4MB's PE determines that the maximum capacity of a single logical volume is 256GB. If you want to use logical volumes larger than 256g, specify a larger PE when creating volume groups. The PE size ranges from 8KB to 512MB and must always be a multiple of 2. If you want to specify the PE size, you only need to add the-s option, specify the PE size, column:
# vgcreate-s 16m myvg / dev/sda5 / dev/sda6. Here the PE size is specified as 16m.
4. Activate the volume group
To use the volume group immediately without restarting the system, you can use the vgchange command to activate the volume group
# vgchage-ay myvg
5. Create a logical volume
The command to create a logical volume is lvcreate, and we create a 6G logical volume on the myvg volume group
-L to specify the size of the logical volume;-n to specify the name of the logical volume
# lvcreate-L 6G-n mylv myvg
6. Format logical volume partitions
Here I am using a file system in ext3 format
# mke2fs-j / dev/myvg/mylv
Create a mount point to mount on the created logical volume partition
# mkdir / mylv
# mount / dev/myvg/mylv / mylv
Expand the content.
1. Add a new physical volume to the volume group
When we create a new physical volume and want to add it to the myvg volume group, we need to use the vgextend command.
# vgextend-t myvg / dev/sda7 # first test whether a physical volume can be added
# vgextend myvg / dev/sda7
Here / dev/sda7 represents the new physical volume we created
2. Remove the physical volume from the volume group
To delete a physical volume from a volume group, first make sure that the physical volume to be deleted is not used by any logical volume, and then use the pvdisplay command to view a physical volume information:
If a physical volume is being used by a logical volume, you need to back up the data of that physical volume somewhere else and then delete it. The command to delete the physical volume is vgreduce:
# vgreduce myvg / dev/sda7 for simplicity here, remove the newly added / dev/sda7 from the volume group
Note:
If we create a volume group that contains two physical volumes, one 7G (/ dev/sda5) and one 3G (/ dev/sda6), and we already have 6G data on our LV, then we cannot remove / dev/sda5, because removing / dev/sda5 is bound to corrupt the data. And we're not sure if the data is all on / dev/sda5, and we can't rashly remove / dev/sda6. If you need to remove / dev/sda6, you should first move the data above / dev/sda6 to other physical volumes of the same volume group, and then remove / dev/sda6. This requires the use of the pvmove command, which is as follows
# pvmove / dev/sda6 # there is no need to specify that the data be moved to that disk, it will automatically move the data to the same group of physical volumes
# vgreduce myvg / dev/sda6 removes physical volume 6
3. Delete logical volumes
When deleting a logical volume, unmount it before deleting it. Here we will take the newly created logical volume as an example for a brief explanation.
# umount / dev/myvg/mylv
# lvremove / dev/myvg/mylv
Do you really want to remove active logical volume mydata? [y/n]: y
4. Expand the logical volume size
The command to expand the logical volume size is lvextend. We still have 4G capacity left when we create the logical volume, so the steps to add another 2G capacity to it are as follows
# lvextend-L 8G / dev/myvg/mylv
Or increase the 1G capacity like this.
# lvextend-L + 2G / dev/myvg/mylv
After increasing the capacity of the logical volume, our physical boundary is expanded, and we can see that the size of the logical volume has not changed because the logical boundary has not been extended. So we need to extend the logical boundaries of the logical volume, with the following command
# resize2fs / dev/myvg/mylv # does not need to be resized here, but will be automatically extended to the extended physical boundary
5. Reduce the size of logical volumes
You need to unmount the file system first. It is important to note that our data files may be affected when shrinking, so reducing the size of logical volumes is generally not recommended. The size we use here is the size of the logical volume after adding 1G, which we reduced to 5G. The steps are as follows
# umount / dev/myvg/mylv
# e2fsck-f / dev/myvg/mylv # forcibly detect logical volumes
# resize2fs / dev/myvg/mylv 5G # resize logical volumes
# lvreduce-L 5G / dev/myvg/mylv # reduce the size of logical volumes
Or
(# lvreduce-L-2G / dev/myvg/mylv)
# mount / dev/myvg/mylv / mylv
# df-lh # View the size of each disk
Description: when we reduce, we need to use the e2fsck command to forcibly detect the logical volume, then use the resize2fs command to adjust the logical volume size, and finally use lvreduce to reduce the logical volume size.
A brief introduction to common commands:
1. Commands related to physical volumes
Pvcreate # create a physical volume
Pvremove # remove physical Volume
Pvmove # move data from physical volumes
Pvscan # scan physical volumes
Pvdisplay # View information about physical volumes
For example:
# pvdisply # View all physical volume information
# pvdisply / dev/sda5 # View only the information of specific physical volumes
Pvs # simply view physical volume information
2. Volume group related commands
Vgcreate # create a volume group
-s: specify the PE size. The default PE size is 4m.
Vgdisplay # View volume group information
Vgextend # expand the volume group size
-t: check whether the defined physical volume can be added
Vgreduce # reduce the volume group size
-t: check whether the specified physical volume can be removed
Vgscan # scan volume group
Vgs # View simple information about volume groups
3. Logical volume related commands
Lvcreate # create logical volumes
-L: specify the size of the logical volume to create
-n: specifies the name of the logical volume
Lvdisplay # View the information of logical volumes
Lvremove # remove logical Volume
Lvreduce # reducing the size of logical volumes
Lvextend # expand logical volume size
Lvs # simply view the information of logical volumes
Second, create a learning chapter
First create the PV, then combine the PV into VG, and finally divide the VG into LV.
1. Create a partition
Use partition tools (such as fdisk, etc.) to create LVM partitions, and note that the partition type of LVM is 8e.
Use fdisk to create partitions and enter partition management according to the absolute path of the device file (/ dev/sda)
Note: be sure to specify the partition format as 8e, which is the partition format of LVM
2. Create a physical volume (PV)
Format: pvcreate device name
View the results:
Format: pvdisplay device name
Format: pvs
3. Create a volume group (VG)
Format: vgcreate VGNAME PV name...
Vgcreate-s PE can specify PE size
View the results:
Format: vgdisplay device name
Format: vgs
4. Create a logical volume (LV)
Format: lvcreate-L SIZE-n LV_NAME VG_NAME
(description:-L specifies the size of logical volumes,-n specifies logical volume names, volume group names-l specifies the number of PE)
View the results:
Format: lvdisplay
Format: lvs
5. LV formatting and mounting
The next step is to format the LV (using mke2fs for the format operation) before LV can store the data
Note: device file path of logical volume: / dev/VG_NAME/LV_NAME
/ dev/mapper/VG_NAME-LV_NAME
III. Management Learning Chapter
1. Extend VG
First prepare a PV, and then use the vgextend command to complete the extension
Command format: vgextend VG_NAME / PATH/TO/PV
2. Reduce VG
First determine the PV to be removed, then transfer the data on this PV to another PV, and finally remove the PV from the volume group
Command format:
Mobile data: pvmore area to disk area
Remove VG:vgreduce VG_NAME / PATH/TO/PV
Note: be sure to transfer the data to another extent before removing the physical volume.
3. Delete PV
Command format: pvremove
4. Expand the logical volume
First of all, how big is the expansion? Then make sure that the volume group of the current logical volume has enough space available, and finally expand: method:
One: extend the physical boundary: lvextend-L [+] SIZE / path/to/lv
(note: "+" can be saved, in which "+" means expanded, and no "+" means expanded)
Second, extend the logical boundary: resize2fs/path/to/device
5. Reduce the logical volume
Because the reduction of logical volumes is risky, the first step is to determine how big the reduction is. In other words, it can at least accommodate the original data, and the second step is to reduce it; reduction requires three steps:
A), uninstall and forcibly detect the file system
Command: e2fsck-f
B), logical boundary
Command: resize2fs/path/to/device SIZE
C), physical boundary
Command: lvextend-L [+ / -] SIZE / path/to/lv
D), view the results
6. Snapshot volume (just the way to do the original, cannot be modified, cannot be written)
Lvcreate
-s: specify snapshot volume
-p r: limit snapshot volumes to read-only access
Format: lvcreate-L SIZE-s-p r-n LV_NAME / path/to/lv
7. Restore the system by using the snapshot function of LV
# lvcreate-L 50m-s-pr-n mylv-snap / dev/myvg/mylv [create Snapshot mylv-snap]
# mount-o ro / dev/myvg/mylv-snap / media [Mount Snapshot]
# tar-jcv-f / backup/lvm.tar.bz2 / media/* [backup snapshot data]
# umount / media
# lvremove / dev/myvg/mylv-snap
Modify the data in / dev/myvg/mylv at will.
Restore:
# tar-jxv-f / backup/lvm.tar.bz2-C / mnt [restore snapshot backup data to lvm]
8. Remove logical and snapshot volumes
First, make sure that the logical volume has been unmounted.
Format: lvremove / path/to/lv
9. Remove volume group
Format: vgremove/path/to/lv
Summary: LVM logical volumes are a great space usage mechanism in Linux, because partitions cannot be enlarged or reduced without formatting. You can use LVM to make your disk space flexible.
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.