我已安装 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 似乎适用于其他设置,例如,在配置文件中设置时出现最终消息。
答案1
答案2
cloud-init query combined_cloud_config
建议命令这答案让我找到了问题的原因。
输出的内容如下:
userdata_raw: "#cloud-config\ngrowpart: {mode: 'off'}\nlocale: en_GB.UTF-8\npreserve_hostname:\...
这是来自/etc/cloud/cloud.cfg.d/99-installer.cfg
早期版本镜像遗留的文件。删除这个包含不需要的配置的文件后,模块growpart
在启动时启用,分区和文件系统也按应有的方式扩展。