linux/centos 分区调整 root与home

通常由于前期主机上线时,管理员对分区使用没有做到准确预测,导致后期该有的分区空间少而不该用的却有多余。重新分区是一件风险性极高的事情,请务必保证在非生产系统中先行验证有效性。
重新分区后,还有可能因为引导分区改变而无法进入系统,请慎重。

一、了解分区

1. 查看当前分区情况 df -h

在这里很明显,root分区只有50G,而home分区却分了431G。
现在想要把home只留下148G,而root拓展到315G。如第二步显示。

Last login: Sun May 31 23:38:01 2020 from 10.38.15.33
[root@SHCTPDB02 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G   44G  2.9G  94% /
tmpfs                 5.9G   72K  5.9G   1% /dev/shm
/dev/sda1             477M   41M  411M   9% /boot
/dev/mapper/VolGroup-lv_home
                      431G  7.8G  402G   2% /home

2. 分区调整后的结果

[root@SHCTPDB02 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                      315G   44G  256G  15% /
tmpfs                 5.9G   72K  5.9G   1% /dev/shm
/dev/sda1             477M   41M  411M   9% /boot
/dev/mapper/VolGroup-lv_home
                      148G  7.8G  133G   6% /home

二、移除home空间

3.卸载home分区

[root@SHCTPDB02 ~]# umount /home
umount: /home: device is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))

[root@SHCTPDB02 ~]# reboot
Broadcast message from root@SHCTPDB02
	(/dev/pts/0) at 2:52 ...
The system is going down for reboot NOW!

[root@SHCTPDB02 ~]# umount /home
[root@SHCTPDB02 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G   44G  2.9G  94% /
tmpfs                 5.9G   72K  5.9G   1% /dev/shm
/dev/sda1             477M   41M  411M   9% /boot

4. 检查磁盘块e2fsck -f /dev/mapper/VolGroup-lv_home

[root@SHCTPDB02 ~]# 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: 13135/28688384 files (0.9% non-contiguous), 3857219/114741248 blocks


5. 调整home分区空间至150Gresize2fs -p /dev/mapper/VolGroup-lv_home 150G

[root@SHCTPDB02 ~]# resize2fs -p /dev/mapper/VolGroup-lv_home 150G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/VolGroup-lv_home to 39321600 (4k) blocks.
Begin pass 2 (max = 886057)
正在重定位块                  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 3502)
正在扫描inode表               XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 4 (max = 1527)
正在更新inode引用             XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/mapper/VolGroup-lv_home is now 39321600 blocks long.

6. 从逻辑块中移除非挂载空间lvreduce -L 250G /dev/mapper/VolGroup-lv_home

[root@SHCTPDB02 ~]# lvreduce -L 250G /dev/mapper/VolGroup-lv_home
  WARNING: Reducing active and open logical volume to 250.00 GiB.
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce VolGroup/lv_home? [y/n]: y
  Size of logical volume VolGroup/lv_home changed from 437.70 GiB (112052 extents) to 250.00 GiB (64000 extents).
  Logical volume lv_home successfully resized.

三、挂载root空间

7. 将空白空间挂载到root即直接拓展 lvextend -L +270G /dev/mapper/VolGroup-lv_root

[root@SHCTPDB02 ~]# lvextend -L +270G /dev/mapper/VolGroup-lv_root
  Size of logical volume VolGroup/lv_root changed from 50.00 GiB (12800 extents) to 320.00 GiB (81920 extents).
  Logical volume lv_root successfully resized.
[root@SHCTPDB02 ~]# 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 = 20
Performing an on-line resize of /dev/mapper/VolGroup-lv_root to 83886080 (4k) blocks.
The filesystem on /dev/mapper/VolGroup-lv_root is now 83886080 blocks long.

四、其它

8.查看当前磁盘情况 fdisk -l

[root@SHCTPDB02 ~]# fdisk -l
Disk /dev/sda: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 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: 0x0002c14b

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64       65271   523774976   8e  Linux LVM

Disk /dev/mapper/VolGroup-lv_root: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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

Disk /dev/mapper/VolGroup-lv_swap: 12.7 GB, 12675186688 bytes
255 heads, 63 sectors/track, 1541 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

Disk /dev/mapper/VolGroup-lv_home: 470.0 GB, 469980151808 bytes
255 heads, 63 sectors/track, 57138 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

9.报错 Insufficient free space: 71680 extents needed, but only 0 available

[root@SHCTPDB02 ~]# lvextend -L +280G /dev/mapper/VolGroup-lv_root
  Insufficient free space: 71680 extents needed, but only 0 available

因为原空间没有从home中卸载出来,执行第五步,从逻辑块中移除非挂载空间lvreduce -L 250G /dev/mapper/VolGroup-lv_home

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值