CentOS 7 uninstall home to expand the root Space

Source: Internet
Author: User

CentOS 7 uninstall home to expand the root Space

Background: Check the gitlab backup server and find that the backup files in the last few days have not been uploaded to this server according to the settings.

Because this server is newer, there are no other files except the received backup files, so inode is not enough to be ruled out first, but the backup file is about 40 Gb +, the server clearly allocates GB of space.

So I ran the backup file command manually on the server where gitlab is located, and "No space left on device" appeared ".

Insufficient space? So I checked the occupied space on the backup server.

df -h

It is found that although the disk space of centos GB is provided, root only has 50 GB of available space, and most of the remaining space is allocated to/home.

After searching for the information, we learned that the default root size of centos7 is 50 GB. That is to say, if the hardware allocation exceeds 50 GB, most of the remaining space will be allocated to home.

If the software is installed in the/usr/local directory and data files are also configured in the root directory, you must adjust the root size after installation, otherwise, the disk space may be insufficient after running for a period of time.

It seems that this is indeed caused by insufficient disk space. Anyway, I don't need to install any services in this virtual machine. If you can remove the home, and then give the root space to solve the problem. So I searched for the information and sorted out the solution based on the actual situation.

1. Uninstall home

1.1 back up the home partition File

tar cvf /tmp/home.tar /home

1.2 modify fstab (this step is very important and never miss it)

Prepare to uninstall the/home file system. When centos is started, the/etc/fstab content will be checked one by one. Because fstab has/home by default, if fstab is not modified, after restart, you will find centos kneeling.

 

Therefore, comment out/home before uninstalling it, so that the system will not check/home at startup.

yum install -y vim
vim /etc/fstab

Add a annotator to/home content, and wq is saved.

#/dev/mapper/centos-home /home                   xfs     defaults        0 0

1.3 install psmisc

yum install -y psmisc

// The Psmisc package contains three programs that help manage the/proc directory. Install the following programs: fuser, killall, pstree, and pstree. x11 (link to pstree)

// Fuser displays the PID of the process that uses the specified file or file system.

// Killall kills a named process and sends a signal to all processes running the specified command.

// The pstree Tree displays the currently running processes.

// Pstree. x11 has the same function as pstree, but must be confirmed before exiting.

1.4 uninstall/home File System

umount /home

If you are prompted that the process cannot be uninstalled because the process occupies/home, you can use the following command to stop the process.

fuser -km /home/

1.5 Delete the lv of/home

lvremove /dev/mapper/centos-home

Then the confirmation content appears. Enter "y" and press Enter.

 

Ii. Expand root

2.1 lv of the extension/root

Because the previous/home space occupied 47 GB, I would like to add these spaces to/root.

lvextend -L +47G /dev/mapper/centos-root

However, we found that the available space is not 47 GB. The system should be rounded down and changed to 48100 MB.

The reason for not setting the available space accurately is that I am not familiar with how to obtain the available space, instead of taking the time to learn about it, I would rather waste a little space (after all, dozens of MB of mechanical hard drives are not worth much, even enterprise hard drives ).

lvextend -L +48100M /dev/mapper/centos-root

The following content indicates that the lv of/root has been expanded to 96.97 GB.

2.2 extension/root file system

xfs_growfs /dev/mapper/centos-root

 

In the figure, the values of 13107200 and 25420800 are calculated based on the file size, which is inconsistent with those of 50G and G. The problem should be put on hold first, and you can check the information later.

2.3 check/root file system space

df -h

We can see that/root has been upgraded from 50 GB to 97 GB.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.