Record the process of expanding the centos-root directory of the linux server

Problem Description:

Today, I found that the centos-root space of the server is full again, reaching 99%.
insert image description here
Take a look at which files in the root directory take up a lot of space, and delete useless things. Last time, I deleted the cache files under /tmp and solved it temporarily. This time, I found that there is no need to delete them.

cd /
du -h -x --max-depth=1

insert image description here
ps: In fact, there is another way, which is to delete the cache frequently. The default cache location of the system is /root/.cache/. Deleting the files in this directory can generally solve the problem.


Start dynamic expansion

The /media disk has a lot of resources, a total of 1.8T, divided into 100G for /dev/mapper/centos-root

1. The first step is to backup /media

Put it in a directory with enough space, otherwise the backup will fail.

tar cvf media.tar /media/

2. The second step to uninstall

The uninstall command is as follows:

fuser -km /media
umount /media
lvremove /dev/mapper/centos-media

Before uninstalling, make sure that the relevant process has stopped. For example, when I uninstalled, the storage volume was busy.
insert image description here
Use the command fuser -mv /media/ to find the running process, and then kill -9 pid. Mine is because several docker services have been opened, and docker needs to be installed. Stop all.

3. The third step of expansion

Give 300G to centos-root

lvextend -L +300G /dev/mapper/centos-root
xfs_growfs /dev/mapper/centos-root

4. The fourth step is to rebuild the media

1.8T in total, 1.5T left after 300G

lvcreate -L 1.5T -n/dev/mapper/centos-media

5. The fifth step is to create a file system

mkfs.xfs  /dev/mapper/centos-media
mount /dev/mapper/centos-media

6. The sixth step is to restore the file

The backup file is in the home directory, pressurize to restore the file, and then delete the tar package to free up space.

tar xvf /home/media.tar -C /
rm -rf /home/media.tar

I won’t take screenshots later to save time, anyway, I will see it by myself. over!

Guess you like

Origin blog.csdn.net/h363924219/article/details/125885534