Skip to content Skip to main navigation Skip to footer

Build minimal debian ARM RootFS

Install host tools

sudo apt-get install qemu-user-static debootstrap fakeroot binfmt-support debian-archive-keyring

Prepare environment variables

# Use buster debian distributive 
export BM_DISTRO=buster

# Set base directory for tmp files and artifacts
#   Note: BM_BASEDIR should not be located on encrypted partition
export BM_BASEDIR=${HOME}/tmp

# Set target directory for RootFS
export BM_RFSDIR=${BM_BASEDIR}/rootfs

Build Debian RootFS

# Create required directories
mkdir -p ${BM_RFSDIR}

# Set list of required packages
export BM_PKGS='vim,net-tools,console-common,console-data,debian-archive-keyring'

# Build rootfs
#   after building RootFS will be avaliable at ${BM_RFSDIR}
sudo qemu-debootstrap --arch=armhf --include=${BM_PKGS} $BM_DISTRO ${BM_RFSDIR} http://ftp.debian.org/debian/

Mandatory Setup

Configure hostname

# Configure hostname
sudo bash -c "echo hostarm42 > ${BM_RFSDIR}/etc/hostname"

Set root password

# Set root password
echo "root:password" | sudo chroot ${BM_RFSDIR} /usr/sbin/chpasswd --crypt-method=SHA512

Configure Fstab

# Install fstab
sudo bash -c "cat << EOF >> ${BM_RFSDIR}/etc/fstab
/dev/mmcblk0p1 / ext4 defaults 0 1
/dev/mmcblk0p2 /data ext4 defaults,rw 0 0
devpts /dev/pts devpts defaults 0 0
proc /proc proc defaults 0 0
tmp /tmp tmpfs defaults 0 0
EOF"

Optional Setup

Add a new user

# Create a new user
sudo chroot ${BM_RFSDIR} /usr/sbin/useradd -m -U -s /bin/bash user42
echo "user42:password" | sudo chroot ${BM_RFSDIR} /usr/sbin/chpasswd --crypt-method=SHA512

Result

$ ll ${BM_RFSDIR}
total 60
lrwxrwxrwx 1 root root 7 Apr 3 20:07 bin -> usr/bin
drwxr-xr-x 2 root root 4096 Mar 20 01:44 boot
drwxr-xr-x 4 root root 4096 Apr 3 20:07 dev
drwxr-xr-x 47 root root 4096 Apr 3 20:15 etc
drwxr-xr-x 2 root root 4096 Mar 20 01:44 home
lrwxrwxrwx 1 root root 7 Apr 3 20:07 lib -> usr/lib
drwxr-xr-x 2 root root 4096 Apr 3 20:07 media
drwxr-xr-x 2 root root 4096 Apr 3 20:07 mnt
drwxr-xr-x 2 root root 4096 Apr 3 20:07 opt
drwxr-xr-x 2 root root 4096 Mar 20 01:44 proc
drwx------ 2 root root 4096 Apr 3 20:07 root
drwxr-xr-x 4 root root 4096 Apr 3 20:07 run
lrwxrwxrwx 1 root root 8 Apr 3 20:07 sbin -> usr/sbin
drwxr-xr-x 2 root root 4096 Apr 3 20:07 srv
drwxr-xr-x 2 root root 4096 Mar 20 01:44 sys
drwxrwxrwt 2 root root 4096 Apr 3 20:15 tmp
drwxr-xr-x 10 root root 4096 Apr 3 20:07 usr
drwxr-xr-x 11 root root 4096 Apr 3 20:07 var

Create rootfs tarball

# Create rootfs tarball
tar -cjvf arm_buster_rootfs.tar.bz2 -C ${BM_RFSDIR}/ .