In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
What the editor wants to share with you this time is how to use logical volume management (LVM) in Linux. The article is rich in content, and interested friends can learn about it. I hope you can get something after reading this article.
Managing disk space is an important daily task for system administrators. Once the disk space is exhausted, a series of time-consuming and complex tasks are required to increase the available disk space in the disk partition. It also needs to be handled offline by the system. Often this task involves installing a new hard disk, booting to recovery mode or single-user mode, creating a partition and a file system on the new hard disk, mounting to a temporary mount point, moving data from a too small file system to a larger new location, modifying the contents of the / etc/fstab file to reflect the correct device name of the new partition, And reboot to remount the new file system to the correct mount point.
I want to tell you that when LVM (logical Volume Management) first appeared in Fedora Linux, I was very resistant to it. My initial reaction was that I didn't need this extra layer of abstraction between me and my device. It turns out that I was wrong, and logical volume management is very useful.
LVM makes disk space management very flexible. It provides features such as increasing disk space reliably to a logical volume and its file system when the file system is mounted and active, and it also allows you to merge multiple physical disks and partitions into a single volume group (VG) that can be divided into logical volumes (LV).
Volume management also allows you to reduce the amount of disk space allocated to a logical volume, but there are two requirements. First, the volume must be unmounted. Second, the space size of the file system itself must be reduced before the volume space is adjusted.
An important hint is that the file system itself must allow resizing operations. When the file system is resized, the EXT2, 3, and 4 file systems all allow resizing offline (unmounted) or online (mounted). You should carefully understand the details of the file systems you plan to resize to verify that they can be fully resized, especially online.
Extend a file system instantly
Before I install a new distribution into my production machine, I always like to run the new distribution in a VirtualBox virtual machine for a while to make sure it doesn't have any fatal problems. One morning a few years ago, I installed a newly released version of Fedora in a virtual machine on my main workstation. I think I have enough disk space to allocate to the primary file system where the virtual machine is mounted. However, I was wrong. I ran out of space on my filesystem when I installed it to about 1/3. Fortunately, VirtualBox detects a state of insufficient disk space, pauses the virtual machine, and then displays an error message that clearly indicates where the problem is.
Note that this problem is not caused by the small size of the virtual machine disk, but because there is not enough space on the host so that the virtual disk on the virtual machine does not have enough space to expand in the logical volume on the host.
Because many current distributions use logical volume management by default, and there is some free space available in my volume group, I can allocate additional disk space to the appropriate logical volumes and then immediately extend the host's file system. This means that I don't have to reformat the entire hard drive, reinstall the operating system or even restart the machine. I simply allocated some free space to the appropriate logical volumes and resized the file system-all while the file system was online and running programs, and the virtual machine used the host file system all the time. After resizing the logical volumes and file systems, I resumed the operation of the virtual machine and continued the installation process as if nothing had happened.
Although you may have never encountered this problem, many people have encountered the problem of running out of disk space when important programs are running. And while many programs, especially Windows programs, are not as well written and flexible as VirtualBox, Linux logical volume management enables it to recover without data loss and does not require a time-consuming installation process.
LVM structure
The disk environment structure of logical volume management is shown in figure 1 below. Logical volume management allows multiple individual hard drives and / or disk partitions to be combined into a single volume group (VG). The volume group can then be subdivided into logical volumes (LV) or used to allocate into a large single volume. A normal file system, such as EXT3 or EXT4, can be created on a logical volume.
In figure 1, two complete physical hard drives and a partition of a third hard disk are combined into a single volume group. Two logical volumes and file systems are created in this volume group, for example, an EXT3 or EXT4 file system can be created on each logical volume.
Figure 1: LVM allows you to combine partitions and entire hard drives into volume groups
Increasing disk space on a host is very simple, and in my experience, such things are rare. The basic steps are listed below. You can also create a complete new volume group or add new space to an existing logical volume, or create a new logical volume.
Add a new logical volume
Sometimes you need to add a new logical volume to the host. For example, when prompted that the / home file system containing the virtual disk of my VirtualBox virtual machine was full, I decided to create a new logical volume to store the virtual machine data including the virtual disk. This frees up a lot of space in my / home file system and also allows me to manage the disk space of the virtual machine independently.
The basic steps to add a new logical volume are as follows:
1 install a new hard drive if necessary.
2 optional: create a partition on the hard drive.
3 create a complete physical volume (PV) or a partition on the hard disk.
4 assign a new physical volume to an existing volume group (VG), or create a new volume group.
5 create a new logical volume (LV) from the volume space.
6 create a file system in the new logical volume.
7 add the appropriate entry in / etc/fstab to mount the file system.
8 Mount the file system.
For a more detailed introduction, we will use an example as an experiment to teach about the Linux file system.
Example
This example shows how to use the command line to extend an existing volume group, add more space to it, create a new logical volume on that space, and then create a file system on the logical volume. This process is always performed on running and mounted file systems.
Warning: only EXT3 and EXT4 file systems can be resized while running and mounted. Many other file systems, including BTRFS and ZFS, cannot do this.
Install the hard disk
If there is not enough space in the volume group on the existing hard disk in the system to increase, you may need to add a new hard disk and then create space to add to the logical volume. First, install the physical hard drive, and then follow the next steps.
Create a physical volume from the hard disk
First you need to create a new physical volume (PV). Using the following command, it assumes that the new hard drive has been allocated as / dev/hdd.
Pvcreate / dev/hdd
It is not necessary to create an arbitrary partition on the new hard drive. The physical volume created will be recognized by the logical volume manager as a newly installed unprocessed disk or a Linux partition of type 83. If you want to use the entire hard drive, there is no special benefit in creating a partition, and the disk space used for metadata can also be used as part of PV.
Extend an existing volume group
In this example, I will extend an existing volume group instead of creating a new one; you can choose another way. After the physical disk has been created, extend the existing volume group (VG) to contain the space for the new PV. In this example, the existing volume group is named: MyVG01.
Vgextend / dev/MyVG01 / dev/hdd
Create a logical volume
First, create a logical volume in the volume group from the existing free space. The following command creates a 50 GB LV. The name of this volume group is MyVG01, and then the name of the logical volume is Stuff.
Lvcreate-L + 50g-- name Stuff MyVG01
Create a file system
Creating a logical volume does not create a file system. This task must be carried out alone. The following command creates an EXT4 file system in the newly created logical volume.
Mkfs-t ext4 / dev/MyVG01/Stuff
Add a file system volume label
Add a file system volume label to make it easier to identify when there is a problem with the file system later.
E2label / dev/MyVG01/Stuff Stuff
Mount the file system
At this point, you can create a mount point and add the appropriate entry to the / etc/fstab file system to mount the file system.
You can also check and verify that the volume created is correct. You can use the df, lvs, and vgs commands to do this.
Resize logical volumes in the LVM file system
Since the first version of Unix, the need for file system extension has been accompanied, and Linux is no exception. With logical volume management (LVM), it is now easier.
1 install a new hard drive if necessary.
2 optional: create a partition on the hard drive.
3 create a complete physical volume (PV) or a partition on the hard disk.
4 assign a new physical volume to an existing volume group (VG), or create a new volume group.
5 create a new logical volume (LV) from the volume space, or extend an existing logical volume with some or all of the space in the volume group.
6 if a new logical volume is created, create a file system on it. If you add space to an existing logical volume, use the resize2fs command to increase the file system to fill the logical volume.
7 add the appropriate entry in / etc/fstab to mount the file system.
8 Mount the file system.
Example
This example shows how to use the command line to extend an existing volume group. It adds about 50GB space to the / Staff file system. This results in a file system that can be mounted, and the EXT3 and EXT4 file systems are instantly available on the Linux 2.6 kernel (and higher). I don't recommend you for any critical system, but it's possible, and I've succeeded many times, even on the root (/) file system. Whether to use your own to handle the risk.
Warning: only EXT3 and EXT4 file systems can be resized while running and mounted. Many other file systems, including BTRFS and ZFS, cannot do this.
Install the hard disk
If there is not enough space in the volume group on the existing hard disk in the system to increase, you may need to add a new hard disk and then create space to add to the logical volume. First, install the physical hard drive, and then follow the next steps.
Create a physical volume from the hard disk
First you need to create a new physical volume (PV). Using the following command, it assumes that the new hard drive has been allocated as / dev/hdd.
Pvcreate / dev/hdd
It is not necessary to create an arbitrary partition on the new hard drive. The physical volume created will be recognized by the logical volume manager as a newly installed unprocessed disk or a Linux partition of type 83. If you want to use the entire hard drive, there is no special benefit in creating a partition, and the disk space used for metadata can also be used as part of PV.
Add a physical volume to an existing volume group
In this example, I will use a new physical volume to extend an existing volume group. After the physical volume has been created, extend the existing volume group (VG) to include the space for the new PV. In this example, the existing volume group is named: MyVG01.
Vgextend / dev/MyVG01 / dev/hdd
Extended logical Volume
First, create a logical volume in the volume group from the existing free space. The following command creates a 50 GB LV. The name of this volume group is MyVG01, and then the name of the logical volume is Stuff.
Lvcreate-L + 50g-- name Stuff MyVG01
Extended file system
If you use the-r option, extending the logical volume will also extend the file system. If you don't use the-r option, you can't do this alone. The following command resizes the file system in the newly resized logical volume.
Resize2fs / dev/MyVG01/Stuff
You can also check and verify that the resized volume is correct. You can use the df, lvs, and vgs commands to do this.
Prompt
Over the past few years, I have learned how to make logical volume management easier. I hope these tips are of value to you.
Unless you have a clear reason to use another file system, an extensible file system is recommended. With the exception of EXT2, 3, and 4, not all file systems support resizing. The EXT file system is not only fast, but also efficient. In any case, if the default parameters do not meet your needs, they (referring to file system parameters) can be tuned by a knowledgeable system administrator.
2 use meaningful volume and volume group names.
3 use EXT file system tags
After reading this article on how to use logical volume management (LVM) in Linux, if you think the article is well written, you can share it with more people.
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.