Ho theha setšoantšo sa Ubuntu bakeng sa ARM "ho tloha qalong"

Ha nts'etsopele e sa tsoa qala, hangata ha ho hlake hore na ke liphutheloana life tse tla ea ho li-rootfs tse lebisitsoeng.

Ka mantsoe a mang, ho sa le qalong haholo ho tšoara LFS, buildroot kapa yocto (kapa ntho e 'ngoe), empa u se u ntse u hloka ho qala. Bakeng sa barui (ke na le 4GB eMMC ka mehlala ea lifofane) ho na le mokhoa oa ho abela bahlahisi kabo e tla ba lumella ho fana ka ntho eo hona joale e leng sieo, 'me joale re ka lula re bokella lethathamo la liphutheloana le ho etsa lethathamo la the rootfs target.

Sengoliloeng sena ha se secha ebile ke taelo e bonolo ea ho kopitsa.

Morero oa sengoloa ke ho aha li-rootfs tsa Ubuntu bakeng sa liboto tsa ARM (tabeng ea ka, e ipapisitse le Colibri imx7d).

Ho haha ​​setšoantšo

Re bokella li-rootfs tse reriloeng bakeng sa ho ikatisa.

Ho notlolla Ubuntu Base

Re khetha tokollo ka borona ho latela tlhoko le likhetho tsa rona. Mona ke fane ka tse 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

Ho hlahloba tšehetso ea BINFMT ka har'a kernel

Haeba u na le kabo e tloaelehileng, ho na le ts'ehetso bakeng sa BINFMT_MISC 'me ntho e' ngoe le e 'ngoe e hlophisitsoe, haeba ho se joalo, ke na le bonnete ba hore u tseba ho thusa BINFMT tšehetso kernel.

Etsa bonnete ba hore BINFMT_MISC e lumelletsoe kernel:

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

Joale o hloka ho lekola li-setting:

$ 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

U ka ingolisa ka letsoho u sebelisa, mohlala, litaelo tsena ke tsena.

Ho theha qemu static arm

Hona joale re hloka mohlala oa qemu o hlophisitsoeng hantle.

!!! HLOKOMELA!!!
Haeba u rera ho sebelisa setshelo ho haha ​​​​ntho e itseng, hlahloba:
https://sourceware.org/bugzilla/show_bug.cgi?id=23960
https://bugs.launchpad.net/qemu/+bug/1805913
Ebe bakeng sa moamoheli oa x86_64 le moeti oa letsoho o hloka ho sebelisa mofuta oa i386 oa 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

chroot

Mongolo o bonolo:

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

Re thabela sephetho:

$ ./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

Bakeng sa monate feela, ha re lekanye boholo pele le ka mor'a ho kenya bonyane (bakeng sa ka) sete ea liphutheloana:

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

Ha re ntjhafatse:

# apt update
# apt upgrade --yes

Ha re kenye liphutheloana tseo re li ratang:

# 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

Lifaele tsa lihlooho tsa Kernel le li-module ke taba e arohaneng. Ehlile, re ke ke ra kenya bootloader, kernel, modules, sefate sa lisebelisoa ka Ubuntu. Ba tla ho rona ba tsoa ka ntle kapa re tla ba bokella ka borona kapa ba tla fuoa rona ke moetsi oa boto, leha ho le joalo sena se ka holimo ho tekanyo ea taelo ena.

Ho isa bohōleng bo itseng, ho fapana ha mofuta hoa amoheleha, empa ho molemo ho li tlosa ho kernel build.

# apt install --yes linux-headers-generic

Ha re bone se etsahetseng mme ho ile ha etsahala haholo:

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

U se ke ua lebala ho beha phasewete.

Ho paka setšoantšo

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

Ho feta moo, re ka kenya etckeeper ka litlhophiso tsa autopush

Ha re re re abile kopano ea rona, mosebetsi o ile oa qala mabapi le mokhoa oa ho kopanya mefuta e fapaneng ea morao-rao ea sistimi ea rona.

etckeeper a ka tla ho re thusa.

Tšireletseho ke taba ea motho ka mong:

  • o ka sireletsa makala a itseng
  • hlahisa senotlolo se ikhethileng bakeng sa sesebelisoa ka seng
  • thibela ho sututsa ka matla
  • etc. ...
# ssh-keygen
# apt install etckeeper
# etckeeper init
# cd /etc
# git remote add origin ...

Ha re theheng autopush

Ha e le hantle, re ka etsa makala ho sesebelisoa esale pele (a re re re etsa script kapa tšebeletso e tla sebetsa ka lekhetlo la pele ha e qala).

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

Kapa re ka etsa ntho e bohlale ho feta ...

Tsela e botsoa

A re be le mofuta o mong oa sekhetho o ikhethileng, re re nomoro ea serial ea processor (kapa MAC - lik'hamphani tse tebileng li reka mefuta):

katse / 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

Joale re ka e sebelisa bakeng sa lebitso la lekala leo re tla sutumelletsa ho lona:

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

Ha re theheng mongolo o bonolo:

# 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

'Me ke phetho - ka mor'a nakoana re ka sheba liphetoho' me ra etsa lethathamo la liphutheloana bakeng sa firmware e reretsoeng.

Lisebelisoa tse khothalelitsoeng

BINFMT_MISC
Tšehetso ea Kernel bakeng sa mefuta e fapaneng ea Binary (binfmt_misc)
Ho kopanya le qemu user chroot
Ho aha li-root tsa Ubuntu bakeng sa ARM
Mokhoa oa ho theha botho ba Ubuntu ho tloha qalong
Crossdev qemu-static-user-chroot
joalo-joalo

getdents64 bothata

readdir() e khutlisa NULL (errno=EOVERFLOW) bakeng sa 32-bit user-static qemu ho moamoheli oa 64-bit
Ext4 64 bit hash breaks 32 bit glibc 2.28+
compiler_id_detection e hloleha bakeng sa armhf ha o sebelisa mohlala oa mosebelisi oa QEMU
CMake ha e sebetse hantle tlasa qemu-arm

Source: www.habr.com