Hello,
Some routers and device running OpenWRT are capable to run Debian from a chroot. To create a chroot with Debian in it the tool Debootstrap can be used. To install Debootstrap in OpenWRT get the packages: debootstrap debian-archive-keyring gpgv2
:
opkg update && opkg install debootstrap debian-archive-keyring gpgv2
For Debian up to bullseye this worked to create a Debian chroot for an x86-64 system:
debootstrap --arch=amd64 bullseye /mnt/USB/debian
However, since Debian bookworm the following error is generated:
W: Failure while configuring required packages.
W: See /mnt/USB/debian/debootstrap/debootstrap.log for details (possibly the package usrmerge is at fault)
To resolve the issue, i figured out that using cdebootstrap-static works:
# CHROOT Debian
THIS_CHROOT="/mnt/USB/debian"
#chroot is not there, build it
if [ ! -d "$THIS_CHROOT" ]; then
echo "changing to directory: $THIS_CHROOT/.."
mkdir -p "$THIS_CHROOT" || exit 1
cd "$THIS_CHROOT/.." || exit 1
mkdir -p "cache" || exit 1
echo "Downloading cdebootstrap-static:"
wget -O cache/cdebootstrap-static.deb http://ftp.debian.org/debian/pool/main/c/cdebootstrap/cdebootstrap-static_0.7.8+b14_amd64.deb || exit 1
echo "unpacking cdebootstrap-static:"
cd cache
ar x cdebootstrap-static.deb || exit 1
tar xvf data.tar.xz || exit 1
echo "Executing cdebootstrap-static:"
./usr/bin/cdebootstrap-static --configdir=./usr/share/cdebootstrap-static --helperdir=./usr/share/cdebootstrap-static/ stable "$THIS_CHROOT" || exit 1
echo "Installing additional packages in chroot:"
chroot "$THIS_CHROOT" /usr/bin/apt update || exit 1
chroot "$THIS_CHROOT" /usr/bin/apt -y install vim wget curl htop || exit 1
fi
# mounted already?
mount | grep "$THIS_CHROOT" > /dev/null
if [ $? -ne 0 ]; then
mount -t proc proc "$THIS_CHROOT/proc/"
mount -t sysfs sys "$THIS_CHROOT/sys/"
mount -o bind /dev "$THIS_CHROOT/dev/"
mount -o bind /dev/pts "$THIS_CHROOT/dev/pts"
fi
chroot "$THIS_CHROOT" /bin/bash
Other architectures:
Arch armhf:
This works for x86 systems. However, a Debian Chroot can also be used on Routers like TP-Link Archer C2600 for example. For that processor adjust the script to use --arch armhf
and http://ftp.debian.org/debian/pool/main/c/cdebootstrap/cdebootstrap-static_0.7.8+b14_armhf.deb
to source cdebootstrap instead.
Arch arm64, for example Raspberry Pi 3 and 4:
#!/bin/sh
THIS_CHROOT="/mnt/USB/debian"
ARCH="arm64"
#chroot is not there, build it
if [ ! -d "$THIS_CHROOT" ]; then
echo "changing to directory: $THIS_CHROOT/.."
mkdir -p "$THIS_CHROOT" || exit 1
cd "$THIS_CHROOT/.." || exit 1
mkdir -p "cache" || exit 1
echo "Downloading cdebootstrap-static:"
wget -O cache/cdebootstrap-static.deb "http://ftp.debian.org/debian/pool/main/c/cdebootstrap/cdebootstrap-static_0.7.8+b15_$ARCH.deb" || exit 1
echo "unpacking cdebootstrap-static:"
cd cache
ar x cdebootstrap-static.deb || exit 1
tar xvf data.tar.xz || exit 1
#check if curl is installed
echo "checking if curl is installed:"
which curl || exit 1
echo "Executing cdebootstrap-static:"
./usr/bin/cdebootstrap-static --arch $ARCH --configdir=./usr/share/cdebootstrap-static --helperdir=./usr/share/cdebootstrap-static/ stable "$THIS_CHROOT" || exit 1
echo "Installing additional packages in chroot:"
chroot "$THIS_CHROOT" /usr/bin/apt update || exit 1
chroot "$THIS_CHROOT" /usr/bin/apt -y install vim wget curl htop || exit 1
fi
HTH!
Edit 2023-08-03: Added RPi3 architecture.