Hot Article
- Centos7 closes and restarts the system firewall and opens firewall ports
- How IID server uses Xshell to connect to Linux (centos) server
- BT panel forgets the background login URL, and the solution to the security entrance verification failure
- The php domain name points to ip, how to use the specified ip address to access a server in the url request domain name in curl mode
- How to purchase a dedicated server
- Error connecting to MySQL: Cant connect to MySQL server (10060)
Merge the /home directory into the / directory under CentOS
- Author:Kevin
- Category:Server Maintain
- Release Time:2023-02-01
- Overview
Linux partition background
In Linux, each disk is used in the form of mounting to a directory.
Example:
When disk 1 is mounted to / directory and disk 2 is mounted to /home directory.
When a folder or file is created under the / directory, it is stored in Disk 1, and when a folder or file is created under the /home directory, it is stored in Disk 2.
Specific steps
Check the current disk partition
[root@localhost ~]# df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 925G 47G 879G 6% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 116K 1.9G 1% /dev/shm
tmpfs 1.9G 191M 1.7G 11% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 494M 97M 398M 20% /boot
tmpfs 376M 0 376M 0% /run/user/0
/dev/mapper/centos-home 2.0G 33M 2.0G 2% /home
Note: Just pay attention to the /dev/ directory, and the rest should be handled by the system.
You can see that there are only three here, namely /dev/mapper/centos-root, /dev/sda1, /dev/mapper/centos-home
Unmount /home partition
Back up the content of /home, then delete the logical volume where the /home file system is located, and expand the / file system.
tar cvf /tmp/home.tar /home #Backup/home, there is nothing to back up
- Record how much free space is available under home, such as 2G, and you will need to expand the root directory later
- Uninstall /home
umount /home
# "Logical volume contains a filesystem in use" appears when deleting lvm
- If it cannot be uninstalled, first terminate the process using the /home file system
Delete the lv where /home is located, if it prompts that the file system is in use, terminate the process first, use the command in the first paragraph below to find the process and kill.
fuser -m /dev/mapper/centos-home
kill -9
- Uninstall again
- Delete /home partition
- View lv partition information
lvdisplay
- Delete the lv partition
If the deletion fails, you can delete it again after reboot
lvremove /dev/centos/home
- extensions/directory
- Extend the lv where /root is located to increase the size of /home
lvextend -L +2G /dev/centos/root
# must appear success, failure may be insufficient space
- extension/filesystem
xfs_growfs /dev/centos/root
- Restore files under /home
# cd /
# tar -xvf /tmp/home.ar
Edit /etc/fstab file to delete /home partition
The /home partition must be deleted, otherwise it cannot be started normally.
[root@master etc]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Sat Apr 4 15:25:10 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/centos-root/xfs defaults 0 0
UUID=9cf092ac-81b6-483e-bb48-fd1e5224340b /boot ext4 defaults 1 2
#/dev/mapper/centos-home /home xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
[root@master etc]#
Confirm result
[root@localhost ~]# df -lh
related topic
- How to change the password of Windows server 2008 server?
- How to solve the Windows 10 prompt "The built-in administrator cannot activate this application"?
- IID.HK shares some commonly used IT network online detection websites
- IDGlobal teaches you to disable ICMP protocol on CentOS
- How to block foreign IP access on Linux server?
- How to modify the remote port in CentOS 7 and 8