Giter Site home page Giter Site logo

caioalarcon / banana-pi-m2-zero-arch-linux Goto Github PK

View Code? Open in Web Editor NEW

This project forked from turyrx/banana-pi-m2-zero-arch-linux

0.0 0.0 0.0 293 KB

installation and configuration of Arch Linux on Banana pi m2 zero board without display

Batchfile 100.00%

banana-pi-m2-zero-arch-linux's Introduction

Arch Linux Installation on Banana Pi M2 Zero (Headless Setup)

Overview

This README provides instructions for installing Arch Linux on a Banana Pi M2 Zero using an SD card without a display. It involves setting up the system using QEMU user-mode emulation and chroot, and includes steps for accessing the system via the serial debug port.

Prerequisites

  • A Linux host system with Arch Linux
  • QEMU user-mode emulation package
  • binfmt_misc support in the kernel
  • An SD card with at least 16GB of storage
  • A serial-to-USB adapter if you plan on using the serial debug port

Instructions

Step 1: Update System and Install Packages

sudo pacman -Syu
sudo pacman -S u-boot-tools dosfstools qemu-arch-extra

Step 2: Enable ARM Binary Translation

This step involves configuring binfmt_misc to recognize and translate ARM binaries so that they can be executed on an x86_64 system using QEMU.

sudo modprobe binfmt_misc
echo ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-arm-static:' | sudo tee /proc/sys/fs/binfmt_misc/register

Explanation of binfmt_misc Commands

  • modprobe binfmt_misc enables the binfmt_misc module, allowing the kernel to support additional binary formats.
  • The echo command registers the ARM binary format with the kernel. It specifies the magic bytes that identify an ARM binary and associates it with the qemu-arm-static emulator.

Step 3: Prepare the SD Card

lsblk # Identify the SD card device name (e.g., /dev/mmcblk0)
sudo dd if=/dev/zero of=/dev/mmcblk0 bs=1M count=8
sudo fdisk /dev/mmcblk0 # Create a new partition table and a primary partition
sudo mkfs.ext4 /dev/mmcblk0p1
sudo mkdir /mnt/banana
sudo mount /dev/mmcblk0p1 /mnt/banana

Step 4: Install Arch Linux ARM

wget http://os.archlinuxarm.org/os/ArchLinuxARM-armv7-latest.tar.gz
sudo bsdtar -xpf ArchLinuxARM-armv7-latest.tar.gz -C /mnt/banana

Step 5: Configure the System with QEMU and chroot

To prepare the system for chroot, we need to enable ARM binary execution and bind the necessary directories. This allows the ARM environment to use the devices and filesystems of the host machine.

First, bind the necessary directories:

sudo mount --bind /dev /mnt/banana/dev
sudo mount --bind /sys /mnt/banana/sys
sudo mount --bind /proc /mnt/banana/proc
sudo mount --bind /dev/pts /mnt/banana/dev/pts
sudo cp /etc/resolv.conf /mnt/banana/etc/resolv.conf

These commands bind the /dev, /sys, /proc, and /dev/pts directories from your host system to the equivalent directories on the Banana Pi filesystem. This is necessary for the ARM environment to access hardware devices and system information as if it were running directly on the hardware. Copying resolv.conf allows the chroot environment to use the host's DNS settings for network operations.

Now you can copy the QEMU ARM static binary to the mounted partition:

sudo cp /usr/bin/qemu-arm-static /mnt/banana/usr/bin/

Finally, you can chroot into your Banana Pi filesystem:

sudo chroot /mnt/banana /usr/bin/qemu-arm-static /bin/bash

With this step, you are now operating inside the Banana Pi's filesystem and can execute ARM binaries with the help of QEMU, allowing you to configure the system as if you were natively running it on the ARM hardware.

chroot into the system:

sudo arch-chroot /mnt/banana

Step 6: Set Up Boot Script

cd /boot
mkimage -A arm -O linux -T script -C none -n "Boot.scr" -d boot.cmd boot.scr

Step 7: Flash U-Boot to the SD Card

sudo dd if=u-boot-sunxi-with-spl.bin of=/dev/mmcblk0 bs=1024 seek=8

Step 8: Accessing the Terminal via Serial Debug Port

To access the terminal through the Banana Pi's serial debug port, connect the serial-to-USB adapter to the debug pins on the Banana Pi. Use a terminal emulator like screen or minicom on your host system to interact with the Banana Pi:

screen /dev/ttyUSB0 115200

This command will open a terminal session to the Banana Pi, replace /dev/ttyUSB0 with the actual device your serial adapter is recognized as.

Step 9: First Boot and System Configuration

After inserting the SD card into the Banana Pi and starting it up, connect via SSH or the serial debug port using the following default credentials:

  • Default user: alarm
  • Password: alarm
  • Default root user: root
  • Password: root

Initialize the keyring and update the system:

pacman-key --init
pacman-key --populate archlinuxarm
pacman -Syu

Configuring WiFi Access Point and SSH

Step 11: Install Access Point and DHCP Server Software

While still chrooted into the system, install the necessary packages to create a wireless access point and DHCP server:

pacman -S hostapd dhcp

Step 12: Configure hostapd

Create and edit the hostapd configuration file:

cat > /etc/hostapd/hostapd.conf <<EOF
interface=wlan0
driver=nl80211
ssid=BananaPi-AP
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=YourPassword
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
EOF

Replace YourPassword with a secure passphrase for your access point.

Enable and start hostapd:

systemctl enable hostapd
systemctl start hostapd

Step 13: Configure DHCP

Set up the DHCP server by configuring dhcpd.conf. Make sure to define the subnet, range of IPs to be assigned, and other settings as per your network configuration.

cat > /etc/dhcpd.conf <<EOF
default-lease-time 600;
max-lease-time 7200;
ddns-update-style none;

authoritative;

subnet 10.0.0.0 netmask 255.255.255.0 {
    range 10.0.0.2 10.0.0.20;
    option broadcast-address 10.0.0.255;
    option routers 10.0.0.1;
    default-lease-time 600;
    max-lease-time 7200;
    option domain-name "local";
    option domain-name-servers 8.8.8.8, 8.8.4.4;
}
EOF

Enable and start dhcpd service:

systemctl enable dhcpd4.service
systemctl start dhcpd4.service

Step 14: Enable SSH

Enable and start the SSH daemon:

systemctl enable sshd
systemctl start sshd

You can also edit /etc/ssh/sshd_config if you need to make changes to the default SSH configuration.

Step 15: Configure Network Interface

Set up a static IP for your wlan0 interface. You will need to create a network configuration file:

cat > /etc/systemd/network/wlan0.network <<EOF
[Match]
Name=wlan0

[Network]
Address=10.0.0.1/24
DHCPServer=yes
EOF

Enable and start systemd-networkd:

systemctl enable systemd-networkd
systemctl start systemd-networkd

Step 16: Clean Up

Before unmounting the SD card:

sudo umount /mnt/banana

Conclusion

With the wireless access point configured and the SSH service running, after booting your Banana Pi you can connect your computer to the SSID "BananaPi-AP" with the passphrase "YourPassword". Once connected, you can SSH into the Banana Pi using the default credentials:

  • SSID: BananaPi-AP
  • Passphrase: YourPassword
  • SSH User: alarm
  • SSH Password: alarm
  • IP: 10.0.0.1

You can now fully manage your Banana Pi without the need for a USB serial adapter or direct network connection.


Replace `10.0.0.1` with the static IP you want the Banana Pi to use within the subnet defined in the DHCP configuration, and `wlan0` with the actual interface name if it is different. Adjust the DHCP server settings (like IP range and default gateway) according to your requirements. Make sure the wireless interface supports the AP mode.

Be aware that not all WiFi chips support AP mode, especially on ARM devices, so ensure your Banana Pi's WiFi chipset is capable of this. If the built-in WiFi cannot be used as an AP, you may need a compatible USB WiFi dongle.

You should now have a working Arch Linux installation on your Banana Pi M2 Zero. This guide omits setting up peripherals and focuses on the initial installation and configuration. For further customization and peripheral setup, consult the Arch Linux ARM community and documentation.


Remember to replace `/dev/mmcblk0` with the actual device name of your SD

banana-pi-m2-zero-arch-linux's People

Contributors

turyrx avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.