LoginSignup
0
0

More than 3 years have passed since last update.

Is your Linux instance okay? Configurations that cloud-init initializes when restoring from AMI

Posted at

This article is an automatic translation of the article[52995b55477f7d8efd19] below.
https://qiita.com/speaktech/items/52995b55477f7d8efd19

What this article introduces

On AWS, the automatic configuration tool"cloud-init"is installed on most Linux instances.
The default settings for cloud-init include items that perform initialization when the AMI is launched for the first time.
If you leave the default setting, there is no problem during normal use, but starting from the AMI at the time of restore will cause some items to be initialized.

In this article, we will introduce the items that user data is initialized at AMI startup and how to prevent it.

Verification environment

-Region: ap-northeast-1
-AMI: RHEL-7.6_HVM-20190515-x86_64-0-Hourly2-GP2-ami-04eb805483f5607a7
-Instance type: t2.micro

Items where user data is initialized when AMI is launched

-Host name (set to a host name based on Private IP named ip-XX-XX-XX-XX)

-Default user (ec2-user is created)

-Locale (set to en_US.UTF-8)

-Package (security update is executed)

How to prevent initialization

Just create a configuration file for initialization prevention with the following command.
(Time zone setting is added just in case, but it was not initialized in RHEL 7.6)

cat >> /etc/cloud/cloud.cfg.d/99_preservesetting.cfg << EOF
repo_update: true
repo_upgrade: none
preserve_hostname: true
locale: ja_JP.UTF-8
timezone: Asia/Tokyo

system_info:
  default_user:
    name: cloudinit-user
    lock_passwd: true
    gecos: Cloudinit User
    groups: [ adm, wheel, systemd-journal ]
    sudo: [ "ALL=(ALL) NOPASSWD:ALL" ]
    shell: /bin/bash
EOF
chmod 644 /etc/cloud/cloud.cfg.d/99_preservesetting.cfg
chown root:root /etc/cloud/cloud.cfg.d/99_preservesetting.cfg

Commentary

-** repo_update : Update locally cached repository metadata (true)/not update (false)
-
repo_upgrade : apply all updates (except for the repo_upgrade_exclude value) (all, on, true)/apply security updates (security)/do not apply updates (none, off, false)
-
preserve_hostname : Maintain hostname (true)/Do not maintain (false)
-
locale : Set the locale (locale)
-
timezone : Set the time zone (time zone)
-
default_user **: Set the default user (default user information)

that's all.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0