Last-modified: 2014-11-27 (木) 17:26:49
QEMU/MIPSアーキテクチャ上でDebianを動かす

概要

QEMUでMIPS CPUをエミュレートした上でDebianを動かします。

手順

  1. QEMUインストール
    Everything is expanded.Everything is shortened.
      1
      2
    
     
     
    
    sudo apt-get update
    sudo apt-get install qemu
  2. DebianはMIPS用イメージがネット上にあるのでダウンロード
    Everything is expanded.Everything is shortened.
      1
      2
      3
    
    -
    !
     
    
    # https://people.debian.org/~aurel32/qemu/mipsに説明があるので確認したほうが良い
    wget https://people.debian.org/~aurel32/qemu/mips/debian_wheezy_mips_standard.qcow2
    wget https://people.debian.org/~aurel32/qemu/mips/vmlinux-3.2.0-4-5kc-malta
  3. 起動
    Everything is expanded.Everything is shortened.
      1
      2
    
    -
    !
    
    # https://people.debian.org/~aurel32/qemu/mipsにあるとおり、root/rootで入れる
    sudo qemu-system-mips64 -M malta -kernel vmlinux-3.2.0-4-5kc-malta -hda debian_wheezy_mips_standard.qcow2 -append "root=/dev/sda1 console=tty0" -m 256
  4. 確認
    するまでもないですが、lscpuやcpuinfoなどで確認できます。
    元々ビッグエンディアンCPU上でC++のコードの動作確認をする目的で作ったので、下の画像ではビッグエンディアンかどうかを確認しています。
    Everything is expanded.Everything is shortened.
      1
      2
    
     
     
    
    lscpu
    cat /proc/cpuinfo
    WS000007.PNG
  5. テキストモード起動にする(Ubuntu)
    ここからは利便性向上に関する操作なので取捨選択してください。
    Everything is expanded.Everything is shortened.
      1
      2
      3
      4
      5
      6
    
     
     
     
     
     
     
    
    sudo vi /etc/default/grub
    GRUB_CMDLINE_LINUX_DEFAULT="text"
     
    sudo update-grub
    sudo update-grub2
    sudo reboot
  6. SSHで接続可能にする(Ubuntu,Debian)
    利便性のためSSHで接続可能にします。SFTPも使えるようになるので便利です。
    ただし、ここではセキュリティを一切考慮しません。
    考慮したい場合はSSH, iptablesを参照してください。
    1. Virtualbox(Ubuntu)
      Everything is expanded.Everything is shortened.
        1
        2
        3
        4
        5
        6
        7
        8
        9
       10
      
      -
      !
      -
      !
       
       
      -
      !
       
       
      
      # ダウンロードしたVMイメージにsshdが入っていなかったのでインストール
      sudo apt-get install ssh
      # ダウンロードしたVMイメージはALL ACCEPTだったのでスルー
      iptables -L
       
      sudo vi /etc/ssh/sshd_config
      # パスワードによるログイン許可
      PasswordAuthentication yes
       
      sudo serive sshd restart
    2. QEMU(Debian)
      Everything is expanded.Everything is shortened.
        1
        2
        3
        4
        5
        6
        7
        8
        9
       10
      
      -
      !
      -
      !
       
       
      -
      !
       
       
      
      # ダウンロードしたイメージにsshdが入っていなかったのでインストール
      apt-get install ssh
      # ダウンロードしたイメージはALL ACCEPTだったのでスルー
      iptables -L
       
      vi /etc/ssh/sshd_config
      # パスワードによるログイン許可
      PasswordAuthentication yes
       
      serive sshd restart
  7. QEMU起動スクリプトを作成(Ubuntu)
    1. run-debian.sh作成
      Everything is expanded.Everything is shortened.
        1
        2
      
      -
      !
      
      #!/bin/bash
      sudo qemu-system-mips64 -M malta -kernel vmlinux-3.2.0-4-5kc-malta -hda debian_wheezy_mips_standard.qcow2 -append "root=/dev/sda1" -m 256 -nographic -redir tcp:20022::22 -no-reboot
    2. 実行権限付加
      Everything is expanded.Everything is shortened.
        1
      
       
      
      chmod +x run-debian.sh
  8. VirtualboxのNATポートフォワーディング設定
    1. [ネットワーク設定] - [ポートフォワーディング]で、UbuntuとDebianのSSHポートへのフォワーディング設定を行う
      WS000005.PNG
  9. 確認
    1. Ubuntu上でrun-debian.shを起動
      Everything is expanded.Everything is shortened.
        1
      
       
      
      ./run-debian.sh
    2. DebianへSSH接続
      Everything is expanded.Everything is shortened.
        1
        2
        3
        4
        5
        6
        7
        8
        9
      
       
       
      -
      !
       
      -
      !
       
      -
      
      apt-get update
       
      # C++でビッグエンディアンの確認がしたいので
      apt-get install build-essential
       
      # ゴミみたいなvim-tinyは使用に耐えないので
      apt-get install vim
       
      # あとは.bashrc, .vimrcをいつものにすればとりあえず使える
      
      WS0000011.PNG

検証時の環境

参考