linux(centos 6) 调整挂载分区大小

xingzhegu 2013-07-18

安装centos6使用自动推荐分区,发现一个问题/home 分区过大。

目标:/home分20G,剩下添加给/目录下

1.查看分区模式

  1. [root@localhost ~]# df -h
  2. 文件系统 容量 已用 可用 已用%% 挂载点
  3. /dev/mapper/VolGroup-lv_root
  4. 50G 2.9G 44G 7% /
  5. tmpfs 5.9G 100K 5.9G 1% /dev/shm
  6. /dev/sda1 485M 37M 423M 8% /boot
  7. /dev/mapper/VolGroup-lv_home
  8. 1.1T 200M 988G 1% /home

2.卸载挂载分区

  1. [root@localhost ~]# umount /home

3.检查VolGroup-lv_home文件的错误性,-f 即使文件系统没有错误迹象,仍强制地检查正确性。

  1. [root@localhost ~]# e2fsck -f /dev/mapper/VolGroup-lv_home
  2. e2fsck 1.41.12 (17-May-2010)
  3. 第一步: 检查inode,块,和大小
  4. 第二步: 检查目录结构
  5. 第3步: 检查目录连接性
  6. Pass 4: Checking reference counts
  7. 第5步: 检查簇概要信息
  8. /dev/mapper/VolGroup-lv_home: 27/69304320 files (0.0% non-contiguous), 4400705/277215232 blocks

4.调整/home为20G,

  1. [root@localhost ~]# resize2fs -p /dev/mapper/VolGroup-lv_home 20G
  2. resize2fs 1.41.12 (17-May-2010)
  3. Resizing the filesystem on /dev/mapper/VolGroup-lv_home to 5242880 (4k) blocks.
  4. Begin pass 2 (max = 32784)
  5. 正在重定位块 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  6. Begin pass 3 (max = 8460)
  7. 正在扫描inode表 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  8. Begin pass 4 (max = 15)
  9. 正在更新inode引用 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  10. The filesystem on /dev/mapper/VolGroup-lv_home is now 5242880 blocks long.

5.重新挂载并查看

  1. [root@localhost ~]# mount /home
  2. [root@localhost ~]# df -h
  3. 文件系统 容量 已用 可用 已用%% 挂载点
  4. /dev/mapper/VolGroup-lv_root
  5. 50G 2.9G 44G 7% /
  6. tmpfs 5.9G 100K 5.9G 1% /dev/shm
  7. /dev/sda1 485M 37M 423M 8% /boot
  8. /dev/mapper/VolGroup-lv_home
  9. 20G 172M 19G 1% /home

6.划分20G外面的剩余空间。使用lvreduce指令用于减少LVM逻辑卷占用的空间大小。可能会删除逻辑卷上已有的数据,所以在操作前必须进行确认。记得输入 “y”

  1. [root@localhost ~]# lvreduce -L 20G /dev/mapper/VolGroup-lv_home
  2. WARNING: Reducing active and open logical volume to 20.00 GiB
  3. THIS MAY DESTROY YOUR DATA (filesystem etc.)
  4. Do you really want to reduce lv_home? [y/n]: y
  5. Reducing logical volume lv_home to 20.00 GiB
  6. Logical volume lv_home successfully resized
  1. [root@localhost ~]# df -h
  2. 文件系统 容量 已用 可用 已用%% 挂载点
  3. /dev/mapper/VolGroup-lv_root
  4. 50G 2.9G 44G 7% /
  5. tmpfs 5.9G 100K 5.9G 1% /dev/shm
  6. /dev/sda1 485M 37M 423M 8% /boot
  7. /dev/mapper/VolGroup-lv_home
  8. 20G 172M 19G 1% /home

7.查看“Free PE / Size”剩余空间

  1. [root@localhost ~]# vgdisplay
  2. --- Volume group ---
  3. VG Name VolGroup
  4. System ID
  5. Format lvm2
  6. Metadata Areas 1
  7. Metadata Sequence No 5
  8. VG Access read/write
  9. VG Status resizable
  10. MAX LV 0
  11. Cur LV 3
  12. Open LV 3
  13. Max PV 0
  14. Cur PV 1
  15. Act PV 1
  16. VG Size 1.09 TiB
  17. PE Size 4.00 MiB
  18. Total PE 285022
  19. Alloc PE / Size 19424 / 75.88 GiB
  20. Free PE / Size 265598 / 1.01 TiB
  21. VG UUID nSbflh-J7fN-xDvf-zLjL-tFcu-Y5Tm-ybnDk0

8.使用lvextend指令:扩展逻辑卷空间到/dev/mapper/VolGroup-lv_root目录下,也就是“/”目录下。

  1. [root@localhost ~]# lvextend -L +1.01T /dev/mapper/VolGroup-lv_root
  2. Rounding size to boundary between physical extents: 1.01 TiB
  3. Extending logical volume lv_root to 1.06 TiB
  4. Logical volume lv_root successfully resized

9.执行操作,使之生效,中间一定要耐心等待。

  1. [root@localhost ~]# resize2fs -p /dev/mapper/VolGroup-lv_root
  2. resize2fs 1.41.12 (17-May-2010)
  3. Filesystem at /dev/mapper/VolGroup-lv_root is mounted on /; on-line resizing required
  4. old desc_blocks = 4, new_desc_blocks = 68
  5. Performing an on-line resize of /dev/mapper/VolGroup-lv_root to 284227584 (4k) blocks.
  6. The filesystem on /dev/mapper/VolGroup-lv_root is now 284227584 blocks long.

10.查看分区成功

  1. [root@localhost ~]# df -h
  2. 文件系统 容量 已用 可用 已用%% 挂载点
  3. /dev/mapper/VolGroup-lv_root
  4. 1.1T 2.9G 1011G 1% /
  5. tmpfs 5.9G 100K 5.9G 1% /dev/shm
  6. /dev/sda1 485M 37M 423M 8% /boot
  7. /dev/mapper/VolGroup-lv_home
  8. 20G 172M 19G 1% /home

11.重启

  1. [root@localhost ~]# shutdown -r now

 安装操作系统的分区操作方案:

参见:http://wenku.baidu.com/view/1b1621d8d15abe23482f4d92.html

相关推荐