R.A. Epigonos et al.

[debian] chroot 環境のアーキテクチャを確認

適当なバイナリファイルを file コマンドで検査して結果から推測する。

たとえば /usr/bin/dpkg という実行ファイルを検査すれば以下のような結果が得られる。以下の例では /path/to/chroot/chroot/testing_amd64 以下の環境が amd64 アーキテクチャで、/path/to/chroot/chroot/testing_i386 以下の環境が i386 アーキテクチャだとわかる。

$ file /path/to/chroot/testing*/usr/bin/dpkg
/path/to/chroot/chroot/testing_amd64/usr/bin/dpkg: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.26, BuildID[sha1]=0xac558e584e526cc16cffd082cd37369d9012ef84, stripped
/path/to/chroot/chroot/testing_i386/usr/bin/dpkg:  ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.26, BuildID[sha1]=0x183c9f7642d7f77645dcd9395b3eee9a55be3f90, stripped

chroot できるなら、その中でdpkg --print-architectureするのがいいかもunameはマウントされているprocから情報を読むので、chroot 環境内ではなくchroot が走っている環境のマシン情報を表示してしまうのでNG。たとえば以下のようなマシン上で i386 アーキテクチャでセットアップしたchroot 環境が動いているとする。

root@localhost:~# uname -a
Linux localhost 3.2.0-4-amd64 #1 SMP Debian 3.2.41-2 x86_64 GNU/Linux
# dpkg --print-architecture
amd64

まずは普通に chroot する場合。uname はchroot を実行したマシンと同じだが、dpkg --print-architecture の結果は期待通り。

root@localhost:~# schroot -c testing_i386
(testing_i386)root@localhost:~# uname -a
Linux localhost 3.2.0-4-amd64 #1 SMP Debian 3.2.41-2 x86_64 GNU/Linux
(testing_i386)root@localhost:~# dpkg --print-architecture
i386
(testing_i386)root@localhost:~# exit
logout

setarch して chroot する場合。uname のマシンのハードウェア名が i686 に変わっている。dpkg --print-architecture の結果は期待通り。

root@localhost:~# setarch i386   -v schroot -c testing_i386
(testing_i386)root@localhost:~# uname -a
Linux localhost 3.2.0-4-amd64 #1 SMP Debian 3.2.41-2 i686 GNU/Linux
(testing_i386)root@localhost:~# dpkg --print-architecture
i386
(testing_i386)root@localhost:~# exit
logout
root@localhost:~# setarch x86_64 -v schroot -c testing_amd64
(testing_amd64)root@localhost:~# uname -a
Linux localhost 3.2.0-4-amd64 #1 SMP Debian 3.2.41-2 x86_64 GNU/Linux
(testing_amd64)root@localhost:~# dpkg --print-architecture
amd64
(testing_amd64)root@localhost:~# exit
logout
root@localhost:~# schroot -c testing_amd64
(testing_amd64)root@localhost:~# uname -a
Linux localhost 3.2.0-4-amd64 #1 SMP Debian 3.2.41-2 x86_64 GNU/Linux
(testing_amd64)root@localhost:~# dpkg --print-architecture
amd64
(testing_amd64)root@localhost:~# exit
logout

リファレンス

  1. 「ビルドされるときのアーキテクチャ名ってどうやったらわかるの?
  2. Manpage for dpkg - man.cx manual pages
  3. CPU Architecture - Linux on the Desktop

ソーシャルブックマーク

  1. はてなブックマーク
  2. Google Bookmarks
  3. del.icio.us

ChangeLog

  1. Posted: 2010-07-17T13:37:54+09:00
  2. Modified: 2010-07-17T13:37:54+09:00
  3. Generated: 2023-08-27T23:09:15+09:00