DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Software Design and Architecture
  3. Performance
  4. Building Embedded Linux With Buildroot

Building Embedded Linux With Buildroot

Building your own embedded Linux environment doesn't have to be a hassle. Buildroot and a few other tools can get you where you need to be.

Christopher Lamb user avatar by
Christopher Lamb
CORE ·
Jan. 04, 17 · Tutorial
Like (2)
Save
Tweet
Share
12.47K Views

Join the DZone community and get the full member experience.

Join For Free

If you followed my previous article on why Buildroot is a good thing and why you should use it, you'll have installed Buildroot in Vagrant VM running with either VMWare or Virtualbox. You can also install it locally on any Linux system by downloading and decompressing the latest version from the website. Follow the README — you need to install ncurses for the nconfig and menuconfig options to work and gcc-multilib to get the system working (e.g. sudo apt install libncurses5 libncurses5-dev gcc-multilib should do the trick).

Now, let's build an image. This first one will run on a 32-bit Intel processor and use the EXT2 filesystem. When we're finished, we'll be able to run it via QEMU.

First, a note on notation. I won't show you each menu, but I will give you the paths through it. For example, for this path...

Image title


...I'll describe as Target Options -> Target Architecture. So let's get started.

First, make sure you start from a default .config file. The .config file, located in the buildroot home directory, contains the configuration for the image you're building. Be careful with these! In a production project, you'll want to keep these under some form of version control. Once you have one configured and working, you don't want to lose it.

Next, start up the configuration system with make nconfig. The default build won't need much in the way of changes or additions. First, go to Kernel -> Linux Kernel, and select it (press either space or enter to select). It's going to ask for a defconfig name; go to that option, hit return, and enter i386.

This screen should look like this:

Image title

Now, go to Target Packages -> Networking Applications, and select openssh. Next, go to Filesystem Images and select ext 2/3/4 root filesystem. Finally, go to Bootloaders and select syslinux.

Now exit, and save the configuration.

Next, at the command line, type make. Go do something else for a bit, this takes a while.

Done? Great.

You should have a couple of files in output/images - bzImage and rootfs.ext2. We're going to use these to start up QEMU.

QEMU is pretty powerful. I suggest you use a script like this to boot it up:

LOCATION=$PWD
ROOT="output/images/"
KERNEL=$ROOT"bzImage"
DISK=$ROOT"rootfs.ext2"
QEMU=qemu-system-i386
NAME=i386Linux

$QEMU \
        -kernel $LOCATION/$KERNEL \
        -drive format=raw,file=$LOCATION/$DISK,index=0,media=disk \
        -boot c \
        -m 128 \
        -append "root=/dev/sda rw" \
        -localtime \
        -no-reboot \
        -name $NAME \
        -net nic -net user \
        -redir tcp:2222::22


Go ahead and create this script file. I call it qemu.sh, and I keep it in the Buildroot home directory. Start it up. You should get a login, so go ahead and log in as root and hit return. We didn't configure a password, so you'll go right in.

That's it! You've created your first embedded Linux environment. If you'd like, you can add a user (via the adduser command) and configure the new image to use networking (add the lines auto eth0 and iface eth0 inet dhcp to the bottom of the /etc/network/interfaces file, in that order). If you do, restart the image via /sbin/poweroff or /sbin/reboot. After it comes back up, you should be able to ssh to the image via the command ssh -p 2222 username@localhost. The last line in the script file forwards traffic to port 2222 on the host to port 22 on the image. Root won't allow remote connections, so you'll need a different account to test SSH.

That's it! Buildroot is very powerful, but with a little work, you can take much of the drudgery out of creating embedded system images.

Buildroot Linux (operating system)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How to Develop a Portrait Retouching Function
  • Unlocking the Power of Polymorphism in JavaScript: A Deep Dive
  • Why Every Fintech Company Needs DevOps
  • Visual Network Mapping Your K8s Clusters To Assess Performance

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: