我安装了 Ubuntu 20.04 虚拟机服务器Cloud-init
。我正在尝试使用 Cloud-init 自动扩展虚拟机的磁盘。虚拟机主机是 ESXi,数据源是 None,因为我只想为新虚拟机进行一些自动配置,而不需要外部数据源。
我尝试根据此文档配置 Cloud-init 模块:https://cloudinit.readthedocs.io/en/latest/reference/modules.html#
- 操作系统:Ubuntu:20.04.6 LTS
- 云初始化:23.4.4-0ubuntu0~20.04.1
Cloud-init 在启动时执行,但由于未知原因始终会跳过growpart
模块:resizefs
2024-04-03 11:59:04,058 - modules.py[DEBUG]: Running module growpart (<module 'cloudinit.config.cc_growpart' from '/usr/lib/python3/dist-packages/cloudinit/config/cc_growpart.py'>) with frequency always
2024-04-03 11:59:04,058 - handlers.py[DEBUG]: start: init-network/config-growpart: running config-growpart with frequency always
2024-04-03 11:59:04,058 - helpers.py[DEBUG]: Running config-growpart using lock (<cloudinit.helpers.DummyLock object at 0x7f8bec612430>)
2024-04-03 11:59:04,059 - cc_growpart.py[DEBUG]: growpart disabled: mode=off
2024-04-03 11:59:04,059 - handlers.py[DEBUG]: finish: init-network/config-growpart: SUCCESS: config-growpart ran successfully
2024-04-03 11:59:04,059 - modules.py[DEBUG]: Running module resizefs (<module 'cloudinit.config.cc_resizefs' from '/usr/lib/python3/dist-packages/cloudinit/config/cc_resizefs.py'>) with frequency always
2024-04-03 11:59:04,059 - handlers.py[DEBUG]: start: init-network/config-resizefs: running config-resizefs with frequency always
2024-04-03 11:59:04,059 - helpers.py[DEBUG]: Running config-resizefs using lock (<cloudinit.helpers.DummyLock object at 0x7f8bec612460>)
2024-04-03 11:59:04,059 - cc_resizefs.py[DEBUG]: Skipping module named resizefs, resizing disabled
2024-04-03 11:59:04,059 - handlers.py[DEBUG]: finish: init-network/config-resizefs: SUCCESS: config-resizefs ran successfully
我有最小的配置/etc/cloud/cloud.cfg
:
cloud_init_modules:
- growpart
- resizefs
growpart:
mode: auto
devices: ["/"]
resize_rootfs: true
system_info:
distro: ubuntu
paths:
cloud_dir: /var/lib/cloud/
templates_dir: /etc/cloud/templates/
分区和文件系统在引导期间处于此状态:
user@server:~$ sudo fdisk /dev/sda
Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
GPT PMBR size mismatch (20971519 != 31457279) will be corrected by write.
The backup GPT table is not on the end of the device. This problem will be corrected by write.
Command (m for help): p
Disk /dev/sda: 15 GiB, 16106127360 bytes, 31457280 sectors
Disk model: Virtual disk
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
Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 20969471 20965376 10G Linux filesystem
user@server:~$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 9.8G 3.4G 6.0G 36% /
根据文档,一个文件可以阻止growpart,但阻止文件不存在:
user@server:~$ ls /etc/growroot-disabled
ls: cannot access '/etc/growroot-disabled': No such file or directory
什么可能导致模块被跳过?我应该怎样做才能使它们正常工作?
更新:
根据cloud-init query
我的设置cloud.cfg
不适用:
user@server:~$ sudo cloud-init query combined_cloud_config
...
"cloud_init_modules": [
"growpart",
"resizefs"
],
...
"growpart": {
"mode": "off"
},
...
"final_message": "This comes from cloud.cfg as it should.",
...
Cloud.cfg 似乎适用于其他设置,例如最终消息显示为配置文件中设置的设置。