解决centos安装完只有50G - 管理猿 2018 年 07 月 13 日 |访问: 255 次

centos安装完后root分区默认分配的是50G,一般的程序都是装载在root分区的,识别出来硬盘就只有50G的容量。
centos的root分区是默认的系统分区,剩下的空间被默认分配到home分区。home作为数据分区。
解决这个问题的方案有两种。
第一是在系统安装的时候在磁盘分区的时候自定义操作,
第二种就是安装完成后手动修改分区配置,也就是接下来要操作的,以centos6.5为例
1.查看整体磁盘空间

[root@yuewangRZ doc]# df -lh
Filesystem                        Size  Used Avail Use% Mounted on
/dev/mapper/vg_yuewangrz-lv_root   50G  4.2G   43G   9% /
tmpfs                             7.8G   72K  7.8G   1% /dev/shm
/dev/sda1                         485M   40M  421M   9% /boot
/dev/mapper/vg_yuewangrz-lv_home  356G  195M  337G   1% /home

可以看到有300多G到了home分区,
2.卸载home分区,并修改home分区为50G

[root@yuewangRZ doc]# umount /home
[root@yuewangRZ doc]# e2fsck -f /dev/mapper/vg_yuewangrz-lv_home 
e2fsck 1.41.12 (17-May-2010)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要信息
/dev/mapper/vg_yuewangrz-lv_home: 11/23650304 files (0.0% non-contiguous), 1534117/94595072 blocks
[root@yuewangRZ doc]# resize2fs -p /dev/mapper/vg_yuewangrz-lv_home 50G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/vg_yuewangrz-lv_home to 13107200 (4k) blocks.
Begin pass 2 (max = 32768)
正在重定位块            XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 2887)
正在扫描inode表          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/mapper/vg_yuewangrz-lv_home is now 13107200 blocks long.

[root@yuewangRZ doc]# lvreduce -L 50G /dev/mapper/vg_yuewangrz-lv_home 
  WARNING: Reducing active logical volume to 50.00 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_home? [y/n]: ye^H
  Reducing logical volume lv_home to 50.00 GiB
  Logical volume lv_home successfully resized

3.挂载home分区,并查询磁盘未分配空间大小,增加到root分区上。

[root@yuewangRZ doc]# mount /dev/mapper/vg_yuewangrz-lv_home /home/
[root@yuewangRZ doc]# df -lh
Filesystem                        Size  Used Avail Use% Mounted on
/dev/mapper/vg_yuewangrz-lv_root   50G  4.2G   43G   9% /
tmpfs                             7.8G   72K  7.8G   1% /dev/shm
/dev/sda1                         485M   40M  421M   9% /boot
/dev/mapper/vg_yuewangrz-lv_home   50G  180M   47G   1% /home
[root@yuewangRZ doc]# vgdisplay|grep "Free  PE"
  Free  PE / Size       79578 / 310.85 GiB
[root@yuewangRZ doc]# lvextend -L +310G /dev/mapper/vg_yuewangrz-lv_root 
  Extending logical volume lv_root to 360.00 GiB
  Logical volume lv_root successfully resized
[root@yuewangRZ doc]# resize2fs -p /dev/mapper/vg_yuewangrz-lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vg_yuewangrz-lv_root is mounted on /; on-line resizing required
old desc_blocks = 4, new_desc_blocks = 23
Performing an on-line resize of /dev/mapper/vg_yuewangrz-lv_root to 94371840 (4k) blocks.
The filesystem on /dev/mapper/vg_yuewangrz-lv_root is now 94371840 blocks long.

[root@yuewangRZ doc]# df -lh
Filesystem                        Size  Used Avail Use% Mounted on
/dev/mapper/vg_yuewangrz-lv_root  355G  4.2G  333G   2% /
tmpfs                             7.8G   72K  7.8G   1% /dev/shm
/dev/sda1                         485M   40M  421M   9% /boot
/dev/mapper/vg_yuewangrz-lv_home   50G  180M   47G   1% /home

最后一步会根据磁盘大小有一段等待时间,这个操作中必须保证不能重启或者断电。否则会导致无法进入系统,所以操作前请备份好关键数据。

标签:none

添加新评论