Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

LVM logical volume management

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

1. What is LVM?

LVM is the abbreviation of logical disk Volume Management (Logical Volume Manager). It is a mechanism for managing disk partitions in Linux environment. LVM is a logical layer built on hard disks and partitions to improve the flexibility of disk partition management.

two。 Why use LVM?

In daily work or study, with the continuous use of computers, our disk space may become smaller and smaller, at this time, we can not directly replace the large hard disk, because the hard disk is valuable, the data is priceless, then we can use LVM LVM virtualizes storage, uses logical volumes, you are not limited by the size of physical disks, and hardware-related storage settings are hidden by it, so you can resize volumes or migrate data without having to stop applying or unmounting file systems. This can reduce the operating cost. The most important feature of LVM is that it can manage the disk dynamically. Because the size of the logical volume can be dynamically resized without losing existing data. If we add a new hard disk, it will not change the existing upper logical volume. As a dynamic disk management mechanism, logical volume technology greatly improves the flexibility of disk management.

How does 3.LVM work?

LVM is to encapsulate the underlying physical hard disk abstractly and then present it 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.

4. Several professional terms

Physical volumes (PV, Physical Volume)

Physical volumes refer to disks, disk partitions or devices that logically have the same function as disk partitions (such as RAID). It is the basic storage logic block of LVM, but compared with basic physical storage media (such as partitions, disks, etc.), it contains management parameters related to LVM. The current LVM allows you to save 0 to 2 metadata copies of this physical volume on each physical volume. The default is 1, saved at the beginning of the device. At 2, save the second backup at the end of the device.

Volume groups (VG, Volume Group)

LVM volume groups are similar to physical hard disks in non-LVM systems and are made up of physical volumes. You can create one or more LVM partitions (logical volumes) on a volume group, which consists of one or more physical volumes.

Logical volumes (LV, Logical Volume)

LVM's logical volumes are similar to hard disk partitions in non-LVM systems, and file systems can be established on top of logical volumes (such as / home or / usr, etc.)

* practical case 1: production of LVM *

0). Open a Shell monitoring device information

Watch-n 1 'pvs; echo =; vgs; echo =; lvs'

1)。 Create three physical partitions and change the partition id to 8e

2)。 Create a physical volume

Pvcreate / dev/vdb {1..3}

3)。 Create a physical volume group

Vgcreate hhh / dev/vdb {1..3}

4)。 Create a logical volume

Extract some space from the physical volume group to generate the logical volume lv0. -L specifies the size of the logical volume, and-n specifies the name of the logical volume

Lvcreate-n lv0-L 1.5G ii

After the logical volume is created successfully, a virtual device file is generated

[root@server0 ~] # ll / dev/mapper/hhh-ii

Lrwxrwxrwx. 1 root root 7 Nov 8 20:38 / dev/mapper/hhh-ii->.. / dm-0

[root@server0 ~] # ll / dev/hhh/ii

Lrwxrwxrwx. 1 root root 7 Nov 8 20:38 / dev/hhh/ii->.. / dm-0

* actual combat case 2: application of logical volumes *

1)。 Format logical volume device

Mkfs.ext4 / dev/westos/lv0

2)。 Mount the device to the file system

Mkdir / lvm

Mount / dev/westos/lv0 / lvm/

3)。 Edit boot auto mount

Mount | tail-1

Vim / etc/fstab

"

/ dev/mapper/westos-lv0 / lvm ext4 defaults 0 0

"

* practical case 3: stretching and shrinking of logical volumes in ext format *

The power of LVM is that it can support online expansion (stretching), but not online reduction. The adjustment command for the ext2/ext3/ext4 file system is resize2fs (both increase and decrease are supported)

Common commands: lvextend, resize2fs

3.1 stretch logical Volume

Goal: how to achieve stretching logical volumes to 1.8G?

1)。 Determine if the volume group has enough space to stretch?

Vgs

2)。 Logical volume stretch command

Lvextend-L 1.8g / dev/westos/lv0

Lvextend-L + 300m / dev/westos/lv0

3)。 View the size of the extruded space

Lvs # check whether the size of the logical volume device is stretched successfully

Df-h # check whether the size of the file system is stretched successfully

4)。 Update the file system

Resize2fs / dev/westos/lv0

5)。 View the updated file system

Df-h

3.2 stretch physical volume group

Goal: how to achieve stretching logical volumes to 3.5G?

0). Determine if the volume group has enough space to stretch?

Vgs

1)。 Create a physical volume

Pvcreate / dev/vdb5

2)。 Add / stretch a new physical volume to a physical volume group

Vgextend westos / dev/vdb5

3)。 View the physical volume group size after stretching

Vgs

4)。 Stretch the logical volume and perform the contents of the 3.1 experiment

Lvextend-L 3.5g / dev/westos/lv0

Df-h

Resize2fs / dev/westos/lv0

Df-h

Man resize2fs

3.3 shrinking logical volumes

1)。 Unmount the logical volume being mounted

Umount / lvm

2)。 Verify the file system

E2fsck-fv / dev/westos/lv0

3)。 Shrink the file system to 1G

Resize2fs / dev/westos/lv0 1G

4)。 Shrink the logical volume

Lvreduce-L 1G / dev/westos/lv0

Remount the device to see if the reduction is effective?

5)。 Check if there are any free partitions in the volume group? If so, remove the free partition.

Vgreduce westos / dev/vdb {3,5}

Pvremove / dev/vdb {3,5}

* practical case 4: stretching of logical volumes in xfs format (cannot be reduced) *

Goal: how to achieve stretching logical volumes to 1.8G?

1)。 Determine if the volume group has enough space to stretch?

Vgs

2)。 Logical volume stretch command

Lvextend-L 1.8g / dev/westos/lv0

Lvextend-L + 300m / dev/westos/lv0

3)。 View the size of the extruded space

Lvs # check whether the size of the logical volume device is stretched successfully

Df-h # check whether the size of the file system is stretched successfully

4)。 Update the file system

Xfs_growfs / dev/westos/lv0

5)。 View the updated file system

Df-h

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report