• Earn real money by being active: Hello Guest, earn real money by simply being active on the forum — post quality content, get reactions, and help the community. Once you reach the minimum credit amount, you’ll be able to withdraw your balance directly. Learn how it works.

Android Arch Linux on Android (chroot)

dEEpEst

☣☣ In The Depths ☣☣
Staff member
Administrator
Super Moderator
Hacker
Specter
Crawler
Shadow
Joined
Mar 29, 2018
Messages
13,861
Solutions
4
Reputation
32
Reaction score
45,552
Points
1,813
Credits
55,350
‎7 Years of Service‎
 
56%
arch-linux-on-android-chroot-v0-gzsthopznjfe1.png


My phone is a 6G RAM Redmi Note 10S Android 14
Requirements

  1. Termux
  2. Root access
  3. You need to flash
    This link is hidden for visitors. Please Log in or register now.
    with Magisk

Setting Arch chroot​

  • Open your terminal app and enter root shell by executing the command su
  • Navigate to folder where you want to download and install Arch

Code:
cd /data/local/tmp
wget http://os.archlinuxarm.org/os/ArchLinuxARM-aarch64-latest.tar.gz
mkdir chrootarch
cd chrootarch
tar xvf /data/local/tmp/ArchLinuxARM-aarch64-latest.tar.gz --numeric-owner

Create a chroot script​


Code:
cd /data/local/tmp
vi arch.sh

  • When in Vi editor, click i to enter Insert mode and copy the script below in

Code:
#!/bin/sh

mnt="/data/local/tmp/chrootarch"

# Function to clean up and unmount filesystems
cleanup() {
  echo "Cleaning up and unmounting filesystems..."

  # Unmount /dev/shm if mounted
  if mountpoint -q "$mnt/dev/shm"; then
    umount "$mnt/dev/shm" || echo "Failed to unmount /dev/shm"
  fi

  # Unmount /var/cache if mounted
  if mountpoint -q "$mnt/var/cache"; then
    umount "$mnt/var/cache" || echo "Failed to unmount /var/cache"
  fi

  # Unmount /sdcard if mounted
  if mountpoint -q "$mnt/media/sdcard"; then
    umount "$mnt/media/sdcard" || echo "Failed to unmount /sdcard"
  fi

  # Unmount /dev/pts if mounted
  if mountpoint -q "$mnt/dev/pts"; then
    umount "$mnt/dev/pts" || echo "Failed to unmount /dev/pts"
  fi

  # Unmount /sys if mounted
  if mountpoint -q "$mnt/sys"; then
    umount "$mnt/sys" || echo "Failed to unmount /sys"
  fi

  # Unmount /proc if mounted
  if mountpoint -q "$mnt/proc"; then
    umount "$mnt/proc" || echo "Failed to unmount /proc"
  fi

  # Unmount /dev if mounted
  if mountpoint -q "$mnt/dev"; then
    umount "$mnt/dev" || echo "Failed to unmount /dev"
  fi

  # Remount /data without dev and suid options
  busybox mount -o remount,nodev,nosuid /data || echo "Failed to remount /data without dev,suid options"

  echo "Cleanup complete."
}

# Trap EXIT signal to ensure cleanup runs on script exit
trap cleanup EXIT

# Remount /data with dev and suid options
if ! busybox mount -o remount,dev,suid /data; then
  echo "Error: Failed to remount /data with dev,suid options."
  exit 1
fi

# Ensure the rootfs path exists
if [ ! -d "$mnt" ]; then
  echo "Error: Arch rootfs path does not exist."
  exit 1
fi

# Create necessary directories if they don't exist
[ ! -d "$mnt/dev/shm" ] && mkdir -p $mnt/dev/shm
[ ! -d "$mnt/media/sdcard" ] && mkdir -p $mnt/media/sdcard
[ ! -d "$mnt/var/cache" ] && mkdir -p $mnt/var/cache

# Mount /dev if not already mounted
if ! mountpoint -q "$mnt/dev"; then
  if ! mount -o bind /dev $mnt/dev; then
    echo "Error: Failed to bind mount /dev."
    exit 1
  fi
fi

# Mount /proc if not already mounted
if ! mountpoint -q "$mnt/proc"; then
  if ! busybox mount -t proc proc $mnt/proc; then
    echo "Error: Failed to mount /proc."
    exit 1
  fi
fi

# Mount /sys if not already mounted
if ! mountpoint -q "$mnt/sys"; then
  if ! busybox mount -t sysfs sysfs $mnt/sys; then
    echo "Error: Failed to mount /sys."
    exit 1
  fi
fi

# Mount /dev/pts if not already mounted
if ! mountpoint -q "$mnt/dev/pts"; then
  if ! busybox mount -t devpts devpts $mnt/dev/pts; then
    echo "Error: Failed to mount /dev/pts."
    exit 1
  fi
fi

# Mount /sdcard if not already mounted
if ! mountpoint -q "$mnt/media/sdcard"; then
  if ! busybox mount -o bind /sdcard $mnt/media/sdcard; then
    echo "Error: Failed to bind mount /sdcard."
    exit 1
  fi
fi

# Mount /var/cache if not already mounted
if ! mountpoint -q "$mnt/var/cache"; then
  if ! busybox mount -t tmpfs /cache $mnt/var/cache; then
    echo "Error: Failed to mount /var/cache."
    exit 1
  fi
fi

# Mount /dev/shm if not already mounted
if ! mountpoint -q "$mnt/dev/shm"; then
  if ! busybox mount -t tmpfs -o size=256M tmpfs $mnt/dev/shm; then
    echo "Error: Failed to mount /dev/shm."
    exit 1
  fi
fi

# Create a default resolv.conf if it doesn't exist
rm $mnt/etc/resolv.conf
if [ ! -f "$mnt/etc/resolv.conf" ]; then
  echo "nameserver 8.8.8.8" > "$mnt/etc/resolv.conf"
  echo "nameserver 8.8.4.4" >> "$mnt/etc/resolv.conf"
fi

# Create hosts file if it doesn't exist
rm $mnt/etc/hosts
if [ ! -f "$mnt/etc/hosts" ]; then
  echo "127.0.0.1 localhost" > "$mnt/etc/hosts"
fi

# Chroot into Arch
if ! busybox chroot $mnt /bin/su - root; then
  echo "Error: Failed to chroot into Arch."
  exit 1
fi

  • Make the script executable and then chroot into Arch

Code:
chmod +x arch.sh
sh arch.sh

  • You should see the prompt changed to [root@localhost ~]#
  • Verify installation

Code:
cat /etc/*-release


Congratulations! now you have successfully chrooted into Arch Linux

But we're not done yet, we have to fix few things first.

Fixing Pacman and other things​

  • Comment CheckSpace pacman config so you can install and update packages

Code:
nano /etc/pacman.conf

  • Initialize pacman keys

Code:
rm -r /etc/pacman.d/gnupg
pacman-key --init
pacman-key --populate archlinuxarm
pacman-key --refresh-keys

Tip: You can edit the mirrorlist and uncomment mirrors close to your location: nano /etc/pacman.d/mirrorlist

  • Execute some fixes

Code:
groupadd -g 3003 aid_inet
groupadd -g 3004 aid_net_raw
groupadd -g 1003 aid_graphics
usermod -G 3003 -a root


  • Upgrade the system and install common tools

Code:
pacman -Syu
pacman -S nano net-tools sudo git

  • Set root password
Code:
passwd root
  • Fix locales to avoid weird characters by uncommenting en_US.UTF-8 UTF-8
Code:
nano /etc/locale.gen
Code:
locale-gen
  • Replace LANG=C with LANG=en_US.UTF-8
Code:
nano /etc/locale.conf
That's it!
 
Back
Top