Find if AWS instance is running Amazon Linux 1 or 2?
Asked Answered
P

5

45

In AWS I need to add amazon linux instance to domain based on this article. However how do i know which Amazon Linux version the instance is using. I do not have access to AWS console. But i do have access to actual instance. What linux command i should be using.

I use uname -srm command which returns Linux 4.4.0-1057-aws x86_64

Not sure if this is Amazon Linux 1 or Amazon Linux 2

Parous answered 17/12, 2018 at 22:15 Comment(0)
G
81

You can use /etc/os-release file to get the info about Amazon Linux Version, the machine is running.

  1. In case of Amazon 1

    [ec2-user@ip-x-x-x- ~]$ cat /etc/os-release
    NAME="Amazon Linux AMI"
    VERSION="2018.03"
    ID="amzn"
    ID_LIKE="rhel fedora"
    VERSION_ID="2018.03"
    PRETTY_NAME="Amazon Linux AMI 2018.03"
    ANSI_COLOR="0;33"
    CPE_NAME="cpe:/o:amazon:linux:2018.03:ga"
    HOME_URL="http://aws.amazon.com/amazon-linux-ami/"
    
  2. In case of Amazon 2

    [ec2-user@x-x-x-x ~]$ cat /etc/system-release
    Amazon Linux release 2.0 (2017.12) LTS Release Candidate
    [ec2-user@fresh-amazon-host ~]$ cat /etc/os-release
    NAME="Amazon Linux"
    VERSION="2.0 (2017.12)"
    ID="amzn"
    ID_LIKE="centos rhel fedora"
    VERSION_ID="2.0"
    PRETTY_NAME="Amazon Linux 2.0 (2017.12) LTS Release Candidate"
    ANSI_COLOR="0;33"
    CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2.0"
    HOME_URL="https://amazonlinux.com/"
    

As you can clearly see the two different versions, mentioned as Amazon Linux and Amazon Linux 2.0

Glisten answered 13/6, 2019 at 8:9 Comment(3)
what is the excet meaning ID_LIKE="centos rhel fedora", Is this support all three distrosQualification
The format of the various environment variables seems to have changed a bit, but these files are indeed present.Hydrochloride
cat /etc/os-releaseIodine
R
14
$ cat /etc/system-release

or

$ cat /etc/issue

or

$ uname -a

and head for https://aws.amazon.com/amazon-linux-ami/

Renunciation answered 4/1, 2019 at 8:19 Comment(0)
G
5

Here's a one-liner.

awk -F '[="]*' '/^PRETTY_NAME/ { print $2 }' < /etc/os-release 

It prints out:

Amazon Linux 2
Gaillard answered 1/6, 2021 at 20:22 Comment(0)
G
3

You can use the following command:

rpm -E %{rhel} 

For Operating System: Amazon Linux 2

The answer is : 7

Gradin answered 27/7, 2020 at 13:37 Comment(1)
without the asterisks logically :)Poet
C
2

Well, the announcement in: https://aws.amazon.com/about-aws/whats-new/2017/12/introducing-amazon-linux-2 states that it uses a 4.9 kernel. Yours is older, so I would say it is Linux 1.

Still, the following call from the terminal should give you the AMI ID and you could do a search on that(see docs at https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html):

curl http://169.254.169.254/latest/meta-data/ami-id
Conduce answered 17/12, 2018 at 22:31 Comment(1)
Just know that the AMI ID may not tell you anything. If the instance was created off of a custom AMI then it may not even exist anymore.Freezer

© 2022 - 2024 — McMap. All rights reserved.