Create an EC2 AMI from the official OPNsense 25.1 Nano (raw) image

  1. Download & Decompress OPNsense Nano Image
wget https://pkg.opnsense.org/releases/25.1/OPNsense-25.1-nano-amd64.img.bz2
bunzip2 OPNsense-25.1-nano-amd64.img.bz2
  1. Upload the Image to S3
aws s3 cp OPNsense-25.1-nano-amd64.img s3://my2-opnsense-imgs/
  1. Create the vmimport IAM Role (only once)

trust-policy.json

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": { "Service": "vmie.amazonaws.com" },
      "Action": "sts:AssumeRole"
    }
  ]
}

role-policy.json

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "s3:GetBucketLocation",
        "s3:GetObject",
        "s3:ListBucket"
      ],
      "Resource": [
        "arn:aws:s3:::my2-opnsense-imgs",
        "arn:aws:s3:::my2-opnsense-imgs/*"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "ec2:ModifySnapshotAttribute",
        "ec2:CopySnapshot",
        "ec2:RegisterImage",
        "ec2:Describe*"
      ],
      "Resource": "*"
    }
  ]
}
aws iam create-role --role-name vmimport --assume-role-policy-document file://trust-policy.json
aws iam put-role-policy --role-name vmimport --policy-name vmimport --policy-document file://role-policy.json
  1. Import the Snapshot
aws ec2 import-snapshot \
  --description "OPNSense 25.1 Nano" \
  --disk-container "{
      \"Format\": \"RAW\",
      \"UserBucket\": {
        \"S3Bucket\": \"my2-opnsense-imgs\",
        \"S3Key\": \"OPNsense-25.1-nano-amd64.img\"
      }
    }"
{
    "Description": "OPNSense 25.1 Nano",
    "ImportTaskId": "import-snap-47c1424cdee9fe71t",
    "SnapshotTaskDetail": {
        "DiskImageSize": 0.0,
        "Format": "RAW",
        "Progress": "0",
        "Status": "active",
        "StatusMessage": "pending",
        "UserBucket": {
            "S3Bucket": "my2-opnsense-imgs",
            "S3Key": "OPNsense-25.1-nano-amd64.img"
        }
    }
}
  1. Monitor Import Progress
watch -n10 -d aws ec2 describe-import-snapshot-tasks --import-task-ids import-snap-47c1424cdee9fe71t
{
    "ImportSnapshotTasks": [
        {
            "Description": "OPNSense 25.1 Nano",
            "ImportTaskId": "import-snap-47c1424cdee9fe71t",
            "SnapshotTaskDetail": {
                "DiskImageSize": 3221225472.0,
                "Format": "RAW",
                "SnapshotId": "snap-0a0edc8d038426df4",
                "Status": "completed",
                "UserBucket": {
                    "S3Bucket": "my2-opnsense-imgs",
                    "S3Key": "OPNsense-25.1-nano-amd64.img"
                }
            },
            "Tags": []
        }
    ]
}
  1. Register the Snapshot as an AMI
aws ec2 register-image \
    --name "OPNSense 25.1 Nano" \
    --root-device-name "/dev/sda1" \
    --virtualization-type "hvm" \
    --block-device-mappings '{"DeviceName":"/dev/sda1","Ebs":{"SnapshotId":"snap-0a0edc8d038426df4","VolumeSize":10,"VolumeType":"gp3"}}' \
    --boot-mode "legacy-bios" \
    --architecture "x86_64"

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top