Skip to content

Instantly share code, notes, and snippets.

@zoilomora
Last active March 22, 2024 09:22
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

@giormatsis
Copy link

works here ubuntu with su (root) server 20.04 rasbian mate rasberry pi4 8g

@JuniperChris929
Copy link

works like a charm here (Ubuntu 20.04.6)

@zogness
Copy link

zogness commented Apr 27, 2022

Works on 21.10 Ubuntu server.

@hisakiyo
Copy link

hisakiyo commented May 8, 2022

Works on Debian 11, thanks

@juliyvchirkov
Copy link

works on 22.04 Ubuntu server, thanks a lot!

@nero-dv
Copy link

nero-dv commented May 30, 2022

Working on ubuntu server 22.04, thanks!

@qupfer
Copy link

qupfer commented Jun 17, 2022

"Stupid Question": Should sudo apt-get purge cloud-init not be enough?
If not, I would say its bad packaging of cloud-init and should be handled as a clound-init bug.

@o-ristow
Copy link

"Stupid Question": Should sudo apt-get purge cloud-init not be enough?
If not, I would say its bad packaging of cloud-init and should be handled as a clound-init bug.

the folders /etc/cloud/ and /var/lib/cloud/ are not empty after sudo apt-get purge cloud-init - they still contain a bunch of config files - otherwise it is sufficient.

@RokkuCode
Copy link

Uninstalling on Ubuntu 22.04 marks neccessary packages like netplan.io for autoremove. you should mark them firs as manual before removing cloud-init

@baalpeteor
Copy link

Fordp12

Fordp12 -> P.I.C.N.I.C.
(Problem in chair, not in computer)

@sean-m-foley
Copy link

Uninstalling on Ubuntu 22.04 marks neccessary packages like netplan.io for autoremove. you should mark them firs as manual before removing cloud-init

I second that. There is no actual reason to delete the cloud init from the server. Once you have the file touched and have the service disabled/stopped it isn't relevant as to whether it is installed or not. It will NEVER run.

@rdewald
Copy link

rdewald commented Jan 17, 2023

While I concur that installation is irrelevant after the service is disabled by the dpkg-reconfigure edits, netplan.io was left alone on my recent 22.04 install after apt purge cloud-init.

@zoilomora, muchas gracias.

@catwhocode
Copy link

works fine on ubuntu 22.04.2 LTS

@j-n7
Copy link

j-n7 commented Jun 7, 2023

Works like a charm, thank you very much ♥

@crkinard
Copy link

crkinard commented Jun 15, 2023

While I concur that installation is irrelevant after the service is disabled by the dpkg-reconfigure edits, netplan.io was left alone on my recent 22.04 install after apt purge cloud-init.

@zoilomora, muchas gracias.

While it does leave netplan.io and some other rather necessary things alone if you EVER run 'sudo apt autoremove' for any reason in the future you will cripple the install. Hope you have physical access or IPMI to fix it at that point.

Because of this I would never run anything more than 'sudo touch /etc/cloud/cloud-init.disabled'.

Really stupid move on Ubuntu's part to tie things in like this for a service not everyone is going to use. I hate opt-out with the fury of 9001 dying suns.

@Fastidious
Copy link

While it does leave netplan.io and some other rather necessary things alone if you EVER run 'sudo apt autoremove' for any reason in the future you will cripple the install. Hope you have physical access or IPMI to fix it at that point.

Because of this I would never run anything more than 'sudo touch /etc/cloud/cloud-init.disabled'.

Strongly agree on this one. Creating the file does the job, and causes no further unforeseen issues.

@qupfer
Copy link

qupfer commented Sep 1, 2023

I have an 22.04.3 minimal-server vm.
I purged cloud-init, and did an autoremove afterwards.
Nothing bad happen. All works fine as before. netplan is still marked as automatic installed and active/working.
Only a few python3-packages are removed, as they are (correctly) not needed by an package anymore.

So, for my conclusion.
sudo touch /etc/cloud/cloud-init.disabled is enough if you just don't need it, but doesn't care about some unused stuff left on disk.

apt-get purge cloud-init if you want to remove it.

@juliyvchirkov
Copy link

juliyvchirkov commented Nov 8, 2023

@qupfer I can confirm it's totally safe to remove cloud-init

Seems I've missed the warnings (if I've seen any) and droped mine on May 23, 2022 on next step after I've googled this gist and my cloud-init has been successfully disabled

Ubuntu 22.04.3, dedicated server at Frankfurt, DE from Hetzner

281287310-ed9cf7d7-64a3-46ce-af1c-64010eae946b (1)

@Ethan-Geyer
Copy link

This worked perfectly thank you!

@Balzabu
Copy link

Balzabu commented Dec 29, 2023

Hello everyone!
I just wanted to inform you that I've created a bash script designed to automate the process of disabling cloud-init on Ubuntu servers. It's a quick and simple solution you can even call through a oneliner.

GitHub Repo: disable-cloud-init

Give it a try and let me know your thoughts! Your feedback is highly appreciated.

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