computerの日記

Cisco,SHELL,C,Qt,C++,Linux,ネットワーク,Windows Scriptなどの発言です

Raspberry Pi 2 用のOS(ディストリビューション)を作成します

Raspberry Pi 2 を持っているんですが、最近全然遊んでいないです。
久しぶりに遊んでみます。
今回、Buildroot を使ってみます。

$ curl -O http://buildroot.org/downloads/buildroot-2018.05.tar.gz
$ tar zxvf buildroot-2018.05.tar.gz
$ cd buildroot-2018.05/
$ make menuconfig

以下、うまくいったやり方となります。

以下のページのとおりやってみました。
(参考)
http://ltekieli.com/buildroot-with-raspberry-pi-what-where-and-how/
------------------------------------------------

$ curl -O http://buildroot.org/downloads/buildroot-2018.05.tar.gz
$ tar zxvf buildroot-2018.05.tar.gz
$ cd buildroot-2018.05/
$ make raspberrypi2_defconfig(*注1)
(表示)
...(snip)...
# configuration written to /home/fujiwara/BUILDROOT/buildroot-2018.05/.config

ここで、make menuconfig として、設定をグラフィカリに確認してもよいでしょう。

では、ビルドを開始します。

$ make all

約 30分弱でビルド完了しました。
以下のディレクトリを確認します。

$ ls -lah output/images
合計 158M
drwxr-xr-x. 3 4.0K 7月 8 04:20 .
drwxrwxr-x. 6 4.0K 7月 8 03:35 ..
-rw-r--r--. 1 23K 7月 8 04:20 bcm2709-rpi-2-b.dtb
-rw-r--r--. 1 32M 7月 8 04:20 boot.vfat
-rw-r--r--. 1 60M 7月 8 04:20 rootfs.ext2
lrwxrwxrwx. 1 11 7月 8 04:20 rootfs.ext4 -> rootfs.ext2
drwxr-xr-x. 2 4.0K 7月 8 04:07 rpi-firmware
-rw-r--r--. 1 93M 7月 8 04:20 sdcard.img
-rw-r--r--. 1 4.7M 7月 8 04:20 zImage
-------------------------
ビルドが一度できたので、安心しました。

(*注1)
下記のようにすると、make のリストが表示されます。
$ make list-defconfigs

SDカードにイメージを書き出します。

# dd if=sdcard.img of=/dev/mmcblk0 status=progress

実施結果です。

# dd if=./output/images/sdcard.img of=/dev/mmcblk0 status=progress
188417+0 レコード入力
188417+0 レコード出力
96469504 bytes (96 MB, 92 MiB) copied, 16.845 s, 5.7 MB/s

うまくいきました。こちらに、展開しました。root : pinkrabbit

pinkrabbit-rpi-2018.05-sdcard.img

 Fedora のイメージを試してみました。

# arm-image-installer --image=Fedora-Workstation-armhfp-28-1.1-sda.raw.xz --target=rpi2 --media=/dev/mmcblk0

次の表示となりました。

=====================================================
= Selected Image:
= ./Fedora-Workstation-armhfp-28-1.1-sda.raw.xz
= Selected Media : /dev/mmcblk0
= U-Boot Target : rpi2
=====================================================

*****************************************************
*****************************************************
******** WARNING! ALL DATA WILL BE DESTROYED ********
*****************************************************
*****************************************************

Type 'YES' to proceed, anything else to exit now

= Proceed?

YES と入力して、Fedora が立ち上がったのを確認できました。

 

以下は、うまくいかなかった一例となります。

Linux kernel の menuconfig かのような画面が立ち上がりました。
以下の設定に変更します。

----------------------
Top level configuration

Target Architecture ARM (little endian)
Target Architecture Variant arm1176jzf-s
Target ABI EABI
----------------------
Build options

Download dir $(HOME)/buildroot/dl デフォルトで、($(TOPDIR)/dl) Download dir となっているので、これでよいかも。
Enable compiler cache YES
Compiler cache location $(HOME)/buildroot/ccache デフォルトで、($(HOME)/.buildroot-ccache) Compiler cache location となっているので、これでよいかも。
----------------------
Toolchain

Kernel Headers Linux 3.6.x kernel headers デフォルトで、Linux 4.16.x kernel headers となっているので、これでよいかも。

GCC compiler Version GCC 4.7.x デフォルトで、GCC compiler Version (gcc 6.x) となっているので、これでよいかも。

Additional gcc options --with-float=hard --with-fpu=vfp

Purge unwanted locales YES
Locales to keep C en_US
Generate locale data en_US
-----------------------
System configuration

System hostname rpi
System banner Welcome to Raspberry Pi!
/dev management Dynamic using mdev デフォルトで、/dev management (Dynamic using devtmpfs only) となっているので、これでよいかも。 │ │

Port to run a getty (login prompt) on tty1
Baudrate to use 38400
-----------------------
ackage selection for target

This is the section where you specify which packages get in and which will be left out.

Busybox - which is enabled by default - gives us a fairly complete userland, so the only extra you should enable here is dropbear, a small SSH server under Networking applications which will let us log in remotely.

Also, if you want to mount NFS filesystems, you should enable Networking applications / Portmap.

You may select other packages too, as you see fit.
------------------------
Filesystem images

Compression method gzip

Here we ask Buildroot to generate a rootfs.tar.gz (besides rootfs.tar). デフォルトで、 [*] tar the root filesystem (NEW) となっているので、これでよいかも。 │ │
------------------------
Kernel
Linux Kernel YES
Kernel version Custom Git tree
URL of custom Git repository https://github.com/raspberrypi/linux
Custom Git version rpi-3.6.y ここは、上記リンクを見ると、4.14.y が正しいかな。
Kernel configuration Using a defconfig
Defconfig name bcmrpi
Kernel binary format zImage

With these settings, Buildroot will clone the foundation's rpi-3.6.y branch, configure it using arch/arm/configs/bcmrpi_defconfig (included in the source) and build a zImage which we can then shove into /boot. (Note that post-processing with the imagetool-uncompressed.py script is not needed anymore as the latest firmware can load zImage kernels without a hitch.)

Now exit the configuration program - save the new configuration as you leave! - and initiate a full build of the system by executing:
------------------------
$ make all

You seem to have the current working directory in your
LD_LIBRARY_PATH environment variable. This doesn't work.
make[1]: *** [support/dependencies/dependencies.mk:21: dependencies] エラー 1
make: *** [Makefile:79: _all] エラー 2
[fujiwara@gns3vm buildroot-2018.05]$ make menuconfig


*** End of the configuration.
*** Execute 'make' to start the build or try 'make help'.

$ ls
CHANGES Config.in DEVELOPERS Makefile.legacy arch boot configs docs linux package system utils
COPYING Config.in.legacy Makefile README board build dl fs output support toolchain
[buildroot-2018.05]$ echo $LD_LIBRARY_PATH
/opt/lib:/opt/lib:

http://lists.busybox.net/pipermail/buildroot/2015-April/124424.html

: が付いているのが悪かったようだ。
変更する。

$ LD_LIBRARY_PATH=/opt/lib:/opt/lib; export LD_LIBRARY_PATH

もう一度、

$ make

 

でも、このままだと、なにも面白いソフトが入っていないです。

もう一度、不備なところを再修正します。
$ make menuconfig

以下の設定を実施します。
System configuration

System hostname Pink Rabbit Linux
System banner Welcome to Raspberry Pi!
------------------------
$ make all

$ ls -lah output/images/
合計 158M
drwxr-xr-x. 3 4.0K 7月 8 04:42 .
drwxrwxr-x. 6 4.0K 7月 8 03:35 ..
-rw-r--r--. 1 23K 7月 8 04:20 bcm2709-rpi-2-b.dtb
-rw-r--r--. 1 32M 7月 8 04:42 boot.vfat
-rw-r--r--. 1 60M 7月 8 04:42 rootfs.ext2
lrwxrwxrwx. 1 11 7月 8 04:42 rootfs.ext4 -> rootfs.ext2
drwxr-xr-x. 2 4.0K 7月 8 04:07 rpi-firmware
-rw-r--r--. 1 93M 7月 8 04:42 sdcard.img
-rw-r--r--. 1 4.7M 7月 8 04:20 zImage
---------------------------
ビルドできました。
まだまだ、面白くないです。
ありったけのソフトをインストールしてみたいですね。
こんな感じに。


Networking appliations --->
では、apache、bind、dhcpcd、ethtool、iptables、ntp、ntpdate、tcpdump と openssh を入れてみます。
チェックを入れます。
Shell and utilities --->
screen にチェックをいれます。
System tools --->
util-linux --->
audit、hwclock、kill、logger にチェックを入れます。
Security --->
semodule-utils
*** checkpolicy needs a glibc toolchain w/ threads, dynamic library ***
って出てます。
Libraries --->
Database --->
mysqlpostgresqlsqlite
Javascript --->
bootstrap、jQuery
Target packages --->
Development tools --->
git、make、pkgconf
Toolchain --->
C library (glibc) --->
これをしたことで、Target Package の Security で、SELinux 関連がインストールできるようになりました。
checkpolicy, policycoreutils, refpolicy, restorecond, selinux-python(audit2allow, sepolgen もチェック),
semodule-utils, setools
にチェックを入れます。
Libraries --->
Interpreter languages and scripting --->
Text and terminal handling --->
ncurses にチェックを入れます。
Enable ECHAR support
Enable toolchain locale/i18n support

Enable root login with password
(root) Root password -- root
https://buildroot.org/downloads/manual/manual.html
Install timezone info
default local time -- Asia/Tokyo
---------------------------
$ make all

glibc に変更したので、結構時間がかかるかも。
エラーになりました。
では、glibc はダメみたいですね。uClibc にしました。
$ make clean
$ make all

ビルドが始まりました。

 

(その他参考にしたサイト)
https://qiita.com/pu_ri/items/75c80e388c79fe0d3f0b