WeAir

动态调整LVM分区大小

查看当前各分区大小

1
df -h
1
2
3
4
5
6
7
8
9
Filesystem                  Size  Used Avail Use% Mounted on
/dev/mapper/openeuler-root 69G 56G 9.9G 85% /
devtmpfs 4.0M 0 4.0M 0% /dev
tmpfs 12G 0 12G 0% /dev/shm
tmpfs 4.0M 0 4.0M 0% /sys/fs/cgroup
tmpfs 4.7G 488M 4.2G 11% /run
tmpfs 12G 8.0K 12G 1% /tmp
/dev/vda2 974M 344M 563M 38% /boot
/dev/mapper/openeuler-home 41G 24K 39G 1% /home

卸载home分区

1
umount /home

检查分区

1
e2fsck -f /dev/mapper/openeuler-home
1
2
3
4
5
6
7
e2fsck 1.47.0 (5-Feb-2023)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/openeuler-home: 11/2698080 files (0.0% non-contiguous), 247204/10782720 blocks

调整home分区大小

1
resize2fs -p /dev/mapper/openeuler-home 10G
1
2
3
4
5
6
7
resize2fs 1.47.0 (5-Feb-2023)
Resizing the filesystem on /dev/mapper/openeuler-home to 2621440 (4k) blocks.
Begin pass 2 (max = 65536)
Relocating blocks XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 330)
Scanning inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/mapper/openeuler-home is now 2621440 (4k) blocks long.

压缩逻辑卷所占空间大小

1
lvreduce -L 10G /dev/mapper/openeuler-home

查看卷组信息

1
vgdisplay
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
--- Volume group ---
VG Name openeuler
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <119.00 GiB
PE Size 4.00 MiB
Total PE 30463
Alloc PE / Size 22493 / 87.86 GiB
Free PE / Size 7970 / 31.13 GiB
VG UUID 1GU3bo-9ztM-DzPZ-VFnZ-VaTF-Am3S-zoCoTO

扩展逻辑卷容量

1
lvextend -l+100%FREE /dev/mapper/openeuler-root

调整根分区大小

1
resize2fs -p /dev/mapper/openeuler-root
1
2
3
4
resize2fs 1.47.0 (5-Feb-2023)
Filesystem at /dev/mapper/openeuler-root is mounted on /; on-line resizing required
old_desc_blocks = 9, new_desc_blocks = 13
The filesystem on /dev/mapper/openeuler-root is now 26511360 (4k) blocks long.

重新挂载home分区

1
mount /dev/mapper/openeuler-home /home

查看调整后各分区大小

1
df -h
1
2
3
4
5
6
7
8
9
Filesystem                  Size  Used Avail Use% Mounted on
/dev/mapper/openeuler-root 99G 56G 40G 59% /
devtmpfs 4.0M 0 4.0M 0% /dev
tmpfs 12G 0 12G 0% /dev/shm
tmpfs 4.0M 0 4.0M 0% /sys/fs/cgroup
tmpfs 4.7G 488M 4.2G 11% /run
tmpfs 12G 8.0K 12G 1% /tmp
/dev/vda2 974M 344M 563M 38% /boot
/dev/mapper/openeuler-home 9.6G 28K 9.1G 1% /home