Raspberry Pi 4にGentoo Linuxを導入する
概要
手順
qemuを導入
すでに構築してあるGentoo環境にqemuを導入していく
1. 設定ファイルを書き換えて環境変数を設定する
1. echo app-emulation/qemu static-user >> /etc/portage/package.use/qemu
2. echo 'QEMU_SOFTMMU_TARGETS="alpha aarch64 arm i386 mips mips64 mips64el mipsel ppc ppc64 s390x sh4 sh4eb sparc sparc64 x86_64"' >> /etc/portage/make.conf
3. echo 'QEMU_USER_TARGETS="alpha aarch64 arm armeb i386 mips mipsel ppc ppc64 ppc64abi32 s390x sh4 sh4eb sparc sparc32plus sparc64"' >> /etc/portage/make.conf
2. パッケージをインストール
emerge --ask app-emulation/qemu
3. バイナリパッケージを作成
quickpkg app-emulation/qemu
4. ハンドラーを登録
echo ':aarch64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00:\xff\xff\xff\xff\xff\xff\xff\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-aarch64:' > /proc/sys/fs/binfmt_misc/register
5. /etc/binfmt.d/qemu-aarch64-static.confに以下のコードを追加
code:/etc/binfmt.d/qemu-aarch64-static.conf
:aarch64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00:\xff\xff\xff\xff\xff\xff\xff\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-aarch64:
6. systemctl restart systemd-binfmt
7. chrootを設定する
2. wgetでDL, 展開
3. qemuをchrootにインストール
ROOT=$PWD/ emerge --usepkgonly --oneshot --nodeps qemu
mkdir -p usr/portage
4. ディレクトリをマウントecho
mount --bind /var/db/repos/gentoo var/db/repos/gentoo
mount --bind /proc proc
mount --bind /sys sys
mount --bind /dev dev
mount --bind /dev/pts dev/pts
5. chrootする
chroot . /bin/bash --login
6. QEMUがchroot内で変更されないようにする
echo 'EMERGE_DEFAULT_OPTS="$EMERGE_DEFAULT_OPTS --exclude app-emulation/qemu"' >>/etc/portage/make.conf
echo app-emulation/qemu >>/var/lib/portage/world
7. qemu-wrapper.cを作成
code:qemu-wrapper.c
/*
* pass arguments to qemu binary
*/
int main(int argc, char **argv, char **envp) {
newargv2 = "cortex-a8"; /* here you can set the cpu you are building for */ memcpy(&newargv3, &argv1, sizeof(*argv) * (argc -1)); return execve("/usr/bin/qemu-arm", newargv, envp);
}
8. コンパイル
gcc -static qemu-wrapper.c -O3 -s -o qemu-wrapper
9. chrootの/etc/portage/make.confにFEATURES = "-pid-sandbox -network-sandbox"を挿入
カーネルの導入
2. make bcm2711_defconfig
3. emerge --ask sys-devel/bc
4. make menuconfig
5. make
6. make modules_install
7. make Image
8. sudo cp arch/arm64/boot/Image mnt/fat32/
9. sudo cp arch/arm64/boot/dts/broadcom/*.dtb mnt/fat32/
10. sudo cp arch/arm64/boot/dts/overlays/*.dtb* mnt/fat32/overlays/
11. mnt/fat32/config.txtに
code:mnt/fat32/config.txt
kernel=Image
arm_control=0x200
を追加
12. elfファイルが足りなくて起動できなかったので出来合いのものを追加
13. 何故か立ち上がらない...
14. bootcode.binを追加
15. 起動成功!
と思ったけど、結局うまくいかなくてboot領域は全部raspberrypi osからコピーした
If name resolve is failed...
mkdir -p ./run/systemd/resolve
cp /run/systemd/resolve/stub-resolve.conf ./run/systemd/resolve/stub-resolve.conf
参考文献