Rocky9根目录存储容量调整

本文最后更新于 318 天前, 如有失效请评论区留言.

简单记录一下Rocky9调整根分区大小.

背景

Rocky9默认安装的时候, 根目录只有70G, 有点小了,而且/home基本用不上, 所以需要调整一下.

[root@localhost ~]# df -h
Filesystem           Size  Used Avail Use% Mounted on
devtmpfs             4.0M     0  4.0M   0% /dev
tmpfs                 16G     0   16G   0% /dev/shm
tmpfs                6.2G   19M  6.2G   1% /run
/dev/mapper/rl-root   70G  4.3G   66G   7% /
/dev/mapper/rl-home  867G  6.1G  861G   1% /home
/dev/nvme0n1p2      1014M  283M  732M  28% /boot
/dev/nvme0n1p1       599M  7.0M  592M   2% /boot/efi
tmpfs                3.1G   96K  3.1G   1% /run/user/987
tmpfs                3.1G   36K  3.1G   1% /run/user/0

操作

Rocky9默认使用的是LVM, 且基于xfs文件系统

备份/home(可选)

可跳过,我的系统是空系统,默认不备份了

xfsdump -f /home.bak /home
xfsdump -f /home.bak /home
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.10 (dump format 3.0) - type ^C for status and control

 ============================= dump label dialog ==============================

please enter label for this dump session (timeout in 300 sec)
 -> home
session label entered: "home"

 --------------------------------- end dialog ---------------------------------

xfsdump: level 0 dump of q-7-206.quickon.me:/home
xfsdump: dump date: Tue Apr 18 04:01:01 2023
xfsdump: session id: b1ae3c16-70ee-4634-9ac2-b4a1a9429498
xfsdump: session label: "home"
xfsdump: ino map phase 1: constructing initial dump list
xfsdump: ino map phase 2: skipping (no pruning necessary)
xfsdump: ino map phase 3: skipping (only one dump stream)
xfsdump: ino map construction complete
xfsdump: estimated dump size: 20800 bytes

 ============================= media label dialog =============================

please enter label for media in drive 0 (timeout in 300 sec)
 -> home
media label entered: "home"

 --------------------------------- end dialog ---------------------------------

xfsdump: creating dump session media file 0 (media 0, file 0)
xfsdump: dumping ino map
xfsdump: dumping directories
xfsdump: dumping non-directory files
xfsdump: ending media file
xfsdump: media file size 21352 bytes
xfsdump: dump size (non-dir files) : 0 bytes
xfsdump: dump complete: 15 seconds elapsed
xfsdump: Dump Summary:
xfsdump:   stream 0 /home.bak OK (success)
xfsdump: Dump Status: SUCCESS

卸载/home

umount /home

缩容/home逻辑卷

lvreduce -L 50G /dev/mapper/rl-home

  WARNING: Reducing active logical volume to 50.00 GiB.
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce rl/home? [y/n]: y
  Size of logical volume rl/home changed from <866.70 GiB (221875 extents) to 50.00 GiB (12800 extents).
  Logical volume rl/home successfully resized.

扩容/逻辑卷

lvextend -l +100%FREE /dev/rl/root

  Size of logical volume rl/root changed from 70.00 GiB (17920 extents) to <886.70 GiB (226995 extents).
  Logical volume rl/root successfully resized.

参数

  • —L: 指定逻辑卷的大小,单位为MmGgTt
  • -l: 指定逻辑卷的大小(LE数)
  • -l +100%FREE: 将卷组中的空闲空间全部分配给当前逻辑卷

执行扩容生效

xfs_growfs /dev/rl/root

重新挂载/home

mkfs.xfs -f /dev/mapper/rl-home
mount /home

恢复(可选)

xfsrestore -f /home.bak /home

验证

[root@localhost ~]# df -h
Filesystem           Size  Used Avail Use% Mounted on
devtmpfs             4.0M     0  4.0M   0% /dev
tmpfs                 16G     0   16G   0% /dev/shm
tmpfs                6.2G   15M  6.2G   1% /run
/dev/mapper/rl-root  887G   11G  877G   2% /
/dev/nvme0n1p2      1014M  356M  659M  36% /boot
/dev/nvme0n1p1       599M  7.0M  592M   2% /boot/efi
tmpfs                3.1G  100K  3.1G   1% /run/user/987
tmpfs                3.1G   36K  3.1G   1% /run/user/0
/dev/mapper/rl-home   50G  390M   50G   1% /home

补充

如果/home不用可以执行卸载

umount /home
# 删除逻辑卷
lvremove /dev/rl/home
# 查看卷组,记录 Free  PE
lvdisplay

# 删除home分区挂载配置
vi /etc/fstab

Comments