Chroot Gentoo in Android

Posted on Tue 12 March 2019 in android

Main skeleton

See this.

My amendment

Tarball mirrors in China

  • TUNA: https://mirrors.tuna.tsinghua.edu.cn/gentoo/experimental/arm64/
  • Aliyun: https://mirrors.aliyun.com/gentoo/experimental/arm64/
  • 163: https://mirrors.163.com/gentoo/experimental/arm64/

Clean env for chroot

If chroot directly, some Android-specific environment variables will be carried on with, causing invalid $PATH and issues alike.

To fix that, run env -i chroot /path/to/gentoo, and add necessary env like $HOME and $PATH, either after the env -i part or in profile/shell's rc. (change accordingly in the startup script)

An example:

# /root/.zshrc
export USER=root
export LOGNAME=root
export HOME=/root
export SHELL=/bin/zsh
export EDITOR=/usr/bin/vim
export TERM=xterm-256color
export COLORTERM=truecolor

And start by env -i chroot /data/gentoo /bin/zsh -l

Hostname

Set a consistent hostname and $HOST:

  • hostname THEHOSTNAME +
  • export HOST=THEHOSTNAME +
  • set THEHOSTNAME in /etc/host

Fix network permission issue

wget alone works fine, but fails when doing emerge

According to gentoo forum and an Arch's case, Do this:

# groupadd -g 3003 aid_inet
# groupadd -g 3004 aid_inet_raw
# usermod -aG aid_inet,aid_inet_raw portage

Fix random SSH broken pipe

SSH connection to this chroot-Gentoo may fail with broken pipe, add IPQoS=throughput to prevent it. See here.

Ungraceful exit script

# after exit chroot
umount /data/gentoo/dev/shm
umount /data/gentoo/dev/pts
umount /data/gentoo/dev
umount /data/gentoo/proc
umount /data/gentoo/sys
umount /data/gentoo/tmp