linux如何无损调整分区大小
程序员文章站
2022-06-19 19:04:33
情况:
home:500g
root:50g
root分区不够用
思路:把home分区的空间划一部分到root分区
# 设置hom...
情况:
- home:500g
- root:50g
- root分区不够用
思路:把home分区的空间划一部分到root分区
# 设置home分区大小为200g,释放300g空间 $ lvreduce -l 200g /dev/centos/home # 将空闲空间扩展到root分区 $ lvextend -l +100%free /dev/centos/root # 使用xfs文件系统自带的命令集增加分区空间 $ xfs_growfs /dev/mapper/centos-root
实例
situation
挂载在根目录的分区 /dev/mapper/centos-root 爆满,占用100%
$ df -h filesystem size used avail use% mounted on /dev/mapper/centos-root 50g 50g 19m 100% / devtmpfs 32g 0 32g 0% /dev tmpfs 32g 0 32g 0% /dev/shm tmpfs 32g 2.5g 29g 8% /run tmpfs 32g 0 32g 0% /sys/fs/cgroup /dev/mapper/centos-home 476g 33m 476g 1% /home /dev/sda1 497m 238m 259m 48% /boot tmpfs 6.3g 0 6.3g 0% /run/user/0
analyze
挂载在根目录的分区空间太小,只有50g,而服务器 home 目录为非常用目录,挂在了近500g的空间。
思路:从 centos-home 分区划出300g空间到 centos-root 分区。
operation
1.查看各分区信息
$ lvdisplay --- logical volume --- lv path /dev/centos/home lv name home vg name centos lv uuid 1fat1e-bqsa-1hxr-mce2-5vz1-xzbz-ii1slv lv write access read/write lv creation host, time localhost, 2016-10-26 17:23:47 +0800 lv status available # open 0 lv size 475.70 gib current le 121778 segments 1 allocation inherit read ahead sectors auto - currently set to 256 block device 253:2 --- logical volume --- lv path /dev/centos/root lv name root vg name centos lv uuid ld64zy-yc3z-szab-dajk-03ym-2gm8-pfj4oo lv write access read/write lv creation host, time localhost, 2016-10-26 17:23:48 +0800 lv status available # open 1 lv size 50.00 gib current le 12800 segments 1 allocation inherit read ahead sectors auto - currently set to 256 block device 253:0
2.减少/home分区空间
# 释放 /dev/centos/home 分区 300g 的空间 # 命令设置 /dev/centos/home 分区 200g空间 $ lvreduce -l 200g /dev/centos/home warning: reducing active logical volume to 200.00 gib. this may destroy your data (filesystem etc.) do you really want to reduce centos/home? [y/n]: y size of logical volume centos/home changed from 475.70 gib (121778 extents) to 200.00 gib (51200 extents). logical volume centos/home successfully resized.
3.增加/root分区空间
$ lvextend -l +100%free /dev/centos/root size of logical volume centos/root changed from 50.06 gib (12816 extents) to 325.76 gib (83394 extents). logical volume centos/root successfully resized.
4.扩展xfs文件空间大小
$ xfs_growfs /dev/mapper/centos-root meta-data=/dev/mapper/centos-root isize=256 agcount=4, agsize=3276800 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 finobt=0 spinodes=0 data = bsize=4096 blocks=13107200, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 log =internal bsize=4096 blocks=6400, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 13107200 to 85395456
完成
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
下一篇: Linux中进程在后台可靠运行的方法总结