centos 6.5 x86_64,因系统分区不当,导致系统根分区空间不足,home分区过剩,想把把多余的home分区的容量调整到了root分区下,方法如下:
1、首先查看磁盘使用情况
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
50G 48G 0 100% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 485M 32M 428M 7% /boot
/dev/mapper/VolGroup-lv_home
240G 410M 228G 1% /home
2、卸载/home
[root@localhost ~]# umount /home
umount /home 如果提示无法卸载,则是有进程占用/home,使用如下命令来终止占用进程:
[root@localhost ~]# fuser -m /home
3、调整分区大小
[root@localhost ~]# resize2fs -p /dev/mapper/VolGroup-lv_home 20G
如果提示运行“e2fsck -f /dev/mapper/VolGroup-lv_home”,则执行相关命令:
[root@localhost ~]# e2fsck -f /dev/mapper/VolGroup-lv_home
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/VolGroup-lv_home: 213/15974400 files (2.3% non-contiguous), 1107321/63894528 blocks
然后重新执行命令:
[root@localhost ~]# resize2fs -p /dev/mapper/VolGroup-lv_home 20G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/VolGroup-lv_home to 5242880 (4k) blocks.
Begin pass 2 (max = 56939)
Relocating blocks XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 1950)
Scanning inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 4 (max = 19)
Updating inode references XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/mapper/VolGroup-lv_home is now 5242880 blocks long.
注:resize2fs 为重新设定磁盘大小,只是重新指定一下大小,并不对结果有影响,需要下面lvreduce的配合
4、挂载上/home,查看磁盘使用情况
[root@localhost ~]# mount /home
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
50G 48G 0 100% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 485M 32M 428M 7% /boot
/dev/mapper/VolGroup-lv_home
20G 395M 19G 3% /home
5、设置空闲空间
使用lvreduce指令用于减少LVM逻辑卷占用的空间大小。可能会删除逻辑卷上已有的数据,所以在操作前必须进行确认。记得输入 “y”
[root@localhost ~]# lvreduce -L 20G /dev/mapper/VolGroup-lv_home注:lvreduce -L 20G的意思为设置当前文件系统为20G;lvreduce -l 20G是指从当前文件系统上减少20G使用lvreduce减小逻辑卷的大小。
WARNING: Reducing active and open logical volume to 20.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 20.00 GiB
Logical volume lv_home successfully resized
注意:减小后的大小不能小于文件的大小,否则会丢失数据。
可以使用vgdisplay命令等查看一下可以操作的大小。也可以是用fdisk -l命令查看详细信息。
[root@localhost ~]# vgdisplay注:vgdisplay为显示LVM卷组的元数据信息
--- 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 297.60 GiB
PE Size 4.00 MiB
Total PE 76185
Alloc PE / Size 18908 / 73.86 GiB
Free PE / Size 57277 / 223.74 GiB
VG UUID NOfYCo-Tr4O-NeoL-nyw1-cvaA-9ar2-1LYa6U
6、把闲置空间挂在到根目录下(这个根据空间大小会等很长时间哈)
[root@localhost ~]# lvextend -L +223G /dev/mapper/VolGroup-lv_root
注:lvextend -L +223G为在文件系统上增加223G
[root@localhost ~]# 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 = 18
Performing an on-line resize of /dev/mapper/VolGroup-lv_root to 71565312 (4k) blocks.
7、最后检查调整结果
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
194G 48G 136G 26% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 485M 32M 428M 7% /boot
/dev/mapper/VolGroup-lv_home
20G 395M 19G 3% /home
貌似空间丢失了一部分啊。。
[root@localhost ~]# fdisk -l
Disk /dev/mapper/VolGroup-lv_root: 293.1 GB, 293131517952 bytes
255 heads, 63 sectors/track, 35637 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000