§2023-09-06
- Using surfacePro to create a disk image holding cross-compiler
$ dd if=/dev/zero of=gentoo-32G-x86_64-systemd-2023-09-06.img bs=1M count=32768
$ sudo losetup -f
[sudo] alexlai のパスワード:
/dev/loop13
$ sudo losetup /dev/loop13 gentoo-32G-x86_64-systemd-2023-09-06.img
$ sudo fdisk /dev/loop13, as
デバイス 起動 開始位置 最後から セクタ サイズ Id タイプ
/dev/loop13p1 2048 1050623 1048576 512M c W95 FAT32 (LBA)
/dev/loop13p2 1050624 67108863 66058240 31.5G 83 Linux
$ sudo partprobe /dev/loop13 <--- !!!!
$ lsblk /dev/loop13
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop13 7:13 0 32G 0 loop
├─loop13p1 259:6 0 512M 0 part
└─loop13p2 259:7 0 31.5G 0 part
$ sudo mkfs.vfat -F 32 /dev/loop13p1
mkfs.fat 4.2 (2021-01-31)
$ sudo mkfs.ext4 /dev/loop13p2
$ wget https://distfiles.gentoo.org/releases/amd64/autobuilds/20230903T170202Z/stage3-amd64-systemd-20230903T170202Z.tar.xz
$ sudo mount /dev/loop13p2 root
$ sudo tar xvpf stage3-amd64-systemd-20230903T170202Z.tar.xz -C root
$ sudo arch-chroot root /bin/bash
SurfacePro / # source /etc/profile
SurfacePro / # export PS1="(chroot) $PS1"
(chroot) SurfacePro / #
(chroot) SurfacePro / # nano /etc/resolv.conf
# as
nameserver 8.8.8.8
nameserver 8.8.4.4
##
(chroot) SurfacePro / # ping google.com
PING google.com (142.251.43.14) 56(84) bytes of data.
64 bytes from tsa03s08-in-f14.1e100.net (142.251.43.14): icmp_seq=1 ttl=115 time=4.53 ms
64 bytes from tsa03s08-in-f14.1e100.net (142.251.43.14): icmp_seq=2 ttl=115 time=4.74 ms
64 bytes from tsa03s08-in-f14.1e100.net (142.251.43.14): icmp_seq=3 ttl=115 time=4.53 ms
^C
(chroot) SurfacePro / # nano /etc/locale.gen
# uncomment
en_US.UTF-8 UTF-8
#
(chroot) SurfacePro / # locale-gen
* Generating 2 locales (this might take a while) with 4 jobs
* (2/2) Generating C.UTF-8 ... [ ok ]
* (1/2) Generating en_US.UTF-8 ... [ ok ]
* Generation complete
* Adding locales to archive ...
- /etc/profile as
# /etc/profile: login shell setup
#
# That this file is used by any Bourne-shell derivative to setup the
# environment for login shells.
#
# Load environment settings from profile.env, which is created by
# env-update from the files in /etc/env.d
if [ -e /etc/profile.env ] ; then
. /etc/profile.env
fi
# You should override these in your ~/.bashrc (or equivalent) for per-user
# settings. For system defaults, you can add a new file in /etc/profile.d/.
export EDITOR=${EDITOR:-/bin/nano}
export PAGER=${PAGER:-/usr/bin/less}
unset ROOTPATH
# process *.sh files in /etc/profile.d
for sh in /etc/profile.d/*.sh ; do
[ -r "$sh" ] && . "$sh"
done
unset sh
if [ -n "${BASH_VERSION-}" ] ; then
# Newer bash ebuilds include /etc/bash/bashrc which will setup PS1
# including color. We leave out color here because not all
# terminals support it.
if [ -f /etc/bash/bashrc ] ; then
# Bash login shells run only /etc/profile
# Bash non-login shells run only /etc/bash/bashrc
# Since we want to run /etc/bash/bashrc regardless, we source it
# from here. It is unfortunate that there is no way to do
# this *after* the user's .bash_profile runs (without putting
# it in the user's dot-files), but it shouldn't make any
# difference.
. /etc/bash/bashrc
else
PS1='\u@\h \w \$ '
fi
else
# Setup a bland default prompt. Since this prompt should be useable
# on color and non-color terminals, as well as shells that don't
# understand sequences such as \h, don't put anything special in it.
PS1="${USER:-$(whoami 2>/dev/null)}@$(uname -n 2>/dev/null) \$ "
fi
# export LANG, LC_ALL
export LANG=en_US.UTF-8
# LANG is the primary environmental variable that sets the default locale for your system.
export LC_ALL=C.UTF-8
# LC_ALL is another environmental variable that can override the settings of LANG and other LC_* variables for all locale categories.
#
# PS1
export PS1="(chroot) $PS1" # or PS1="(rpi3Chr) $PS1" to idicating building for rpi3
(chroot) SurfacePro / # source /etc/profile
(chroot) SurfacePro / # ln -sf /usr/share/zoneinfo/Asia/Taipei /etc/localtime
(chroot) SurfacePro / # date
Wed Sep 6 14:05:03 CST 2023
¶2. /etc/portage/repos.conf/gentoo.conf
-
(chroot) hc4Gentoo / # mkdir /etc/portage/repos.conf
-
nano /etc/portage/repos.conf/gentoo.conf
[gentoo]
location = /var/db/repos/gentoo
sync-type = rsync
sync-uri = rsync://rsync.namerica.gentoo.org/gentoo-portage
auto-sync = yes
priority = 10
¶3. /etc/portage/make.conf,( targeted rpi3, 64bits)
- sample make.conf is from,
# These settings were set by the catalyst build script that automatically
# built this stage.
# Please consult /usr/share/portage/config/make.conf.example for a more
# detailed example.
COMMON_FLAGS="-O2 -pipe"
CFLAGS="${COMMON_FLAGS}"
CXXFLAGS="${COMMON_FLAGS}"
FCFLAGS="${COMMON_FLAGS}"
FFLAGS="${COMMON_FLAGS}"
# WARNING: Changing your CHOST is not something that should be done lightly.
# Please consult https://wiki.gentoo.org/wiki/Changing_the_CHOST_variable before changing.
# CHOST="aarch64-unknown-linux-gnu"
# to be able to `crossdev -t aarch64-unknown-linux-gnu --ov-output /opt/toolchains/`
# error messages:
# * Refusing to create a cross-compiler using the same
# * target name as your host utils.
# you have to comment `CHOST="aarch64-unknown-linux-gnu"`
# NOTE: This stage was built with the bindist Use flag enabled
# This sets the language of build output to English.
# Please keep this setting intact when reporting bugs.
LC_MESSAGES=C.utf8
# Pi3 users (or Pi4 users with a 1GiB variant) should be
# less aggressive here
MAKEOPTS="-j4"
¶6. emerge-webrsync
¶7. emerge --ask --verbose --update --deep --newuse @world
¶8. emerge --ask sys-devel/crossdev
emerge --ask sys-devel/crossdev
¶9. set up cross-dev
ENV
# ls /var/db/repos/
gentoo
# mkdir -p /var/db/repos/crossdev/{profiles,metadata}
# echo 'crossdev' > /var/db/repos/crossdev/profiles/repo_name
# echo 'masters = gentoo' > /var/db/repos/crossdev/metadata/layout.conf
# chown -R portage:portage /var/db/repos/crossdev
If the Gentoo ebuild repository is synchronized using Git, or any other method with Manifest files that do not include checksums for ebuilds, prevent "masked by: corruption" errors with:
- FILE
nano /var/db/repos/crossdev/metadata/layout.conf
as,
masters = gentoo
thin-manifests = true
- Then instruct Portage and crossdev to use this ebuild repository:
- FILE /etc/portage/repos.conf/crossdev.conf
# ls /etc/portage/repos.conf/crossdev.conf
ls: cannot access '/etc/portage/repos.conf/crossdev.conf': No such file or directory
# nano /etc/portage/repos.conf/crossdev.conf # as follows
[crossdev]
location = /var/db/repos/crossdev
priority = 10
masters = gentoo
auto-sync = no
¶ 10 crossdev -t aarch64-unknown-linux-gnu
¶ 11, Test
(chroot) SurfacePro / # gcc-config -l
[1] aarch64-unknown-linux-gnu-13 *
[2] x86_64-pc-linux-gnu-12 *
(chroot) SurfacePro / # aarch64-unknown-linux-gnu-gcc --version
aarch64-unknown-linux-gnu-gcc (Gentoo 13.2.1_p20230826 p7) 13.2.1 20230826
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.