「DeveloperWiki:クリーンな chroot でビルドする」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(英語版から転載)
 
(翻訳を修正)
 
(同じ利用者による、間の5版が非表示)
2行目: 2行目:
 
[[Category:DeveloperWiki]]
 
[[Category:DeveloperWiki]]
 
[[en:DeveloperWiki:Building in a clean chroot]]
 
[[en:DeveloperWiki:Building in a clean chroot]]
== Why ==
 
   
  +
== 理由 ==
Building in a clean chroot prevents missing dependencies in packages, whether due to unwanted linking or packages missing in the depends array in the PKGBUILD. It also allows users to build a package for the stable repositories ([[core]], [[extra]]) while having packages from [[core-testing]] or [[extra-testing]] installed.
 
   
  +
クリーンな chroot でビルドすると、不要なリンクや PKGBUILD の depend 配列にパッケージが欠落していることが原因で、パッケージ内の依存関係が欠落することがなくなります。また、ユーザーは [[公式リポジトリ#core-testing|core-testing]] または [[公式リポジトリ#extra-testing|extra-testing]] のパッケージをインストールしたまま、安定したリポジトリ ([[core]]、[[extra]]) のパッケージをビルドすることもできます。
== Convenience way ==
 
   
  +
== 便利な方法 ==
To quickly build a package in a clean chroot without any further tinkering, one can use the helper scripts from the {{Pkg|devtools}} package.
 
   
  +
それ以上いじることなく、クリーンな chroot でパッケージをすばやくビルドするには、{{Pkg|devtools}} パッケージのヘルパースクリプトを使用できます。
These helper scripts should be called in the same directory where the PKGBUILD is, just like with makepkg. For instance, {{ic|extra-x86_64-build}} automatically sets up a chroot from a clean chroot matrix in {{ic|/var/lib/archbuild}}, updates it, and builds a package for the extra repository. For multilib builds there is just {{ic|multilib-build}} without an architecture. Consult the table below for information on which script to use when building for a specific repository and architecture.
 
   
  +
これらのヘルパースクリプトは、makepkg と同様に、PKGBUILD と同じディレクトリで呼び出す必要があります。たとえば、{{ic|extra-x86_64-build}} は、{{ic|/var/lib/archbuild}} 内のクリーンな chroot マトリックスから chroot を自動的にセットアップして、更新し、追加のリポジトリ用のパッケージをビルドします。multilib ビルドの場合は、アーキテクチャのない {{ic|multilib-build}} だけが存在します。特定のリポジトリおよびアーキテクチャ向けに構築するときにどのスクリプトを使用するかについては、以下の表を参照してください。
The {{ic|-c}} parameter resets the chroot matrix, which can be useful in case of breakage. It is not needed for building in a clean chroot.
 
  +
  +
{{ic|-c}} パラメータは chroot マトリックスをリセットします。これは破損した場合に役立ちます。クリーンな chroot でのビルドには必要ありません。
   
 
{{Note|
 
{{Note|
  +
* これらのパッケージは ''core'' に入る前にまず ''core-testing'' を通過する必要があるため、''core'' は省略されています。
* ''core'' is omitted because those packages are required to go through ''core-testing'' first before landing in ''core''.
 
  +
* ''core'' パッケージをビルドしてローカルで使用するのが目的であれば、テスト用リポジトリではなく安定版リポジトリを使用するのが望ましいでしょう。この場合、追加のビルドスクリプトを使うだけです。
* If the objective is to build a ''core'' package for your own local usage, it may be desirable to use the stable repositories instead of the testing ones. In this case you may simply use the extra build scripts.
 
 
}}
 
}}
   
 
{| class="wikitable"
 
{| class="wikitable"
  +
! ターゲットリポジトリ || アーキテクチャ || 使用するビルドスクリプト || 使用される Pacman 設定ファイル
! Target repository || Architecture || Build script to use || Pacman configuration file used
 
 
|-
 
|-
 
| extra || x86_64 || extra-x86_64-build || /usr/share/devtools/pacman.conf.d/extra.conf
 
| extra || x86_64 || extra-x86_64-build || /usr/share/devtools/pacman.conf.d/extra.conf
35行目: 36行目:
 
|}
 
|}
   
  +
{{Tip|{{ic|pkgctl build}} は、クリーンな chroot でビルドするための適切なビルドスクリプトを自動的に選択します。}}
{{Tip|{{ic|pkgctl build}} automatically chooses the right build script to build in a clean chroot.}}
 
   
== Classic way ==
+
== 古典的な方法 ==
   
=== Setting up a chroot ===
+
=== chroot のセットアップ ===
   
  +
{{Pkg|devtools}} パッケージは、クリーンな chroot 内で作成および設定するためのツールを提供します。まだインストールしていない場合はインストールしてください。
The {{Pkg|devtools}} package provides tools for creating and building within clean chroots. Install it if not done already.
 
   
  +
クリーンな chroot を作成するには、chroot が存在するディレクトリを作成します。たとえば、{{ic|$HOME/chroot}} などです。
To make a clean chroot, create a directory in which the chroot will reside. For example, {{ic|$HOME/chroot}}.
 
   
 
$ mkdir ~/chroot
 
$ mkdir ~/chroot
   
Define the {{ic|CHROOT}} variable:
+
{{ic|CHROOT}} 変数を定義します:
   
 
$ CHROOT=$HOME/chroot
 
$ CHROOT=$HOME/chroot
   
  +
次に、chroot を作成します ({{ic|$CHROOT}} ディレクトリはクリーンな作業コピー用に他のサブディレクトリを取得するため、サブディレクトリ {{ic|root}} が必要です):
Now create the chroot (the sub directory {{ic|root}} is required because the {{ic|$CHROOT}} directory will get other sub directories for clean working copies):
 
   
 
$ mkarchroot $CHROOT/root base-devel
 
$ mkarchroot $CHROOT/root base-devel
   
 
{{Note|
 
{{Note|
  +
* 繰り返し使う場所であれば、{{ic|$HOME/.bashrc}} で {{ic|CHROOT}} 変数を定義することもできます。
* One can also define the {{ic|CHROOT}} variable in {{ic|$HOME/.bashrc}} using the export command if the location is to be repeatedly used.
 
* On [[btrfs]], the chroot is created as a subvolume, so you have to remove it by removing the subvolume by running {{ic|btrfs subvolume delete $CHROOT/root}} as root.
+
* [[btrfs]] では、chroot はサブボリュームとして作成されるので、root 権限で {{ic|btrfs subvolume delete $CHROOT/root}} を実行してサブボリュームを削除することで chroot を削除する必要があります。
 
}}
 
}}
   
Edit {{ic|~/.makepkg.conf}} to set the packager name and any makeflags. Also adjust the [[Pacman#Repositories and mirrors|mirrorlist]] in {{ic|$CHROOT/root/etc/pacman.d/mirrorlist}} and enable the [[testing]] repositories in {{ic|$CHROOT/root/etc/pacman.conf}}, if desired.
+
{{ic|~/.makepkg.conf}} を編集して、パッケージャー名と make フラグを設定します。また、{{ic|$CHROOT/root/etc/pacman.d/mirrorlist}} [[Pacman#Repositories and Mirrors|mirrorlist]] を調整し、{{ic|$CHROOT/ [[testing]] リポジトリを有効にします必要に応じて、{{ic|root/etc/pacman.conf}} を選択します。
   
{{Note|The {{ic|~}} and {{ic|$HOME}} variable are resolved to {{ic|/root/}} by the ''makechrootpkg'' script (described below).}}
+
{{Note|{{ic|~}} {{ic|$HOME}} 変数は、''makechrootpkg'' スクリプト (後述) によって {{ic|/root/}} に解決されます。}}
   
==== Custom pacman.conf ====
+
==== pacman.conf をカスタム ====
   
Alternatively, provide a custom {{ic|pacman.conf}} and {{ic|makepkg.conf}} with the following:
+
あるいは、次のようにカスタムの {{ic|pacman.conf}} {{ic|makepkg.conf}} を指定します。
   
 
$ mkarchroot -C <pacman.conf> -M <makepkg.conf> $CHROOT/root base-devel
 
$ mkarchroot -C <pacman.conf> -M <makepkg.conf> $CHROOT/root base-devel
   
{{Warning|Using a custom {{ic|pacman.conf}} or {{ic|makepkg.conf}} during the initial creation of clean chroot can result in unintended custom adjustments to the chroot environment. ''Use with caution.''}}
+
{{Warning|クリーンな chroot の最初の作成中にカスタムの {{ic|pacman.conf}} または {{ic|makepkg.conf}} を使用すると、chroot 環境に意図しないカスタム調整が行われる可能性があります。''注意して使用してください''}}
   
=== Building in the chroot ===
+
=== chroot でのビルド ===
   
Firstly, make sure the base chroot ({{ic|$CHROOT/root}}) is up to date:
+
まず、ベースの chroot ({{ic|$CHROOT/root}}) が最新であることを確認します:
   
 
$ arch-nspawn $CHROOT/root pacman -Syu
 
$ arch-nspawn $CHROOT/root pacman -Syu
   
  +
次に、[[PKGBUILD]] を含むディレクトリで {{ic|makechrootpkg}} を呼び出してパッケージをビルドします:
Then, build a package by calling {{ic|makechrootpkg}} in the directory containing its [[PKGBUILD]]:
 
   
 
$ makechrootpkg -c -r $CHROOT
 
$ makechrootpkg -c -r $CHROOT
   
{{Note|Passing the {{ic|-c}} flag to {{ic|makechrootpkg}} ensures that the working chroot ({{ic|$CHROOT/$USER}}) is cleaned before building.}}
+
{{Note|{{ic|-c}} フラグを {{ic|makechrootpkg}} に渡すと、作業中の chroot ({{ic|$CHROOT/$USER}}) がビルド前に確実にクリーンアップされます。}}
   
  +
==== 必要なパッケージを事前にインストールする ====
==== Pre-install required packages ====
 
   
  +
{{ic|$CHROOT/root/pacman.conf}} で有効になっているリポジトリから利用できない依存関係を含むパッケージをビルドするには、{{ic|-I ''package''}} を使用してそれらを作業中の chroot にプレインストールします。:
To build a package with dependencies unavailable from the repositories enabled in {{ic|$CHROOT/root/pacman.conf}}, pre-install them to the working chroot with {{ic|-I ''package''}}:
 
   
 
$ makechrootpkg -c -r $CHROOT -I build-dependency-1.0-1-x86_64.pkg.tar.xz -I required-package-2.0-2-x86_64.pkg.tar.xz
 
$ makechrootpkg -c -r $CHROOT -I build-dependency-1.0-1-x86_64.pkg.tar.xz -I required-package-2.0-2-x86_64.pkg.tar.xz
   
==== Passing arguments to makepkg ====
+
==== makepkg に引数を渡す ====
   
To pass arguments to [[Makepkg#Usage|makepkg]], list them after an [https://wiki.bash-hackers.org/dict/terms/end_of_options end-of-options marker]; e.g., to force a {{ic|check()}}:
+
[[Makepkg#使用方法|makepkg]] に引数を渡すには、[https://wiki.bash-hackers.org/dict/terms/end_of_options オプションの終了マーカー] の後に引数をリストします。たとえば、{{ic|check()}} を強制するには:
   
 
$ makechrootpkg -c -r $CHROOT -- --check
 
$ makechrootpkg -c -r $CHROOT -- --check
   
  +
== 大規模なリビルドの処理 ==
== Handling major rebuilds ==
 
   
  +
大規模なリビルドを処理する最もクリーンな方法は、''staging'' リポジトリを使用することです。最初のパッケージを ''extra'' に対してビルドし、それを ''staging'' にプッシュします。次に、後続のすべてのパッケージを ''staging'' に対してリビルドし、そこにプッシュします。
The cleanest way to handle a major rebuild is to use the ''staging'' repositories. Build the first package against ''extra'' and push it to ''staging''. Then rebuild all following packages against ''staging'' and push them there.
 
   
  +
''staging'' を使用できない場合は、次のようなコマンドを使用してカスタムパッケージに対してビルドできます。
If you cannot use ''staging'', you can build against custom packages using a command like this:
 
   
 
# extra-x86_64-build -- -I ~/packages/foobar/foobar-2-1-any.pkg.tar.xz
 
# extra-x86_64-build -- -I ~/packages/foobar/foobar-2-1-any.pkg.tar.xz
   
  +
{{ic|-I}} 引数を使用して、インストールする複数のパッケージを指定できます。
You can specify more than one package to be installed using multiple {{ic|-I}} arguments.
 
   
  +
大規模なリビルドを処理するより簡単な方法として、ビルドされたすべてのパッケージを chroot にインストールし、決してクリーンアップしない雑な方法もあります。以下を使用して最初のパッケージをビルドします:
A simpler, but dirtier way to handle a major rebuild is to install all built packages in the chroot, never cleaning it. Build the first package using:
 
   
 
# extra-x86_64-build
 
# extra-x86_64-build
   
  +
そして、以下を使用して以下のパッケージをすべてビルドします:
And build all following packages using:
 
   
 
# makechrootpkg -n -r /var/lib/archbuild/extra-x86_64
 
# makechrootpkg -n -r /var/lib/archbuild/extra-x86_64
   
  +
namcap ({{ic|-n}} 引数) を実行すると、chroot にパッケージがインストールされることになります。''*-build'' もデフォルトでこれを行います。
Running namcap (the {{ic|-n}} argument) implies installing the package in the chroot. ''*-build'' also does this by default.
 
   
  +
== ヒントとテクニック ==
== Tips and tricks ==
 
   
=== Build in tmpfs ===
+
=== tmpfs でビルドする ===
   
  +
システムに十分な RAM がある場合は、{{Pkg|devtools}} ビルドスクリプトに [[tmpfs]] を指定できます。
If the system has enough RAM, it is possible to specify a [[tmpfs]] for the {{Pkg|devtools}} build scripts.
 
   
 
# mount --mkdir -t tmpfs -o defaults,size=20G tmpfs /mnt/chroots/arch
 
# mount --mkdir -t tmpfs -o defaults,size=20G tmpfs /mnt/chroots/arch

2023年12月23日 (土) 17:20時点における最新版


理由

クリーンな chroot でビルドすると、不要なリンクや PKGBUILD の depend 配列にパッケージが欠落していることが原因で、パッケージ内の依存関係が欠落することがなくなります。また、ユーザーは core-testing または extra-testing のパッケージをインストールしたまま、安定したリポジトリ (coreextra) のパッケージをビルドすることもできます。

便利な方法

それ以上いじることなく、クリーンな chroot でパッケージをすばやくビルドするには、devtools パッケージのヘルパースクリプトを使用できます。

これらのヘルパースクリプトは、makepkg と同様に、PKGBUILD と同じディレクトリで呼び出す必要があります。たとえば、extra-x86_64-build は、/var/lib/archbuild 内のクリーンな chroot マトリックスから chroot を自動的にセットアップして、更新し、追加のリポジトリ用のパッケージをビルドします。multilib ビルドの場合は、アーキテクチャのない multilib-build だけが存在します。特定のリポジトリおよびアーキテクチャ向けに構築するときにどのスクリプトを使用するかについては、以下の表を参照してください。

-c パラメータは chroot マトリックスをリセットします。これは破損した場合に役立ちます。クリーンな chroot でのビルドには必要ありません。

ノート:
  • これらのパッケージは core に入る前にまず core-testing を通過する必要があるため、core は省略されています。
  • core パッケージをビルドしてローカルで使用するのが目的であれば、テスト用リポジトリではなく安定版リポジトリを使用するのが望ましいでしょう。この場合、追加のビルドスクリプトを使うだけです。
ターゲットリポジトリ アーキテクチャ 使用するビルドスクリプト 使用される Pacman 設定ファイル
extra x86_64 extra-x86_64-build /usr/share/devtools/pacman.conf.d/extra.conf
core-testing / extra-testing x86_64 extra-testing-x86_64-build /usr/share/devtools/pacman.conf.d/extra-testing.conf
core-staging / extra-staging x86_64 extra-staging-x86_64-build /usr/share/devtools/pacman.conf.d/extra-staging.conf
multilib x86_64 multilib-build /usr/share/devtools/pacman.conf.d/multilib.conf
multilib-testing x86_64 multilib-testing-build /usr/share/devtools/pacman.conf.d/multilib-testing.conf
multilib-staging x86_64 multilib-staging-build /usr/share/devtools/pacman.conf.d/multilib-staging.conf
ヒント: pkgctl build は、クリーンな chroot でビルドするための適切なビルドスクリプトを自動的に選択します。

古典的な方法

chroot のセットアップ

devtools パッケージは、クリーンな chroot 内で作成および設定するためのツールを提供します。まだインストールしていない場合はインストールしてください。

クリーンな chroot を作成するには、chroot が存在するディレクトリを作成します。たとえば、$HOME/chroot などです。

$ mkdir ~/chroot

CHROOT 変数を定義します:

$ CHROOT=$HOME/chroot

次に、chroot を作成します ($CHROOT ディレクトリはクリーンな作業コピー用に他のサブディレクトリを取得するため、サブディレクトリ root が必要です):

$ mkarchroot $CHROOT/root base-devel
ノート:
  • 繰り返し使う場所であれば、$HOME/.bashrcCHROOT 変数を定義することもできます。
  • btrfs では、chroot はサブボリュームとして作成されるので、root 権限で btrfs subvolume delete $CHROOT/root を実行してサブボリュームを削除することで chroot を削除する必要があります。

~/.makepkg.conf を編集して、パッケージャー名と make フラグを設定します。また、$CHROOT/root/etc/pacman.d/mirrorlistmirrorlist を調整し、{{ic|$CHROOT/ の testing リポジトリを有効にします必要に応じて、root/etc/pacman.conf を選択します。

ノート: ~$HOME 変数は、makechrootpkg スクリプト (後述) によって /root/ に解決されます。

pacman.conf をカスタム

あるいは、次のようにカスタムの pacman.confmakepkg.conf を指定します。

$ mkarchroot -C <pacman.conf> -M <makepkg.conf> $CHROOT/root base-devel
警告: クリーンな chroot の最初の作成中にカスタムの pacman.conf または makepkg.conf を使用すると、chroot 環境に意図しないカスタム調整が行われる可能性があります。注意して使用してください

chroot でのビルド

まず、ベースの chroot ($CHROOT/root) が最新であることを確認します:

$ arch-nspawn $CHROOT/root pacman -Syu

次に、PKGBUILD を含むディレクトリで makechrootpkg を呼び出してパッケージをビルドします:

$ makechrootpkg -c -r $CHROOT
ノート: -c フラグを makechrootpkg に渡すと、作業中の chroot ($CHROOT/$USER) がビルド前に確実にクリーンアップされます。

必要なパッケージを事前にインストールする

$CHROOT/root/pacman.conf で有効になっているリポジトリから利用できない依存関係を含むパッケージをビルドするには、-I package を使用してそれらを作業中の chroot にプレインストールします。:

$ makechrootpkg -c -r $CHROOT -I build-dependency-1.0-1-x86_64.pkg.tar.xz -I required-package-2.0-2-x86_64.pkg.tar.xz

makepkg に引数を渡す

makepkg に引数を渡すには、オプションの終了マーカー の後に引数をリストします。たとえば、check() を強制するには:

$ makechrootpkg -c -r $CHROOT -- --check

大規模なリビルドの処理

大規模なリビルドを処理する最もクリーンな方法は、staging リポジトリを使用することです。最初のパッケージを extra に対してビルドし、それを staging にプッシュします。次に、後続のすべてのパッケージを staging に対してリビルドし、そこにプッシュします。

staging を使用できない場合は、次のようなコマンドを使用してカスタムパッケージに対してビルドできます。

# extra-x86_64-build -- -I ~/packages/foobar/foobar-2-1-any.pkg.tar.xz

-I 引数を使用して、インストールする複数のパッケージを指定できます。

大規模なリビルドを処理するより簡単な方法として、ビルドされたすべてのパッケージを chroot にインストールし、決してクリーンアップしない雑な方法もあります。以下を使用して最初のパッケージをビルドします:

# extra-x86_64-build

そして、以下を使用して以下のパッケージをすべてビルドします:

# makechrootpkg -n -r /var/lib/archbuild/extra-x86_64

namcap (-n 引数) を実行すると、chroot にパッケージがインストールされることになります。*-build もデフォルトでこれを行います。

ヒントとテクニック

tmpfs でビルドする

システムに十分な RAM がある場合は、devtools ビルドスクリプトに tmpfs を指定できます。

# mount --mkdir -t tmpfs -o defaults,size=20G tmpfs /mnt/chroots/arch
# extra-x86_64-build -c -r /mnt/chroots/arch