#Build a Debian Jessie root filesystem

<div class="row">
	<div class="col-md-2">
		<img src="debian.jpg" class="img-thumbnail"/>
	</div>
	<div class="col-md-10">
		<div class="text-success lead">
		This article illustrates how to build an Debian Jessie root filesystem for 
		the all the Acme Systems boards based on Atmel MCU 
		</div>
	</div>
</div>

<br/>
<div class="alert alert-success" role="alert" markdown="1">
<span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
This article is not valid with the latest Ubuntu versions. Please follow this 
article: @article='debos'
</div>

##Requirements

To create the rootfs contents you need an Ubuntu PC (we used
an Ubuntu 15.04) with the some packages installed. Type these commands
to install them:

<pre class="terminal">
~$ <b>sudo apt-get install multistrap</b>
~$ <b>sudo apt-get install qemu</b>
~$ <b>sudo apt-get install qemu-user-static</b>
~$ <b>sudo apt-get install binfmt-support</b>
~$ <b>sudo apt-get install dpkg-cross</b>
</pre>

##Use Multistrap to generate the rootfs contents

<i>"Multistrap is a tool that automates the creation of complete, bootable, 
Debian root filesystems. It can merge packages from different repositories.
Extra packages are added to the rootfs simply by listing them. All 
dependencies are taken care of."</i>.

Create a working directory in your home directory:

<pre class="terminal">
~$ <b>mkdir debian_jessie</b>
~$ <b>cd debian_jessie</b>
~/debian_jessie$
</pre>

Download the configuration file for your board:

* [multistrap_acqua.conf](./multistrap_acqua.conf)
* [multistrap_aria.conf](./multistrap_aria.conf)
* [multistrap_arietta.conf](./multistrap_arietta.conf)
* [multistrap_fox.conf](./multistrap_fox.conf)

Read [Multistrap man page](https://wiki.debian.org/MultistrapManPage) to understand each directive meanings.

##Create the root filesystem

When your multistrap.conf file is ready launch type:

* if you are using a board without FPU like FOX Board G20, Aria G25 or Arietta G25 type for example:

<pre class="terminal">
~/debian_jessie$ <b>sudo multistrap -a armel -f multistrap_</b><i>boardname</i><b>.conf</b>
</pre>

* if you are using a board with FPU like Acqua A5 type:
<pre class="terminal">
~/debian_jessie$ <b>sudo multistrap -a armhf -f multistrap_acqua.conf</b>
</pre>

At the end of this procedure the directory **target-rootfs** directory will contents 
the whole rootfs tree to be moved into the second partition of an Acme board bootable microSD.

Configure now the Debian packages using the armel CPU emulator **QEMU** and  **chroot** to 
create a jail where **dpkg** will see the **target-rootfs** as its root (/) directory.   

<pre class="terminal">
~/debian_jessie$ <b>sudo cp /usr/bin/qemu-arm-static target-rootfs/usr/bin</b>
~/debian_jessie$ <b>sudo mount -o bind /dev/ target-rootfs/dev/</b>
~/debian_jessie$ <b>sudo LC_ALL=C LANGUAGE=C LANG=C chroot target-rootfs dpkg --configure -a</b>
</pre>

At this prompt:

<img src="./configuring_dash.jpg"/>

Reply with **< No >**.

Some other prompt will appear during the configuration. Reply to them as you like.

When finished the target rootfs will be almost ready to be moved on the 
target microSD but it still needs some last extra configuration file before using it.

Based on type board you are using select one of these script to create the the
right configuration files:

* Acqua A5 [acqua.sh](./acqua.sh)
* Aria G25 [aria.sh](./aria.sh)
* Arietta G25 [arietta.sh](./arietta.sh)
* FOX board G20 [fox.sh](./fox.sh)

<pre class="terminal">
~/debian_jessie$ <b>chmod +x arietta.sh</b>
~/debian_jessie$ <b>sudo ./arietta.sh</b>
</pre>

create now the target root login password:

<pre class="terminal">
~/debian_jessie$ <b>sudo chroot target-rootfs passwd</b>
Enter new UNIX password: <b>type your password</b>
Retype new UNIX password: <b>type your password again</b>
passwd: password updated successfully
</pre>

If you want to take a look to the packages installed type:

<pre class="terminal">
~/debian_jessie$ <b>sudo chroot target-rootfs dpkg --get-selections | more</b>
</pre>

Check the Debian version installed:

<pre class="terminal">
~/debian_jessie$ <b>cat target-rootfs/etc/debian_version</b>
8.2
</pre>

Add more packages if needed by typing:

<pre class="terminal">
~/debian_jessie$ <b>sudo LC_ALL=C LANGUAGE=C LANG=C chroot target-rootfs apt-get update</b>
~/debian_jessie$ <b>sudo LC_ALL=C LANGUAGE=C LANG=C chroot target-rootfs apt-get install <i>packagename</i></b>
</pre>

Please note that will be possible to add packages also directly on the target board. In than case the
command will be simply:

<pre class="terminal">
# <b>apt-get install <i>packagename</i></b>
</pre>

then remove the **qemu-arm-static** executable:

<pre class="terminal">
~/debian_jessie$ <b>sudo rm target-rootfs/usr/bin/qemu-arm-static</b>
</pre>

##Enable the root access via ssh

By default the sshd server is installed inhibiting the root login via ssh. 
To enabled it change in <b>target-rootfs/etc/ssh/sshd_config</b> this line:

<pre class="minicom">
PermitRootLogin <b>without-password</b>
</pre>

with this:

<pre class="minicom">
PermitRootLogin <b>yes</b>
</pre>

##Copy the rootfs contents on microSD

[Format a new microSD](/microsd_format). 

Mount the microSD on your Ubuntu Linux PC 
and copy all the target-rootfs contents in the second microSD partition mounted 
on **/media/$USER/rootfs**.

<pre class="terminal">
~/debian_jessie$ <b>sudo rsync -axHAX --progress target-rootfs/ /media/$USER/rootfs/</b>
</pre>

Unmount the microSD, insert it in your board, insert the [DPI cable](/DPI) to see the Kernel bootstrap
messages and boot.

##Related links

* [Multistrap](http://wiki.debian.org/Multistrap)
* [Multistrap man page](http://wiki.debian.org/MultistrapManPage)
* [Building a small Debian root filesystem with Multistrap](http://free-electrons.com/blog/embdebian-with-multistrap/)
* [QEMU User Emulation](http://wiki.debian.org/QemuUserEmulation)
* [Debian mailing list](http://lists.debian.org/debian-embedded/)
* [foreign debian bootstrapping without root priviliges](http://blog.mister-muffin.de/2011/04/02/foreign-debian-bootstrapping-without-root-priviliges-with-fakeroot,-fakechroot-and-qemu-user-emulation/)
* [Changing your locale on Linux and UNIX systems](http://publib.boulder.ibm.com/infocenter/wmbhelp/v7r0m0/index.jsp?topic=%2Fcom.ibm.etools.mft.doc%2Fae19494_.htm)
* [Locale](http://en.wikipedia.org/wiki/Locale)

