blog/posts/2015-06-02-using-os-containers-for-openembedded-build.markdown
2017-06-10 17:43:43 +05:30

53 lines
3.8 KiB
Markdown

---
author: Sanchayan Maity
title: Using OS containers for OpenEmbedded build
tags: openembedded, containers
---
<p style='text-align: justify;'> I use Arch Linux on my laptop and on the server which I use and maintain in office for my openembedded builds. However openembedded does not exactly like rolling release distros it seems. Somehow for whatever reason, my current openembedded builds just fail. I remember facing the problem when I was using Arch and learning openembedded during my early days which lead to my first openembedded post. Why? I do not know nor do I have the time to debug such a thing when there is another solution at hand.</p>
<p style='text-align: justify;'>Now I am certainly not going to stop using Arch Linux, I like it quite a bit with the setup I have. The solution is to use a chroot jail or having systemd as my init, that would be resorting to the use of systemd-nspawn. So lets get on how to set up an environment which we can use for openembedded builds. I assume you have yaourt installed. yaourt is pretty cool as I do not have to bother with downloading pkgbuilds anymore.</p>
```bash
yaourt -S debootstrap
mkdir ~/debian-root
sudo debootstrap --arch=amd64 --variant=minbase jessie ~/debian-root
sudo systemd-nspawn -D debian-root
```
<p style='text-align: justify;'>The third command is gonna take a while. After you run the last command you would be inside the chroot jail as a root user. After that run the following.</p>
```bash
apt-get install update
apt-get install sudo
adduser -uid 1000 -gid 100 username
visudo
su username
```
<p style='text-align: justify;'>I assume you know what to add after running visudo. Basically add yourself to the sudoers file. In case you are wondering how I got the user id and group id for the adduser command, that would be by running "id" on my host. The last command will drop you in the home directory for the newly created user. Whenever you want to work on openembedded, just use systemd-nspawn to log in to the debian environment. You can keep this environment for as long you like to maintain your build setup while your normal userspace can be updated without fear of breaking the build. You can replicate the exact debian environment by just copying the complete debian root directory using something like rsync to any number of your machines.</p>
<p style='text-align: justify;'>Nice ain't it? Now I don't have to bother that something will break when I update. I am writing this while my openembedded build is going on. I mean to look into how vagrant, docker and CoreOS are exactly used. May be it will be something which can be used to help our customers replicate the setup which we know to be working at our end. Do not know if it is actually possible, but I read somewhere something like this atleast in the context of vagrant while messing around a bit with vim related stuff. Also do note that debian is not the only one you can use. You can do this for Fedora, Arch and probably other distros too, however I have not tried that. This is my first time using this. I do remember using a chroot jail while setting up Arch Linux, but, it's not something I looked closely into which I mean to rectify soon.</p>
<p style='text-align: justify;'>Output from my debian root environment.</p>
```bash
sanchayan@debian-root:~/oe-core/build$ uname -a
Linux debian-root 4.0.0-ck1-bfs-ck+ #8 SMP PREEMPT Wed Apr 29 11:35:34 IST 2015 x86_64 GNU/Linux
sanchayan@debian-root:~/oe-core/build$ pwd
/home/sanchayan/oe-core/build
```
<p style='text-align: justify;'>Output of machinectl from my host.</p>
```bash
machinectl
MACHINE CLASS SERVICE
debian-root container nspawn
1 machines listed.
```
[systemd for Administrators](http://0pointer.net/blog/archives.html) series should be interesting to you.
<p style='text-align: justify;'>Do have a look at the man pages for systemd-nspawn and machinectl.</p>