CentOS7.9 扩容 调整/Home分区大小

阿里云服务器可以参考: https://help.aliyun.com/document_detail/25451.html

CentOS7刚安装时如果选择默认分区设置,则根目录/的分区大小只有50G,swap分区与内存大小一致,其余所有的空间都会放在/home分区下。比如总共200G的磁盘空间情况下,默认分区home分区会有144G。

1.首先查看磁盘分区的默认初始情况:

[root@localhost ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                  16G     0   16G    0% /dev
tmpfs                     16G     0   16G    0% /dev/shm
tmpfs                     16G   17M   16G    1% /run
tmpfs                     16G     0   16G    0% /sys/fs/cgroup
/dev/mapper/centos-root   50G  2.9G   48G    6% /
/dev/vda1               1014M  181M  834M   18% /boot
/dev/mapper/centos-home  142G   33M  142G    1% /home
tmpfs                    2.6G     0  2.6G    0% /run/user/0

可以用 df -Th 查看服务器文件类型, 这里是 xfs文件系统

2.使用 lsblk 命令,列出所有可用块设备的信息,而且还能显示他们之间的依赖关系,但是它不会列出RAM盘的信息。块设备有硬盘,闪存盘,cd-ROM等

[root@localhost ~]# lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sr0              11:0    1   973M  0 rom
vda             252:0    0   200G  0 disk
├─vda1          252:1    0     1G  0 part /boot
└─vda2          252:2    0   199G  0 part
  ├─centos-root 253:0    0    50G  0 lvm  /
  ├─centos-swap 253:1    0   7.8G  0 lvm  [SWAP]
  └─centos-home 253:2    0 141.2G  0 lvm

3.卸载/home分区,此时如果/home分区有已经正在执行的程序需要先停止正在执行的程序,然后再卸载

[root@localhost ~]# umount /home
[root@localhost ~]# lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sr0              11:0    1   973M  0 rom
vda             252:0    0   200G  0 disk
├─vda1          252:1    0     1G  0 part /boot
└─vda2          252:2    0   199G  0 part
  ├─centos-root 253:0    0    50G  0 lvm  /
  ├─centos-swap 253:1    0   7.8G  0 lvm  [SWAP]

4.删除逻辑/Home卷

[root@localhost ~]# lvremove /dev/mapper/centos-home
Do you really want to remove active logical volume centos/home? [y/n]: y
  Logical volume "home" successfully removed
[root@localhost ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0              11:0    1  973M  0 rom
vda             252:0    0  200G  0 disk
├─vda1          252:1    0    1G  0 part /boot
└─vda2          252:2    0  199G  0 part
  ├─centos-root 253:0    0   50G  0 lvm  /
  └─centos-swap 253:1    0  7.8G  0 lvm  [SWAP]

5.重新创建逻辑home卷,并设置分区大小,我这里设置10G

[root@localhost ~]# lvcreate -L  10G -n home centos
WARNING: xfs signature detected on /dev/centos/home at offset 0. Wipe it? [y/n]: y
  Wiping xfs signature on /dev/centos/home.
  Logical volume "home" created.

6.格式化home分区

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

7.挂载home分区

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

8.将home分区压缩下来的空间 全部放到根分区下

[root@localhost ~]# lvextend -l +100%FREE /dev/mapper/centos-root
  Size of logical volume centos/root changed from 50.00 GiB (12800 extents) to <181.25 GiB (46399 extents).
  Logical volume centos/root successfully resized.

9.重新查看磁盘分区信息

[root@localhost ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                  16G     0   16G    0% /dev
tmpfs                     16G     0   16G    0% /dev/shm
tmpfs                     16G   17M   16G    1% /run
tmpfs                     16G     0   16G    0% /sys/fs/cgroup
/dev/mapper/centos-root   50G  2.9G   48G    6% /
/dev/vda1               1014M  181M  834M   18% /boot
tmpfs                    2.6G     0  2.6G    0% /run/user/0
/dev/mapper/centos-home   10G   33M   10G    1% /home

最后执行扩容命令即可

type xfs_growfs || yum install -y xfsprogs
xfs_growfs /dev/mapper/centos-root

 

posted @ 2023-07-12 17:11  study_php_java_C++  阅读(609)  评论(0编辑  收藏  举报