ubuntu 扩展硬盘未使用的空间
查看根分区空间
df -hl
Filesystem Size Used Avail Use% Mounted on
udev 1.9G 0 1.9G 0% /dev
tmpfs 389M 41M 349M 11% /run
/dev/mapper/ubuntu–vg-ubuntu–lv 9.8G 9.8G 0 100% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/loop0 64M 64M 0 100% /snap/core20/2434
/dev/loop1 45M 45M 0 100% /snap/snapd/23545
/dev/loop2 64M 64M 0 100% /snap/core20/2496
/dev/loop4 92M 92M 0 100% /snap/lxd/29619
/dev/sda2 1.8G 211M 1.4G 13% /boot
/dev/loop3 45M 45M 0 100% /snap/snapd/23258
/dev/loop5 92M 92M 0 100% /snap/lxd/24061
tmpfs 389M 0 389M 0% /run/user/1000
磁盘使用率已经100%了。没有空间了
查看磁盘分区列表
fdisk -l
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk model: VMware Virtual S
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: 95884844-E26A-4659-AD65-04BAFBAD132C
Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 3719167 3715072 1.8G Linux filesystem
/dev/sda3 3719168 41940991 38221824 18.2G Linux filesystem
硬盘是20G的,还有10G的空间未使用
查看lv信息
lvdisplay
— Logical volume —
LV Path /dev/ubuntu-vg/ubuntu-lv
LV Name ubuntu-lv
VG Name ubuntu-vg
LV UUID DShaVN-9W2Y-3E3s-atMC-4iL2-zG8h-N0w0rN
LV Write Access read/write
LV Creation host, time ubuntu-server, 2024-11-08 07:31:01 +0000
LV Status available
open 1
LV Size 10.00 GiB
Current LE 2560
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
正在使用的是10G
增加根分区命令
lvextend -l +100%FREE -r /dev/ubuntu-vg/ubuntu-lv
Size of logical volume ubuntu-vg/ubuntu-lv changed from 10.00 GiB (2560 extents) to 18.22 GiB (4665 extents).
Logical volume ubuntu-vg/ubuntu-lv successfully resized.
resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/mapper/ubuntu–vg-ubuntu–lv is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 3
The filesystem on /dev/mapper/ubuntu–vg-ubuntu–lv is now 4776960 (4k) blocks long.
查看文件系统类型
df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
udev devtmpfs 1944180 0 1944180 0% /dev
tmpfs tmpfs 398164 41424 356740 11% /run
/dev/mapper/ubuntu–vg-ubuntu–lv ext4 18696940 9988420 7802004 57% /
tmpfs tmpfs 1990816 0 1990816 0% /dev/shm
tmpfs tmpfs 5120 0 5120 0% /run/lock
tmpfs tmpfs 1990816 0 1990816 0% /sys/fs/cgroup
/dev/loop0 squashfs 65280 65280 0 100% /snap/core20/2434
/dev/loop1 squashfs 45568 45568 0 100% /snap/snapd/23545
/dev/loop2 squashfs 65280 65280 0 100% /snap/core20/2496
/dev/loop4 squashfs 94208 94208 0 100% /snap/lxd/29619
/dev/sda2 ext4 1790136 215068 1465808 13% /boot
/dev/loop3 squashfs 45440 45440 0 100% /snap/snapd/23258
/dev/loop5 squashfs 94080 94080 0 100% /snap/lxd/24061
tmpfs tmpfs 398160 0 398160 0% /run/user/1000
为ext文件系统类型
重置大小
不同文件系统类型使用不同的指令。
xfs文件系统类型使用xfs_groufs进行扩容。
xfs_growfs 逻辑卷完整路径(如/dev/vg1/lv1)
ext文件系统类型用resize2fs命令进行扩容。
resize2fs 逻辑卷完整路径(如/dev/vg1/lv1)
resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
resize2fs 1.45.5 (07-Jan-2020)
The filesystem is already 4776960 (4k) blocks long. Nothing to do!
硬盘已经扩容成功,查看
lvdisplay
— Logical volume —
LV Path /dev/ubuntu-vg/ubuntu-lv
LV Name ubuntu-lv
VG Name ubuntu-vg
LV UUID DShaVN-9W2Y-3E3s-atMC-4iL2-zG8h-N0w0rN
LV Write Access read/write
LV Creation host, time ubuntu-server, 2024-11-08 07:31:01 +0000
LV Status available
open 1
LV Size 18.22 GiB
Current LE 4665
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
注意事项
如果逻辑卷已经挂载,扩容逻辑卷后需要扩容文件系统。
1065

被折叠的 条评论
为什么被折叠?



