5
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[メモ] ARM向けdebパッケージをx86_64マシンでビルド

Last updated at Posted at 2016-08-17

概要

環境

  • Linux : debian-8.5.0-amd64-i386-netinst.iso から、64bit版をインストール
  • Ubuntuだと、Ubuntu向けパッケージができる。

手順

  1. sudo vi /root/.pbuilderrc
    .pbuilderrc ファイル作成

    /root/.pbuilderrc
    #!/bin/sh
    
    set -e
    
    if [ "$OS" == "debian" ]; then
    	MIRRORSITE="http://ftp.no.debian.org/debian/"
    	COMPONENTS="main contrib non-free"
    	DEBOOTSTRAPOPTS=("${DEBOOTSTRAPOPTS[@]}"
    		"--keyring=/usr/share/keyrings/debian-archive-keyring.gpg")
    	: ${DIST:="wheezy"}
    	: ${ARCH:="amd64"}
    	if [ "$DIST" == "wheezy" ]; then
    		#EXTRAPACKAGES="$EXTRAPACKAGES debian-backports-keyring"
    		OTHERMIRROR="$OTHERMIRROR | deb $MIRRORSITE wheezy-backports $COMPONENTS"
    	fi
    elif [ "$OS" == "raspbian" ]; then
    	MIRRORSITE="http://ftp.acc.umu.se/mirror/raspbian/raspbian/"
    	COMPONENTS="main contrib non-free"
    	DEBOOTSTRAPOPTS=("${DEBOOTSTRAPOPTS[@]}"
    		"--keyring=/usr/share/keyrings/raspbian-archive-keyring.gpg")
    	: ${DIST:="wheezy"}
    	: ${ARCH:="armhf"}
    elif [ "$OS" == "ubuntu" ]; then
    	MIRRORSITE="http://no.archive.ubuntu.com/ubuntu/"
    	COMPONENTS="main restricted universe multiverse"
    	DEBOOTSTRAPOPTS=("${DEBOOTSTRAPOPTS[@]}"
    		"--keyring=/usr/share/keyrings/ubuntu-archive-keyring.gpg")
    else
    	echo "Unknown OS: $OS"
    	exit 1
    fi
    
    if [ "$DIST" == "" ]; then
    	echo "DIST is not set"
    	exit 1
    fi
    
    if [ "$ARCH" == "" ]; then
    	echo "ARCH is not set"
    	exit 1
    fi
    
    NAME="$OS-$DIST-$ARCH"
    
    if [ "$ARCH" == "armel" ] && [ "$(dpkg --print-architecture)" != "armel" ]; then
    	DEBOOTSTRAP="qemu-debootstrap"
    fi
    if [ "$ARCH" == "armhf" ] && [ "$(dpkg --print-architecture)" != "armhf" ]; then
    	DEBOOTSTRAP="qemu-debootstrap"
    fi
    
    DEBOOTSTRAPOPTS=("${DEBOOTSTRAPOPTS[@]}" "--arch=$ARCH")
    BASETGZ="/var/cache/pbuilder/$NAME-base.tgz"
    DISTRIBUTION="$DIST"
    BUILDRESULT="/var/cache/pbuilder/$NAME/result/"
    APTCACHE="/var/cache/pbuilder/$NAME/aptcache/"
    BUILDPLACE="/var/cache/pbuilder/build"
    HOOKDIR="/var/cache/pbuilder/hook.d/"
    

    `.pbuilderrc`ファイルは3つの環境変数の面倒を見てくれるよ。
    - `OS`: debian, raspbian, ubuntuのどれか
    - `DIST`: 例: wheezy, jessie, trusty
    - `ARCH`: 例: amd64, i386, armel, armhf


2. pbuilder環境の準備

    ```bash:環境の準備
#  install pbuilder and qemu-debootstrap:
sudo apt install pbuilder qemu-user-static
#
# Ubuntu and Debian keyrings
sudo apt install ubuntu-keyring 
sudo apt install debian-archive-keyring
#
# Raspbian keyring
wget http://archive.raspbian.org/raspbian/pool/main/r/raspbian-archive-keyring/raspbian-archive-keyring_20120528.2_all.deb
sudo dpkg -i raspbian-archive-keyring_20120528.2_all.deb
#
# chroot .. Raspbian-Jessie だけでいいよね..
time sudo OS=raspbian DIST=jessie ARCH=armhf pbuilder --create
# real    12m17.598s
# user    2m1.832s
# sys     0m9.284s
#
# その他の例
# sudo OS=debian DIST=wheezy ARCH=amd64 pbuilder --create
# sudo OS=debian DIST=wheezy ARCH=i386 pbuilder --create
# sudo OS=debian DIST=wheezy ARCH=armel pbuilder --create
# sudo OS=raspbian DIST=wheezy ARCH=armhf pbuilder --create
# sudo OS=debian DIST=wheezy ARCH=armhf pbuilder --create
#
# ここにつくられました?.
ls -l /var/cache/pbuilder/raspbian-jessie-armhf-base.tgz
# -rw-r--r-- 1 root root 124023585 Aug 16 12:34 /var/cache/pbuilder/raspbian-jessie-armhf-base.tgz
  1. raspbian-jessie-armhfのdebパッケージビルド

    1. ソース取得:
      apt-get source パッケージ名
    2. ソースが展開されたフォルダの中に入って
      cd パッケージ名-ほにゃらら
    3. ビルド:
      OS=raspbian DIST=jessie ARCH=armhf pdebuild
    4. 成果物:
      ls -l /var/cache/pbuilder/raspbian-jessie-armhf/result/*.deb
    実行例

cd ~
mkdir deb
cd deb
apt-get source i2c-tools
cd i2c-tools-3.1.1/
OS=raspbian DIST=jessie ARCH=armhf pdebuild


## その他
- 依存してるライブラリとかあると、そのへんうまくやってくれてるっぽい?
- うまくやってくれないのも、ある。
- ビルドのたびに、`raspbian-jessie-armhf-base.tgz`が`/var/cache/pbuilder/build/<数字>`へ展開されるので、毎回、きれいな環境で、ビルドされる
- `qemu-arm-static` が がんばってる
5
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?