In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to create and manage LVM volumes in linux related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe you will have a harvest after reading this article on how to create and manage LVM volumes in linux, let's take a look.
LVM (Logical Volume Manager) logical volume management is a disk management technology implemented above the Linux2.4 kernel. It is a mechanism for managing disk partitions in Linux environment. Now it is not only on Linux systems that LVM disk management mechanism can be used, for other UNIX-like operating systems, as well as windows operating systems, there are similar disk management software like LVM.
The working principle of LVM is actually very simple, it is through the underlying physical hard disk abstractly encapsulated, and then presented to the upper application as a logical volume. In the traditional disk management mechanism, our upper application accesses the file system directly to read the underlying physical hard disk, while in LVM, it encapsulates the underlying physical hard disk. When we operate on the underlying physical hard disk, it is no longer aimed at the partition, but through something called a logical volume to manage the underlying disk. For example, when I add a physical hard disk, the upper service is not felt, because what was presented to the last service was in the form of a logical volume. LVM uses a hierarchical structure, as shown in the following figure.
At the top of the figure, first is the actual physical disk and its partitions and the physical volumes on it (PV). One or more physical volumes can be used to create volume groups (VG). Logical volumes (LV) can then be created based on volume groups. As long as there is space available in the volume group, you can create logical volumes at will. The file system is created on a logical volume and can then be mounted and accessed on the operating system.
LVM test description
We will be divided into two parts. In the first part, we first create multiple logical volumes on a hard disk and mount them in the / lvm-mount directory. Then we will resize the created volume. In the second part, we will add additional volumes to LVM from another hard drive.
Prepare the disk partition
Create a disk partition by using fdisk. We need to create three 1G partitions, and note that the partitions are not required to be the same size. Similarly, partitions need to use the'8e 'type to make them available for LVM.
# fdisk / dev/sdbCommand (m for help): n # # New Command action e extended p primary partition (1-4) p # # Primary Partition Partition number (1-4): 1 # # Partition number First cylinder (1-1044, default 1): # # default 1Last cylinder for carriage return, + cylinders or + size {Kjinger Mjorg} (1-1044) Default 1044): + 1G # # size Command (m for help): t # # change type Selected partition 1Hex code (type L to list codes): 8e # # LVM partition code Changed system type of partition 1 to 8e (Linux LVM)
Repeat the above to create the other two partitions. After the partition is created, we should have output similar to the following:
# fdisk-l Device Boot Start End Blocks Id System/dev/sdb1 1 132 1060258 + 8e Linux LVM/dev/sdb2 133264 1060290 8e Linux LVM/dev/sdb3 265 396 1060290 8e Linux LVM prepare physical Volume (PV)
The partition you just created is used to store physical volumes. LVM can use physical volumes of different sizes.
# pvcreate / dev/sdb1# pvcreate / dev/sdb2# pvcreate / dev/sdb3
Use the following command to check the creation of physical volumes. The following intercepts some of the output. "/ dev/sdb2" is a new "1.01 GiB" physical volume.
# pvdisplay-NEW Physical volume-PV Name / dev/sdb2 VG Name PV Size 1.01 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID jszvzz-ENA2-g5Pd-irhV-T9wi-ZfA3-0xo092
Use the following command to delete a physical volume.
# pvremove / dev/sdb1 preparation volume group (VG)
The following command is used to create a volume group named 'volume-group1', using / dev/sdb1, / dev/sdb2, and / dev/sdb3.
# vgcreate volume-group1 / dev/sdb1 / dev/sdb2 / dev/sdb3
Use the following command to verify the volume group.
# vgdisplay-Volume group-VG Name volume-group1 System ID Format lvm2 Metadata Areas 3 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 3 Act PV 3 VG Size 3.02 GiB PE Size 4.00 MiB Total PE 774 Alloc PE / Size 0 / 0 Free PE / Size 774 / 3.02 GiB VG UUID bwd2pS-fkAz-lGVZ-qc7C-TaKv-fFUC-IzGNBK
From the output, we can see the volume group usage / total. Physical volumes provide space for volume groups. As long as there is space available in this volume group, we can create logical volumes at will.
Use the following command to delete the volume group.
# vgremove volume-group1 create logical Volume (LV)
The following command creates a logical volume named '1v1' with a size of 100MB. We use small partitions to reduce execution time. This logical volume uses the space of the previously created volume group.
# lvcreate-L 100m-n lv1 volume-group1
Logical volumes can be viewed using the lvdisplay command.
# lvdisplay-Logical volume--LV Name / dev/volume-group1/lv1 VG Name volume-group1 LV UUID YNQ1aa-QVt1-hEj6-ArJX-I1Q4-y1h2-OFEtlW LV Write Access read/write LV Status available # open 0 LV Size 100.00 MiB Current LE 25 Segments 1 Allocation inherit Read ahead sectors auto-currently set to 256 Block device 253VR 2
Now that the logical volumes are ready, we can format and mount them, just like other ext2/3/4 partitions!
# mkfs.ext4 / dev/volume-group1/lv1# mkdir / lvm-mount# mount/ dev/volume-group1/lv1 / lvm-mount/
Once the logical volume is mounted, we can read and write to the mount point / lvm-mount/. To create and mount other logical volumes, we repeat this process.
Finally, we can delete logical volumes with lvremove.
# umount / lvm-mount/# lvremove / dev/volume-group1/lv1 extends a LVM volume
The ability to resize logical volumes is the most useful feature of LVM. This section will discuss how we can extend a logical volume of existence. Next, we will expand the previously created logical volume 'lv1' to 200MB.
Note that after you resize the logical volumes, you also need to match the file system resizing. This extra step varies, depending on the type of file system you created. In this article, we used 'lv1' to create a file system of type ext4, so the operation here is for the ext4 file system. (the ext2/3 file system is the same). The order in which the commands are executed is important.
First, we unmount the lv1 volume
# umount / lvm-mount/
Then, set the size of the volume to 200m
# lvresize-L 200m / dev/volume-group1/lv1
Next, check for disk errors
# e2fsck-f / dev/volume-group1/lv1
After you run the following command to extend the file system, the ext4 information is updated.
# resize2fs / dev/volume-group1/lv1
By now, the logical volume should have been extended to 200MB. We check the status of the LV to verify.
# lvdisplay-Logical volume--LV Name / dev/volume-group1/lv1 VG Name volume-group1 LV UUID 9RtmMY-0RIZ-Dq40-ySjU-vmrj-f1es-7rXBwa LV Write Access read/write LV Status available # open 0 LV Size 200.00 MiB Current LE 50 Segments 1 Allocation inherit Read ahead sectors auto-currently set to 256 Block device 253VR 2
Now, this logical volume can be mounted again, and this method can also be used for other partitions.
Reduce one LVM volume
This section describes how to reduce the size of LVM volumes. The order of commands is equally important. Also, the following command is also valid for the ext2/3/4 file system.
Note that if the size of the logical volume is smaller than the size of the stored data, the data stored later will be lost.
First, unmount the volume.
# umount / dev/volume-group1/lv1 then, detect disk errors. # e2fsck-f / dev/volume-group1/lv1
Next, shrink the file system and update the ext4 information.
# resize2fs / dev/volume-group1/lv1 100M
When finished, reduce the logical volume size
# lvresize-L 100m / dev/volume-group1/lv1
❝
WARNING: Reducing active logical volume to 100.00 MiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce lv1? [y/n]: y Reducing logical volume lv1 to 100.00 MiB Logical volume lv1 successfully resized
Finally, verify the adjusted logical volume size.
# lvdisplay--- Logical volume- LV Name / dev/volume-group1/lv1 VG Name volume-group1 LV UUID 9RtmMY-0RIZ-Dq40-ySjU-vmrj-f1es-7rXBwa LV Write Access read/write LV Status available # open 0 LV Size 100.00 MiB Current LE 25 Segments 1 Allocation inherit Read ahead sectors auto-currently set to 256 Block device 253 Block device 2 extends a volume group
This section discusses ways to extend the volume group by adding a physical volume to the volume group. Let's assume that our volume group 'volume-group1' is full and needs to be expanded. There are no other free partitions on the hard drive (sdb), so we have added another hard drive (sdc). We will see how to add sdc partitions to the volume group to extend.
Detect the current volume group status
# vgdisplay volume-group1--- Volume group-VG Name volume-group1 System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 8 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 0 Max PV 0 Cur PV 3 Act PV 3 VG Size 3.02 GiB PE Size 4.00 MiB Total PE 774 Alloc PE / Size 25 / 100.00 MiB Free PE / Size 749 / 2.93 GiB VG UUID bwd2pS-fkAz-lGVZ-qc7C-TaKv-fFUC-IzGNBK
First, we create a 2GB partition sdc1 of type LVM (8e), as described earlier in the tutorial.
# fdisk / dev/sdcCommand (m for help): nCommand action e extended p primary partition (1-4) pPartition number (1-4): 1First cylinder (1-1044, default 1): Using default value 1Last cylinder, + cylinders or + size {K default G m for help} (1-1044, default 1044): + 2GCommand (m for help): tSelected partition 1Hex code (type L to list codes): 8eChanged system type of partition 1 to 8e (Linux LVM) Command (m for help): wThe partition table has been altered!
Then, we create a physical volume / dev/sdc1
# pvcreate / dev/sdc1
Now that the physical volume is ready, we can simply add it to the existing volume group 'volume-group1'.
# vgextend volume-group1 / dev/sdc1
Use vgdisplay to verify (you can see that the volume group size has increased).
# vgdisplay-Volume group-VG Name volume-group1 System ID Format lvm2 Metadata Areas 4 Metadata Sequence No 9 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 0 Max PV 0 Cur PV 4 Act PV 4 VG Size 5.03 GiB PE Size 4.00 MiB Total PE 1287 Alloc PE / Size 25 / 100.00 MiB Free PE / Size 1262 / 4.93 GiB VG UUID bwd2pS-fkAz-lGVZ-qc7C-TaKv-fFUC-IzGNBK
Note that although we use a separate disk for demonstration, any disk partition of type'8e 'can be used to extend the volume group.
This is the end of the article on how to create and manage LVM volumes in linux. Thank you for reading! I believe you all have a certain understanding of "how to create and manage LVM volumes in linux". If you want to learn more, you are welcome to follow the industry information channel.
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: 291
*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.