linux text模式安装CentOS系统,完成之后发现默认分区是这样子的:
[root@cw-gz_d1 ~]# df -lh
文件系统 容量 已用 可用 已用%% 挂载点
/dev/mapper/VolGroup-lv_root
50G 714M 47G 2% /
tmpfs 1.7G 0 1.7G 0% /dev/shm
/dev/sda1 485M 32M 429M 7% /boot
/dev/mapper/VolGroup-lv_home
406G 199M 385G 1% /home
500G的硬盘根分区才50G,/home分区有406G,需要重新调整/home分区和根分区大小
首先卸载/home分区
[root@cw-gz_d1 ~]# umount /home
[root@cw-gz_d1 ~]# df -h
文件系统 容量 已用 可用 已用%% 挂载点
/dev/mapper/VolGroup-lv_root
50G 714M 47G 2% /
tmpfs 1.7G 0 1.7G 0% /dev/shm
/dev/sda1 485M 32M 429M 7% /boot
调整/home分区大小
[root@cw-gz_d1 ~]# resize2fs -p /dev/mapper/VolGroup-lv_home 60G
resize2fs 1.41.12 (17-May-2010)
请先运行 'e2fsck -f /dev/mapper/VolGroup-lv_home'.
[root@cw-gz_d1 ~]# e2fsck -f /dev/mapper/VolGroup-lv_home
e2fsck 1.41.12 (17-May-2010)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要信息
/dev/mapper/VolGroup-lv_home: 11/27000832 files (0.0% non-contiguous), 1745368/107979776 blocks
[root@cw-gz_d1 ~]# resize2fs -p /dev/mapper/VolGroup-lv_home 60G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/VolGroup-lv_home to 15728640 (4k) blocks.
Begin pass 2 (max = 32768)
正在重定位块 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 3296)
正在扫描inode表 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/mapper/VolGroup-lv_home is now 15728640 blocks long.
PS:
1. umount /home 如果提示无法卸载,则是有进程占用/home,使用如下命令来终止占用进程:fuser -m /home
2. resize2fs为重新设定磁盘大小,只是重新指定一下大小,并不对结果有影响,需要下面lvreduce的配合
重新挂载/home分区
[root@cw-gz_d1 ~]# mount /home
[root@cw-gz_d1 ~]# df -h
文件系统 容量 已用 可用 已用%% 挂载点
/dev/mapper/VolGroup-lv_root
50G 714M 47G 2% /
tmpfs 1.7G 0 1.7G 0% /dev/shm
/dev/sda1 485M 32M 429M 7% /boot
/dev/mapper/VolGroup-lv_home
60G 180M 56G 1% /home
设置空闲空间
[root@cw-gz_d1 ~]# lvreduce -L 60G /dev/mapper/VolGroup-lv_home
WARNING: Reducing active and open logical volume to 60.00 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_home? [y/n]: y
Reducing logical volume lv_home to 60.00 GiB
Logical volume lv_home successfully resized
[root@cw-gz_d1 ~]# vgdisplay
--- Volume group ---
VG Name VolGroup
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size 465.27 GiB
PE Size 4.00 MiB
Total PE 119109
Alloc PE / Size 29020 / 113.36 GiB
Free PE / Size 90089 / 351.91 GiB
VG UUID hdzu3E-n4Bk-kACP-4imC-dkhN-MKDo-dWdBbc
PS:
1.lvreduce -L 60G的意思为设置当前文件系统为60G,如果lvreduce -l 60G是指从当前文件系统上减少60G
2.使用lvreduce减小逻辑卷的大小。减小后的大小不能小于文件的大小,否则会丢失数据。
3.可以使用vgdisplay命令等查看一下可以操作的大小。也可以是用fdisk -l命令查看详细信息。
把空闲空间挂载到根目录
[root@cw-gz_d1 ~]# lvextend -L +351G /dev/mapper/VolGroup-lv_root
Extending logical volume lv_root to 401.00 GiB
Logical volume lv_root successfully resized
[root@cw-gz_d1 ~]# resize2fs -p /dev/mapper/VolGroup-lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/VolGroup-lv_root is mounted on /; on-line resizing required
old desc_blocks = 4, new_desc_blocks = 26
Performing an on-line resize of /dev/mapper/VolGroup-lv_root to 105119744 (4k) blocks.
The filesystem on /dev/mapper/VolGroup-lv_root is now 105119744 blocks long.
[root@cw-gz_d1 ~]# df -h
文件系统 容量 已用 可用 已用%% 挂载点
/dev/mapper/VolGroup-lv_root
395G 733M 374G 1% /
tmpfs 1.7G 0 1.7G 0% /dev/shm
/dev/sda1 485M 32M 429M 7% /boot
/dev/mapper/VolGroup-lv_home
60G 180M 56G 1% /home
PS:
1. 最后执行 resize2fs -p /dev/mapper/VolGroup-lv_root 命令需要很长一段时间,请耐心等待不可中断
2. lvextend -L +351G为在文件系统上增加351G