Creating a NetBSD AMI with bsdec2-image-upload

About bsdec2-image-upload

The bsdec2-image-upload tool automates creation of AMIs based on raw disk images. This tool is available in pkgsrc as sysutils/bsdec2-image-upload.

Getting a disk image

The following images are configured to automatically detect an EC2 environment and resize the root disk at boot. Creating a custom image is not covered in this document.

x86

Arm

Prerequisites

Install bsdec2-image-upload

Install sysutils/bsdec2-image-upload from pkgsrc.

Setup AWS credentials

In the IAM Management Console, create an access key. Enter these into in a file named keyfile.txt:

keyfile.txt

ACCESS_KEY_ID=your_access_key_id
ACCESS_KEY_SECRET=your_access_key_secret

Create S3 bucket for image upload

An S3 bucket is required for temporary storage during the upload and conversion process. This can be created on the S3 Management Console.

Creating an AMI

x86

$ gunzip NetBSD-9.99.72-amd64-live.img.gz
$ AWS_REGION=us-east-1
$ S3BUCKET=my-bucket-name
$ bsdec2-image-upload --sriov --ena NetBSD-9.99.72-amd64-live.img "NetBSD 9.99.72 x86 2020-09-10" "NetBSD/amd64 -current (9.99.72) built on Sep 10 2020" ${AWS_REGION} ${S3BUCKET} keyfile.txt

Arm

$ gunzip arm64.img.gz
$ AWS_REGION=us-east-1
$ S3BUCKET=my-bucket-name
$ bsdec2-image-upload --sriov --ena --arm64 arm64.img "NetBSD 9.99.72 Arm 2020-09-10" "NetBSD/evbarm -current (9.99.72) built on Sep 10 2020" ${AWS_REGION} ${S3BUCKET} keyfile.txt

Cleanup

Once the images are uploaded, some artifacts will be left in the S3 bucket. These can be safely deleted.

Starting an instance

On the EC2 Management Console, select the region matching the AMI you just uploaded. Then under the AMIs section on the left, select your newly created AMI and click the Launch button to create a new instance.

The credentials specified during creation of the instance can be used to login with ssh as the root user (NetBSD 9) or ec2-user (NetBSD -current) after NetBSD has booted:

remote login (NetBSD 9.x)

$ ssh -i netbsd.pem root@my-instance-ip

remote login (NetBSD -current)

$ ssh -i netbsd.pem ec2-user@my-instance-ip