Linux logical volume related!

Recently, I was working on a basic construction project, which involved a problem of extending VG.

 

There is nothing wrong with extending the VG itself, but it seems a little special to the problem I encountered. . .

Phenomenon:

When installing a Linux virtual machine, there was a 200G disk, but only 160G was used when partitioning, leaving 40G, and then the 160G disk was made into LVM, and now I hope to add the unused 40G to the VG (volume group) inside.

 

Investigation: In order to do the above, I found some information on the Internet. Understand the principle and configuration process of LVM

1. Create a logical volume

①Format the physical hard disk into PV (physical volume) using the pvcreate command

②Create a volume group (VG) and add PV to the volume group through the vgcreate command

③ Create a logical volume (LV) based on the volume group (VG) through the lvcreate command

2. Use formatted logical volumes

mkfs.ext4 /dev/xiaoluo/mylv

3. Delete the logical volume

① First unmount the logical volume in use through the umount command

②Delete the logical volume first through the lvremove command

③ Delete the volume group through the vgremove command

④ Finally, delete our physical volume through the pvremove command

4. Stretch the logical volume (stretching of the logical volume can be done online, no need to unmount to the logical volume)

①Check the information of the current VG and ensure that there is enough free space in the VG through the vgdisplay or vgs command

②Extend the logical volume through the lvextend command

③ After viewing the expansion, after the LV size is expanded, we can use the lvdisplay or lvs command to view the current lv information

④Update the file system through the resize2fs command

5. Stretch roll set

①Format the hard disk to be added to the VG as PV through the pvcreate command

②Add the new PV to the specified VG through the vgextend command

③ View the information of the current VG through the vgdisplay or vgs command

6. Shrink the logical volume

①Unmount the mounted logical volume through the umount command

② Shrink the file system (you will be prompted to run fsck to check the file system) through the resize2fs command

③Reduce LV through lvreduce command

The operation of shrinking a logical volume is a dangerous operation. If we are not careful, our logical volume may be damaged, resulting in the loss or damage of files, so we generally do not shrink the logical volume! ! !

Finally, one more point: the operation of shrinking the logical volume must first unmount the logical volume, then shrink the file system first, and finally shrink our logical volume! !

7. Shrink the volume group

①First of all, we must also unmount our logical volume   through the umount command

②Remove a PV from the specified volume group through the vgreduce command

View the information of the current volume group through the vgdisplay or vgs command

④Delete the PV through the pvremove command

Envisioned solution:

 Based on the above learning, I plan to make the remaining 40G a virtual device first. So the above phenomenon is simulated locally.

1. Add a new disk /dev/sdd (16G)

2. Divide the disk into two logical partitions /dev/sdd1(4G), /dev/sdd2(8G)

3. Make these two partitions into PV, which can be successfully made

4. Based on the above pv, create a volume group VG

5. Create LV based on VG

6. Make the remaining 4G in /dev/sdd into /dev/sdd3, and use the Pvcreate command to create a physical volume, and it prompts that the creation cannot be successful. It seems that there is no way to put the remaining 4G into the volume group.

7. Recreate a virtual disk /dev/sde. The pvcreate command creates a physical volume, which can be successfully created or added to the VG.

 

result:

Unsuccessful : Make the remaining 4G in /dev/sdd into /dev/sdd3, and use the Pvcreate command to create a physical volume, and it prompts that the creation cannot be successful. It seems that there is no way to put the remaining 4G into the volume group.

Success: recreate a virtual disk /dev/sde, pvcreate command creates a physical volume, which can be successfully created or added to VG

 

refer to:

The documentation below is really well written and detailed

http://www.cnblogs.com/xiaoluo501395377/archive/2013/05/22/3093405.html

CentOS for Linux Learning (25)--Linux Disk Management: Basic Concepts of LVM Logical Volumes and How LVM Works

CentOS for Linux Learning (26)--Linux Disk Management: Creation and Use of LVM Logical Volumes

CentOS for Linux learning (27)--Linux disk management: stretching and shrinking of LVM logical volumes

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326343740&siteId=291194637