这些是我正在尝试的步骤从这个答案:
我跑的步骤:
- 运行以下命令获取PV(物理量)姓名(前任:
/dev/sda1
)
sudo pvs
tini-wini # pvs
PV VG Fmt Attr PSize PFree
/dev/sda3 ubuntu-vg lvm2 a-- <9,00g 0
tini-wini #
- 调整PV大小
sudo pvresize /dev/sda3
tini-wini # sudo pvresize /dev/sda3
Physical volume "/dev/sda3" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
tini-wini #
- 运行以下命令获取根逻辑卷名称(行的文件系统值
/
;例如/dev/mapper/ubuntu--vg-root
:)
df -h
tini-wini # df -h
Filesystem Size Used Avail Use% Mounted on
udev 948M 0 948M 0% /dev
tmpfs 199M 1,1M 198M 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 8,8G 8,2G 211M 98% /
tmpfs 992M 0 992M 0% /dev/shm
tmpfs 5,0M 0 5,0M 0% /run/lock
tmpfs 992M 0 992M 0% /sys/fs/cgroup
/dev/loop0 45M 45M 0 100% /snap/snapd/15314
/dev/loop1 62M 62M 0 100% /snap/core20/1405
/dev/loop2 62M 62M 0 100% /snap/core20/1376
/dev/loop3 68M 68M 0 100% /snap/lxd/22753
/dev/loop4 56M 56M 0 100% /snap/core18/2344
/dev/loop5 68M 68M 0 100% /snap/lxd/22526
/dev/loop6 44M 44M 0 100% /snap/snapd/15177
/dev/loop7 56M 56M 0 100% /snap/core18/2253
/dev/sda2 976M 207M 703M 23% /boot
tmpfs 199M 0 199M 0% /run/user/1000
tini-wini #
- 扩展逻辑卷:
sudo lvextend -r -l +100%FREE /dev/mapper/ubuntu--vg-root
tini-wini # lvextend -r -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
Size of logical volume ubuntu-vg/ubuntu-lv unchanged from <9,00 GiB (2303 extents).
Logical volume ubuntu-vg/ubuntu-lv successfully resized.
resize2fs 1.45.5 (07-Jan-2020)
The filesystem is already 2358272 (4k) blocks long. Nothing to do!
tini-wini #
通过lsblk
命令,它告诉我磁盘中有空间。
tini-wini # lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 44,7M 1 loop /snap/snapd/15314
loop1 7:1 0 61,9M 1 loop /snap/core20/1405
loop2 7:2 0 61,9M 1 loop /snap/core20/1376
loop3 7:3 0 67,8M 1 loop /snap/lxd/22753
loop4 7:4 0 55,5M 1 loop /snap/core18/2344
loop5 7:5 0 67,9M 1 loop /snap/lxd/22526
loop6 7:6 0 43,6M 1 loop /snap/snapd/15177
loop7 7:7 0 55,5M 1 loop /snap/core18/2253
sda 8:0 0 21G 0 disk
├─sda1 8:1 0 1M 0 part
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 9G 0 part
└─ubuntu--vg-ubuntu--lv 253:0 0 9G 0 lvm /
sr0 11:0 1 1024M 0 rom
tini-wini #
在这种情况下我需要做什么?
更新
fdisk -l
Disk /dev/loop0: 55,5 MiB, 58183680 bytes, 113640 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop1: 67,94 MiB, 71221248 bytes, 139104 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop2: 67,83 MiB, 71106560 bytes, 138880 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop3: 44,65 MiB, 46804992 bytes, 91416 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop4: 61,92 MiB, 64901120 bytes, 126760 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop5: 55,53 MiB, 58212352 bytes, 113696 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop6: 43,64 MiB, 45748224 bytes, 89352 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/loop7: 61,92 MiB, 64901120 bytes, 126760 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/sda: 21 GiB, 22548578304 bytes, 44040192 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: 363D35B2-1971-493B-B67D-6C40297B89AB
Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 2101247 2097152 1G Linux filesystem
/dev/sda3 2101248 20969471 18868224 9G Linux filesystem
Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 8,102 GiB, 9659482112 bytes, 18866176 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
tini-wini #
答案1
根据评论,该过程似乎不完整。这是在 VirtualBox VM 上调整 LV 大小时需要发生的事件序列。
- 从 VirtualBox 级别开始。 VirtualBox 将虚拟机磁盘作为主机系统上的单独文件保存。将磁盘大小更新为所需的值。
- 在来宾虚拟机上,内核将识别磁盘大小的增加,但尚不可用。您需要使用
fdisk
、gdisk
、 或gparted
(或其他 GUI 等效工具)等工具从额外空间创建分区。如果可用空间紧随现有分区,您还可以扩展现有分区。 - 接下来是最低的 LVM 级别 - 物理卷。如果创建了新分区,请运行
pvcreate
以从中创建新的 PV。如果扩展了分区,请运行pvresize
以获取更改。 - 进入 LVM 的第二层——卷组。如果添加了 PV,您需要使用 将其添加到卷组中
vgextend
。如果调整了 PV 的大小,则应自动获取更改。
此时,您应该看到目标卷组下有一些可用空间。
- 接下来是 LVM 的顶层——逻辑卷。使用
lvextend
从卷组分配可用空间来扩展所需的 LV 。使用诸如 之类的命令lsblk
来确定要扩展哪个 LV。 - 最后一步是告诉 LV 上的文件系统占用新空间。
lvextend
可以使用该--resizefs
选项管理多个文件系统。否则,您可以使用特定于文件系统的工具来扩展它(resize2fs
对于 ext2/3/4、xfs_growfs
XFS 等)。
您现在应该拥有一个具有所需额外存储空间量的文件系统。