Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Amazon Linux 2 first boot on Virtual Box
# Download the VDI from https://cdn.amazonlinux.com/os-images/latest/
# Doc is at http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/amazon-linux-2-virtual-machine.html
# Be sure you have config/meta-data and config/user-data ready as per the below
# change ec2-user's password to your password
$ cat config/meta-data
local-hostname: amazonlinux.onprem
# eth0 is the default network interface enabled in the image. You can configure
# static network settings with an entry like below.
#network-interfaces: |
# iface eth0 inet static
# address 192.168.1.10
# network 192.168.1.0
# netmask 255.255.255.0
# broadcast 192.168.1.255
# gateway 192.168.1.254
$ cat config/user-data
#cloud-config
# vim:syntax=yaml
users:
# A user by the name ec2-user is created in the image by default.
- default
# Following entry create user1 and assigns password specified in plain text.
# Please not use of plain text password is not recommended from security best
# practises standpoint
# - name: user1
# groups: sudo
# sudo: ['ALL=(ALL) NOPASSWD:ALL']
# plain_text_passwd: < plain text password here >
# lock_passwd: false
# Following entry creates user2 and attaches a hashed passwd to the user. Hashed
# passwords can be generated with:
# python -c 'import crypt,getpass; print crypt.crypt(getpass.getpass())'
# - name: user2
# passwd: < hashed password here >
# lock_passwd: false
# Following entry creates user3, disables password based login and enables an SSH public key
# - name: user3
# ssh-authorized-keys:
# - < ssh public key here >
# lock_passwd: true
chpasswd:
list: |
ec2-user:password
# On Mac OS, you can use hdiutil instead of genisoimage
hdiutil makehybrid -o init.iso -hfs -joliet -iso -default-volume-name cidata config
## Then attach the init.iso file to the virtual machine before to boot the VDI.
## Cloud-init configuration happens ar first boot only, you do not need the ISO file for subsequent boots
## If you need to retry, re-try from the originally downloaded VDI
## Keep a copy of the downloaded VDI if you need to make changes to your root disk image.
@dwhite-beerhawk

This comment has been minimized.

Copy link

commented Apr 30, 2018

Could you expand on this gist a little? I've been following the docs and such examples - but cannot log into the VM. I get a "Login incorrect" for all users.
The .vdi I've set as the SATA drive in Vbox and I've mounted the init.iso as the IDE.

@jonathan-automox

This comment has been minimized.

Copy link

commented Jul 2, 2018

Yeah, I couldn't get it to work either same setup as dwhite-beehawk.

@sdbruder

This comment has been minimized.

Copy link

commented Jul 27, 2018

I can login locally (on the terminal) but not via ssh because of 2 things:
as described the eth0 does not go up, there is no ONBOOT=yes in eth0 config.
and sshd is denying any by password login.

So after manually fixing these issues up Ive being able to login.

As configured eth0 will be directly in your network, bridged, not on the NAT’ed VMware Fusion network.

So if someone has some more information on how we can get ONBOOT=yes for eth0 on meta-data, that password thing can be avoided configuring a key for the user.

@cuoituoi1996

This comment has been minimized.

Copy link

commented Jul 27, 2018

i also have the same issue where it said "login incorrect". Could you elaborate on what you did to be able to log in @sdbruder?

@AndrewStringerJS

This comment has been minimized.

Copy link

commented Aug 15, 2018

I had this issue too, the solution (for me) was to validate the files used to create the seed.iso file, this worked for me:- http://www.yamllint.com/ and found an error.

#cloud-config
# vim:syntax=yaml
users:
# A user by the name ec2-user is created in the image by default.
- default

In the last line, the default statement needed two spaces in front of it, then it validated ok, the rebuild seed.iso then seemed to do the trick and I could log in as ec2-user with my password.

Remember to use a fresh .vdi file as the seed.iso is only valid on first boot and booting touches the vdi image so it cannot be used again. You may be able to do a snapshot before the initial boot too to preserver the initial state. But I have not tried this.

@omenking

This comment has been minimized.

Copy link

commented Sep 6, 2018

I noticed during boot on mine it thought the seed is not valid

screen shot 2018-09-06 at 10 16 46 am

I built it on osx
hdiutil makehybrid -o seed.iso -hfs -joliet -iso -default-volume-name cidata seedconfig/

I did validate my yaml

Reading through here:
https://cloudinit.readthedocs.io/en/latest/topics/datasources/nocloud.html

I think its something to do with my seed.iso, it is mounted in VirtualBox

@davidkaufman

This comment has been minimized.

Copy link

commented Oct 16, 2018

Thanks for the suggestions!

In my case, it turned out that my "incrorrect login" errors were fixed by removing a COMMENT line that i had added above the first line of the user-data file. So my file started with:

# my comment here ( a URL to the docs), then...

#cloud-config
#vim:syntax=yaml

Although it was still syntactically correct yaml, it didn't actually work until i removed that top/first comment that i'd added...

So there is, apparently, an undocumented requirement that the file MUST BEGIN WITH with the #cloud-config comment...

#cloud-config
#vim:syntax=yaml

Still not sure if the vim:syntax comment is required too but I'm leaving it, cuz I've lost enough time to this nonsense already :-)

Thanks again for your suggestions, which led me to to my discovery and the fix for my situation!

Hope this helps someone googling this issue like i did!

-dave

@lantrix

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.