Centos移动/home目录空间到/根目录下

硬盘只有100G空间,在安装系统时划分得不够恰当,/根目录与/home目录基本各占一半空间

$ df -h
文件系统                 容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root   50G  2.7G   48G    6% /
......
/dev/mapper/centos-home   42G   33M   42G    1% /home
......

因此,想把/home目录下的空间挪一些到/目录下去

  • 备份并卸载/home目录
# 如果/home下有文件要备份,可以在这里先复制到另外的目录(我这里不需要就跳过了)
$ umount /home/
$ lvremove /dev/mapper/centos-home
Do you really want to remove active logical volume centos/home? [y/n]: y
  Logical volume "home" successfully removed
  • 将腾的的空间移动根目录下,这里移走85%
$ lvextend -l +85%FREE /dev/centos/root
  Size of logical volume centos/root changed from 50.00 GiB (12800 extents) to 84.95 GiB (21748 extents).
  Logical volume centos/root successfully resized.
$ cat /etc/fstab |grep root   # 查看文件类型
/dev/mapper/centos-root /                       xfs     defaults        0 0
# 扩充到空间
$ xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=3276800 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        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=1
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 22269952
  • 再创建回/home目录
$ lvcreate -l +100%FREE -n home centos
Logical volume "home" created.
$ mkfs.xfs  /dev/mapper/centos-home
meta-data=/dev/mapper/centos-home isize=512    agcount=4, agsize=404224 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=1616896, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
$ mount  /dev/mapper/centos-home  /home
# 之前如果有备份的,可以在这时复制回来
  • 完成,查看一下
$ df -h
文件系统                 容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root   85G  2.4G   83G    3% /    # 容量从50G增加到了85G
......
/dev/mapper/centos-home  6.2G   33M  6.2G    1% /home

你可能感兴趣的:(Centos移动/home目录空间到/根目录下)