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

Simple Application of LVM-New-expand-reduce-remove-migrate

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

LVM is the abbreviation of logical disk Volume Management (LogicalVolumeManager). It is a mechanism for managing disk partitions under Linux environment. LVM is a logical layer based on hard disks and partitions. Its biggest feature is to improve the flexibility of disk partition management.

The implementation principle of LVM:

1. Compose the physical disks and partitions in Linux into a physical volume by command (the capacity can be different, and the disks can be used by mixed partitions directly).

2. Create physical volumes into volume groups

3. Split the volume group to form a logical volume (the size of the logical volume is the integral multiple of the PE when allocating the volume group)

Lab (based on centos7):

Lab 1: creating a LVM

1. Let's first create three partitions and change their partition type to Linux LVM

2. Create a PV and view it (pvdisplay or pvs is available for viewing PV status)

(note: the warning here is because I did it with a made disk. Just overwrite it directly. If you do this with a clean disk, this warning will not appear.)

3. Create a volume group vg0, set the PE size to 16m, and view the details of the vg0.

4. Create a logical volume lv0 and use all the volume group space

5. Create a file system for a logical volume and create a mount point to mount it, so that you can use it just like a normal partition

6. Create files casually and use them

Experiment 2: expanding LVM

Logical volumes are very flexible to use, and when there is not enough space, we can directly increase the available space to the logic by increasing the physical volume and directly expanding the size of the volume group.

1. Create a new PV. With pvdisplay, you can see that there are three pv,/dev/sdb3 that are not in use.

2. Use the vgextend command to add pv / dev/sdb3 to the volume group vg0 and check, where the volume group has been increased by 10G.

3. Use the lvextend command to increase the size of the logical volume, using all the available space of vg0

4. Use resize2fs for logical volumes to unify the file system format of the newly added part with the previous one, making it easy to use.

Using the lsblk command, we can see that our logical volume has been increased by 10G.

Experiment 3: reducing logical volumes

1. Unmount and check the logical volume. I am here because there is a lack of an option in the command I executed during the check, which leads to an error and can be re-added.

2. First reduce the size of the space to 20g

3. The disk space size of the logical volume is also reduced to 20g. Then mount it again to see that the size of the logical volume has been reduced to 20g

Experiment 4: remove (you need to remove pv when the disk is broken or something else causes this to be replaced)

1. Before removing it, let's take a look at the details of pv to see if the size and capacity of the disk to be removed is enough to move to other disks.

2. When removing, use pvmove to move the information of the disk to be removed to another disk (no need to indicate where to move, it will find its own location)

Then remove the partition from the volume group vg0

Finally, the partition is removed from the physical volume, and the disk can be pulled out.

Lab 5: migrating logical volumes across hosts

1. First take a look at the details of the logical volume. In order to avoid migrating to other machines with the same command, simply change the name here to newvg0

2. On the source host

(1) Unmount

(2) disable volume group

(3) Export volume group

3. Remove the pv corresponding to the volume group and insert it into the new target host.

4. On the target host

(1) what are the pv on the scanning host

(2) Import a new volume group

(3) activate the volume group

(4) create a new mount point and use it

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