Skip to content

Instantly share code, notes, and snippets.

@YaSuenag
Last active May 12, 2017 03:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YaSuenag/382ab8855905600e735c to your computer and use it in GitHub Desktop.
Save YaSuenag/382ab8855905600e735c to your computer and use it in GitHub Desktop.
Raspbian/Pidoraをvirt-managerから使ってみる

環境

  • Fedora21
    • libvirt
    • virt-manager
    • qemu-system-arm
    • libguestfs-tools-c
  • Raspbian
  • Pidora20

下準備

qemu-system-armとlibguestfs-tools-cをインストールする。

# yum install qemu-system-arm libguestfs-tools-c

QEMU用Raspbian設定 ※Raspbianのみ

  • Raspbianイメージのマウント
# fdisk -l 2014-12-24-wheezy-raspbian.img

Disk 2014-12-24-wheezy-raspbian.img: 7.1 GiB, 7571767296 bytes, 14788608 sectors
単位: セクタ (1 * 512 = 512 バイト)
セクタサイズ (論理 / 物理): 512 バイト / 512 バイト
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
ディスクラベルのタイプ: dos
ディスク識別子: 0x000c45c9

Device                          Boot  Start      End  Sectors Size Id Type
2014-12-24-wheezy-raspbian.img1        8192   122879   114688  56M  c W95 FAT32
2014-12-24-wheezy-raspbian.img2      122880 14788607 14665728   7G 83 Linux

セクタサイズが512、開始セクタが122880なので、512×122880=62914560をオフセットにしてマウントする。

# mount -o loop,offset=62914560 <イメージ> <マウントポイント>
  • <マウントポイント>/etc/ld.so.preloadのコメントアウト
#/usr/lib/arm-linux-gnueabihf/libcofi_rpi.so

Jessieの場合でも、ここでロードされているモジュールはコメントアウトしておく。

  • デバイスファイルのマッピング <マウントポイント>/etc/udev/rules.d/90-qemu.rulesの新規作成 ※Jessieでは不要。その代わり、/etc/fstabのmmcblkのマウントポイントをコメントアウトしておく。
KERNEL=="sda", SYMLINK+="mmcblk0"
KERNEL=="sda?", SYMLINK+="mmcblk0p%n"
KERNEL=="sda2", SYMLINK+="root"
  • タイムゾーン変更
# cp <マウントポイント>/usr/share/zoneinfo/Asia/Tokyo <マウントポイント>/etc/localtime
  • アンマウント

ディスクサイズ変更

# qemu-img resize <イメージ> +<サイズ>
# fdisk <イメージ>

この手順でqemu-imgがエラーを吐く場合は、 -f raw を追加する。

一旦2番目のパーティションを削除削除し、同じ開始セクタでパーティションを作り直す。

libvirt定義用ドメインファイルの作成

<domain type='qemu'>
  <name>Raspbian</name>
  <uuid><!-- UUID。uuidgenで生成可能。 --></uuid>
  <memory unit='KiB'>262144</memory>
  <currentMemory unit='KiB'>262144</currentMemory>
  <vcpu placement='static'>1</vcpu>
  <os>
    <type arch='armv7l' machine='versatileab'>hvm</type>
    <kernel><!-- QEMU用ARMカーネル https://github.com/polaco1782/raspberry-qemu --></kernel>
    <boot dev='hd'/>
    <cmdline>root=/dev/sda2 panic=1 rootfstype=ext4 rw</cmdline>
  </os>
  <features>
    <acpi/>
  </features>
  <cpu mode='custom' match='exact'>
    <model fallback='allow'>arm1176</model>
  </cpu>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <devices>
    <emulator>/usr/bin/qemu-system-arm</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='イメージファイル'/>
      <target dev='hdc' bus='scsi'/>
      <address type='drive' controller='0' bus='0' target='0' unit='2'/>
    </disk>
    <controller type='scsi' index='0'/>
    <graphics type='vnc' port='-1' autoport='yes'/>
    <video>
      <model type='xen' vram='4096' heads='1'/>
    </video>
    <interface type='network'>
      <source network='default'/>
      <model type='smc91c111'/>
    </interface>
  </devices>
  <seclabel type='dynamic' model='selinux' relabel='yes'/>
</domain>

ポイント

  • メモリは256MB固定。それ以外だと起動しない。
  • アーキテクチャはarmv7l、マシンはversatileabにする。
    • 様々なサイトでマシンにversatilepbを指定するとあるが、versatilepbだとPCIバスがないとエラーになる
  • CPUはarm1176
  • videoはxen。これ以外だと起動しない。
  • NICはsm91c111。これ以外だとvirbr0につながらない。

libvirt への組み込み

# virsh define <ドメイン定義ファイル>

起動

virshでもvirt-managerでも、好きな方法で。 でも、初期設定が走るのでvirt-manager経由がオススメ。 起動が終わったら

# resize2fs /dev/sda2

でパーティションサイズを変更しておく。

参考リンク

@YaSuenag
Copy link
Author

YaSuenag commented May 12, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment