Ukudala isithombe se-Ubuntu se-ARM “kusuka ekuqaleni”

Uma ukuthuthukiswa kuqala nje, ngokuvamile akucaci ukuthi yimaphi amaphakheji azoya ku-rootfs eqondiwe.

Ngamanye amazwi, kusesekuseni kakhulu ukubamba i-LFS, i-buildroot noma i-yocto (noma enye into), kodwa usuvele udinga ukuqala. Kwabacebile (ngine-4GB eMMC kumasampula omshayeli) kunendlela yokuphuma yokusabalalisa kubathuthukisi ukusabalalisa okuzobavumela ukuthi balethe ngokushesha okuthile okushodayo njengamanje, bese singahlala siqoqa uhlu lwamaphakheji futhi sidale uhlu lwamaphakheji. the rootfs target.

Lesi sihloko asisisha futhi siwumyalelo olula wokukopisha nokunamathisela.

Inhloso ye-athikili ukwakha i-Ubuntu rootfs yamabhodi e-ARM (endabeni yami, ngokusekelwe ku-Colibri imx7d).

Ukwakha isithombe

Sihlanganisa ama-rootfs okuhlosiwe ukuze aphindaphinde.

Ukukhipha i-Ubuntu Base

Sikhetha ukukhululwa ngokwethu ngokusekelwe esidingweni nasezintweni esizithandayo. Nakhu nginikele angu-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

Ihlola ukwesekwa kwe-BINFMT ku-kernel

Uma unokusabalalisa okuvamile, khona-ke kukhona usekelo lwe-BINFMT_MISC futhi yonke into iyalungiswa, uma kungenjalo, ngiyaqiniseka ukuthi uyakwazi ukunika amandla usekelo lwe-BINFMT ku-kernel.

Qiniseka ukuthi i-BINFMT_MISC inikwe amandla ku-kernel:

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

Manje udinga ukuhlola izilungiselelo:

$ 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

Ungabhalisa ngesandla usebenzisa, isibonelo, nansi imiyalelo.

Isetha ingalo emile ye-qemu

Manje sidinga isibonelo seqemu esihlanganiswe ngokwezibalo.

!!! QAPHELA!!!
Uma uhlela ukusebenzisa isitsha ukwakha okuthile, bheka:
https://sourceware.org/bugzilla/show_bug.cgi?id=23960
https://bugs.launchpad.net/qemu/+bug/1805913
Bese kuthi ku-x86_64 umsingathi nesivakashi sengalo udinga ukusebenzisa inguqulo ye-i386 ye-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

Umbhalo olula:

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

Sincoma umphumela:

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

Ukuzijabulisa nje, ake silinganise usayizi ngaphambi nangemva kokufaka ubuncane (mina) isethi yamaphakheji:

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

Masibuyekeze:

# apt update
# apt upgrade --yes

Masifake amaphakheji esiwathandayo:

# 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

Amafayela ekhanda le-Kernel namamojula ayindaba ehlukile. Vele, ngeke sifake i-bootloader, i-kernel, amamojula, isihlahla sedivayisi nge-Ubuntu. Bazoza kithi bevela ngaphandle noma sizozihlanganisa thina noma sizonikezwa umkhiqizi webhodi, noma ngabe yikuphi lokhu kungaphezu komthamo walo myalelo.

Ngokwezinga elithile, ukuhlukana kwenguqulo kuyamukeleka, kodwa kungcono ukuwathatha ekwakhiweni kwe-kernel.

# apt install --yes linux-headers-generic

Ake sibone ukuthi kwenzekeni futhi kwavela okuningi:

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

Ungakhohlwa ukusetha iphasiwedi.

Ukupakisha isithombe

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

Ukwengeza, singafaka njllkeeper ngokulungiselelwa kwe-autopush

Hhayi-ke, ake sithi sisabalalise umhlangano wethu, umsebenzi waqala wokuthi singahlanganisa kanjani kangcono izinhlobo zakamuva zohlelo lwethu.

etckeeper angasisiza.

Ukuphepha kuyindaba yomuntu siqu:

  • ungavikela amagatsha athile
  • khiqiza ukhiye oyingqayizivele wedivayisi ngayinye
  • khubaza i-force push
  • njll. ...
# ssh-keygen
# apt install etckeeper
# etckeeper init
# cd /etc
# git remote add origin ...

Asisethe i-autopush

Yebo, singakwazi ukudala amagatsha kudivayisi kusengaphambili (ake sithi senza iskripthi noma isevisi ezosebenza lapho yethulwa okokuqala).

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

Noma singenza okuthile ngobuhlakani...

Indlela evilaphayo

Ake sibe nohlobo oluthile lwesikhombi esiyingqayizivele, isho inombolo ye-serial ye-processor (noma i-MAC - izinkampani ezibucayi zithenga uhla):

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

Ngemuva kwalokho singayisebenzisela igama legatsha esizophusha kulo:

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

Masidale umbhalo olula:

# 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

Futhi yilokho kuphela - ngemva kwesikhashana singabheka izinguquko futhi sakhe uhlu lwamaphakheji we-firmware eqondiwe.

Izinto ezinconyiwe

BINFMT_MISC
Usekelo lwe-Kernel lwamafomethi kanambambili ahlukahlukene (binfmt_misc)
Ukuhlanganisa ne-qemu user chroot
Ukwakha i-Ubuntu rootfs ye-ARM
Ungawakha kanjani Ubuntu ngokwezifiso kusuka ekuqaleni
I-Crossdev qemu-static-user-chroot
njll umgcini

getdents64 inkinga

readdir() ibuyisela NULL (errno=EOVERFLOW) ye-qemu engu-32-bit yomsebenzisi-static kumsingathi we-64-bit
I-Ext4 64 bit hash iphula i-32 bit glibc 2.28+
compiler_id_detection yehluleka ku-armhf uma usebenzisa ukulingisa kwemodi yomsebenzisi ye-QEMU
I-CMake ayisebenzi kahle ngaphansi kwe-qemu-arm

Source: www.habr.com