Ịmepụta ihe oyiyi Ubuntu maka ARM "site na ọkọ"

Mgbe mmepe malitere, ọ naghị adịkarị mfe nke ngwugwu ga-aga na mgbọrọgwụ mgbọrọgwụ.

N'ikwu ya n'ụzọ ọzọ, ọ dị oke n'oge ijide LFS, buildroot ma ọ bụ yocto (ma ọ bụ ihe ọzọ), mana ịkwesịrị ịmalite. Maka ndị ọgaranya (Enwere m 4GB eMMC na nlele pilot) enwere ụzọ iji kesaa ndị mmepe nkesa nke ga-enye ha ohere ịnye ngwa ngwa ihe na-efu ugbu a, mgbe ahụ anyị nwere ike ịnakọta ndepụta nchịkọta mgbe niile wee mepụta ndepụta maka. mgbọrọgwụ mgbọrọgwụ.

Edemede a abụghị nke ọhụrụ ma bụrụ ntụziaka nnomi-paste dị mfe.

Ebumnuche nke isiokwu a bụ iwulite mgbọrọgwụ Ubuntu maka bọọdụ ARM (n'ọnọdụ m, dabere na Colibri imx7d).

Iwulite onyonyo

Anyị na-achịkọta mgbọrọgwụ ebumnuche maka mmụgharị.

Na-ewepu Ubuntu Base

Anyị na-ahọrọ ntọhapụ n'onwe anyị dabere na mkpa na mmasị anyị. Ebe a ka m nyere 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

Na-enyocha nkwado BINFMT na kernel

Ọ bụrụ na ị nwere nkesa a na-ahụkarị, mgbe ahụ enwere nkwado maka BINFMT_MISC na ahaziri ihe niile, ọ bụrụ na ọ bụghị, mgbe ahụ enwere m n'aka na ị maara otu esi eme nkwado BINFMT na kernel.

Gbaa mbọ hụ na agbanyere BINFMT_MISC na kernel:

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

Ugbu a ịkwesịrị ịlele ntọala:

$ 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

Ị nwere ike iji aka debanye aha, dịka ọmụmaatụ, ebe a bụ ntuziaka ndị a.

Ịtọlite ​​ogwe aka kwụ ọtọ

Ugbu a, anyị chọrọ ihe atụ qemu gbakọtara nke ọma.

!!! Ntị!!!
Ọ bụrụ na ị na-eme atụmatụ iji akpa wuo ihe, lelee:
https://sourceware.org/bugzilla/show_bug.cgi?id=23960
https://bugs.launchpad.net/qemu/+bug/1805913
Mgbe ahụ maka x86_64 onye ọbịa na ogwe aka ị ga-eji ụdị i386 nke 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

Ochie

Ederede dị mfe:

ch-ugwu.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

Anyị nwere mmasị na nsonaazụ ya:

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

Naanị maka ntụrụndụ, ka anyị tụọ nha tupu na mgbe ị wụnye ngwugwu kacha nta (maka m):

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

Ka anyị kwalite:

# apt update
# apt upgrade --yes

Ka anyị tinye ngwugwu anyị nwere mmasị na ya:

# 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

Faịlụ nkụnye eji isi mee kernel na modul bụ ihe dị iche. N'ezie, anyị agaghị etinye bootloader, kernel, modul, osisi ngwaọrụ site na Ubuntu. Ha ga-esi n'èzí bịakwute anyị ma ọ bụ anyị ga-akpọkọta ha n'onwe anyị ma ọ bụ na-enye anyị ndị na-emepụta osisi, n'ọnọdụ ọ bụla nke a karịrị ntụziaka a.

Ruo n'ókè ụfọdụ, a na-anabata ọdịiche dị iche iche nke ụdị, mana ọ ka mma iwere ha site na nrụpụta kernel.

# apt install --yes linux-headers-generic

Ka anyị hụ ihe mere wee pụta nke ukwuu:

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

Echefula ịtọ paswọọdụ.

Na-ebukọ ihe onyonyo a

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

Ọzọkwa, anyị nwere ike ịwụnye etckeeper na autopush ntọala

Ọfọn, ka anyị kwuo na anyị kesara mgbakọ anyị, ọrụ ahụ malitere na otú kacha mma isi chịkọta nsụgharị dị iche iche nke usoro anyị.

etckeeper nwere ike ịbịa nyere anyị aka.

Nchekwa bụ ihe gbasara onwe gị:

  • ị nwere ike ichebe ụfọdụ alaka
  • wepụta igodo pụrụ iche maka ngwaọrụ ọ bụla
  • gbanyụọ ike ịkwanye
  • wdg. ...
# ssh-keygen
# apt install etckeeper
# etckeeper init
# cd /etc
# git remote add origin ...

Ka anyị guzobe autopush

Anyị nwere ike, n'ezie, ịmepụta alaka na ngwaọrụ n'ihu (ka anyị kwuo na anyị na-eme edemede ma ọ bụ ọrụ nke ga-arụ ọrụ na mbụ).

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

Ma ọ bụ anyị nwere ike ime ihe ka mma ...

Ụzọ umengwụ

Ka anyị nwee ụdị njirimara pụrụ iche, kwuo nọmba serial nke processor (ma ọ bụ MAC - ụlọ ọrụ siri ike zụta oke):

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

Mgbe ahụ, anyị nwere ike iji ya maka aha ngalaba nke anyị ga-akwaga:

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

Ka anyị mepụta edemede dị mfe:

# 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

Ma nke ahụ bụ ihe niile - mgbe obere oge gasịrị, anyị nwere ike ilele mgbanwe ndị ahụ ma mepụta ndepụta nchịkọta maka ngwa ngwa ngwa.

Ihe akwadoro

BINFMT_MISC
Nkwado kernel maka ụdị ọnụọgụ abụọ dị iche iche (binfmt_misc)
Iji qemu onye ọrụ chroot na-achịkọta
Iwulite mgbọrọgwụ Ubuntu maka ARM
Otu esi emepụta Ubuntu omenala site na ọkọ
Crossdev qemu-static-onye ọrụ-chroot
wdg onye nche

getdents64 nsogbu

readdir() weghachi NULL (errno=EOVERFLOW) maka 32-bit user-static qemu na onye nnabata 64-bit
Ext4 64 bit hash na-agbaji 32 bit glibc 2.28+
compiler_id_detection ada ada maka armhf mgbe ị na-eji ụdị onye ọrụ QEMU
CMake anaghị arụ ọrụ nke ọma n'okpuru qemu-arm

isi: www.habr.com