ユーザーモードエミュレーションqemu を使って Kono on Debian のイメージを Host PC で apt-get とかする

Kobo on Debian ですが,ストレージがmicroSD のせいかよくイメージが壊れてしまいます.そのたびに書き込みなおして設定を行ってというのは大変です.ということで Kobo on Debian のイメージをホストのLinux マシンでマウントしてユーザーモードqemu を利用して apt-get したりする方法の紹介です.

ここではhost pc に Debian jessie を利用していますが,wheezy や Ubuntu 13.10 なんかでも全く同じように動作しそうです.
(他のディストリビューションでも大丈夫でしょうがパッケージ名などが異なると思われます.)

qemu-user-static パッケージを導入

先ず,ユーザーモードqemu のパッケージを導入します.これで,別のアーキテクチャのバイナリをユーザーモードで動作させることが出来ます.

% sudo apt-get install qemu-user-static

パッケージの中を見ると以下のアーキテクチャが動作するようです.

% dpkg -L qemu-user-static
/usr/bin/qemu-mipsn32-static
/usr/bin/qemu-or32-static
/usr/bin/qemu-mips-static
/usr/bin/qemu-m68k-static
/usr/bin/qemu-ppc64-static
/usr/bin/qemu-sparc-static
/usr/bin/qemu-i386-static
/usr/bin/qemu-armeb-static
/usr/bin/qemu-mipsn32el-static
/usr/bin/qemu-ppc-static
/usr/bin/qemu-ppc64abi32-static
/usr/bin/qemu-mipsel-static
/usr/bin/qemu-arm-static
/usr/bin/qemu-x86_64-static
/usr/bin/qemu-sh4-static
/usr/bin/qemu-mips64el-static
/usr/bin/qemu-sparc64-static
/usr/bin/qemu-unicore32-static
/usr/bin/qemu-sh4eb-static
/usr/bin/qemu-microblazeel-static
/usr/bin/qemu-microblaze-static
/usr/bin/qemu-mips64-static
/usr/bin/qemu-cris-static
/usr/bin/qemu-sparc32plus-static
/usr/bin/qemu-alpha-static
/usr/bin/qemu-s390x-static

ディスクイメージをマウント

Kobo on Debian のイメージを loopback mount します.イメージは複数パーティションなので,fdisk コマンドでパーティション情報を確認して mount 時に offset を指定します.

% /sbin/fdisk -l -u ./2013-08-17_kobo_debian.img

Disk ./2013-08-17_kobo_debian.img: 8014 MB, 8014266368 bytes
255 heads, 63 sectors/track, 974 cylinders, total 15652864 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000aad1a

                       Device Boot      Start         End      Blocks   Id  System
./2013-08-17_kobo_debian.img1           19456    10506239     5243392   83  Linux
./2013-08-17_kobo_debian.img2        10506240    14698495     2096128    b  W95 FAT32
./2013-08-17_kobo_debian.img3        14698496    15652863      477184   82  Linux swap / Solaris

今回利用したいのは1つめのパーティションの ./2013-08-17_kobo_debian.img1 19456 10506239 5243392 83 Linux 部分です.
先頭ブロックは 19456 で,ブロックサイズは 512 なので, 19456*512 = 9961472 が offset になります.(若しくは expr 19456 \* 512 とかしても判りやすいかもです.)

% sudo mount -o loop,offset=9961472 ./2013-08-17_kobo_debian.img /mnt

これで 2013-08-17_kobo_debian.img の第1パーティションが /mnt にマウントされました.

ユーザーモードエミュレーションQEMU コマンドをコピーする

Kobo on Debian 部分を chroot で利用したいので,ユーザーモードエミュレーションQEMU コマンドをイメージ内にコピーします.
マウント時に /usr/bin になる部分にコピーします.

% sudo cp -p /usr/bin/qemu-arm-static /mnt/debian/usr/bin

chroot してapt とかする

イメージを chroot して apt とかしてみます.

% sudo chroot /mnt/debian /bin/bash
# vi etc/apt/sources.list

名前解決に失敗するので,nameserver を設定します.以下は Google の 8.8.8.8 を指定した時の例です.chroot 前に host のresolv.conf を cp しておいてもいいかもしれません.

# cat <<__EOF__> /etc/resolv.conf
> nameserver 8.8.8.8
> __EOF__
# apt-get update
  :

後は普通に設定していきます.
設定が終了したらexit コマンドで chroot を抜け,umount コマンドでアンマウントします.

RaspberryPi の Rasbian イメージでも行けるだろうと思って試したのですが,失敗してしまいました.解決したいところです….

ADD: その後やり直したらうまく行った

「ユーザーモードエミュレーションqemu を使って Kono on Debian のイメージを Host PC で apt-get とかする」への4件のフィードバック

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

To respond on your own website, enter the URL of your response which should contain a link to this post's permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post's URL again. (Find out more about Webmentions.)