Files
chill_notes/Linux/CentOS/CentOS调整分区大小.md
2026-04-21 20:34:54 +08:00

142 lines
1.8 KiB
Markdown
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# CentOS 调整分区大小
> 将 /home 分区空间调整到 /root 分区
---
## 1. 查看当前分区
```bash
df -h
```
```bash
vgdisplay
```
查看空闲磁盘大小(`Free PE / Size`
---
## 2. 备份 home 分区
```bash
tar cvf /tmp/home.tar /home
```
---
## 3. 卸载 /home
如果无法卸载,先终止使用 /home 的进程:
```bash
fuser -km /home/
umount /home
```
---
## 4. 删除 home 所在的 LV
```bash
lvremove /dev/mapper/centos-home
```
> ⚠️ 确认已备份!
---
## 5. 扩展 root 所在的 LV
```bash
# 扩展 50GB根据实际空闲空间调整
lvextend -L +50G /dev/mapper/centos-root
```
---
## 6. 扩展 root 文件系统
```bash
# XFS 文件系统
xfs_growfs /dev/mapper/centos-root
# 如果是 ext4
# resize2fs /dev/mapper/centos-root
```
---
## 7. 重新创建 home LV
```bash
# 创建 50GB 的 home根据实际需求调整
lvcreate -L 50G -n /dev/mapper/centos-home
```
---
## 8. 创建文件系统
```bash
mkfs.xfs /dev/mapper/centos-home
```
---
## 9. 挂载 home
```bash
mount /dev/mapper/centos-home
```
---
## 10. 恢复 home 文件
```bash
tar xvf /tmp/home.tar -C /home/
```
---
## 完整流程
```bash
# 1. 备份
tar cvf /tmp/home.tar /home
# 2. 卸载
umount /home
# 或强制终止
fuser -km /home/
# 3. 删除旧 LV
lvremove /dev/mapper/centos-home
# 4. 扩展 root LV
lvextend -L +50G /dev/mapper/centos-root
# 5. 扩展文件系统
xfs_growfs /dev/mapper/centos-root
# 6. 创建新 home LV
lvcreate -L 50G -n /dev/mapper/centos-home
# 7. 创建文件系统
mkfs.xfs /dev/mapper/centos-home
# 8. 挂载
mount /dev/mapper/centos-home
# 9. 恢复
tar xvf /tmp/home.tar -C /home/
```
---
> ⚠️ **操作前务必备份数据!**
> 参考:[CentOS 分区调整](https://www.jianshu.com/p/27c87f390175)