Skip to content

Instantly share code, notes, and snippets.

@jarmitage
Last active May 22, 2020 21:12
Show Gist options
  • Save jarmitage/00aa168500f7af605e75ae2f13ebc2bc to your computer and use it in GitHub Desktop.
Save jarmitage/00aa168500f7af605e75ae2f13ebc2bc to your computer and use it in GitHub Desktop.
Building a Bela image using VirtualBox and Ubuntu

Building a Bela image using VirtualBox and Ubuntu

  • Size of VM after running ./build_bela.sh: 27.52GB
  • Size of bela-image-builder folder after running ./build_bela.sh: 12GB

Creating the Ubuntu VM

Install and configure git and ssh

  • Install git and setup global config
sudo apt-get install git git-core
git config --global user.email johndoe@example.com
git config --global user.name "John Doe"

If you want to git clone the image builder repo rather than just download it, set up ssh https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/

Optional: install zsh and Sublime Text

(Optionally) set up a decent shell (setting up zsh on Ubuntu: https://gist.github.com/tsabat/1498393)

sudo apt-get install curl zsh
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
chsh -s `which zsh`
sudo shutdown -r 0

Ubuntu does not come with a text editor, so you may also want to install something like Sublime Text: https://www.sublimetext.com/docs/3/linux_repositories.html

wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add -
sudo apt-get install apt-transport-https
echo "deb https://download.sublimetext.com/ apt/stable/" | sudo tee /etc/apt/sources.list.d/sublime-text.list
sudo apt-get update
sudo apt-get install sublime-text

Install bela-image-builder dependencies

Install some necessary dependencies:

  • The build script will complain about the absence of qemu-arm-static when it means qemu-user-static
  • libtool-bin is required because libtool doesn't install binaries for some reason
sudo apt-get install qemu qemu-user-static dh-autoreconf daemontools binutils-arm-linux-gnueabihf lzma lzop libtool-bin debootstrap kpartx bison flex pkg-config libncurses5-dev:amd64

If you can't find all the above packages, find alternatives:

sudo apt-get install apt-file
sudo apt-file update
sudo apt-file search PACKAGE_NAME

For example in this case I used the following alternatives compared to what the build script asked for:

autoreconf -> dh-autoreconf
setuidgid  -> daemontools
arm-linux-gnueabihf-ranlib -> binutils-arm-linux-gnueabihf

Clone/download the repo and run the main script

Clone the repo somewhere (e.g. ~/Documents/git/)

git clone git@github.com:BelaPlatform/bela-image-builder.git

Now try running the script as root

cd path/to/bela-image-builder
sudo ./build_bela.sh

The result

Eventually you will get a ~3.9GB file bela.img. At this point you should take a Snapshot of your VM.

To transfer this file to your host machine, you may want to first compress it (use -k to prevent deleting the original file, and --verbose for progress updates):

xz -k --verbose bela.img

Or you may not, since this could take longer than just copying it to your host and compressing it there if required.

In the case that your host is a Mac, you will need to set up Guest Additions which is somewhat involved: https://matthewpalmer.net/blog/2017/12/10/install-virtualbox-mac-high-sierra/index.html

Note on above: I couldn't access the folder from my user so had to use sudo cp to copy to the shared folder.

To use the image file, follow this article: https://github.com/BelaPlatform/Bela/wiki/Manage-your-SD-card#flashing-an-sd-card

Build process notes (@giuliomoro)

The build process is slow. There are three steps in the build process that take the longest (after the first run, which is the one that does all the downloads, including the KERNEL):

  1. Building the kernel
  2. Building the base debian image (the debootstrap command, which reads packages.txt)
  3. The scripts/chroot.sh part. This runs inside a chroot, using qemu, so everything that happens in here is using qemu to emulate the ARM architecture.

The first two steps can normally be skipped when you re-build an image, as the kernel version is frozen anyhow, and debootstrap takes forever (and requires a lot of network bandwidth).

Most of the changes these days happen either in:

  • packages.txt in which case you need to re-run debootstrap, so you can run, e.g.: sudo ./build_bela.sh --no-kernel --no-bootloader --no-build-xenomai --no-downloads
  • Or in chroot.sh or in misc/rootfs/ (files that are manually created on the file system, so you can run, e.g. sudo ./build_bela.sh --no-kernel --cached-fs --no-bootloader --no-build-xenomai --no-downloads

It could be tempting for you to add your packages to packages.txt, but I'd suggest maybe you add them as an apt-get install ... line at the bottom of scripts/chroot.sh, so you can more quickly iterate the builds and test

@Bobisback
Copy link

Hey,

We are trying to run a bela image in a virtualbox. Is this what this document is doing?

@jarmitage
Copy link
Author

This is for building not running a Bela image. A Bela image can only run on Bela hardware, as far as I know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment