最近,我的一台多路径虚拟机上的空间用完了。我决定在这里写下扩展虚拟机磁盘大小的步骤。
请考虑下面的多路径虚拟机列表:
kenneth@laptop:~$ multipass list
Name State IPv4 Image
altruistic-impala Running 172.17.244.151 Ubuntu 22.04 LTS
awx Stopped -- Ubuntu 22.04 LTS
database Stopped -- Ubuntu 22.04 LTS
haproxy Stopped -- Ubuntu 22.04 LTS
The VM named altruistic-impala
is the one concerned by the disk expansion. It has the following specs:
kenneth@laptop:~$ multipass info altruistic-impala
Name: altruistic-impala
State: Running
IPv4: 172.17.244.151
Release: Ubuntu 22.04.3 LTS
Image hash: 870bd58b5c1e (Ubuntu 22.04 LTS)
CPU(s): 1
Load: 0.02 0.03 0.00
Disk usage: 7.6GiB out of 7.6GiB
Memory usage: 180.4MiB out of 892.2MiB
Mounts: --
As you can see above, the VM has a 7.6GiB
disk, used at 100% of its capacity.
I will expand the disk size to 32G (feel free to put with the desired size you want):
kenneth@laptop:~$ multipass stop altruistic-impala
kenneth@laptop:~$ multipass set local.altruistic-impala.disk=32G
kenneth@laptop:~$ multipass start altruistic-impala
Note: Substitute
altruistic-impala
in all the commands of this article with the name of your target VM.
在这一点上,我应该完成。根据Multipass文档,以上步骤就足够了。虚拟机磁盘大小应该已经扩展,根分区的大小应该已经调整。但就我而言,我得到了一个惊喜:之前的说法部分属实。调整大小操作需要一小部分可用空间。
我为什么这么说?
因为我发现,如果您的虚拟机磁盘在进行扩展时没有剩余空间,磁盘大小会发生变化,但根分区不会自动调整大小。那么修改将不会反映在操作系统中。因此,在扩展磁盘之后,我需要手动扩展主分区,并从VM中扩展文件系统。如果你也处于同样的情况,请阅读。
您可以在VM上使用lsblk命令,如下所示进行验证:
kenneth@laptop:~$ multipass exec altruistic-impala -- 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 32G 0 disk
├─sda1 8:1 0 7.9G 0 part /
├─sda14 8:14 0 4M 0 part
└─sda15 8:15 0 106M 0 part /boot/efi
sr0 11:0 1 52K 0 rom
我们可以看到,sda磁盘大小已成功地从8G增加到32G。但它的主分区sda1安装在/仍然显示7.9G的大小。我们需要调整分区大小以利用所有可用空间。
让我们进入altruistic-impala的shell:
kenneth@laptop:~$ multipass shell altruistic-impala
From that shell:
ubuntu@altruistic-impala:~$ sudo parted /dev/sda
GNU Parted 3.4
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) resizepart
Warning: Not all of the space available to /dev/sda appears to be used, you can fix the GPT to use all of the space (an extra 50331648 blocks) or continue with
the current setting?
Fix/Ignore? Fix
Partition number? 1
Warning: Partition /dev/sda1 is being used. Are you sure you want to continue?
Yes/No? Yes
End? [8590MB]? 100%
(parted) quit
Information: You may need to update /etc/fstab.
We also need to resize the filesystem:
ubuntu@altruistic-impala:~$ sudo resize2fs /dev/sda1
resize2fs 1.46.5 (30-Dec-2021)
Filesystem at /dev/sda1 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 4
The filesystem on /dev/sda1 is now 8360187 (4k) blocks long.
And now we’re done! We check it out:
ubuntu@altruistic-impala:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
fd0 2:0 1 4K 0 disk
loop0 7:0 0 53.3M 1 loop /snap/snapd/19457
loop1 7:1 0 63.4M 1 loop /snap/core20/1974
loop2 7:2 0 111.9M 1 loop /snap/lxd/24322
sda 8:0 0 32G 0 disk
├─sda1 8:1 0 31.9G 0 part /
├─sda14 8:14 0 4M 0 part
└─sda15 8:15 0 106M 0 part /boot/efi
sr0 11:0 1 52K 0 rom
The /dev/sda1
partition is now used at 25%
against 100% at the beginning of this write-up:
ubuntu@altruistic-impala:~$ df -h
Filesystem Size Used Avail Use% Mounted on
tmpfs 96M 5.7M 90M 6% /run
/dev/sda1 31G 7.6G 24G 25% /
tmpfs 476M 0 476M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/sda15 105M 6.1M 99M 6% /boot/efi
tmpfs 96M 4.0K 96M 1% /run/user/1000
It corresponds to 7.6GiB
used out of 30.9GiB
:
kenneth@laptop:~$ multipass info altruistic-impala
Name: altruistic-impala
State: Running
IPv4: 172.17.244.151
Release: Ubuntu 22.04.3 LTS
Image hash: 870bd58b5c1e (Ubuntu 22.04 LTS)
CPU(s): 1
Load: 0.08 0.10 0.07
Disk usage: 7.6GiB out of 30.9GiB
Memory usage: 148.2MiB out of 951.9MiB
Mounts: --
That’s all !
最新内容
- 1 week ago
- 1 week ago
- 1 week ago
- 1 week ago
- 1 week ago
- 1 week 6 days ago
- 2 weeks ago
- 2 weeks 3 days ago
- 2 weeks 3 days ago
- 2 weeks 3 days ago