Te hanga i tetahi ahua Ubuntu mo te ARM "mai i te wahanga"

I te wa ka timata te whakawhanaketanga, kaore i te maarama ko tehea nga kohinga ka haere ki nga pakiaka o te whaainga.

I etahi atu kupu, he moata rawa ki te hopu i te LFS, buildroot, yocto ranei (he mea ke atu ranei), engari me timata koe. Mo te hunga whai rawa (kei a au te 4GB eMMC i runga i nga tauira pairati) he huarahi ki te tohatoha ki nga kaiwhakawhanake he tohatoha e taea ai e ratou te tuku tere i tetahi mea kei te ngaro i tenei wa, katahi ka taea e matou te kohikohi i nga rarangi o nga kohinga me te hanga rarangi mo nga rootfs ūnga.

Ehara tenei tuhinga i te mea hou, he tohutohu kape-whakapiri ngawari.

Ko te kaupapa o te tuhinga ko te hanga i nga pakiaka Ubuntu mo nga papa ARM (i taku keehi, i runga i te Colibri imx7d).

Te hanga whakaahua

Ka whakahiatohia e matou nga pakiaka o te whaainga mo te tukurua.

Wewetehia te turanga Ubuntu

Ka tohua e maatau te tuku i runga i nga hiahia me o maatau ake hiahia. I konei kua hoatu e ahau 20.

$ mkdir ubuntu20
$ cd ubuntu20
$ mkdir rootfs
$ wget http://cdimage.ubuntu.com/ubuntu-base/releases/20.04/release/ubuntu-base-20.04-base-armhf.tar.gz
$ tar xf ubuntu-base-20.04-base-armhf.tar.gz -C rootfs

Te tirotiro i te tautoko BINFMT i roto i te pata

Mena he tohatoha noa koe, he tautoko mo te BINFMT_MISC ka whirihorahia nga mea katoa, mena kaore, ka tino mohio ahau kei te mohio koe me pehea e taea ai te tautoko BINFMT i roto i te kernel.

Me mohio kei te whakahohea te BINFMT_MISC i te kernel:

$ zcat /proc/config.gz | grep BINFMT
CONFIG_BINFMT_ELF=y
CONFIG_COMPAT_BINFMT_ELF=y
CONFIG_BINFMT_SCRIPT=y
CONFIG_BINFMT_MISC=y

Inaianei me tirotiro koe i nga tautuhinga:

$ ls /proc/sys/fs/binfmt_misc
qemu-arm  register  status
$ cat /proc/sys/fs/binfmt_misc/qemu-arm
enabled
interpreter /usr/bin/qemu-arm
flags: OC
offset 0
magic 7f454c4601010100000000000000000002002800
mask ffffffffffffff00fffffffffffffffffeffffff

Ka taea e koe te rehita a-ringa ma te whakamahi, hei tauira, anei enei tohutohu.

Te whakatu ringa pateko qemu

Inaianei kei te hiahia tatou i tetahi tauira qemu kua whakaemihia.

!!! WHAKAARO!!!
Mena ka whakamahere koe ki te whakamahi i tetahi ipu hei hanga i tetahi mea, tirohia:
https://sourceware.org/bugzilla/show_bug.cgi?id=23960
https://bugs.launchpad.net/qemu/+bug/1805913
Na mo x86_64 kaihautu me te manuhiri ringa me whakamahi koe i te putanga i386 o qemu:
http://ftp.ru.debian.org/debian/pool/main/q/qemu/qemu-user-static_5.0-13_i386.deb

$ wget http://ftp.debian.org/debian/pool/main/q/qemu/qemu-user-static_5.0-13_amd64.deb
$ alient -t qemu-user-static_5.0-13_amd64.deb
# путь в rootfs и имя исполняемого файла должно совпадать с /proc/sys/fs/binfmt_misc/qemu-arm
$ mkdir qemu
$ tar xf qemu-user-static-5.0.tgz -C qemu
$ file qemu/usr/bin/qemu-arm-static
qemu/usr/bin/qemu-arm-static: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, BuildID[sha1]=be45f9a321cccc5c139cc1991a4042907f9673b6, for GNU/Linux 3.2.0, stripped
$ cp qemu/usr/bin/qemu-arm-static rootfs/usr/bin/qemu-arm
$ file rootfs/usr/bin/qemu-arm
rootfs/usr/bin/qemu-arm: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, BuildID[sha1]=be45f9a321cccc5c139cc1991a4042907f9673b6, for GNU/Linux 3.2.0, stripped

Kotahitanga

Tuhituhi ngawari:

ch-mount.sh

#!/bin/bash

function mnt() {
    echo "MOUNTING"
    sudo mount -t proc /proc proc
    sudo mount --rbind /sys sys
    sudo mount --make-rslave sys
    sudo mount --rbind /dev dev
    sudo mount --make-rslave dev
    sudo mount -o bind /dev/pts dev/pts
    sudo chroot 
}

function umnt() {
    echo "UNMOUNTING"
    sudo umount proc
    sudo umount sys
    sudo umount dev/pts
    sudo umount dev

}

if [ "$1" == "-m" ] && [ -n "$2" ] ;
then
    mnt $1 $2
elif [ "$1" == "-u" ] && [ -n "$2" ];
then
    umnt $1 $2
else
    echo ""
    echo "Either 1'st, 2'nd or both parameters were missing"
    echo ""
    echo "1'st parameter can be one of these: -m(mount) OR -u(umount)"
    echo "2'nd parameter is the full path of rootfs directory(with trailing '/')"
    echo ""
    echo "For example: ch-mount -m /media/sdcard/"
    echo ""
    echo 1st parameter : 
    echo 2nd parameter : 
fi

Ka mihi matou ki te hua:

$ ./ch-mount.sh -m rootfs/
# cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
# uname -a
Linux NShubin 5.5.9-gentoo-x86_64 #1 SMP PREEMPT Mon Mar 16 14:34:52 MSK 2020 armv7l armv7l armv7l GNU/Linux

Mo te ngahau noa, me ine i te rahi i mua i muri i muri i te whakaurunga o nga kohinga iti (mo au):

# du -d 0 -h / 2>/dev/null
63M     /

Kia whakahou tatou:

# apt update
# apt upgrade --yes

Me whakauru nga kete e pai ana ki a tatou:

# SYSTEMD_IGNORE_CHROOT=yes apt install --yes autoconf kmod socat ifupdown ethtool iputils-ping net-tools ssh g++ iproute2 dhcpcd5 incron ser2net udev systemd gcc minicom vim cmake make mtd-utils util-linux git strace gdb libiio-dev iiod

He take motuhake nga konae pane pane Kernel me nga waahanga. Ae ra, kaore matou e whakauru i te bootloader, kernel, modules, rakau taputapu ma Ubuntu. Ka haere mai ratou ki a matou i waho, ka whakaemihia ranei e matou, ka tukuna mai ranei e te kaihanga poari, ahakoa he aha tenei kei tua atu i te waahanga o tenei tohutohu.

I etahi waahanga, ka whakaaetia te rereketanga o te putanga, engari he pai ake te tango mai i te hanga kernel.

# apt install --yes linux-headers-generic

Kia kite tatou i te mea i tupu, a he maha nga mea i puta:

# apt clean
# du -d 0 -h / 2>/dev/null
770M    /

Kaua e wareware ki te whakatakoto kupuhipa.

Te takai i te ahua

$ sudo tar -C rootfs --transform "s|^./||" --numeric-owner --owner=0 --group=0 -c ./ | tar --delete ./ | gzip > rootfs.tar.gz

I tua atu, ka taea e tatou te whakauru i te etckeeper me te tautuhinga autopush

Ana, me kii kua tohatohahia ta maatau huihuinga, i timata te mahi me pehea te pai ki te whakahiato i nga waahanga rereke o to maatau punaha.

Ka taea e te kaitiaki te haere mai ki te awhina.

Ko te haumaru he take whaiaro:

  • ka taea e koe te tiaki i etahi peka
  • hangaia he taviri ahurei mo ia taputapu
  • mono kaha pana
  • etc. ...
# ssh-keygen
# apt install etckeeper
# etckeeper init
# cd /etc
# git remote add origin ...

Me whakarite te pana aunoa

Ka taea e taatau te hanga manga i runga i te taputapu i mua atu (me kii ka hangaia he tuhinga, he ratonga ranei ka rere i te wa tuatahi ka whakarewahia).

# cat /etc/etckeeper/etckeeper.conf
PUSH_REMOTE="origin"

Ka taea ranei e tatou tetahi mea maamaa ake ...

Ara mangere

Me whiwhi tatou i etahi momo tohu tohu motuhake, me kii te tau rangatū o te tukatuka (MAC ranei - ka hokona e nga kamupene nui te awhe):

ngeru / proc / cpuinfo

# cat /proc/cpuinfo
processor       : 0
model name      : ARMv7 Processor rev 5 (v7l)
BogoMIPS        : 60.36
Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm 
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xc07
CPU revision    : 5

processor       : 1
model name      : ARMv7 Processor rev 5 (v7l)
BogoMIPS        : 60.36
Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm 
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x0
CPU part        : 0xc07
CPU revision    : 5

Hardware        : Freescale i.MX7 Dual (Device Tree)
Revision        : 0000
Serial          : 06372509

Na ka taea e tatou te whakamahi mo te ingoa o te peka ka panaia e tatou:

# cat /proc/cpuinfo | grep Serial | cut -d':' -f 2 | tr -d [:blank:]
06372509

Me hanga he tuhinga ngawari:

# cat /etc/etckeeper/commit.d/40myown-push
#!/bin/sh
set -e

if [ "$VCS" = git ] && [ -d .git ]; then
  branch=$(cat /proc/cpuinfo | grep Serial | cut -d':' -f 2 | tr -d [:blank:])
  cd /etc/
  git push origin master:${branch}
fi

Na ko te mea katoa - i muri i etahi wa ka taea e tatou te titiro ki nga huringa me te hanga i te rarangi o nga kohinga mo te umanga kua whakaritea.

Nga rauemi e taunaki ana

BINFMT_MISC
Tautoko Kernel mo nga momo momo whakahōputu-rua (binfmt_misc)
Te whakahiato me te chroot kaiwhakamahi qemu
Te hanga i nga pakiaka Ubuntu mo te ARM
Me pehea te hanga i tetahi ritenga Ubuntu ora mai i te wahanga
Crossdev qemu-static-user-chroot
etc kaitiaki

getdents64 raruraru

readdir() whakahoki NULL (errno=EOVERFLOW) mo te moka-32-kaiwhakamahi qemu i runga i te ope moka-64
Ext4 64 bit hash breaks 32 bit glibc 2.28+
Ka rahua te compiler_id_detection mo te armhf ina whakamahi ana i te tauira aratau-kaiwhakamahi QEMU
Ko te CMake e kore e mahi tika i raro i te ringaringa qemu

Source: will.com