2

I'm sorry to bring this up again as I know this question has been asked a few times before as shown here, here and here.

These solutions have worked excellently for me right up until 22.04, but now despite following the same instructions I cannot get these messages to away, as shown in this screenshot:

cloud-init messages on login tty:

cloud-init messages on login tty

Has the configuration of cloud-init changed in 22.04? Is there another way to fix this?

To be clear, I don't want to disable cloud-init, I want its initialization to stop cluttering my login screen.

karel
  • 122,292
  • 133
  • 301
  • 332

3 Answers3

2

So after much messing around and trying to wrap my head around the inner workings of systemd after reading DigitalOcean's rather excellent guide, I essentially tried the reverse of the previous recommendations. Instead of instructing getty@tty not to start until cloud-init had finished, I asked cloud-init not to allow getty@tty to start until it had finished (if that makes sense).

In detail, this means I made a directory called cloud-init.service.d within which I made a .conf file that looks like this:

[Unit]

Before=getty@tt1.service

This appears to work, though in theory this should be logically equivalent to the previous solutions. Anyhow I hope this helps others with the same problem.

Any further comments or clarifications would be appreciated.

1

For Ubuntu 20.04 and 22.04 this works.
All you need to do is create 2 files to have the output written to the journal instead of the console:

Files:

  • /etc/systemd/system/cloud-config.service.d/override.conf
  • /etc/systemd/system/cloud-final.service.d/override.conf

Contents

[Service]
StandardOutput=journal

Explanation
There are 2 services called by cloud-init that are the ones printing to console:

  • cloud-config
  • cloud-final

How To:

sudo -i
DIR=/etc/systemd/system
cd $DIR
mkdir cloud-config.service.d  cloud-final.service.d
FILE1=$DIR/cloud-config.service.d/override.conf
FILE2=$DIR/cloud-final.service.d/override.conf

cat >$FILE1 <<-EOF [Service] StandardOutput=journal EOF

cat >$FILE2 <<-EOF [Service] StandardOutput=journal EOF

Confirming it works Reboot --> no output in console --> log in --> check journalctl

journalctl -t cloud-init -g "modules:"
journalctl -t cloud-init -o verbose

You should see the lines that were previously printing to the console inside the journal. The verbose output will show you that cloud-init was calling cloud-final and cloud-config which were the actual services printing the messages.

0

If you want cloud-init to run and to not write to the console then you can change the Systemd setting for StandardOutput for the cloud-init service files.

One method to do this is to create an override file. This snippet will change the setting for the services cloud-init-local.service, cloud-init.service, cloud-config.service, and cloud-final.service.

for i in init-local init config final ; do 
  mkdir -p /etc/systemd/system/cloud-${i}.service.d
  cat <<EOF > /etc/systemd/system/cloud-${i}.service.d/override.conf
[Service]
StandardOutput=journal
EOF
done
systemctl daemon-reload

This might have negative consequences because the service files include the comment

Output needs to appear in instance console output

I don't know why the output needs to be written to the console but the commit history says

write stdout to tty so it shows up in GetConsoleOutput

GetConsoleOutput appears to be an Amazon EC2 call, so writing to console might be a way for cloud-init to provide information to users with cloud servers.