Skip to content

Instantly share code, notes, and snippets.

@zoilomora
Last active June 28, 2024 04:59
Show Gist options
  • Save zoilomora/f862f76335f5f53644a1b8e55fe98320 to your computer and use it in GitHub Desktop.
Save zoilomora/f862f76335f5f53644a1b8e55fe98320 to your computer and use it in GitHub Desktop.
How to disable cloud-init in Ubuntu

How to disable cloud-init in Ubuntu

Prevent start

  • Create an empty file to prevent the service from starting

      sudo touch /etc/cloud/cloud-init.disabled
    

Uninstall

  • Disable all services (uncheck everything except "None"):

      sudo dpkg-reconfigure cloud-init
    
  • Uninstall the package and delete the folders

      sudo dpkg-reconfigure cloud-init
      sudo apt-get purge cloud-init
      sudo rm -rf /etc/cloud/ && sudo rm -rf /var/lib/cloud/
    
  • Restart the computer

      sudo reboot
    

Sources

@miazj
Copy link

miazj commented May 31, 2024

After purged cloud-init (on 22.04), the netplan package is also removed. I followed this section 3.3. Temporary Static IP via ip to temporary get an IP address, then reinstall netplan using: sudo apt install netplan.io

Almost had a heart attack...

Thankfully, can confirm that these instructions worked without removing the netplan package for me (Server 22.04).

@Balzabu
Copy link

Balzabu commented Jun 21, 2024

Hello guys, since the issue with "netplan.io" seems to be affecting more and more people recently I've decided to study a solution that would avoid having to mess with temporary IPs and other stuff.
I've found a quick and dirty workaround everyone can use in case the netplan.io package is installed.

Basically, before proceeding to purge the "cloud-init" package with APT, we can mark the package "netplan.io" as on hold in order to be sure it will not be removed; this will ensure that the "netplan.io" dependency is not touched by APT at all.

The following one-liner can be used before the sudo apt-get purge cloud-init command to check if "netplan.io" is installed and put it on hold automatically: dpkg-query -W -f='${Status}' netplan.io 2>/dev/null | grep -q "install ok installed" && { sudo apt-mark hold netplan.io && echo "netplan.io put on hold"; } || echo "netplan.io is not available";

More informations about apt-mark can be found in the official debian manpage: manpages.debian.org

I've also updated my Bash Script (disable-cloud-init) to include this solution.

@juliyvchirkov
Copy link

juliyvchirkov commented Jun 28, 2024

Ubuntu 24.04 server (minimal configuration) comes with the following at file /etc/netplan/50-cloud-init.yaml

# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment