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

Commit 1781435

Browse files
author
Alistair Strachan
committed
Add support for Ubuntu Base.
Install the base system from a downloadable image, then patch it with the PACKAGES we need. This method produces a much smaller image than with debootstrap, and the building process completes much more quickly. The process also does not require root (with some caveats). The debian program 'fakeroot' replaces all uses of 'sudo' to ensure that the user and group of files in the final tarball remains the same. Signed-off-by: Alistair Strachan <astrachan@google.com>
1 parent efdb6bf commit 1781435

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ at least 2 GB free space in the data partition.
3434

3535
Host:
3636
A machine running recent Ubuntu or Debian, with 4GB of memory and 4GB free space.
37-
Host needs debootstrap and qemu-user-static packages. To install these,
37+
Host needs debootstrap, fakeroot and qemu-user-static packages. To install these,
3838
run `sudo apt-get install debootstrap fakeroot qemu-user-static`.
3939
Other distributions may work but they are not tested.
4040

androdeb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ esac
6363
case $DISTRO in
6464
buster) ;;
6565
bionic)
66+
DISTRO_VERSION=18.04
6667
if [ "$ARCH" == "i386" -o "$ARCH" == "amd64" ]; then
6768
MIRROR=http://archive.ubuntu.com/ubuntu/
6869
else
@@ -182,7 +183,7 @@ fi
182183
PACKAGES+="$DEFAULT_PACKAGES"
183184
echo "Using temporary directory: $TDIR"
184185

185-
$spath/buildstrap $ARCH $DISTRO $TDIR $OUT_TMP "$PACKAGES" "$INSTALL_BCC" $MIRROR
186+
$spath/buildstrap $ARCH $DISTRO $TDIR $OUT_TMP "$PACKAGES" "$INSTALL_BCC" $MIRROR "$DISTRO_VERSION"
186187

187188
# Push tar to device and start unpack
188189
$ADB shell mkdir -p /data/androdeb/

buildstrap

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,42 @@ OUT_TMP=$4
1111
PACKAGES=$5
1212
INSTALL_BCC=$6
1313
MIRROR=$7
14+
DISTRO_VERSION=$8
1415

15-
root=sudo
16+
if [[ ! -z $DISTRO_VERSION ]]; then
17+
# Assume non-empty DISTRO_VERSION is Ubuntu; see if there's a base image..
18+
echo "Checking for Ubuntu Base image from the web..."; echo ""
19+
if [ ! -f $TDIR/ubuntu-base-$DISTRO_VERSION-base-$ARCH.tar.gz ]; then
20+
curl -L http://cdimage.ubuntu.com/ubuntu-base/releases/$DISTRO_VERSION/release/ubuntu-base-$DISTRO_VERSION-base-$ARCH.tar.gz \
21+
--output $TDIR/ubuntu-base-$DISTRO_VERSION-base-$ARCH.tar.gz; fi
22+
if [ -f $TDIR/ubuntu-base-$DISTRO_VERSION-base-$ARCH.tar.gz ]; then
23+
time tar -C $OUT_TMP --exclude=dev -xf $TDIR/ubuntu-base-$DISTRO_VERSION-base-$ARCH.tar.gz;
24+
mkdir $OUT_TMP/dev; fi; fi
1625

17-
if [ $EUID -ne 0 ]; then echo "The next stage runs as sudo, please enter password if asked."; fi
26+
if [ ! -f $OUT_TMP/etc/debian_version ]; then
27+
root=sudo
1828

19-
# It's easier to just really be root for debootstrap
20-
time $root qemu-debootstrap --arch $ARCH --include="$(make_csv "$PACKAGES")" \
21-
$DISTRO $OUT_TMP $MIRROR
29+
if [ $EUID -ne 0 ]; then echo "The next stage runs as sudo, please enter password if asked."; fi
2230

23-
# Some reason debootstrap leaves these mounted
24-
$root umount $OUT_TMP/proc/sys/fs/binfmt_misc || true
25-
$root umount $OUT_TMP/proc || true
31+
# It's easier to just really be root for debootstrap
32+
time $root qemu-debootstrap --arch $ARCH --include="$(make_csv "$PACKAGES")" \
33+
$DISTRO $OUT_TMP $MIRROR
34+
35+
# Some reason debootstrap leaves these mounted
36+
$root umount $OUT_TMP/proc/sys/fs/binfmt_misc || true
37+
$root umount $OUT_TMP/proc || true
38+
else
39+
root=fakeroot
40+
41+
# Avoid 'apt-get install' because this requires chroot, which requires root
42+
# FIXME: Note, this only works if PACKAGES fully describes the dependency
43+
# chain, and it also only if the postinst scripts for the packages
44+
# are not critical.
45+
for PACKAGE in $PACKAGES; do
46+
FILE=`cat $OUT_TMP/var/lib/apt/lists/*Packages | grep -e "^Filename:.*/${PACKAGE}_" | cut -d' ' -f2`
47+
echo "Fetching ${MIRROR}${FILE}..."; echo ""
48+
curl -L ${MIRROR}${FILE} --output $TDIR/`basename $FILE`
49+
$root dpkg-deb -x $TDIR/`basename $FILE` $OUT_TMP; done; fi
2650

2751
# Make bash the default shell
2852
$root ln -sf /bin/bash $OUT_TMP/bin/sh || true

0 commit comments

Comments
 (0)