# Creating a NetBSD AMI with bsdec2-image-upload ## About bsdec2-image-upload The [bsdec2-image-upload](https://github.com/cperciva/bsdec2-image-upload) tool automates creation of AMIs based on raw disk images. This tool is available in pkgsrc as [sysutils/bsdec2-image-upload](https://pkgsrc.se/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 * NetBSD -current: * NetBSD 9.x: *not supported* ### Arm * NetBSD -current: * NetBSD 9.x: ## Prerequisites ### Install bsdec2-image-upload Install sysutils/bsdec2-image-upload from pkgsrc. ### Setup AWS credentials In the [IAM Management Console](https://console.aws.amazon.com/iam), create an access key. Enter these into in a file named *keyfile.txt*: [[!template id=filecontent name="keyfile.txt" text=""" 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](https://s3.console.aws.amazon.com). ## Creating an AMI [[!template id=filecontent name="x86" text=""" $ 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 """]] [[!template id=filecontent name="Arm" text=""" $ 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](https://console.aws.amazon.com/ec2), 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: [[!template id=filecontent name="remote login (NetBSD 9.x)" text=""" $ ssh -i netbsd.pem root@my-instance-ip """]] [[!template id=filecontent name="remote login (NetBSD -current)" text=""" $ ssh -i netbsd.pem ec2-user@my-instance-ip """]]