When troubleshooting cloud-init initialization on cloud instances (AWS EC2, Azure, GCP etc.), the logging system can initially seem fragmented. Unlike traditional services that log to a single file, cloud-init employs a multi-file approach that captures different stages of the boot process.
Cloud-init stores logs across several files in /var/log/
:
/var/log/cloud-init.log # Main execution log (often truncated) /var/log/cloud-init-output.log # Full output of user-data scripts /var/log/boot.log # System boot messages including early cloud-init stages
For a complete picture of your instance initialization, examine these files in combination:
# Check all cloud-init related logs: sudo cat /var/log/cloud-init.log sudo cat /var/log/cloud-init-output.log # For timing information: journalctl -u cloud-init # Debugging modules: sudo cat /var/lib/cloud/data/result.json
To get more detailed logging, modify your cloud-init configuration:
# /etc/cloud/cloud.cfg.d/05_logging.cfg debug: True log_dir: /var/log/cloud log_file: cloud-init-debug.log
When debugging a failing user-data script, this command sequence helps pinpoint issues:
# Check if cloud-init completed successfully: cloud-init status --wait # View all initialization stages: cloud-init analyze show # Filter logs for specific modules: sudo journalctl -u cloud-init | grep "cc_scripts_user"
For persistent logging across reboots in AWS environments:
# EC2 user-data to preserve logs in S3 #!/bin/bash exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1 apt-get update apt-get install -y awscli aws s3 cp /var/log/cloud-init-output.log s3://your-bucket/${INSTANCE_ID}-logs/
When debugging instance initialization on cloud platforms like AWS EC2, DigitalOcean, or Azure, cloud-init generates logs in multiple locations:
/var/log/cloud-init.log
/var/log/cloud-init-output.log
/run/cloud-init/
/var/lib/cloud/instance/
The key log files contain different stages of initialization:
- cloud-init.log: Core initialization process and module execution
- cloud-init-output.log: Combined stdout/stderr from user-data scripts
- /var/lib/cloud/instance/: Contains user-data, meta-data, and processed configs
Verify if cloud-init completed successfully:
cloud-init status
# Expected output: status: done
For detailed analysis of execution phases:
cloud-init analyze show
When troubleshooting user-data scripts:
- Check timestamps in logs for execution duration
- Look for error markers in cloud-init-output.log
- Verify cloud-init modules executed as expected
To locate output from your custom user-data script:
grep "user-data" /var/log/cloud-init.log
# Or examine the full output:
cat /var/log/cloud-init-output.log
For verbose logging, create /etc/cloud/cloud.cfg.d/05_logging.cfg:
# Debug level logging
debug: True
log_dir: /var/log/cloud-init
log_file: cloud-init-debug.log
- Log rotation deleting older entries
- Different cloud platforms having varying default log locations
- Permission issues preventing log access
Platform | Additional Log Location |
---|---|
AWS EC2 | /var/log/amazon/ec2/ |
Google Cloud | /var/log/google-cloud/ |
Azure | /var/log/waagent.log |