欢迎光临
我们一直在努力

扩充bhyve 虚拟Ubuntu系统的系统盘大小,比往常多用了一个partd命令

bhyve虚拟机的磁盘空间不够了,需要扩充一下。

bhyve的管理记录:https://skywalk.blog.csdn.net/article/details/157032015

以前扩充系统盘的记录:https://skywalk.blog.csdn.net/article/details/140570088

先到bhyve虚拟机的宿主机里,找到虚拟机磁盘文件/vm_images/ub19_ub22.img ,用truncate 调整磁盘文件大小。

先上结论

扩充bhyve 虚拟Ubuntu系统的系统盘大小,普通过程就是扩充逻辑卷和扩展文件系统。

如果空间没有分配,那么就用partd扩展逻辑卷对应的分区,然后再扩充逻辑卷和扩展文件系统。

常规操作

truncate 扩充虚拟机磁盘文件大小

找到 虚拟Ubuntu系统的系统盘,在/vm_images ,文件是ub19_ub22.img

root@fb5:/vm_images # ls -la
total 12423627
drwxr-xr-x 3 root wheel 5 Feb 4 18:41 .
drwxr-xr-x 24 root wheel 29 Jan 25 16:17 ..
drwxr-xr-x 2 root wheel 2 Jan 20 12:27 .trash
-rw-r–r– 1 root wheel 19327352832 Mar 5 13:50 truenas_true13.img
-rw-r–r– 1 root wheel 17179869184 Mar 4 09:23 ub19_ub22.img

停止虚拟机,调整磁盘大小:

truncate -s +10G /vm_images/ub19_ub22.img

调整完毕:

root@fb5:/vm_images # ls -la
total 12423627
drwxr-xr-x 3 root wheel 5 Feb 4 18:41 .
drwxr-xr-x 24 root wheel 29 Jan 25 16:17 ..
drwxr-xr-x 2 root wheel 2 Jan 20 12:27 .trash
-rw-r–r– 1 root wheel 19327352832 Mar 5 13:50 truenas_true13.img
-rw-r–r– 1 root wheel 17179869184 Mar 4 09:23 ub19_ub22.img
root@fb5:/vm_images # truncate -s +10G /vm_images/ub19_ub22.img
root@fb5:/vm_images # ls -la
total 12424023
drwxr-xr-x 3 root wheel 5 Feb 4 18:41 .
drwxr-xr-x 24 root wheel 29 Jan 25 16:17 ..
drwxr-xr-x 2 root wheel 2 Jan 20 12:27 .trash
-rw-r–r– 1 root wheel 19327352832 Mar 5 13:55 truenas_true13.img
-rw-r–r– 1 root wheel 27917287424 Mar 5 13:55 ub19_ub22.img

启动Ubuntu,现在系统里面是这样的:

skywalk@ub19:/$ df -H
Filesystem Size Used Avail Use% Mounted on
tmpfs 206M 1.1M 205M 1% /run
/dev/mapper/ubuntu–vg-ubuntu–lv 11G 11G 0 100% /
tmpfs 1.1G 0 1.1G 0% /dev/shm
tmpfs 5.3M 0 5.3M 0% /run/lock
/dev/vda2 1.9G 284M 1.5G 17% /boot
/dev/vda1 799M 6.4M 793M 1% /boot/efi
tmpfs 206M 4.1k 206M 1% /run/user/1000

扩充逻辑卷

sudo lvextend -l +100%FREE /dev/mapper/ubuntu–vg-ubuntu–lv

可以看到磁盘从10G扩充到13G

sudo lvextend -l +100%FREE /dev/mapper/ubuntu–vg-ubuntu–lv
Size of logical volume ubuntu-vg/ubuntu-lv changed from 10.00 GiB (2560 extents) to 13.50 GiB (3456 extents).
Logical volume ubuntu-vg/ubuntu-lv successfully resized.

扩展文件系统

sudo resize2fs /dev/mapper/ubuntu–vg-ubuntu–lv

扩展完毕

sudo resize2fs /dev/mapper/ubuntu–vg-ubuntu–lv
resize2fs 1.46.5 (30-Dec-2021)
Filesystem at /dev/mapper/ubuntu–vg-ubuntu–lv is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 2
The filesystem on /dev/mapper/ubuntu–vg-ubuntu–lv is now 3538944 (4k) blocks long.

skywalk@ub19:~/.cache$ df
Filesystem 1K-blocks Used Available Use% Mounted on
tmpfs 200784 1032 199752 1% /run
/dev/mapper/ubuntu–vg-ubuntu–lv 13827112 10135468 2983204 78% /
tmpfs 1003920 0 1003920 0% /dev/shm
tmpfs 5120 0 5120 0% /run/lock
/dev/vda2 1768056 276444 1383480 17% /boot
/dev/vda1 779768 6232 773536 1% /boot/efi
tmpfs 200784 4 200780 1% /run/user/1000

但是我还有一些空间呢? 我估计这是我以前分配给磁盘的,今天扩展上去了。

新分配的空间还没扩展。

lsblk命令查看当前磁盘和分区情况

lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 63.8M 1 loop /snap/core20/2686
loop1 7:1 0 63.8M 1 loop /snap/core20/2717
loop2 7:2 0 91.4M 1 loop /snap/lxd/36918
loop3 7:3 0 38.8M 1 loop /snap/snapd/21759
loop4 7:4 0 91.6M 1 loop /snap/lxd/37982
loop5 7:5 0 48.1M 1 loop /snap/snapd/25935
vda 252:0 0 26G 0 disk
├─vda1 252:1 0 763M 0 part /boot/efi
├─vda2 252:2 0 1.8G 0 part /boot
└─vda3 252:3 0 13.5G 0 part
└─ubuntu–vg-ubuntu–lv 253:0 0 13.5G 0 lvm /

通过vgs查看未分配空间

sudo vgs

不过这台系统,刚开始看到了母系统的空间,后来再发同样的命令,看到的就是自己的了,看,还有13.5G空间没有分配。

skywalk@ub19:~/.cache$ sudo sudo vgs
Free
ubuntu-vg 1 1 0 wz–n- 235.42g 135.42g VG #PV #LV #SN Attr VSize VFree
ubuntu-vg 1 1 0 wz–n- 235.42g 135.42g VG #PV #LV #SN Attr VSize VFree
ubuntu-vg 1 1 0 wz–n- 235.42g 135.42g VG #PV #LV #SN Attr VSize VFree
ubuntu-vg 1 1 0 wz–n- 13.50g 0
skywalk@ub19:~/.cache$ sudo vgs
r VSize VFree
ubuntu-vg 1 1 0 wz–n- 235.42g 135.42g VG #PV #LV #SN Attr VSize VFree
ubuntu-vg 1 1 0 wz–n- 235.42g 135.42g VG #PV #LV #SN Attr VSize VFree
ubuntu-vg 1 1 0 wz–n- 13.50g 0
skywalk@ub19:~/.cache$ vgs
WARNING: Running as a non-root user. Functionality may be unavailable.
/run/lock/lvm/P_global:aux: open failed: Permission denied
skywalk@ub19:~/.cache$ sudo vgs
VG #PV #LV #SN Attr VSize VFree
ubuntu-vg 1 1 0 wz–n- 13.50g 0
skywalk@ub19:~/.cache$ sudo vgs
VG #PV #LV #SN Attr VSize VFree
ubuntu-vg 1 1 0 wz–n- 13.50g 0

看错了,VFree是0,没有free空间了

lsblk看到还有空间,怎么分配出来?

vda                       252:0    0   26G  0 disk ├─vda1                    252:1    0  763M  0 part /boot/efi ├─vda2                    252:2    0  1.8G  0 part /boot └─vda3                    252:3    0 13.5G  0 part   └─ubuntu–vg-ubuntu–lv 253:0    0 13.5G  0 lvm  /

多一步partd扩展

用partd把前面lsblk看到的空间扩展到vda3分区。

用partd扩展vda3分区

sudo parted /dev/vda
GNU Parted 3.4
Using /dev/vda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: Virtio Block Device (virtblk)
Disk /dev/vda: 27.9GB
Sector size (logical/physical): 512B/131072B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags
1 1049kB 801MB 800MB fat32 boot, esp
2 801MB 2680MB 1879MB ext4
3 2680MB 17.2GB 14.5GB

(parted) resizepart 3 100%
(parted) print
Model: Virtio Block Device (virtblk)
Disk /dev/vda: 27.9GB
Sector size (logical/physical): 512B/131072B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags
1 1049kB 801MB 800MB fat32 boot, esp
2 801MB 2680MB 1879MB ext4
3 2680MB 27.9GB 25.2GB

(parted) quit
Information: You may need to update /etc/fstab.

扩展之后,使用pvresize更新 /dev/vda3

pvresize 更新 /dev/vda3

skywalk@ub19:~$ sudo pvresize /dev/vda3
Physical volume "/dev/vda3" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
skywalk@ub19:~$ lvextend -l +100%FREE /dev/mapper/ubuntu–vg-ubuntu–lv
WARNING: Running as a non-root user. Functionality may be unavailable.
/dev/mapper/control: open failed: Permission denied
Failure to communicate with kernel device-mapper driver.
Incompatible libdevmapper 1.02.175 (2021-01-08) and kernel driver (unknown version).
/run/lock/lvm/V_ubuntu-vg:aux: open failed: Permission denied
Can't get lock for ubuntu-vg.
Cannot process volume group ubuntu-vg
skywalk@ub19:~$ sudo lvextend -l +100%FREE /dev/mapper/ubuntu–vg-ubuntu–lv
Size of logical volume ubuntu-vg/ubuntu-lv changed from 13.50 GiB (3456 extents) to 23.50 GiB (6016 extents).
Logical volume ubuntu-vg/ubuntu-lv successfully resized.

扩充逻辑卷和文件系统

skywalk@ub19:~$ sudo lvextend -l +100%FREE /dev/mapper/ubuntu–vg-ubuntu–lv
Size of logical volume ubuntu-vg/ubuntu-lv changed from 13.50 GiB (3456 extents) to 23.50 GiB (6016 extents).
Logical volume ubuntu-vg/ubuntu-lv successfully resized.

sudo resize2fs /dev/mapper/ubuntu–vg-ubuntu–lv
resize2fs 1.46.5 (30-Dec-2021)
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 6160384 (4k) blocks long.

skywalk@ub19:~$ df -H
Filesystem Size Used Avail Use% Mounted on
tmpfs 206M 1.1M 205M 1% /run
/dev/mapper/ubuntu–vg-ubuntu–lv 25G 9.8G 14G 42% /
tmpfs 1.1G 0 1.1G 0% /dev/shm
tmpfs 5.3M 0 5.3M 0% /run/lock
/dev/vda2 1.9G 265M 1.5G 16% /boot
/dev/vda1 799M 6.4M 793M 1% /boot/efi
tmpfs 206M 4.1k 206M 1% /run/user/1000

搞定!

空间够了,可以装ollama啦!

sudo snap install ollama

不过这个ollama版本低了,是0.15.1,抽空再去升级一下就行了。

赞(0)
未经允许不得转载:171主机测评 » 扩充bhyve 虚拟Ubuntu系统的系统盘大小,比往常多用了一个partd命令
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址