Build-up your own NetBSD AMI

Fetch and build NetBSD

EC2 does not provide direct access to console. As a consequence, we cannot rely on it for installation, especially via

Description

Use this template to create a man page link. The template can use four parameters:

Examples

Link to

Description

Use this template to create a man page link. The template can use four parameters:

Examples

Link to

Description

Use this template to create a man page link. The template can use four parameters:

Examples

Link to

Description

Use this template to create a man page link. The template can use four parameters:

Examples

Link to

Description

Use this template to create a man page link. The template can use four parameters:

Examples

Link to

Description

Use this template to create a man page link. The template can use four parameters:

Examples

Link to

Description

Use this template to create a man page link. The template can use four parameters:

Examples

Link to

Description

Use this template to create a man page link. The template can use four parameters:

Examples

Link to [[!templatebody preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 10]]

Description

Use this template to create a man page link. The template can use four parameters:

Examples

Link to [[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 11]] man page:

    [[!template  id=man name="ls"]]

Link to [[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 12]] man page, with section:

    [[!template  id=man name="ls" section="1"]]

Link to [[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 13]] man page, specifying section and architecture:

    [[!template  id=man name="ls" section="1" arch="i386"]]

Link to [[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 14]] man page, specifying section, architecture and collection:

    [[!template  id=man name="ls" section="1" arch="i386" collection="NetBSD-5.0"]]

man page:

    [[!template  id=man name="ls"]]

Link to [[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 14]] man page, with section:

    [[!template  id=man name="ls" section="1"]]

Link to [[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 15]] man page, specifying section and architecture:

    [[!template  id=man name="ls" section="1" arch="i386"]]

Link to [[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 16]] man page, specifying section, architecture and collection:

    [[!template  id=man name="ls" section="1" arch="i386" collection="NetBSD-5.0"]]

man page:

    [[!template  id=man name="ls"]]

Link to [[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 16]] man page, with section:

    [[!template  id=man name="ls" section="1"]]

Link to [[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 17]] man page, specifying section and architecture:

    [[!template  id=man name="ls" section="1" arch="i386"]]

Link to [[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 18]] man page, specifying section, architecture and collection:

    [[!template  id=man name="ls" section="1" arch="i386" collection="NetBSD-5.0"]]

man page:

    [[!template  id=man name="ls"]]

Link to [[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 18]] man page, with section:

    [[!template  id=man name="ls" section="1"]]

Link to [[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 19]] man page, specifying section and architecture:

    [[!template  id=man name="ls" section="1" arch="i386"]]

Link to [[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 20]] man page, specifying section, architecture and collection:

    [[!template  id=man name="ls" section="1" arch="i386" collection="NetBSD-5.0"]]

man page:

    [[!template  id=man name="ls"]]

Link to [[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 20]] man page, with section:

    [[!template  id=man name="ls" section="1"]]

Link to [[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 21]] man page, specifying section and architecture:

    [[!template  id=man name="ls" section="1" arch="i386"]]

Link to [[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 22]] man page, specifying section, architecture and collection:

    [[!template  id=man name="ls" section="1" arch="i386" collection="NetBSD-5.0"]]

man page:

    [[!template  id=man name="ls"]]

Link to [[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 22]] man page, with section:

    [[!template  id=man name="ls" section="1"]]

Link to [[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 23]] man page, specifying section and architecture:

    [[!template  id=man name="ls" section="1" arch="i386"]]

Link to [[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 24]] man page, specifying section, architecture and collection:

    [[!template  id=man name="ls" section="1" arch="i386" collection="NetBSD-5.0"]]

man page:

    [[!template  id=man name="ls"]]

Link to [[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 24]] man page, with section:

    [[!template  id=man name="ls" section="1"]]

Link to [[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 25]] man page, specifying section and architecture:

    [[!template  id=man name="ls" section="1" arch="i386"]]

Link to [[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 26]] man page, specifying section, architecture and collection:

    [[!template  id=man name="ls" section="1" arch="i386" collection="NetBSD-5.0"]]

man page:

    [[!template  id=man name="ls"]]

Link to [[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 26]] man page, with section:

    [[!template  id=man name="ls" section="1"]]

Link to [[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 27]] man page, specifying section and architecture:

    [[!template  id=man name="ls" section="1" arch="i386"]]

Link to [[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 28]] man page, specifying section, architecture and collection:

    [[!template  id=man name="ls" section="1" arch="i386" collection="NetBSD-5.0"]]

man page:

    [[!template  id=man name="ls"]]

Link to [[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 28]] man page, with section:

    [[!template  id=man name="ls" section="1"]]

Link to [[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 29]] man page, specifying section and architecture:

    [[!template  id=man name="ls" section="1" arch="i386"]]

Link to [[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 30]] man page, specifying section, architecture and collection:

    [[!template  id=man name="ls" section="1" arch="i386" collection="NetBSD-5.0"]]

. We must therefore build and install NetBSD in a separate directory, and configure it manually, before upload.

This tutorial assumes that you will build the system under /mnt/ec2.

/!\Please note that you will need the [[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 30]] tool later in the process, so you can build a file system image that can be uploaded to Amazon EC2. You are therefore advised to perform the installation directly under a living NetBSD system, or in case your are not, to fetch the src tree to build the toolchain, which will contain the nbmakefs utility.

Details regarding on how you can fetch src are given in the NetBSD's guide. Here are the basic commands you should type to build and install NetBSD under /mnt/ec2:

[[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 31]]

Configuration of your NetBSD EC2 tree

/!\This part assumes that you have a non-configured NetBSD system extracted under /mnt/ec2; that is, it should have not been modified through [[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 32]], nor by you.

Under /mnt/ec2, edit the files to add (or modify) these lines:

[[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 33]]

[[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 34]]

This file is needed if you want to login via the EC2 SSH key pair created previously:

[[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 35]]

Create various files and directories:

[[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 36]]

You can then proceed to modifying the system living under /mnt/ec2, so it can fit your needs (adding custom binaries, packages, etc). When done, build the NetBSD-AMI.img.gz ffs image, via [[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 37]], or nbmakefs, from the toolchain:

[[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 38]]

Upload NetBSD to EC2

We must now upload our NetBSD system to EC2. For that, we will have to create a minimalist EC2 instance, to which we will copy our files to construct our snapshots. We will use an Amazon Linux AMI instance.

EC2 being localized in geographical regions, you have to carefully choose the AMI identifier you want to use there. This depends on where you want to execute your instance. Amazon Linux AMI IDs are listed on the main page of the project, by regions. Choose ones backed by EBS.

The examples listed here assume that the instances run in US East, within the c zone (e.g. us-east-1c). To have a list of EC2 regions, you can use the command ec2-describe-regions, and ec2-describe-availability-zones for availability zones.

Create an Amazon Linux instance

Creating an instance is straightforward. Amazon provides different types of instances, with varying levels of billing and reliability. We will use a micro instance; its pricing is almost free.

[[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 39]]

Use the instance identifier i-XXXXXXX to query the instance state via ec2-describe-instances. It will take some time to launch:

[[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 40]]

Create and attach your NetBSD volumes

We will have to create and attach two EBS volumes:

  1. one to contain the Grub menu.lst config file, as well as the NetBSD kernel.
  2. the other one will contain the root file-system.

[[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 41]]

Snapshots!

Before we can connect to our brand new instance, we have to allow connections on SSH port (22) through the AWS EC2 firewall:

[[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 42]]

We can now upload the kernel and the NetBSD disk image created earlier, NetBSD-AMI.img.gz, to our instance host:

[[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 43]]

Then, log in to the instance, via its name. We will format and mount the Grub partition, create the menu.lst file, then copy files to their respective partitions.

[[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 44]]

Shutdown the Linux instance

We now have to detach volumes, snapshot them, then we shutdown the Linux instance.

[[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 45]]

Playing with your first NetBSD instance

Create your first NetBSD AMI

An AMI requires multiples components to be registered: the snapshots IDs we made in the previous chapter, as well as a specific AKI: the one that can chain-load Xenified kernels through PyGrub.

/!\ AKIs are entitled to the same conditions as AMIs: their IDs are region-specific. So choose one carefully, or you will not be able to launch your NetBSD instance later!

The list of AKIs that suits our situation can be obtained with the following command:

[[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 46]]

Pick the one with the correct architecture (x86_64 here). hd0 are for AMIs where the snapshot contains no partition (where the volume is itself the whole partition), while hd00 are for snapshots partitioned in a classical way (via MBR). Choose hd0 AKIs. In this case, that will be aki-427d952b.

We can proceed to the creation of our AMI, with:

  1. /dev/sda1 as Grub partition (/dev/sdg, snapshot snap-8aef2be6 of volume vol-24f88d4c)
  2. /dev/sda2 as root file-system (/dev/sdf, snapshot snap-deef2bb2 of volume vol-36f88d5e)

[[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 47]]

Launch your first instance

You can now start your own NetBSD instance, via:

[[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 48]]

Connect to your NetBSD instance

Connection is similar to the one you used for the Amazon Linux instance, except that you login as "root" instead of "ec2-user":

[[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 49]]

Done!

And now?

Well, you got a NetBSD instance that is in almost every part similar to what a NetBSD domU can be. You can use this domU to host Internet services, run a database, extend your build farm, or use it as a sandbox. The AMI being built around snapshots, you can play and break your instance in every way you want; just restart one anew if you need to. Don't forget that Amazon will charge acccordingly :)

Remember, you can query information regarding your AWS account through [[!template preprocessing loop detected on amazon_ec2/build_your_own_ami at depth 50]] package. It is quite easy to use these tools for scripting; for a more elaborate, graphical interface, use the Amazon Management Console.

Add a comment