# Run ArchLinux on Amlogic S905x S912 S905w Android TV Box

This might be a roundabout way of getting ArchLinux up and running on Amlogic based TV boxes, but it worked for me. It builds upon the great work done by the Armbian development team. Arch provides a generic ARMv8 root filesystem download on their site. In this tutorial, we will be flashing Armbian to a SD card and then replacing the Debian filesystem with the downloaded ArchLinux root FS. The tutorial uses the dd command, which does not hold your hand or offer any warnings or confirmations. TAKE YOUR TIME AND PROCEED AT YOUR OWN RISK

## Things You Will Need

- A microSD card at least 8 GB https://amzn.to/36CpShC | https://amzn.to/3CXJngt | https://amzn.to/3JqyxSP

## Downloads and Flashing to MicroSD

1. Download Armbian Download | Alternate
2. Download ArchLinux for ARM Download
3. Insert the microSD card to write Armbian/Arch Linux to
4. Run the following commands in a terminal window:
   # install prerequisites
   sudo apt install xz-utils -y
   # extract downloaded armbian image
   unxz ~/Downloads/Armbian_20.10_Arm-64_bullseye_current_5.9.0.img.xz
   # list out disks
   sudo fdisk -l
   # run the following to restore the Armbian .img to the target device
   # replace sdx with the correct source disk
   # MAKE ABSOLUTELY CERTAIN THE OUTPUT TARGET IS CORRECT
   # OR YOU COULD POTENTIALLY DAMAGE YOUR OS
   # OR OTHER STORAGE DEVICES ATTACHED TO THE PC
   # restore img
   sudo dd if=~/Downloads/Armbian_20.10_Arm-64_bullseye_current_5.9.0.img of=/dev/sdx bs=4M status=progress
   # after the dd completes, run the following to list mounted drives and partitions
   df -h
   # locate the ROOTFS partition on the SD card, using sdx from above
   # delete the armbian OS filesystem, replace the path with the SD card ROOTFS partition
   sudo rm /media/i12bretro/ROOTFS/* -r
   # extract the archlinux rootfs to the SD card ROOTFS partition, replace the path with the SD card ROOTFS partition
   sudo tar -xf ~/Downloads/ArchLinuxARM-aarch64-latest.tar.gz -C /media/i12bretro/ROOTFS

## Configure MicroSD Card for ArchLinux

1. Open the BOOT partition of the microSD card in a file browser
2. Rename the appropriate file from below to u-boot.ext on the root of the SD card

   u-boot-s905 (for s905)
   u-boot-s905x-s912 (for s905x and s912)
   u-boot-s905x2-s922 (for s905x2 and s922)

3. Edit /extlinux/extlinux.conf in a text editor
   1. Comment out rk-3399 lines by adding #
   2. Uncomment aml s9xx FDT and APPEND lines by removing #
   3. Update the FDT line to point to a working .dtb file for your device
      # aml s9xxx
      FDT /dtb/amlogic/meson-gxl-s905w-tx3-mini.dtb
      APPEND root=LABEL=ROOTFS rootflags=data=writeback rw console=ttyAML0,115200n8 console=tty0 no_console_suspend consoleblank=0 fsck.fix=yes fsck.repair=yes net.ifnames=0
   4. Save
   5. Close
4. Safely eject the microSD
5. Insert microSD card to Android TV box

## Booting to ArchLinux for the First Time

1. Plug the power adapter into the Android TV box
2. If the device has never booted from external storage before the stock Android OS will load
3. In Android, navigate to the application drawer > Run Update & Backup
4. Select Local > Navigate to the microSD card > aml_autoscript.zip
5. Select Update
6. The system will reboot twice and should then begin booting ArchLinux from the microSD card
7. You should see the ArchLinux terminal running startup scripts
8. When prompted, login with username: root password: root
   NOTE: the default user level account is username: alarm password: alarm
9. Run the following commands to install sudo and create a new sudo user
   # change the root password
   passwd
   # delete the default alarm user
   userdel -r alarm
   # initialize pacman keyring
   pacman-key --init
   pacman-key --populate archlinuxarm
   # update software repositories
   pacman -Syu
   # install sudo
   pacman -S sudo
   # create a new user account
   # change i12bretro in all the commands below to the new username
   useradd --create-home i12bretro
   # set the new user's password
   passwd i12bretro
   # add the user to the wheel group
   usermod -aG wheel i12bretro
   # add the user to the sudoers file
   nano /etc/sudoers
   # uncomment the following line by removing the # symbol
   %wheel ALL=(ALL) ALL
10. Press CTRL+O, Enter, CTRL+X to write the changes to sudoers
11. Exit out of the root session and login with the newly created user account
12. Verify that sudo is working by running the following command
    sudo pacman -Syu
13. Welcome to ArchLinux running on your Amlogic Android TV box

Special thanks to the developers and forum members over at Armbian.com and ArchLinuxARM.org for making this possible