How Linux shrinks the lvm root partition

  
 

We all know that lvm can expand the file system online, the function is very convenient, but if the space of one of our partitions is too large, or there is a need to separate a directory in the later use, then Need to use lvm to reduce it, but lvm does not support online shrinkage, you need to uninstall the partition before you can operate. If you happen to need to be reduced, the system must be in the mount state root partition from the time you open it. How to do? An example of this article: After the system is installed, forget to create a separate swap partition, and only the root partition has sufficient space, so you need to separate the space from the system root partition, and then create a swap partition. Solution 1, start through the BIOS setup CD, restart the server to enter rescue mode; 2, select language, keyboard, English, US, and select Local CD/DVD; 3, because lvm does not support online reduction, so do not choose to let rescue The mode automatically mounts the system root partition to /mnt/sysimage, but selects skip skip to open the shell directly. 4. Because the lvm2 service is not automatically enabled in the rescue mode, it needs to be activated after manual activation, as shown below. After that, you can see the system root partition lv_root; # lvm vgchange – ay 5, it is best to forcibly scan and check the partition before shrinking; 6, the experimental environment lv_root partition has 18G, assuming we need 4G space as a swap partition, First, the file system of the lv_root partition is reduced to 14G by the resize2fs command, and then the disk space of the lv_root partition is reduced to 14G by the lvm lvresize command, and finally the file system is forcibly scanned and checked again, so that the entire volume group is successfully made empty. 4G space; 7, after rebooting, enter the system normally, and perform the conventional swap partition creation step. To non This article focuses, then slightly. Summary of the solution to the problem: 1, when found that lvm does not support online expansion, first of all should be associated with "when can the root partition not be mounted? ”, naturally will think of the rescue mode, and do not use the automatic mount root partition to the /mnt/sysimage directory; 2, after entering the rescue mode, found that the volume group vg and logical volume are not visible in the /dev directory Lv, at this time will be associated with "rescue", for the streamlined mode, it should be the default does not open the lvm2 service, so you need to manually activate the service before you can view it; 3, through the lvm vgchange – To the information of the logical volume, and then the steps of shrinking the partition in the normal way, but remember that when the system prompts that some commands for operating the logical volume do not exist, you need to add the lvm command before the command to specify it; If you happen to be accustomed to using the lvreduce command to specify how much capacity to reduce the size of the partition to reduce the size, it is unsuccessful in the current environment, and you must use the lvresize command to redefine the total size of the partition (the total size before the space reduction) The difference is the space of the contraction), in order to succeed, this may be a system bug, because in theory lvreduce and lvresize Lacks distinction.

Copyright © Windows knowledge All Rights Reserved