装ubuntu22,使用时发现根文件系统空间不够,随即查看
root@root:/dev/ubuntu-vg# df -h
Filesystem Size Used Avail Use% Mounted on
tmpfs 3.2G 1.7M 3.2G 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 98G 93G 0 100% /
tmpfs 16G 0 16G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/sda2 2.0G 130M 1.7G 8% /boot
/dev/sda1 1.1G 6.1M 1.1G 1% /boot/efi
tmpfs 3.2G 4.0K 3.2G 1% /run/user/1000
tmpfs 3.2G 4.0K 3.2G 1% /run/user/0
root@root:/dev/ubuntu-vg# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 63.4M 1 loop /snap/core20/1974
loop1 7:1 0 111.9M 1 loop /snap/lxd/24322
loop2 7:2 0 53.3M 1 loop /snap/snapd/19457
sda 8:0 0 931.5G 0 disk
├─sda1 8:1 0 1G 0 part /boot/efi
├─sda2 8:2 0 2G 0 part /boot
└─sda3 8:3 0 928.5G 0 part
└─ubuntu--vg-ubuntu--lv 253:0 0 100G 0 lvm /
sdb 8:16 0 465.8G 0 disk
├─sdb1 8:17 0 512M 0 part
└─sdb2 8:18 0 465.3G 0 part
sdc 8:32 0 14.6T 0 disk
sr0 11:0 1 1024M 0 rom
发现根目录所用的磁盘sda3
并没有全部使用。
进一步查看
root@root:/dev/ubuntu-vg# lvdisplay
--- Logical volume ---
LV Path /dev/ubuntu-vg/ubuntu-lv
LV Name ubuntu-lv
VG Name ubuntu-vg
LV UUID RToKk1-GbJM-MDa7-grPB-4G7w-P0rf-CebMGx
LV Write Access read/write
LV Creation host, time ubuntu-server, 2024-02-01 11:49:44 +0000
LV Status available
# open 1
LV Size 100.00 GiB
Current LE 25600
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
root@root:/dev/ubuntu-vg# vgdisplay
--- Volume group ---
VG Name ubuntu-vg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size <928.46 GiB
PE Size 4.00 MiB
Total PE 237685
Alloc PE / Size 25600 / 100.00 GiB
Free PE / Size 212085 / <828.46 GiB
VG UUID uk62ul-FktK-OGXv-Q205-0zw1-TSoa-JrvWYc
root@root:/dev/ubuntu-vg# pvdisplay
--- Physical volume ---
PV Name /dev/sda3
VG Name ubuntu-vg
PV Size 928.46 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 237685
Free PE 212085
Allocated PE 25600
PV UUID FbHwHf-f252-LmPi-70Gz-o8cq-YSdF-Pl8ZAP
扩展操作如下
1. 扩展逻辑卷:
sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
此命令将逻辑卷扩展到卷组中的所有可用空间。
2. 调整文件系统大小:
sudo resize2fs /dev/ubuntu-vg/ubuntu-lv
此命令将文件系统调整到逻辑卷的新大小。
3.再次查看文件系统大小:
root@root:/dev/ubuntu-vg# df -h
Filesystem Size Used Avail Use% Mounted on
tmpfs 3.2G 1.7M 3.2G 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 914G 93G 783G 11% /
tmpfs 16G 0 16G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/sda2 2.0G 130M 1.7G 8% /boot
/dev/sda1 1.1G 6.1M 1.1G 1% /boot/efi
tmpfs 3.2G 4.0K 3.2G 1% /run/user/1000
tmpfs 3.2G 4.0K 3.2G 1% /run/user/0
调整完毕