Linux分配home容量给根目录

Linux分配home容量给根目录

1.概述

使用KVM创建的Linux系统,为系统分配了500G空间,创建完成后才发现根目录只有50G,其他的都在home文件夹下,下面将home下的空间分配给根目录。

2.卸载home

2.1.查看磁盘信息

[root@localhost java]# df -hl
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 908M     0  908M    0% /dev
tmpfs                    919M     0  919M    0% /dev/shm
tmpfs                    919M  8.6M  911M    1% /run
tmpfs                    919M     0  919M    0% /sys/fs/cgroup
/dev/mapper/centos-root   50G  2.0G   49G    4% /
/dev/vda1               1014M  150M  865M   15% /boot
tmpfs                    184M     0  184M    0% /run/user/0
/dev/mapper/centos-home  447G   33M  447G    1% /home

2.2.卸载home目录

[root@localhost java]# umount /dev/mapper/centos-home

注意如果提示busy,可以执行下面命令解决

[root@localhost java]# umount /dev/mapper/centos-home
umount: /home: target is busy.

查看占用home分区的进程

fuser -m /home/
/home:                7243m  7261c  7265cm  7294c  7386cm  7418c  7423c  7475cm  7480c  7483c  7572cm  7666c  7670cm  7671cm  7674c  7676c  7679c  7693cm  7704cm  7
711cm  7722c  7726c  7729cm  7733c  7738c  7749c  7759cm  7761c  7762c  7763c  7764cm  7770cm  7775cm  7777cm  7778c  7792cm  7797cm  7798cm  7799c  7800cm  7803cm
 7807cm  7808cm  7809cm  7849cm  7866cm  7867cm  7870cm  7886c  7899c  7905cm  7934c  7989cm  8024c  8033cm  8056cm  8199cm  8209c  8246cm  8319cm  8477c  8487cm  8
500c 40805c

杀掉这些进程在卸载home

kill -9 进程号
umount /dev/mapper/centos-home

2.3.删除home的lv

[root@localhost java]# lvremove /dev/mapper/centos-home
Do you really want to remove active logical volume centos/home? [y/n]: y
  Logical volume "home" successfully removed

3.扩容根目录

3.1.扩展根目录

[root@localhost java]# lvextend -L +445G /dev/mapper/centos-root
  Size of logical volume centos/root changed from 50.00 GiB (12800 extents) to 495.00 GiB (126720 extents).
  Logical volume centos/root successfully resized.

3.2.扩展根目录文件系统

[root@localhost java]# 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 129761280

3.3.查看根目录扩容信息

[root@localhost java]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 908M     0  908M    0% /dev
tmpfs                    919M     0  919M    0% /dev/shm
tmpfs                    919M  8.6M  911M    1% /run
tmpfs                    919M     0  919M    0% /sys/fs/cgroup
/dev/mapper/centos-root  495G  2.0G  494G    1% /
/dev/vda1               1014M  150M  865M   15% /boot
tmpfs                    184M     0  184M    0% /run/user/0

4.创建home

4.1.创建home的lv

查看挂载的vg

[root@localhost java]# vgscan
  Reading volume groups from cache.
  Found volume group "centos" using Metadata type lvm2

创建home的lv到vg

[root@localhost java]# lvcreate -L 1G -n home centos
  Logical volume "home" created.

4.2.创建home的文件系统

[root@localhost java]# mkfs.xfs /dev/mapper/centos-home
Meta-data=/dev/mapper/centos-home isize=512    agcount=4, agsize=65536 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=262144, 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

4.3.挂载home

[root@localhost java]# mount /dev/mapper/centos-home

4.4.查看home信息

[root@localhost java]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 908M     0  908M    0% /dev
tmpfs                    919M     0  919M    0% /dev/shm
tmpfs                    919M  8.6M  911M    1% /run
tmpfs                    919M     0  919M    0% /sys/fs/cgroup
/dev/mapper/centos-root  495G  2.0G  494G    1% /
/dev/vda1               1014M  150M  865M   15% /boot
tmpfs                    184M     0  184M    0% /run/user/0
/dev/mapper/centos-home 1014M   33M  982M    4% /home

相关文章

Centos下搭建性能监控Spotlight
CentOS 6.3下Strongswan搭建IPSec VPN
在CentOS6.5上安装Skype与QQ
阿里云基于centos6.5主机VPN配置
CentOS 6.3下配置multipah
CentOS安装、配置APR和tomcat-native