900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > Centos: 磁盘空间分配 将home空间分配给root

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

时间:2024-01-17 12:34:26

相关推荐

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

文章目录

磁盘情况:思路:把home分区的空间划一部分到root分区示例问题分析操作步骤1.查看各分区信息2.减少`/dev/cl/home`分区空间3.将空闲空间扩展到`/dev/centos/root`分区空间4.扩展XFS文件空间大小验证xfs_growfs疑问点`df -hl`显示的`/dev/mapper/cl-home`空间和实际不一致df和lvdisplay的巨大区别参考链接:

磁盘情况:

home目录:945Groot目录:70Groot分区不够用

思路:把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.8G0 7.8G 0% /devtmpfstmpfs7.8G0 7.8G 0% /dev/shmtmpfstmpfs7.8G 9.2M 7.8G 1% /runtmpfstmpfs7.8G0 7.8G 0% /sys/fs/cgroup/dev/mapper/cl-root xfs 70G 70G 12M 100% //dev/sda2 xfs1014M 237M 778M 24% /boot/dev/mapper/cl-home xfs 945G 6.9G 938G 1% /home/dev/sda1 vfat599M 7.3M 592M 2% /boot/efitmpfstmpfs1.6G0 1.6G 0% /run/user/0overlay overlay 70G 70G 12M 100% /var/lib/docker/overlay2/bb3e7c89d63c2647a88190874c89eb587991785738f9f6929da3aa0797f96378/merged# 查看文件系统大小[root@localhost bigunion]# df -hl文件系统 容量 已用 可用 已用% 挂载点devtmpfs 7.8G0 7.8G 0% /devtmpfs7.8G0 7.8G 0% /dev/shmtmpfs7.8G 9.2M 7.8G 1% /runtmpfs7.8G0 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/efitmpfs1.6G0 1.6G 0% /run/user/0overlay70G 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/swapLV NameswapVG NameclLV UUIDNdwWIy-HWMw-rlbK-mifr-c1jF-4rrP-8YtgvJLV Write Access read/writeLV Creation host, time localhost, -07-21 15:47:37 +0800LV Status available# open 2LV Size7.89 GiBCurrent LE Segments1Allocation inheritRead ahead sectorsauto- currently set to8192Block device 253:1--- Logical volume ---LV Path/dev/cl/homeLV NamehomeVG NameclLV UUIDTly4h6-pMT8-1LYJ-Jjkl-GGch-3taH-VVQ0zSLV Write Access read/writeLV Creation host, time localhost, -07-21 15:47:37 +0800LV Status available# open 1LV Size<944.52 GiBCurrent LE 241797Segments1Allocation inheritRead ahead sectorsauto- currently set to8192Block device 253:2--- Logical volume ---LV Path/dev/cl/rootLV NamerootVG NameclLV UUIDKeic5y-q0fQ-6fAy-ccyc-Cirp-Kpeg-NuzYrgLV Write Access read/writeLV Creation host, time localhost, -07-21 15:47:43 +0800LV Status available# open 1LV Size70.00 GiBCurrent LE 17920Segments1Allocation inheritRead ahead sectorsauto- currently set to8192Block device 253:0

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

# 释放 /dev/cl/home 分区 844.52G 的空间# 命令设置 /dev/cl/home 分区 100G空间[root@localhost bigunion]# lvreduce -L 100G /dev/cl/homeWARNING: 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]: ySize 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/rootSize 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/rootSize 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-rootmeta-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=1data= bsize=4096 blocks=18350080, imaxpct=25= sunit=0swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0, ftype=1log=internal log bsize=4096 blocks=8960, version=2= sectsz=512 sunit=0 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0data blocks changed from 18350080 to 239735808

验证

[root@localhost bigunion]# lvdisplay--- Logical volume ---LV Path/dev/cl/swapLV NameswapVG NameclLV UUIDNdwWIy-HWMw-rlbK-mifr-c1jF-4rrP-8YtgvJLV Write Access read/writeLV Creation host, time localhost, -07-21 15:47:37 +0800LV Status available# open 2LV Size7.89 GiBCurrent LE Segments1Allocation inheritRead ahead sectorsauto- currently set to8192Block device 253:1--- Logical volume ---LV Path/dev/cl/homeLV NamehomeVG NameclLV UUIDTly4h6-pMT8-1LYJ-Jjkl-GGch-3taH-VVQ0zSLV Write Access read/writeLV Creation host, time localhost, -07-21 15:47:37 +0800LV Status available# open 1LV Size100.00 GiBCurrent LE 25600Segments1Allocation inheritRead ahead sectorsauto- currently set to8192Block device 253:2--- Logical volume ---LV Path/dev/cl/rootLV NamerootVG NameclLV UUIDKeic5y-q0fQ-6fAy-ccyc-Cirp-Kpeg-NuzYrgLV Write Access read/writeLV Creation host, time localhost, -07-21 15:47:43 +0800LV Status available# open 1LV Size<914.52 GiBCurrent LE 234117Segments2Allocation inheritRead ahead sectorsauto- currently set to8192Block device 253:0

[root@localhost bigunion]# fdisk -lDisk /dev/sda:1 TiB,1099511627776 字节,2147483648 个扇区单元:扇区 / 1 * 512 = 512 字节扇区大小(逻辑/物理):512 字节 / 512 字节I/O 大小(最小/最佳):512 字节 / 512 字节磁盘标签类型:gpt磁盘标识符:FCD2E4E9-95FA-4E25-9B07-FD489CBDF52A设备起点 末尾 扇区 大小 类型/dev/sda12048 1230847 1228800 600M EFI 系统/dev/sda2 1230848 3327999 20971521G Linux 文件系统/dev/sda3 3328000 2147481599 2144153600 1022.4G Linux LVMDisk /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-1013142910070.png)]

xfs_growfs

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

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

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

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

[root@localhost bigunion]# xfs_growfs --helpxfs_growfs: 不适用的选项 -- -Usage: xfs_growfs [options] mountpointOptions:-dgrow data/metadata section-lgrow log section-rgrow realtime section-ndon't change anything, just show geometry-iconvert log from external to internal format-talternate location for mount table (/etc/mtab)-xconvert log from internal to external format-D sizegrow data/metadata section to size blks-L sizegrow/shrink log section to size blks-R sizegrow realtime section to size blks-e sizeset realtime extent size to size blks-m imaxpct set inode max percent to imaxpct-Vprint version information

疑问点

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

磁盘空间分配分配前

# 查看文件系统大小[root@localhost bigunion]# df -hl文件系统 容量 已用 可用 已用% 挂载点devtmpfs 7.8G0 7.8G 0% /devtmpfs7.8G0 7.8G 0% /dev/shmtmpfs7.8G 9.2M 7.8G 1% /runtmpfs7.8G0 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/efitmpfs1.6G0 1.6G 0% /run/user/0overlay70G 70G 14M 100% /var/lib/docker/overlay2/bb3e7c89d63c2647a88190874c89eb587991785738f9f6929da3aa0797f96378/merged

磁盘空间分配分配后

[root@localhost ~]# df -h文件系统 容量 已用 可用 已用% 挂载点devtmpfs 7.8G0 7.8G 0% /devtmpfs7.8G0 7.8G 0% /dev/shmtmpfs7.8G 9.2M 7.8G 1% /runtmpfs7.8G0 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/efitmpfs1.6G0 1.6G 0% /run/user/0

df和lvdisplay的巨大区别

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

参考链接:

/ct0811/p/11010955.html

/lxw983520/article/details/115132507

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。