{"id":18603636,"url":"https://github.com/cogini/buildroot_ec2","last_synced_at":"2025-07-24T12:38:51.606Z","repository":{"id":147373545,"uuid":"141803368","full_name":"cogini/buildroot_ec2","owner":"cogini","description":"AWS EC2 board configuration for the Buildroot embedded Linux build system","archived":false,"fork":false,"pushed_at":"2020-11-10T06:36:21.000Z","size":85,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-11T05:39:54.980Z","etag":null,"topics":["ami","aws","aws-ec2","buildroot"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cogini.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-07-21T10:39:03.000Z","updated_at":"2024-03-19T07:33:30.000Z","dependencies_parsed_at":null,"dependency_job_id":"13f8130a-53d4-4c01-beb8-cd3c54ebfea3","html_url":"https://github.com/cogini/buildroot_ec2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cogini/buildroot_ec2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cogini%2Fbuildroot_ec2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cogini%2Fbuildroot_ec2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cogini%2Fbuildroot_ec2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cogini%2Fbuildroot_ec2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cogini","download_url":"https://codeload.github.com/cogini/buildroot_ec2/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cogini%2Fbuildroot_ec2/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266844497,"owners_count":23993965,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-24T02:00:09.469Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ami","aws","aws-ec2","buildroot"],"created_at":"2024-11-07T02:14:57.762Z","updated_at":"2025-07-24T12:38:51.595Z","avatar_url":"https://github.com/cogini.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Buildroot config for AWS EC2\n\nThis is an example of using the [Buildroot](https://buildroot.org/) embedded\nLinux build system to create a custom AMI for Amazon.\n\nIt is a basic Buildroot \"board\" config, with ssh and a few utilities.\n\nThe Linux kernel config comes from NixOS Linux 4.14.32 AWS.\n\nThe general approach is to build on an EC2 instance and create an\nimage on an EBS volume, then create a snapshot of the volume and turn it into an AMI.\n\nCheck out this repo on an EC2 build server. I used a t2.xlarge instance running\nUbuntu 18.04. The build generates a lot of files, so I added a 100GB gp2 EBS\nvolume, mounted under my home directory.\n\nI used a 1GB gp2 volume for the target system, mounted under `/dev/sdf`.\n\nThis was a preliminary step in getting the\n[Nerves embedded Elixir system running on EC2](https://github.com/cogini/nerves_system_ec2).\n\n## Install build deps\n\n```shell\nsudo apt install sed make binutils gcc g++ bash patch gzip bzip2 perl tar cpio python unzip rsync wget libncurses-dev libelf-dev\n```\n\n## Check out this repo\n\n```shell\ngit clone https://github.com/cogini/buildroot_ec2\n```\n\n# Allow your user to log in via ssh\n\n```shell\ncp ~/.ssh/authorized_keys buildroot_ec2/board/ec2/rootfs_overlay/root/.ssh/\n```\n\n## Download buildroot\n\n```shell\nwget https://buildroot.org/downloads/buildroot-2018.05.tar.bz2\nmkdir work\ncd work\nbzip2 -dc buildroot-2018.05.tar.bz2 | tar xvf -\nln -s buildroot-2018.05 buildroot\n```\n\n## Build\n\n```shell\ncd buildroot\nmake BR2_EXTERNAL=../buildroot_ec2 ec2_defconfig\n```\n\nThis will take a while, so you may want to run it under tmux.\n\n## Write disk image to mounted volume\n\n```shell\nsudo dd if=output/images/disk.img of=/dev/xvdf\n```\n\n## Configure AWS\n\nAt this point, the new system is all set up on the EBS volume.\nNow we need to launch an instance from it. We do that using the AWS API, so\nit can run from anywhere. I normally run it from my dev machine, but you\ncan do it from the build server as well.\n\nIn order to talk to the API, we need permissions. When you create an AWS\naccount, you get a \"root\" account with full permissions, but you should\nnot use it for for everyday operations. You should create an admin user\nfor yourself and a role for your app to run under which gives it access\nto specific resources.\n\nGo to [IAM](https://console.aws.amazon.com/iam/home) in the AWS console.\n\nCreate a group called `Admins` and attach policy `AdministratorAccess`, giving members full access.\n\nCreate a user for yourself, e.g. `cogini-jake`. Under \"Access type,\" check\n\"Programmatic access\" and \"AWS Management Console access.\" Set your login password.\nClick \"Next: Permissions\" and then \"Add user to group\", selecting the `Admins` group.\nRecord the \"Access key id\" and \"Secret access key\" now, this is your only chance.\n\nOn your local dev machine, set up an AWS profile in `~/.aws/credentials` with the keys:\n\n    [buildroot-dev]\n    aws_access_key_id = XXX\n    aws_secret_access_key = YYY\n\nMost AWS client tools will automatically look up the access keys using the profile,\nso you can control keys on a per-project basis by setting the profile in the environment.\n\n```shell\nexport AWS_PROFILE=buildroot-dev\n```\n\nInstall the [AWS Command Line Interface](https://aws.amazon.com/cli/):\n\n```shell\npip install awscli\n```\n\nCreate an ssh [key pair](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html).\nRun `create-key-pair.sh`\n\n```shell\nboard/ec2/create-key-pair.sh buildroot\n```\n\nCopy the output to `~/.ssh/buildroot.pem` and `chmod 0600 buildroot.pem`.\n\nCreate an AWS security group (like a firewall) which allows access to the ports on the instance from the Internet.\n`create-security-group.sh`\nopens port 22 for the IEx console and port 80 for HTTP.\n\n```shell\nboard/ec2/create-security-group.sh buildroot\n```\n\n## Launch the instance\n\n`launch-instance-from-volume.sh` takes a snapshot of the volume, builds an AMI,\nthen launches an EC2 instance with it.\n\nEdit the script to match your details:\n\n```shell\n# Name of security group\nSECURITY_GROUP=buildroot\n# Name of instance to create\nNAME=buildroot\nKEYPAIR=buildroot\n# Tag instance with owner so admins can clean up stray instances\nTAG_OWNER=jake\n```\n\nRun the script, specifying your volume:\n\n```shell\nboard/ec2/launch-instance-from-volume.sh vol-abc123\n```\n\nThe script will print the IP of the new instance, or you can get it from the AWS console.\n\n## Launch an EC2 instance\n\nThe `board/ec2/launch-instance-from-volume.sh` script launches an instance\nby making a snapshot of the volume, turning the snapshot into an AMI,\nthen starting it. I normally run it from my local machine, not the build\ninstance.\n\nEdit the script to match your environment:\n\n    SECURITY_GROUP=buildroot\n    NAME=buildroot\n    TAG_OWNER=jake\n    KEYPAIR=buildroot\n\nRun it, specifying your volume:\n\n```shell\nboard/ec2/launch-instance-from-volume.sh vol-abc123\n```\n\n## Docs\n\n* https://buildroot.org/downloads/manual/manual.html\n* https://bootlin.com/doc/training/buildroot/buildroot-labs.pdf\n* http://www.jumpnowtek.com/rpi/Raspberry-Pi-Systems-with-Buildroot.html\n* https://dzone.com/articles/building-embedded-linux-with-buildroot\n\n## Useful commands\n\nConfigure buildroot:\n\n    make menuconfig\n\nSave buildroot config to `buildroot_ec2/configs/ec2_defconfig`:\n\n    make savedefconfig\n\nUse a different kernel config:\n\n    cp ~/nixos-4.14.32.config output/build/linux-4.16.13/.config\n\nConfigure Linux kernel\n\n    make linux-menuconfig\n\nSave to `.config`, then save the kernel config back to `buildroot_ec2/board/ec2/linux.config`:\n\n    make linux-savedefconfig\n\nSee the available buildroot configs\n\n```shell\nmake list-defconfigs\n```\n\n## Qemu\n\nInstall\n```shell\nsudo apt install qemu\n```\n\nRun with text UI\n```shell\nqemu-system-x86_64 -nographic -serial mon:stdio -M pc -m 128 -drive file=output/images/disk.img,if=virtio,format=raw -net nic,model=virtio -net user,hostfwd=tcp::10022-:22\n```\nTo quit: CTRL-A, x\n\nRun with curses UI\n```shell\nqemu-system-x86_64 -curses -M pc -m 128 -drive file=output/images/disk.img,if=virtio,format=raw -net nic,model=virtio -net user,hostfwd=tcp::10022-:22\n```\nTo quit: ESC-2, quit\n\nRun without grub bootloader\n\n```shell\nqemu-system-x86_64 -nographic -M pc -kernel output/images/bzImage -drive file=output/images/rootfs.ext2,if=virtio,format=raw -append \"root=/dev/vda console=ttyS0\" -net nic,model=virtio -net user\n```\n\nConnect via ssh\n```shell\nssh -p10022 root@localhost\n```\nConnect to build server using `ssh -A build-server` to use your workstation's keys.\n\nEnable password under \"System configuration | Enable root login with password\".\nSet password under \"System configuration | Root password\"\n\nLinux config for qemu: `board/qemu/x86_64/linux-4.15.config`\n\n## systemd-nspawn\n\n```shell\nsudo apt install systemd-container\nsudo systemd-nspawn -b -i output/images/rootfs.ext2 -n\n```\n\nDoesn't work unless kernel in image matches host\n\nView partitions in image\n\n```\nsudo losetup -v -f --show `pwd`/output/images/disk.img\nsudo fdisk /dev/loop2\n```\n\n## Notes\n\n### Configs\n\nBuildroot\n    Started with `board/pc`\n    configs/pc_x86_64_bios_defconfig\n\n    output/build/linux-4.16.13/arch/x86/configs/x86_64_defconfig\n    output/build/linux-4.16.13/arch/x86/configs/xen.config\n    board/qemu/x86_64/linux-4.15.config\n\n### Grub\n\n* https://github.com/buildroot/buildroot/tree/master/boot/grub2\n* https://www.systutorials.com/docs/linux/man/8-grub-bios-setup/\n* https://git.busybox.net/buildroot/tree/boot/grub2/Config.in#n69\n\nMost of the space is in linux kernel modules that we probably don't need.\nReduce config.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcogini%2Fbuildroot_ec2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcogini%2Fbuildroot_ec2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcogini%2Fbuildroot_ec2/lists"}