Debian on OpenWRT: Issues with Debootstrap and creating a chroot for Debian Bookworm

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.

I don't think a TP-Link Archer C2600 has the power to chroot into a debian environment,

perhaps a minimal service can be chrooted

Actually I am using it for years to run FHEM (=Homeautomation written in Perl), Owntone, TVHeadend to record Sat>IP besides some other daemons like mosquitto, adblocker etc.

sorry I understood that you wanted to chroot an entire debian distribution on the router

and I didn't realize that you are a long-time Openwrt user (it would be more convenient if in addition to the icon with the username there is also the registration time)

1 Like

Yeah, well - it is the complete Debian userland with apt and all other software I am used to. Of course, running an Xorg or Desktop is not possible, but command line applications and network daemons just run fine.

For instance on another device (=not TP-Link C2600) I am using FFMPEG to convert RTSP to HLS and serve it with uhttpd. Using Debian in a chroot allows me to update FFMPEG without too much hassle by using apt update && apt full-upgrade && apt clean && apt autoremove.

I apologize again

I have now seen some of your activities
good job
thank you for your support to the Openwrt group

All good, No need to apologize. I am happy if it turns out to be useful to others as well. This "bookworm" issue was bugging me now for a couple of weeks, since bookworm was released and it took me a while to figure out how to get it resolved. I assume that the package in OpenWRT needs an update to properly solve the issue, but I already have restic-rest-server on my ToDo list...

Cheers

1 Like