Centos: 磁盘空间分配,将home空间分配给root

简介: Centos: 磁盘空间分配,将home空间分配给root

文章目录


磁盘情况:

  1. home目录:945G
  2. root目录:70G
  3. root分区不够用


思路:把home分区的空间划一部分到root分区

# 设置home分区大小为100G,释放300G空间 [LV Path]
$ lvreduce -L 100G /dev/cl/home
# 将空闲空间扩展到root分区 [LV Path]
$ lvextend -l +100%FREE /dev/cl/root
# 使用XFS文件系统自带的命令集增加分区空间 [Filesystem]
$ xfs_growfs /dev/mapper/cl-root


示例

挂载在根目录的分区/dev/mapper/cl-root 爆满,占用100%

# 查看文件系统类型
[root@localhost bigunion]# df -Th
文件系统            类型      容量  已用  可用 已用% 挂载点
devtmpfs            devtmpfs  7.8G     0  7.8G    0% /dev
tmpfs               tmpfs     7.8G     0  7.8G    0% /dev/shm
tmpfs               tmpfs     7.8G  9.2M  7.8G    1% /run
tmpfs               tmpfs     7.8G     0  7.8G    0% /sys/fs/cgroup
/dev/mapper/cl-root xfs        70G   70G   12M  100% /
/dev/sda2           xfs      1014M  237M  778M   24% /boot
/dev/mapper/cl-home xfs       945G  6.9G  938G    1% /home
/dev/sda1           vfat      599M  7.3M  592M    2% /boot/efi
tmpfs               tmpfs     1.6G     0  1.6G    0% /run/user/0
overlay             overlay    70G   70G   12M  100% /var/lib/docker/overlay2/bb3e7c89d63c2647a88190874c89eb587991785738f9f6929da3aa0797f96378/merged
# 查看文件系统大小
[root@localhost bigunion]# df -hl
文件系统             容量  已用  可用 已用% 挂载点
devtmpfs             7.8G     0  7.8G    0% /dev
tmpfs                7.8G     0  7.8G    0% /dev/shm
tmpfs                7.8G  9.2M  7.8G    1% /run
tmpfs                7.8G     0  7.8G    0% /sys/fs/cgroup
/dev/mapper/cl-root   70G   70G   14M  100% /
/dev/sda2           1014M  237M  778M   24% /boot
/dev/mapper/cl-home  945G  6.9G  938G    1% /home
/dev/sda1            599M  7.3M  592M    2% /boot/efi
tmpfs                1.6G     0  1.6G    0% /run/user/0
overlay               70G   70G   14M  100% /var/lib/docker/overlay2/bb3e7c89d63c2647a88190874c89eb587991785738f9f6929da3aa0797f96378/merged


问题分析

挂载在根目录的分区空间太小,只有70G,而服务器 home 目录为非常用目录,挂在了近945G的空间。

思路:从cl-home 分区划出300G空间到 cl-root 分区。


操作步骤

1.查看各分区信息

[root@localhost bigunion]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/cl/swap
  LV Name                swap
  VG Name                cl
  LV UUID                NdwWIy-HWMw-rlbK-mifr-c1jF-4rrP-8YtgvJ
  LV Write Access        read/write
  LV Creation host, time localhost, 2021-07-21 15:47:37 +0800
  LV Status              available
  # open                 2
  LV Size                7.89 GiB
  Current LE             2020
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
  --- Logical volume ---
  LV Path                /dev/cl/home
  LV Name                home
  VG Name                cl
  LV UUID                Tly4h6-pMT8-1LYJ-Jjkl-GGch-3taH-VVQ0zS
  LV Write Access        read/write
  LV Creation host, time localhost, 2021-07-21 15:47:37 +0800
  LV Status              available
  # open                 1
  LV Size                <944.52 GiB
  Current LE             241797
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2
  --- Logical volume ---
  LV Path                /dev/cl/root
  LV Name                root
  VG Name                cl
  LV UUID                Keic5y-q0fQ-6fAy-ccyc-Cirp-Kpeg-NuzYrg
  LV Write Access        read/write
  LV Creation host, time localhost, 2021-07-21 15:47:43 +0800
  LV Status              available
  # open                 1
  LV Size                70.00 GiB
  Current LE             17920
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0


2.减少/dev/cl/home分区空间

# 释放 /dev/cl/home 分区 844.52G 的空间
# 命令设置 /dev/cl/home 分区 100G空间
[root@localhost bigunion]# lvreduce -L 100G /dev/cl/home
  WARNING: Reducing active and open logical volume to 100.00 GiB.
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce cl/home? [y/n]: y
  Size of logical volume cl/home changed from <944.52 GiB (241797 extents) to 100.00 GiB (25600 extents).
  Logical volume cl/home successfully resized.


3.将空闲空间扩展到/dev/centos/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.
# 将空闲空间扩展到root分区 [LV Path]
[root@localhost bigunion]# lvextend -l +100%FREE /dev/cl/root
  Size of logical volume cl/root changed from 70.00 GiB (17920 extents) to <914.52 GiB (234117 extents).
  Logical volume cl/root successfully resized.


4.扩展XFS文件空间大小

[root@localhost bigunion]# xfs_growfs /dev/mapper/cl-root
meta-data=/dev/mapper/cl-root    isize=512    agcount=4, agsize=4587520 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=18350080, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=8960, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 18350080 to 239735808
  1. 验证
[root@localhost bigunion]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/cl/swap
  LV Name                swap
  VG Name                cl
  LV UUID                NdwWIy-HWMw-rlbK-mifr-c1jF-4rrP-8YtgvJ
  LV Write Access        read/write
  LV Creation host, time localhost, 2021-07-21 15:47:37 +0800
  LV Status              available
  # open                 2
  LV Size                7.89 GiB
  Current LE             2020
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
  --- Logical volume ---
  LV Path                /dev/cl/home
  LV Name                home
  VG Name                cl
  LV UUID                Tly4h6-pMT8-1LYJ-Jjkl-GGch-3taH-VVQ0zS
  LV Write Access        read/write
  LV Creation host, time localhost, 2021-07-21 15:47:37 +0800
  LV Status              available
  # open                 1
  LV Size                100.00 GiB
  Current LE             25600
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2
  --- Logical volume ---
  LV Path                /dev/cl/root
  LV Name                root
  VG Name                cl
  LV UUID                Keic5y-q0fQ-6fAy-ccyc-Cirp-Kpeg-NuzYrg
  LV Write Access        read/write
  LV Creation host, time localhost, 2021-07-21 15:47:43 +0800
  LV Status              available
  # open                 1
  LV Size                <914.52 GiB
  Current LE             234117
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
[root@localhost bigunion]# fdisk -l
Disk /dev/sda:1 TiB,1099511627776 字节,2147483648 个扇区
单元:扇区 / 1 * 512 = 512 字节
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:gpt
磁盘标识符:FCD2E4E9-95FA-4E25-9B07-FD489CBDF52A
设备          起点       末尾       扇区    大小 类型
/dev/sda1     2048    1230847    1228800    600M EFI 系统
/dev/sda2  1230848    3327999    2097152      1G Linux 文件系统
/dev/sda3  3328000 2147481599 2144153600 1022.4G Linux LVM
Disk /dev/mapper/cl-root:914.5 GiB,981957869568 字节,1917886464 个扇区
单元:扇区 / 1 * 512 = 512 字节
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
Disk /dev/mapper/cl-swap:7.9 GiB,8472494080 字节,16547840 个扇区
单元:扇区 / 1 * 512 = 512 字节
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
Disk /dev/mapper/cl-home:100 GiB,107374182400 字节,209715200 个扇区
单元:扇区 / 1 * 512 = 512 字节
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-PZskAdrd-1634110105901)(C:\Users\FLY\AppData\Roaming\Typora\typora-user-images\image-20211013142910070.png)]


xfs_growfs

XFS是一个开源的(GPL)日志文件系统,最初由硅谷图形(SGI)开发,现在大多数的Linux发行版都支持。

事实上,XFS已被最新的CentOS/RHEL 7采用,成为其默认的文件系统。在其众多的特性中,包含了“在线调整大小”这一特性,使得现存的XFS文件系统在已经挂载的情况下可以进行扩展。

然而,对于XFS文件系统的缩减却还没有支持。

要扩展一个现存的XFS文件系统,你可以使用命令行工具xfs_growfs,这在大多数Linux发行版上都默认可用。由于XFS支持在线调整大小,目标文件系统可以挂载,也可以不挂载。

[root@localhost bigunion]# xfs_growfs --help
xfs_growfs: 不适用的选项 -- -
Usage: xfs_growfs [options] mountpoint
Options:
  -d          grow data/metadata section
  -l          grow log section
  -r          grow realtime section
  -n          don't change anything, just show geometry
  -i          convert log from external to internal format
  -t          alternate location for mount table (/etc/mtab)
  -x          convert log from internal to external format
  -D size     grow data/metadata section to size blks
  -L size     grow/shrink log section to size blks
  -R size     grow realtime section to size blks
  -e size     set realtime extent size to size blks
  -m imaxpct  set inode max percent to imaxpct
  -V          print version information


疑问点

df -hl显示的/dev/mapper/cl-home空间和实际不一致

磁盘空间分配分配前

# 查看文件系统大小
[root@localhost bigunion]# df -hl
文件系统             容量  已用  可用 已用% 挂载点
devtmpfs             7.8G     0  7.8G    0% /dev
tmpfs                7.8G     0  7.8G    0% /dev/shm
tmpfs                7.8G  9.2M  7.8G    1% /run
tmpfs                7.8G     0  7.8G    0% /sys/fs/cgroup
/dev/mapper/cl-root   70G   70G   14M  100% /
/dev/sda2           1014M  237M  778M   24% /boot
/dev/mapper/cl-home  945G  6.9G  938G    1% /home
/dev/sda1            599M  7.3M  592M    2% /boot/efi
tmpfs                1.6G     0  1.6G    0% /run/user/0
overlay               70G   70G   14M  100% /var/lib/docker/overlay2/bb3e7c89d63c2647a88190874c89eb587991785738f9f6929da3aa0797f96378/merged

磁盘空间分配分配后

[root@localhost ~]# df -h
文件系统             容量  已用  可用 已用% 挂载点
devtmpfs             7.8G     0  7.8G    0% /dev
tmpfs                7.8G     0  7.8G    0% /dev/shm
tmpfs                7.8G  9.2M  7.8G    1% /run
tmpfs                7.8G     0  7.8G    0% /sys/fs/cgroup
/dev/mapper/cl-root  915G   77G  839G    9% /
/dev/sda2           1014M  237M  778M   24% /boot
/dev/mapper/cl-home  945G  6.9G  938G    1% /home
/dev/sda1            599M  7.3M  592M    2% /boot/efi
tmpfs                1.6G     0  1.6G    0% /run/user/0


df和lvdisplay的巨大区别

lvdisplay报告磁盘上的实际大小,但df显示系统可用的磁盘空间,即实际磁盘大小减去所使用的文件系统空间。


参考链接:

https://www.cnblogs.com/ct20150811/p/11010955.html

https://blog.csdn.net/lxw983520/article/details/115132507


目录
相关文章
|
2月前
|
缓存
ecs-centos分区空间大于70时发送钉钉告警并清理
当分区空间大于70时,开始清理并发送钉钉告警。
35 1
|
6月前
|
Linux Shell 数据安全/隐私保护
超简单五步实现Linux虚拟机CentOS 7系统Root密码忘记重置
超简单五步实现Linux虚拟机CentOS 7系统Root密码忘记重置
802 0
|
5月前
|
Linux
centos7添加用户并授权root权限
centos7添加用户并授权root权限
271 0
|
4月前
|
Linux
Centos下增加swap空间
Centos下增加swap空间
144 0
|
4月前
|
Linux 数据安全/隐私保护
Centos重置ROOT密码
忘记root密码怎么办
54 1
Centos重置ROOT密码
|
4月前
|
Linux
百度搜索:蓝易云【centos系统应用日志文件被删,空间无法释放怎么办】
通过以上方法,你应该能够解决应用日志文件被删除但空间无法释放的问题,并恢复磁盘空间。
31 1
|
4月前
|
关系型数据库 MySQL Linux
CentOS7下忘记MySQL数据库root密码与密码过期
CentOS7下忘记MySQL数据库root密码与密码过期
121 0
|
6月前
|
Linux 虚拟化
VMware虚拟机中Centos 6.x系统磁盘空间扩容实战
VMware虚拟机中Centos 6.x系统磁盘空间扩容实战
176 0
|
7月前
|
Linux
CentOS开机自动登陆root用户
CentOS开机自动登陆root用户
288 0
|
7月前
|
安全 Linux Shell
百度搜索:蓝易云【Linux系统Centos7修改或重置root密码教程。】
在Linux系统中,root用户是具有最高权限的超级管理员账号。如果忘记了root用户的密码或需要更改密码,可以通过以下方法来修改或重置root密码。
190 0

热门文章

最新文章