Skip to content

Instantly share code, notes, and snippets.

@sdrabb
Last active February 17, 2021 10:21
Show Gist options
  • Save sdrabb/ea6215e3d92992c692548ed9ee004f48 to your computer and use it in GitHub Desktop.
Save sdrabb/ea6215e3d92992c692548ed9ee004f48 to your computer and use it in GitHub Desktop.
Developer Gems

Build Debian Buster root FS from Linux x86_64 host to arm64 target 🤘

sudo apt-get install debootstrap qemu-utils qemu qemu-user-static flex bison

https://a-delacruz.github.io/debian/debian-arm64.html

NOTE: while running --second-stage after chroot Error while loading /debootstrap/debootstrap: Exec format error can occur, then a possible solution is the following: sudo apt purge qemu-user-static sudo apt install qemu-user-static i.e. try to uninstall and reinstall qemu-user-static

foo@pc:~$ mkdir arm64_buster_debian
foo@pc:~$ sudo debootstrap --arch=arm64 --no-check-gpg --foreign buster arm64_buster_debian http://deb.debian.org/debian/

Copy arm64 qemu binary into chroot

foo@pc:~$ sudo cp /usr/bin/qemu-aarch64-static arm64_buster_debian/usr/bin/

Chroot and run bash + qemu arm64x

foo@pc:~$ sudo chroot arm64_buster_debian/ qemu-aarch64-static /bin/bash

Inside qemu run debootstrap second stage

foo@pc:~$ /debootstrap/debootstrap --second-stage

Create uInitrd once chrooted

foo@pc:~$ update-initramfs -v -c -k 3.14.79+`
foo@pc:~$ mkimage -A arm64 -O linux -T ramdisk -C none -a 0 -e 0 -n uInitrd -d /boot/initrd.img-3.14.79+ /boot/uInitrd`

Mount SD card inside chroot env

foo@pc:~$ sudo mount /dev/sdc2 arm64_buster_debian_21032020/mnt/
foo@pc:~$ cp -ar /* /mnt

Remove root psw from FS

foo@pc:~$ passwd -d root

run

foo@pc:~$ tftp 0x1000000 meson64_odroidc2.dtb
foo@pc:~$ tftp 0x11000000 Image
foo@pc:~$ tftp 0x13000000 uInitrd
foo@pc:~$ setenv bootargs "root=/dev/mmcblk0p2 rw init=/sbin/init rootwait console=ttyS0,115200"
foo@pc:~$ booti 0x11000000 0x13000000 0x1000000

SD card Partitions

NOTE:
(FAT32) /dev/sdc1 partition should be small(about 32MB) and must start at +32M, it contains Kernel Image, DTB and uInitrd.
(EXT4) /dev/sdc2 contains previous built File System.

foo@pc:~$ sudo fdisk /dev/sdc
foo@pc:~$ sudo mkfs.fat -F 32 /dev/sdc1
foo@pc:~$ sudo mkfs.ext4 /dev/sdc2

NFS Server as bootargs

foo@pc:~$ setenv bootcmd "tftp 0x1000000 meson64_odroidc2.dtb; tftp 0x11000000 Image; tftp 0x13000000 uInitrd; booti 0x11000000 0x13000000 0x1000000"
foo@pc:~$ setenv bootargs "root=/dev/nfs ip=192.168.0.2:::::eth0 nfsroot=192.168.0.10:/targetfs,nfsvers=3 rw init=/sbin/init rootwait console=ttyS0,115200"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment