Insufficient disk space allocated by Linux CentOS 7, space expansion method, nanny level operation

Foreword: In the process of learning java, there are more and more projects in the computer, and the space allocated when the system is installed before is too small, resulting in insufficient space in the Linux system. What should I do? Lets go follow me to expand centOS 7.

1. Shut down the virtual machine, find the hard disk in VMWare's "This virtual machine settings", and expand the disk capacity.

        At this point, although the expansion is complete, VMware will prompt you to re-partition. The expanded disk space has not been allocated to the corresponding Linux partition and needs to be allocated by yourself. It is equivalent to making a mark to tell the computer that this part of the disk space is allocated to the virtual machine. Used it for me.

2. Enter df -Th and find that the root space remains unchanged

df -Th

 3. Enter fdisk -l to check the hard disk space of the virtual machine and find that it has become larger (I used to be 20GB, but now it is 30GB. Generally, only sda1 and sda2 have not been expanded. ) Pay attention to the ID 8e of sda2

fdisk -l

 4. Run fdisk /dev/sda , we can enter m for help. It can be found that input n is to add a partition (the so-called partition), and then keep entering to select the default value, and finally you can see that partition 3 has allocated 10G space

 

fdisk /dev/sda

   

 5. Then enter  to change the system id of the partition , and enter L to view all the codes. We can see that the sda2 that you noticed before is 8e. We set it to  8e . You can see that the Linux type has been changed to Linux LVM .

 6. Then enter w to save the table to the disk, and then enter reboot to restart the virtual machine (if you do not restart, there will be problems later)

 7. Type fdisk -l again, we can find that the newly added partition has been set up, but the centos-root space is still not increased, don’t worry, let’s format the partition first

fdisk -l

        format:

mkfs -t ext3 /dev/sda3

 8. Now we create a physical volume pvcreate /dev/sda3 . After the creation is successful, enter pvdisplay , we can see that there is a new physical volume, but there is no data volume group yet

pvcreate /dev/sda3
pvdisplay

 9. We enter df -Tl and we can see that the name we want to expand the file system is centos, and you should also correspond to it.

10. Enter vgextend centos /dev/sda3 ( divide the partition sda3 into the required expansion data volume group, or directly share centos with sda2), enter pvdisplay, we can see the data volume group that belongs to centos, and the allocation of sda3 Allocatable has changed to yes, and there is 10G free space

df -Tl 
vgextend centos /dev/sda3
pvdisplay

 

 11. Enter vgdisplay to view the status of the data volume group, we can see that the total space of the centos data volume is 28.99g, basically the expansion is completed,

 

 12. Enter lvextend -l +100%free /dev/mapper/centos-root to give 100% of the free allocatable space to /dev/mappercentos-root, -l, the lowercase l is the allocation percentage, and the uppercase L is the allocation specific Value, we can see different changes after the allocation is successful.

        //You can also use lvresize -L + 10G /dev/mapper/centos-root . (Pay attention to the size of the expanded memory. If an error is reported, it means that there is no such a large space for expansion. You need to reduce and increase the space. For example, change it to: lvresize -L + 9.9G /dev/mapper/centos-root)

lvextend -l +100%free /dev/mapper/centos-root

 13. Finally, synchronize the system files. xfs_growfs /dev/mapper/centos-root. (cent os 7)

        If it is cent os 6, enter resize2fs to check the help for details.

xfs_growfs /dev/mapper/centos-root

 We can see that centos-root has expanded

Acknowledgments: This article draws on the articles and videos of these two. (891 messages) VMware virtual machine hard disk expansion_vmware virtual machine hard disk expansion_Fangshi Yangmingi's Blog-CSDN Blog

The root partition space of the Centos7 system is small, and the /home space is large. How to delete /home partition and add to / partition_哔哩哔哩_bilibili

Guess you like

Origin blog.csdn.net/xudingzhang/article/details/129905679