Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit aaa1541

Browse files
author
Alistair Strachan
committed
Add support for rootless prepare.
Support using 'debootstrap --foreign' instead of qemu-debootstrap and eliminate all use of sudo. Use fakeroot to preserve permissions in the output filesystem. The finalization of the debootstrap is done on the device side. This change enables the use of distributions which are not compatible with the distribution debootstrap is being run on (normally not a supported configuration by debootstrap without --foreign), including alternative architecture and, more importantly, different glibc versions. Signed-off-by: Alistair Strachan <astrachan@google.com>
1 parent 7ca8929 commit aaa1541

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ section.
4040

4141
Host:
4242
A machine running recent Ubuntu or Debian, with 4GB of memory and 4GB free space.
43-
Host needs the debootstrap and qemu-user-static packages. To install
44-
these, run `sudo apt-get install debootstrap qemu-user-static`.
43+
Host needs the debootstrap, fakeroot and qemu-user-static packages. To install
44+
these, run `sudo apt-get install debootstrap fakeroot qemu-user-static`.
4545
Other distributions may work but they are not tested.
4646

4747
Quick Start Instructions
@@ -157,5 +157,9 @@ example for x86_64 architecture, run:
157157
```
158158
adeb prepare --build --arch amd64 --bcc --kernelsrc /path/to/kernel-source/
159159
```
160+
Normally you want to use --foreign too, especially if your distro's glibc
161+
version does not match the --distro option. This mode eliminates the need
162+
for root (chroot) or qemu-debootstrap, but it does cause more setup to be
163+
done on the device side the first time you enter adeb.
160164
Note: The --download option ignores the --arch flag. This is because we only
161165
provide pre-built filesystems for ARM64 at the moment.

androdeb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ FULL=0 # Default to a minimal install
1717
DOWNLOAD=1 # Default to downloading from web
1818
SKIP_DEVICE=0 # Skip device preparation
1919
INSTALL_BCC=0 # Decide if BCC is to be installed
20+
FOREIGN=0 # Use debootstrap --foreign mode
2021

2122
# Default packages
2223
PACKAGES=""
@@ -52,6 +53,7 @@ case $key in
5253
--full) FULL=1; config_full_build; shift || true; ;;
5354
--arch) ARCH=$2; shift || true; shift || true; ;;
5455
--distro) DISTRO="$2"; shift || true; shift || true; ;;
56+
--foreign) FOREIGN=1; shift || true; ;;
5557
--archive) TARF=$2; shift || true; shift || true; ;;
5658
--bcc) source $spath/packages/bcc; shift || true; ;;
5759
--kernelsrc) KERNELSRC="$2"; shift || true; shift || true; ;;
@@ -301,7 +303,7 @@ c_info "Using temporary directory: $TDIR"
301303
ex_files=$(mktemp); echo $EXTRA_FILES > $ex_files
302304

303305
$spath/buildstrap $ARCH $DISTRO $TDIR $OUT_TMP "$PACKAGES" \
304-
$ex_files $INSTALL_BCC $SKIP_DEVICE $MIRROR
306+
$ex_files $INSTALL_BCC $SKIP_DEVICE $MIRROR $FOREIGN
305307
rm $ex_files
306308

307309
# If we only wanted to prepare a rootfs and don't have

buildstrap

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,20 @@ EXTRA_FILES="$(cat $6)"
1313
INSTALL_BCC=$7
1414
SKIP_DEVICE=$8 # Skip any device-specific stages
1515
MIRROR=$9
16+
shift
17+
FOREIGN=$9
1618
VARIANT="--variant=minbase"
1719

18-
root=sudo
19-
20-
if [ $EUID -ne 0 ]; then echo "The next stage runs as sudo, please enter password if asked."; fi
20+
if [ $FOREIGN -eq 1 ]; then
21+
debootstrap="debootstrap --foreign"
22+
root=fakeroot
23+
else
24+
if [ $EUID -ne 0 ]; then echo "The next stage runs as sudo, please enter password if asked."; fi
25+
debootstrap=qemu-debootstrap
26+
root=sudo
27+
fi
2128

22-
# It's easier to just really be root for debootstrap
23-
time $root qemu-debootstrap --arch $ARCH --include=$PACKAGES $VARIANT \
29+
time $root $debootstrap --arch $ARCH --include=$PACKAGES $VARIANT \
2430
$DISTRO $OUT_TMP $MIRROR
2531

2632
# Some reason debootstrap leaves these mounted
@@ -63,7 +69,7 @@ else
6369
fi
6470

6571
# Add a default DNS server
66-
$root tee -a $OUT_TMP/etc/resolv.conf >/dev/null <<EOF
72+
$root tee $OUT_TMP/etc/resolv.conf >/dev/null <<EOF
6773
nameserver 4.2.2.2
6874
EOF
6975

0 commit comments

Comments
 (0)