目录
现象
现象就是使用动态分配存储,虚拟分配空间为25G,实际分配空间为10.05G,此时虚拟机用了11G,然后记提示磁盘已满。刚好文末的链接解决了我的问题,可以直接跳转到那,这里做下记录而已。
root@xxx:~
Disk /dev/sda: 25 GiB, 26843545600 bytes, 52428800 sectors
Disk model: VBOX HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: B97EFFC5-317E-4FC8-B4D5-82166607DEE6
Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 4198399 4194304 2G Linux filesystem
/dev/sda3 4198400 52426751 48228352 23G Linux filesystem
/dev/sda4 52426752 52428766 2015 1007.5K Linux filesystem
root@xxx:~
Filesystem Size Used Avail Use% Mounted on
tmpfs 197M 1.2M 196M 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 12G 11G 0 100% /
tmpfs 982M 0 982M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/sda2 2.0G 251M 1.6G 14% /boot
tmpfs 197M 4.0K 197M 1% /run/user/1000
lsblk -f |grep ext4
├─sda2 ext4 1.0 63999313-9585-4fe0-ae16-61ff495e7aaf 1.5G 13% /boot
└─ubuntu--vg-ubuntu--lv ext4 1.0 643076fe-0b95-497c-963b-ea460b372202 0 96% /
解决办法
扩展 LVM
a) 找出你使用 lsblk --fs 的文件系统
root@xxx:~
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
loop0 squashfs 4.0 0 100% /snap/core20/2318
loop1 squashfs 4.0 0 100% /snap/core20/2182
loop2 squashfs 4.0 0 100% /snap/core22/1439
loop3 squashfs 4.0 0 100% /snap/docker/2904
loop4 squashfs 4.0 0 100% /snap/docker/2915
loop5 squashfs 4.0 0 100% /snap/core22/1122
loop6 squashfs 4.0 0 100% /snap/snapd/21184
loop7 squashfs 4.0 0 100% /snap/lxd/29351
loop8 squashfs 4.0 0 100% /snap/lxd/27428
loop9 squashfs 4.0 0 100% /snap/snapd/21759
sda
├─sda1
├─sda2 ext4 1.0 63999313-9585-4fe0-ae16-61ff495e7aaf 1.5G 13% /boot
└─sda3 LVM2_member LVM2 001 Xac0Ne-TRen-LJ4c-yKzY-2WuV-2ZV2-rof2j7
└─ubuntu--vg-ubuntu--lv ext4 1.0 643076fe-0b95-497c-963b-ea460b372202 0 96% /
sr0 iso9660 Joliet Extension VBox_GAs_7.0.8 2023-04-17-17-27-11-59
b) 检查卷组的可用空间。您可以使用快捷方式 vgs
root@xxx:~
VG
ubuntu-vg 1 1 0 wz--n- <23.00g 11.50g
c) 使用 lvs 检查您拥有的逻辑卷的大小:
root@xxx:~
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
ubuntu-lv ubuntu-vg -wi-ao---- <11.50g
d) 要扩展它,您需要扩展逻辑卷。
对于我的来说,它会是(运行 lvdisplay 时,您会在 LV 路径中找到它)。要占用运行所需的所有可用空间,请执行以下操作:
root@xxx:~
--- Logical volume ---
LV Path /dev/ubuntu-vg/ubuntu-lv
LV Name ubuntu-lv
VG Name ubuntu-vg
LV UUID h8KdE5-a492-ADRo-Qe1x-PhwQ-U4TO-Dg7nq0
LV Write Access read/write
LV Creation host, time ubuntu-server, 2023-09-14 08:34:13 +0000
LV Status available
LV Size <11.50 GiB
Current LE 2943
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
root@xxx:~
Size of logical volume ubuntu-vg/ubuntu-lv changed from <11.50 GiB (2943 extents) to <23.00 GiB (5887 extents).
Logical volume ubuntu-vg/ubuntu-lv successfully resized.
root@xxx:~
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
ubuntu-lv ubuntu-vg -wi-ao---- <23.00g
e) 然后你需要扩展你的文件系统。在我的情况下 ext4。
警告:请确保您的内核和文件系统在挂载时支持在线调整大小 - tune2fs -l /dev/magnetron-vg/home| grep resize_inode (如果你得到输出,这意味着你的文件系统支持在线调整大小)
root@xxx:~# resize2fs /dev/ubuntu-vg/ubuntu-lv
resize2fs 1.46.5 (30-Dec-2021)
Filesystem at /dev/ubuntu-vg/ubuntu-lv is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 3
The filesystem on /dev/ubuntu-vg/ubuntu-lv is now 6028288 (4k) blocks long.
root@xxx:~
e2fsck 1.46.5 (30-Dec-2021)
/dev/ubuntu-vg/ubuntu-lv is mounted.
e2fsck: Cannot continue, aborting.
root@xxx:~
Filesystem Size Used Avail Use% Mounted on
tmpfs 197M 1.2M 196M 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 23G 11G 11G 51% /
tmpfs 982M 0 982M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/sda2 2.0G 251M 1.6G 14% /boot
tmpfs 197M 4.0K 197M 1% /run/user/1000
参考
Cannot mount sda3 “mount: /media/drive: unknown filesystem type ‘LVM2_member’.”