User avatar
socialdefect
Posts: 110
Joined: Mon Jun 25, 2012 9:02 pm
Location: Tilburg, the Netherlands
Contact: Website

Automated Raspbian chroot set-up

Thu May 01, 2014 3:09 pm

If you want to develop software for the Raspberry Pi and you don't have the hardware or prefer to work on your fast Linux desktop PC then setting up a chroot environment is the way to go. Some people might find this not so simple to accomplish so I've created a simple script to help you out.

A chroot environment is a basic form of virtualization that installs a minimal working OS copy to a directory or mounted image file. By using the qemu emulator's static user files for ARM it's possible to run a Raspbian (armhf) system inside a 32 or 64 bit OS. This is very useful when developing and testing new software applications since it's easy to access the files inside the chroot environment from the outside but what happens inside the chroot stays inside the chroot so you won't mess up your host system (unless you've bind-mounted any writable filesystems inside the chroot!).

The script has been tested on Debian/Ubuntu but it should work on any Linux/BSD/OSX OS that is compatible with debootstrap and qemu. If you are missing any dependencies the script will warn you so you can install them using your system's package manager.

Install:

Get the script using GIT or download a zip archive:

Code: Select all

git clone https://github.com/socialdefect/mkraspbian-chroot.git
Execute from inside the downloaded directory:

Code: Select all

cd mkraspbian-chroot
./mkraspbian-chroot
or install system wide:

Code: Select all

cd mkraspbian-chroot
sudo cp mkraspbian-chroot /usr/local/bin/
Examples:

When you run mkraspbian-chroot without any arguments a raspbian wheezy chroot will be created in your current directory ($PWD). The chroot directory will be named 'chroot-raspbian-armhf'. If this directory exists you can choose to overwrite or auto-rename it.

Create a new raspbian wheezy chroot
in directory: /home/username/raspi
named: wheezy-armhf

Code: Select all

mkraspbian-chroot /home/username/raspi wheezy-armhf wheezy
== If it's not broke... I'm not done fixing it! ==

User avatar
DougieLawson
Posts: 35814
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Automated Raspbian chroot set-up

Thu May 01, 2014 3:13 pm

Thank you. That's saved me a lot of effort since I was just about to have a play with a chroot'ed environment.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
socialdefect
Posts: 110
Joined: Mon Jun 25, 2012 9:02 pm
Location: Tilburg, the Netherlands
Contact: Website

Re: Automated Raspbian chroot set-up

Thu May 01, 2014 4:08 pm

Since you're new to chrooting please be aware there are 2 things that can cause trouble:

1) Leave the network settings and hostname as they are, this might mess up your host's networking
2) When mounting or bind-mounting filesystems inside your chroot always make sure you unmount them before doing anything else.

Bind mounting dynamic filesystems (/dev, /proc, /sys) let's you use the system's hardware so it's quite usefull. But when you have not properly unmounted the filesystems and you destroy files inside the chroot folder you'll also mess-up any mounted filesystems inside the chroot. This can break your host OS beyond repair. So always check twice by executing the mount command to see if all filesystems are unmounted properly. If not reboot your system just to be sure. The script will do the first test and will warn you if it finds any errors.
== If it's not broke... I'm not done fixing it! ==

User avatar
DougieLawson
Posts: 35814
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Automated Raspbian chroot set-up

Thu May 01, 2014 4:14 pm

I'm not new to chrooting it's just your script has saved me looking up the nitty gritty details. Chrooting is used extensively in Linux from Scratch (which I went through about 10 years or more ago).
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
socialdefect
Posts: 110
Joined: Mon Jun 25, 2012 9:02 pm
Location: Tilburg, the Netherlands
Contact: Website

Re: Automated Raspbian chroot set-up

Thu May 01, 2014 5:08 pm

DougieLawson wrote:I'm not new to chrooting it's just your script has saved me looking up the nitty gritty details.
That's what I guessed after seeing your signature just when I submitted my comment.
Chrooting is used extensively in Linux from Scratch (which I went through about 10 years or more ago).
That's also where I got my chrooting skills.
== If it's not broke... I'm not done fixing it! ==

supercruise
Posts: 1
Joined: Wed Sep 14, 2016 1:30 pm

Re: Automated Raspbian chroot set-up

Wed Sep 14, 2016 1:52 pm

Thank you for the docker image!

I was trying to understand what's happening under the hood, but was unable to. Hoping you can help me out :)

1. When exactly is qemu-arm-static getting invoked? From within the docker container? On the host machine?
2. If it is on the host machine, how does it know that it needs to use qemu for this container?

Return to “Other projects”