I was to install a VM on QEMU using Ubuntu 22.04 TLS autoinstall.
An error brought up about subiquity
.
The root cause turned out to be network inaccessibility within the VM, because my host manchine was behind a proxy. At the installation time, the autoinstaller/cloud-init was not able to access Internet in the default NAT network protocol.
After comprehending the bug, I was going to find a way to enable system-wide proxy at the very beginning of cloud-init. There was an urgen proposal for such a system-wide proxy. However, such an issue has so far not been introduced to cloud-init.
The above bug report mentioned several workarounds by specying the proxy using the user-data. However, the basic cloud-config based one could not take effect during the installation phase. An alternative choice followed that was the cloud boothook.
#cloud-boothook
#!/bin/sh
#### Ubuntu/Debian
# Add proxies to Apt config
cat > /etc/apt/apt.conf.d/00-proxy <<EOC
Acquire::http { Proxy "http://proxy.example.com:8080"; };
Acquire::https { Proxy "http://proxy.example.com:8080"; };
Acquire::http::Pipeline-Depth "23";
Acquire::Languages "none";
EOC
# Add it to the environment
cat >> /etc/environment <<EOC
http_proxy="http://myproxy.server.com:8080/"
https_proxy="http://myproxy.server.com:8080/"
ftp_proxy="http://myproxy.server.com:8080/"
no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
HTTP_PROXY="http://myproxy.server.com:8080/"
HTTPS_PROXY="http://myproxy.server.com:8080/"
FTP_PROXY="http://myproxy.server.com:8080/"
NO_PROXY="localhost,127.0.0.1,localaddress,.localdomain.com"
EOC
This script perfectly solved the error.
However, in my case, I have to use another cloud-config as the user data. How to combine the cloud-boothook and cloud-config? Here is ther answer: Mime Multi Part Archive to merge them. cloud-init provides a tool to easily achieve this.
sudo apt-get install cloud-init
cloud-init devel make-mime -a config.yaml:cloud-config -a boothook.sh:boothook > userdata