# Embedded custom distribution with minimal env

**URL:** <http://discourse.heig-vd.ch/t/embedded-custom-distribution-with-minimal-env/337>\
**Category:** SOO Framework\
**Created:** [June 27, 2022, 8:04am UTC](http://discourse.heig-vd.ch/t/embedded-custom-distribution-with-minimal-env/337 "2022-06-27T08:04:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rossierd](http://discourse.heig-vd.ch/user_avatar/discourse.heig-vd.ch/rossierd/32/4_2.png) [@rossierd](http://discourse.heig-vd.ch/u/rossierd)\
**Post date:** [June 27, 2022, 8:04am UTC](http://discourse.heig-vd.ch/t/embedded-custom-distribution-with-minimal-env/337/1 "2022-06-27T08:04:31Z")

</div>

We know that buildroot enables the creation of a minimal rootfs environment. A huge number of packages are available and can be easily configured using `make menuconfig` on the host dev machine.  
There is another way to build a customized distribution by using the `debootstrap` utility.

Here are the commands to do that (tested on RPi4, but can be achieved on any platform).

(The content is taken from [bionic.md](https://gitlab.com/smartobject/soo/-/blob/master/agency/rootfs/board/rpi4/bionic.md) available on gitlab)

* * *

Generate the base rootfs in out/ subdirectory  
(armhf stands for ARM-32 bit, or arm64 for ARM-64 bit)  
(focal matches with Ubuntu 20.04)

> sudo debootstrap --arch=armhf --verbose --foreign focal out

Edit a /init script as follows:

> #!/bin/sh
> 
> /bin/mount -t devtmpfs devtmpfs /dev
> 
> if (exec 0\</dev/console) 2\>/dev/null; then  
> exec 0\</dev/console  
> exec 1\>/dev/console  
> exec 2\>/dev/console  
> fi
> 
> exec /bin/sh

Boot the target and start with the following command :

> ./debootstrap/debootstrap --second-stage

with the target connected to the network.

Set a password for root with `passwd` – OR – `passwd -d root` (to remove password)

Adapt the /init script to launch sbin/init application

To have autologin, it is necessary to adapt the file /lib/systemd/system/serial-getty@.service  
and modify the line as follows:

> ExecStart=-/sbin/agetty 115200 %I $TERM

Configure /etc/apt/source.list as follows:

> deb `http://ports.ubuntu.com/ubuntu-ports/ bionic` main restricted universe

> deb `http://ports.ubuntu.com/ubuntu-ports/ bionic-updates` main universe

Network activation:

> ip address add 192.168.1.99 dev eth0  
> ip link set dev eth0 up  
> ip route add 192.168.1.1 dev eth0

Finally

> service systemd-resolved start  
> dhclient
