diff --git a/README.md b/README.md index 9f326e2..c8202cf 100644 --- a/README.md +++ b/README.md @@ -31,15 +31,17 @@ on device without having to cripple it. Requirements for running ------------------------ Target: -An ARM64 android N or later device which has "adb root" supported. Typically -this is a build in a userdebug configuration. Device should have atleast 2 GB -free space in the data partition. If you would like to use other architectures, -see the [Other Architectures](https://github.com/joelagnel/adeb/blob/master/README.md#how-to-use-adeb-for-other-architectures-other-than-arm64) section. +An armhf, arm64, i386 or amd64 Android N or later device which has "adb root" +supported. Typically this is a build in a userdebug configuration. Device should +have at least 2 GB free space in the data partition. If you would like to use an +architecture other than the default of arm64, see the +[Other Architectures](https://github.com/joelagnel/adeb/blob/master/README.md#how-to-use-adeb-for-other-architectures-other-than-arm64) +section. Host: A machine running recent Ubuntu or Debian, with 4GB of memory and 4GB free space. -Host needs debootstrap and qemu-debootstrap packages. -To install it, run `sudo apt-get install qemu-user-static debootstrap`. +Host needs the debootstrap, fakeroot and qemu-user-static packages. To install +these, run `sudo apt-get install debootstrap fakeroot qemu-user-static`. Other distributions may work but they are not tested. Quick Start Instructions @@ -155,5 +157,9 @@ example for x86_64 architecture, run: ``` adeb prepare --build --arch amd64 --bcc --kernelsrc /path/to/kernel-source/ ``` +Normally you want to use --foreign too, especially if your distro's glibc +version does not match the --distro option. This mode eliminates the need +for root (chroot) or qemu-debootstrap, but it does cause more setup to be +done on the device side the first time you enter adeb. Note: The --download option ignores the --arch flag. This is because we only provide pre-built filesystems for ARM64 at the moment. diff --git a/androdeb b/androdeb index 3fcf2dc..418f883 100755 --- a/androdeb +++ b/androdeb @@ -11,12 +11,13 @@ source $spath/utils/support source $spath/utils/banners # Set default vars -DISTRO=buster; ARCH=arm64 +DISTRO=buster; ARCH=arm64; MIRROR=http://deb.debian.org/debian/ ADB="adb" FULL=0 # Default to a minimal install DOWNLOAD=1 # Default to downloading from web SKIP_DEVICE=0 # Skip device preparation INSTALL_BCC=0 # Decide if BCC is to be installed +FOREIGN=0 # Use debootstrap --foreign mode # Default packages PACKAGES="" @@ -51,6 +52,8 @@ case $key in prepare) PREPARE=1; shift || true; ;; --full) FULL=1; config_full_build; shift || true; ;; --arch) ARCH=$2; shift || true; shift || true; ;; + --distro) DISTRO="$2"; shift || true; shift || true; ;; + --foreign) FOREIGN=1; shift || true; ;; --archive) TARF=$2; shift || true; shift || true; ;; --bcc) source $spath/packages/bcc; shift || true; ;; --kernelsrc) KERNELSRC="$2"; shift || true; shift || true; ;; @@ -80,6 +83,24 @@ if [ ! -z $BTAR ] && [ -z $TARDIR ]; then TARDIR=$spath fi +case $ARCH in + i386) ;; + amd64) ;; + arm64) ;; + armhf) ;; + *) echo "Unsupported arch ($ARCH)"; ;; +esac + +case $DISTRO in + buster) ;; + bionic) + if [ "$ARCH" == "i386" -o "$ARCH" == "amd64" ]; then + MIRROR=http://archive.ubuntu.com/ubuntu/ + else + MIRROR=http://ports.ubuntu.com/; fi ;; + *) echo "Unusupported distro ($DISTRO)"; ;; +esac + if [ ! -z "$GIT_PULL" ]; then c_info "Updating androdeb by git pull" cd $spath @@ -279,13 +300,10 @@ fi PACKAGES+="$DEFAULT_PACKAGES" c_info "Using temporary directory: $TDIR" -if [[ $EUID -ne 0 ]]; then c_info "The next stage runs as sudo, please enter password if asked."; fi - ex_files=$(mktemp); echo $EXTRA_FILES > $ex_files -sudo $spath/buildstrap $ARCH $DISTRO $TDIR $OUT_TMP \ - "$(make_csv "$PACKAGES")"\ - $ex_files $INSTALL_BCC $SKIP_DEVICE +$spath/buildstrap $ARCH $DISTRO $TDIR $OUT_TMP "$PACKAGES" \ + $ex_files $INSTALL_BCC $SKIP_DEVICE $MIRROR $FOREIGN rm $ex_files # If we only wanted to prepare a rootfs and don't have diff --git a/buildstrap b/buildstrap index 0aaa635..88310ba 100755 --- a/buildstrap +++ b/buildstrap @@ -8,44 +8,55 @@ ARCH=$1 DISTRO=$2 TDIR=$3 OUT_TMP=$4 -PACKAGES=$5 +PACKAGES="$(make_csv "$5")" EXTRA_FILES="$(cat $6)" INSTALL_BCC=$7 SKIP_DEVICE=$8 # Skip any device-specific stages +MIRROR=$9 +shift +FOREIGN=$9 VARIANT="--variant=minbase" -time qemu-debootstrap --arch $ARCH --include=$PACKAGES $VARIANT \ - $DISTRO $OUT_TMP http://deb.debian.org/debian/ +if [ $FOREIGN -eq 1 ]; then + debootstrap="debootstrap --foreign" + root=fakeroot +else + if [ $EUID -ne 0 ]; then echo "The next stage runs as sudo, please enter password if asked."; fi + debootstrap=qemu-debootstrap + root=sudo +fi + +time $root $debootstrap --arch $ARCH --include=$PACKAGES $VARIANT \ + $DISTRO $OUT_TMP $MIRROR # Some reason debootstrap leaves these mounted -umount $OUT_TMP/proc/sys/fs/binfmt_misc || true -umount $OUT_TMP/proc || true +$root umount $OUT_TMP/proc/sys/fs/binfmt_misc || true +$root umount $OUT_TMP/proc || true # Make bash the default shell -chroot $OUT_TMP rm /bin/sh || true -chroot $OUT_TMP ln -s /bin/bash /bin/sh || true -cp $spath/addons/bashrc $OUT_TMP/.bashrc -cp $spath/addons/bashrc.common $OUT_TMP/.bashrc.common -cp $spath/addons/bashrc.silent $OUT_TMP/.bashrc.silent -cp $spath/addons/get_kvers.sh $OUT_TMP/ +$root ln -sf /bin/bash $OUT_TMP/bin/sh || true +$root cp $spath/addons/bashrc $OUT_TMP/.bashrc +$root cp $spath/addons/bashrc.common $OUT_TMP/.bashrc.common +$root cp $spath/addons/bashrc.silent $OUT_TMP/.bashrc.silent +$root cp $spath/addons/get_kvers.sh $OUT_TMP/ for f in $EXTRA_FILES; do if [ $f == "none" ]; then continue; fi - cp $f $OUT_TMP/ + $root cp $f $OUT_TMP/ done # Cleanup -rm -rf $OUT_TMP/lib/udev/* -rm -rf $OUT_TMP/var/lib/apt/lists/* -rm -rf $OUT_TMP/var/cache/apt/archives/*deb -rm -rf $OUT_TMP/usr/share/locale/* -rm -rf $OUT_TMP/usr/lib/share/locale/* -rm -rf $OUT_TMP/usr/share/doc/* -rm -rf $OUT_TMP/usr/lib/share/doc/* -rm -rf $OUT_TMP/usr/share/ieee-data/* -rm -rf $OUT_TMP/usr/lib/share/ieee-data/* -rm -rf $OUT_TMP/usr/share/man/* -rm -rf $OUT_TMP/usr/lib/share/man/* +$root rm -rf $OUT_TMP/lib/udev/* +$root rm -rf $OUT_TMP/var/lib/apt/lists/* +$root rm -rf $OUT_TMP/var/cache/apt/archives/*deb +$root rm -rf $OUT_TMP/usr/share/locale/* +$root rm -rf $OUT_TMP/usr/lib/share/locale/* +$root rm -rf $OUT_TMP/usr/share/doc/* +$root rm -rf $OUT_TMP/usr/lib/share/doc/* +$root rm -rf $OUT_TMP/usr/share/ieee-data/* +$root rm -rf $OUT_TMP/usr/lib/share/ieee-data/* +$root rm -rf $OUT_TMP/usr/share/man/* +$root rm -rf $OUT_TMP/usr/lib/share/man/* # Fix apt-get issue: Android requires _apt user to be in the # AID_INET group which is also android specific. @@ -53,11 +64,14 @@ grep -ri _apt:x:100:65534 $OUT_TMP/etc/passwd > /dev/null 2>&1 if [ $? -ne 0 ]; then c_warning "_apt user cannot be added to AID_INET group" else - sed -i -e 's/_apt:x:100:65534/_apt:x:100:3003/' $OUT_TMP/etc/passwd + $root sed -i -e 's/_apt:x:100:65534/_apt:x:100:3003/' \ + $OUT_TMP/etc/passwd fi # Add a default DNS server -echo "nameserver 4.2.2.2" > $OUT_TMP/etc/resolv.conf +$root tee $OUT_TMP/etc/resolv.conf >/dev/null <