Android Chroot 網路問題

Android Chroot 網路問題

我正在嘗試 chroot Nvidia 的 Ubuntu 16.04 映像,以便在盾牌上開發。我把它放在一個 SD 卡上,安裝在 /mnt/chroots 上,我無法讓 apt-get update 正常工作,ping 也失敗。如有幫助,不勝感激。

cd rootfs
mount -t proc proc proc/
mount -t sysfs sys sys/
mount -o bind /dev dev/
mount -o bind /dev/pts dev/pts/
chroot . /bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH

我還將 root 添加到群組中:

groupadd -g 3001 aid_net_bt_admin
groupadd -g 3002 aid_net_bt
groupadd -g 3003 aid_inet
groupadd -g 3004 aid_inet_raw
groupadd -g 3005 aid_inet_admin

gpasswd -a root aid_net_bt_admin
gpasswd -a root aid_net_bt
gpasswd -a root aid_inet
gpasswd -a root aid_inet_raw
gpasswd -a root aid_inet_admin

/etc/resolv.conf
nameserver 8.8.8.8

透過 /etc/init.d/networking 啟動

root@localhost:/# apt-get update
Err:1 http://ports.ubuntu.com/ubuntu-ports xenial InRelease
Temporary failure resolving 'ports.ubuntu.com'
Err:2 http://ports.ubuntu.com/ubuntu-ports xenial-updates InRelease
Temporary failure resolving 'ports.ubuntu.com'
Err:3 http://ports.ubuntu.com/ubuntu-ports xenial-security InRelease
Temporary failure resolving 'ports.ubuntu.com'
Reading package lists... Done
W: Failed to fetch http://ports.ubuntu.com/ubuntu-ports...nial/InRelease Temporary failure resolving 'ports.ubuntu.com'
W: Failed to fetch http://ports.ubuntu.com/ubuntu-ports...ates/InRelease Temporary failure resolving 'ports.ubuntu.com'
W: Failed to fetch http://ports.ubuntu.com/ubuntu-ports...rity/InRelease Temporary failure resolving 'ports.ubuntu.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.

答案1

您這裡有兩個不同的問題

  • apt不解析DNS
  • ping 不工作

-


APT 未解析 DNS:

問題是 APT 使用 _apt 作為我們的非特權使用者。在有偏執網路的Android上,只有3003 aid_inet或3004 aid_inet_raw群組中的使用者可以開啟網路套接字。當 apt 安裝時,它會建立使用者 _apt。

    # add unprivileged user for the apt methods
     adduser --force-badname --system --home /nonexistent  \
       --no-create-home --quiet _apt || true

用戶在 /etc/passwd 中看起來像這樣

    root@localhost:~
    # grep -E "_apt" /etc/passwd
    _apt:x:103:65534::/nonexistent:/bin/false

密碼格式是

使用者名稱:加密密碼:使用者ID號碼(UID):使用者群組ID號碼(GID):使用者全名(GECOS):使用者主目錄:登入shell

查看 _apt 用戶,GID 設定為 65534,這意味著沒有群組,在普通的 Linux 系統上這很好。在 Android 上,此 GID 將永遠​​無法建立網路連線 需要將 GID 變更為 3003

# usermod -g 3003 _apt 會改變GID

    root@localhost:~
    # grep -E "_apt" /etc/passwd
    _apt:x:103:3003::/nonexistent:/bin/false

現在 APT 將在 Android chroot 上運行

Ping 不工作


對我來說,我注意到當我使用這個命令範例 chroot 時

# chroot /linux /bin/bash -l

在 Android 中,群組在某種程度上用於應用程式。所以 root 呼叫 bash 只在 root 群組中,你可以透過以下方式檢查

    # groups
     root

無用戶名運行的群組輸出目前進程組

現在試試這個

# su - root

su指令是切換用戶

    # groups
    root sdcard-rw aid_bt aid_bt-net aid_inet aid_net-raw aid_net_admin

現在 ping 可以正常運作了

我現在用

# chroot /linux /bin/su - root

從 Linux 以 root 身分登錄,而不是從 Android 以 root 身分登入

相關內容