ARM, debian, linux, networking, OYB software, qemu, raspberrypi

Raspbian on QEMU with network access

This is a little guide to emulate the Raspbian operating system for ARM on QEMU with network connectivity.

I found most resources on this outdated, relying on broken links, and lacking the steps for network access, so I reviewed them and streamlined the process.

Long story short

If you haven’t yet, install QEMU on your system. On my Arch machine this means

sudo pacman -S qemu qemu-arch-extra bridge-utils

on Debian based

sudo apt-get install kvm qemu bridge-utils

Then, clone my qemu-raspbian-network repository, download a raspbian image and launch qemu-pi.sh

git clone https://github.com/nachoparker/qemu-raspbian-network.git
cd qemu-raspbian-network
wget https://downloads.raspberrypi.org/raspbian_lite_latest -O raspbian_lite_latest.zip
unzip rasbian_lite_latest.zip
sudo ./qemu-pi.sh 2017-01-11-raspbian-jessie-lite.img # correct to real name

If you want network access, edit qemu-pi.sh  line 30 and set

NO_NETWORK=0

If you do this, the script will setup a bridge called br0  on your enp3s0  interface, and restore your routes after QEMU exits. If you want to modify this behaviour, change the relevant lines in the script.

NO_NETWORK=1            # set to 1 to skip network configuration
IFACE=enp3s0            # interface that we currently use for internet
BRIDGE=br0              # name for the bridge we will create to share network with the raspbian img

Now your Raspbian image will have network connectivity, so you can SSH to it, and apt-get  from it.

For QEMU to have access to the network bridge configuration, this needs to be in /etc/sudoers . Access with sudo visudo.

Cmnd_Alias      QEMU=/usr/bin/ip,/usr/bin/modprobe,/usr/bin/brctl
%kvm     ALL=NOPASSWD: QEMU

If you ever need more disk space, you can

qemu-img resize 2017-01-11-raspbian-jessie-lite.img +2G

When you are done modifying the image, you can dd  it to an SD card and run it directly on a Raspberry Pi.

Remember to use <CTRL><ALT>g in order to regain mouse control on QEMU.

Long story long

The Raspbian operating system is a Debian based GNU/Linux distribution that targets the Raspberry Pi board.

It can be convenient to play around with the OS without the need for a Rasberry Pi or an SD card. For this, we want to run it on the QEMU virtual machine.

The original Raspberry Pi has an ARM11 (ARMv6) processor, RPi2 has an ARM Cortex-A7, and RPi3 has an ARM Cortex-A53. I recommend going easy for the arm1136  or arm1176 . To see what your qemu-system-arm can emulate run

$ qemu-arm -cpu help                                          
Available CPUs:
  arm1026
  arm1136
  arm1136-r2
  arm1176
  arm11mpcore
  arm926
  arm946
  cortex-a15
  cortex-a7
  cortex-a8
  cortex-a9
  cortex-m3
  cortex-m4
  cortex-r5
  pxa250
  pxa255
  pxa260
  pxa261
  pxa262
  pxa270-a0
  pxa270-a1
  pxa270
  pxa270-b0
  pxa270-b1
  pxa270-c0
  pxa270-c5
  sa1100
  sa1110
  ti925t
  any

The problem is that the kernel that ships with Raspbian is taylored for the Raspberry Pi board, which is not supported by QEMU.

For this reason, the kernel needs to be patched and cross-compiled in order to be run on the ARM Versatile development board, which is supported by QEMU. I included a modified kernel 4.4.34 is in my repo.

After this, it is a matter of invoking qemu with the -kernel  option to replace the one that comes with Raspbian, and the -M versatilepb  option to specify the emulated hardware.

Then, we are only left with the task of interfacing the block devices that raspbian expects, which are of the form mmcblk0 to what it will receive from the QEMU virtual block device, which come on the form sda . That is what the following lines of the script do

cat > tmpmnt/etc/udev/rules.d/90-qemu.rules <<EOF
KERNEL=="sda", SYMLINK+="mmcblk0"
KERNEL=="sda?", SYMLINK+="mmcblk0p%n"
KERNEL=="sda2", SYMLINK+="root"
EOF

In order to achieve network connectivity, it is common to use TUNTAP with QEMU.

TUNTAP creates a virtual network interface that can be accesed by a hypervisor. All packets sent to this virtual interface will appear on the hypervisor’s network stack and viceversa, allowing communication with the virtual machine through the regular network interface.

Therefore, we will include both the real interface and the TUNTAP interface on a network bridge, which will cause any packet sent to the bridge from outside to appear on both interfaces, and any packet sent from inside will appear as if it originates on the bridge.

QEMU requires hooks on /etc/qemu-ifup  and /etc/qemu-ifdown  to manage the TUNTAP interface, which is dealt with by the following lines taken from the Arch wiki.

cat > /etc/qemu-ifup <<EOF
#!/bin/sh
echo "Executing /etc/qemu-ifup"
echo "Bringing up \$1 for bridged mode..."
sudo /usr/bin/ip link set \$1 up promisc on
echo "Adding \$1 to $BRIDGE..."
sudo /usr/bin/brctl addif $BRIDGE \$1
sleep 2
EOF

  cat > /etc/qemu-ifdown <<EOF
#!/bin/sh
echo "Executing /etc/qemu-ifdown"
sudo /usr/bin/ip link set \$1 down
sudo /usr/bin/brctl delif $BRIDGE \$1
sudo /usr/bin/ip link delete dev \$1
EOF
Cross-compile or get a newer kernel

The first ones to share this work as far as I know were Xecdesign, for the 3.10.25 kernel. At some point, their website went down, so Dhruv Vyas rescued the kernel patches and has been providing newer kernels as well as cross-compiling instructions on his github.

Code
#!/bin/bash

# Run a raspbian image in qemu with network access
# Tested with 2017-01-11-raspbian-jessie.img (and lite)
#
# Copyleft 2017 by Ignacio Nunez Hernanz <nacho _a_t_ ownyourbits _d_o_t_ com>
# GPL licensed (see end of file) * Use at your own risk!
#
# Usage:
#   qemu-pi.sh 2017-01-11-raspbian-jessie.img # or any other image
#
# Notes:
#   If NO_NETWORK=0 it will include your network interface on a bridge
#     with the same gateway and routes, and restore it when exiting qemu
#
#   If NO_NETWORK=1 (default), that configuration will have to be done manually
#     in order to obtain network access inside raspbian
#
#   It requires a modified kernel image for qemu. (variable $KERNEL)
#
#   It enables SSH on the image (but have to login once on lite version)
#
#   For the network bridge configuration, this needs to be in /etc/sudoers
#      Cmnd_Alias      QEMU=/usr/bin/ip,/usr/bin/modprobe,/usr/bin/brctl
#      %kvm     ALL=NOPASSWD: QEMU

IMG=$1
KERNEL=kernel-qemu-4.4.34-jessie

NO_NETWORK=1            # set to 1 to skip network configuration
IFACE=enp3s0            # interface that we currently use for internet
BRIDGE=br0              # name for the bridge to share network with the raspbian img
MAC='52:54:be:36:42:a9' # comment this line for random MAC (annoying if on DHCP)

# sanity checks
test -f $IMG && test -f $KERNEL || { echo "$IMG or $KERNEL not found"; exit; }

[[ "$IFACE" == "" ]] || [[ "$BRIDGE" == "" ]] && NO_NETWORK=1

# some more checks
[[ "$NO_NETWORK" != "1" ]] && {
    IP=$( ip a | grep "global $IFACE" | grep -oP '\d{1,3}(.\d{1,3}){3}' | head -1 ) 
    [[ "$IP" == "" ]]      && { echo "no IP found for $IFACE"; NO_NETWORK=1; }
    type brctl &>/dev/null || { echo "brctl is not installed"; NO_NETWORK=1; }
    modprobe tun &>/dev/null
    grep -q tun <(lsmod)   || { echo "need to tun module"    ; NO_NETWORK=1; }
}

# network configuration
[[ "$NO_NETWORK" != "1" ]] && {
  test -f /etc/qemu-ifup   && cp -nav /etc/qemu-ifup   /etc/qemu-ifup.bak
  test -f /etc/qemu-ifdown && cp -nav /etc/qemu-ifdown /etc/qemu-ifdown.bak

  cat > /etc/qemu-ifup <<EOF
#!/bin/sh
echo "Executing /etc/qemu-ifup"
echo "Bringing up \$1 for bridged mode..."
sudo /usr/bin/ip link set \$1 up promisc on
echo "Adding \$1 to $BRIDGE..."
sudo /usr/bin/brctl addif $BRIDGE \$1
sleep 2
EOF

  cat > /etc/qemu-ifdown <<EOF
#!/bin/sh
echo "Executing /etc/qemu-ifdown"
sudo /usr/bin/ip link set \$1 down
sudo /usr/bin/brctl delif $BRIDGE \$1
sudo /usr/bin/ip link delete dev \$1
EOF

  chmod 750 /etc/qemu-ifdown /etc/qemu-ifup
  chown root:kvm /etc/qemu-ifup /etc/qemu-ifdown

  IPFW=$( sysctl net.ipv4.ip_forward | cut -d= -f2 )
  sysctl net.ipv4.ip_forward=1

  ROUTES=$( ip r | grep $IFACE                       )
  BRROUT=$( echo "$ROUTES" | sed "s=$IFACE=$BRIDGE=" )
  brctl addbr $BRIDGE
  brctl addif $BRIDGE $IFACE
  ip l set up dev $BRIDGE
  ip r flush dev $IFACE
  ip a a $IP dev $BRIDGE
  echo "$BRROUT" | tac | while read l; do ip r a $l; done

  precreationg=$(ip tuntap list | cut -d: -f1 | sort)
  ip tuntap add user $USER mode tap
  postcreation=$(ip tuntap list | cut -d: -f1 | sort)
  TAPIF=$(comm -13 <(echo "$precreationg") <(echo "$postcreation"))
  [[ "$MAC" == "" ]] && printf -v MAC "52:54:%02x:%02x:%02x:%02x" \
    $(( RANDOM & 0xff)) $(( RANDOM & 0xff )) $(( RANDOM & 0xff)) $(( RANDOM & 0xff ))

  NET_ARGS="-net nic,macaddr=$MAC -net tap,ifname=$TAPIF"
}

# prepare the image
SECTOR1=$( fdisk -l $IMG | grep FAT32 | awk '{ print $2 }' )
SECTOR2=$( fdisk -l $IMG | grep Linux | awk '{ print $2 }' )
OFFSET1=$(( SECTOR1 * 512 ))
OFFSET2=$(( SECTOR2 * 512 ))

mkdir -p tmpmnt
mount $IMG -o offset=$OFFSET1 tmpmnt
touch tmpmnt/ssh   # this enables ssh
umount tmpmnt

mount $IMG -o offset=$OFFSET2 tmpmnt
cat > tmpmnt/etc/udev/rules.d/90-qemu.rules <<EOF
KERNEL=="sda", SYMLINK+="mmcblk0"
KERNEL=="sda?", SYMLINK+="mmcblk0p%n"
KERNEL=="sda2", SYMLINK+="root"
EOF

umount -l tmpmnt
rmdir tmpmnt &>/dev/null

# do it
qemu-system-arm -kernel $KERNEL -cpu arm1176 -m 256 -M versatilepb $NET_ARGS \
  -no-reboot -append "root=/dev/sda2 panic=1" -drive format=raw,file=$IMG \

# restore network to what it was
[[ "$NO_NETWORK" != "1" ]] && {
  ip l set down dev $TAPIF 
  ip tuntap del $TAPIF mode tap
  sysctl net.ipv4.ip_forward="$IPFW"
  ip l set down dev $BRIDGE
  brctl delbr $BRIDGE
  echo "$ROUTES" | tac | while read l; do ip r a $l; done
}

# License
#
# This script is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this script; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
# Boston, MA  02111-1307  USA

This was tested on Arch Linux (qemu-arm version 2.8.0), and only some parts on a Debian container.

In the next post we will do something useful with this.

Author: nachoparker

Humbly sharing things that I find useful [ github dockerhub ]

37 Comments on “Raspbian on QEMU with network access

      1. Thanks for the guide! I ran into this same issue. After “Attempting to kill init” the terminal output says it’s going down for reboot. I’m using Ubuntu 16.04 . When I ran your apt-get command it couldn’t find qemu-kvm-extras. From what I could find (http://packages.ubuntu.com/search?keywords=qemu-kvm-extras) it looks like the -extras package was only transitional for 12.04

        Otherwise:

        $ qemu-arm -version
        qemu-arm version 2.5.0 (Debian 1:2.5+dfsg-5ubuntu10.9), Copyright (c) 2003-2008 Fabrice Bellard
        


        $ qemu-arm -cpu help
        Available CPUs:
          arm1026
          arm1136
          arm1136-r2
          arm1176
          arm11mpcore
          arm926
          arm946
          cortex-a15
          cortex-a8
          cortex-a9
          cortex-m3
          cortex-m4
          cortex-r5
          pxa250
          pxa255
          pxa260
          pxa261
          pxa262
          pxa270-a0
          pxa270-a1
          pxa270
          pxa270-b0
          pxa270-b1
          pxa270-c0
          pxa270-c5
          sa1100
          sa1110
          ti925t
          any
        

        $ lsmod | grep kvm
        kvm_intel             172032  0
        kvm                   544768  1 kvm_intel
        irqbypass              16384  1 kvm
        

        1. Thanks for the feedback, I updated that bit.

          As it says in the post, I have only tested it througout on Arch.

          my version of qemu-arm is 2.8.0, unfortunatedly I have not tested it with 2.5.0

          Maybe you can try

          git clone -b v2.8.0 https://github.com/qemu/qemu
          mkdir build
          cd build
          ../configure --python=/usr/bin/python2
          make -j`nproc`
          

          There is many guides on compiling QEMU out there 😉

          Let us know if you manage to get it working

        2. Nacho, Thanks for sticking with me. You’re probably right that recompiling QEMU would have been a good fix. I really need to switch over to arch one of these days.

          I was able to get it working be recompiling the kernel following Dhruv Vyas’s instructions. I also made some of the file system changes that his guide recommends. I’m still using your qemu-pi.sh to start the QEMU session.

          Thanks again for the guide and for collecting the pieces necessary to get this working.

        3. Awesome!

          It is a bit weird because I just use Dhruv Vyas’s kernel as well.

          For the record… What version of the kernel did you compile? what changes did you have to do?

          It looks like maybe there is something with QEMU 2.5.0 and RPi kernel 4.34?

          I will investigate this when I have time

  1. Thanks for the great HOWTO, unfortunately my machine fails with:
    VFS: Cannot open root device “sda/2” or unknown-block(0,0): error -6
    What can I do?

  2. Hi,

    Thank you for this script and tutorial. I have managed to boot into raspbian, but can’t get network to work.
    This is config from qemu-pi.sh:

    
    NO_NETWORK=0            # set to 1 to skip network configuration
    IFACE=enp1s0            # interface that we currently use for internet
    BRIDGE=br0              # name for the bridge we will create to share network w$
    MAC='B8:CA:3A:DC:78:E4' # comment this line for random MAC (maybe annoying if o$
    

    My interface name is enp1s0 and MAC is the one written.

    Error is no IP found for enp1s0 altough I have an IP from DHCP.

    
    [domagoj@domagoj-pc qemu-raspbian-network]$ sudo ./qemu-pi.sh 2017-01-11-raspbian-jessie.img 
    [sudo] password for domagoj: 
    no IP found for enp1s0
    pulseaudio: set_sink_input_volume() failed
    pulseaudio: Reason: Invalid argument
    pulseaudio: set_sink_input_mute() failed
    pulseaudio: Reason: Invalid argument
    

    Can you help me with this issue?

    Best regards

  3. Hi,
    Thank you for the script!
    I’m using Ubuntu to emulate raspbian in QEMU.
    But when I assign no_network=0, it should have an ip address similar to the host network. It doesn’t work.

    NO_NETWORK=0            # set to 1 to skip network configuration
    IFACE=eno1                     # interface that we currently use for internet
    BRIDGE=br0                    # name for the bridge we will create to share network with the raspbian img
    MAC='52:54:be:36:42:a9' # comment this line for random MAC (maybe annoying if on DHCP)
    

    And the output for ip address is,

    dpremkum@cse-per148-05:~$ ip address 
    1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
           valid_lft forever preferred_lft forever
        inet6 ::1/128 scope host 
           valid_lft forever preferred_lft forever
    2: eno1:  mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
        link/ether 48:0f:cf:5b:dd:9b brd ff:ff:ff:ff:ff:ff
        inet 192.168.1.107/24 brd 192.168.1.255 scope global dynamic eno1
           valid_lft 84784sec preferred_lft 84784sec
        inet6 fe80::7659:1e6f:5f2e:56d0/64 scope link 
           valid_lft forever preferred_lft forever
    

    1. Hello,

      Let me explain what should happen, to make sure we are in the same page.

      After you run `qemu-pi.sh` and while it is running, a new brigde interface `br0` should appear in `ip address` with the same IP and routing that the host computer had at the moment of running `qemu-pi.sh`. Also a new interface `tap0`.

      Then, inside Raspbian, you have an `eth0` interface. If you have DHCP in your network it will get the IP and gateway from there. Otherwise you have to configure a static IP, DNS and gateway yourself.

      Your emulated Raspbian will not and should not have the same IP address as the host. That would not work, for the similar reasons that you cannot have two machines with the same IP in a network.

      In any case, can you show me the output of

      
      ip link
      
      
      ip address
      
      
      ip route
      

      before running `qemu-pi.sh` and while it is running?

      See my output

      before I run QEMU

      
      $ ip address
      1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
          link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
          inet 127.0.0.1/8 scope host lo
             valid_lft forever preferred_lft forever
          inet6 ::1/128 scope host
             valid_lft forever preferred_lft forever
      2: enp3s0:  mtu 1500 qdisc fq_codel state UP group default qlen 1000
          link/ether 48:5b:39:ae:d2:5e brd ff:ff:ff:ff:ff:ff
          inet 192.168.0.31/24 scope global enp3s0
             valid_lft forever preferred_lft forever
          inet6 fe80::4a5b:39ff:feae:d25e/64 scope link
             valid_lft forever preferred_lft forever
      

      after

      
      $ ip address
      1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
          link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
          inet 127.0.0.1/8 scope host lo
             valid_lft forever preferred_lft forever
          inet6 ::1/128 scope host
             valid_lft forever preferred_lft forever
      2: enp3s0:  mtu 1500 qdisc fq_codel master br0 state UP group default qlen 1000
          link/ether 48:5b:39:ae:d2:5e brd ff:ff:ff:ff:ff:ff
          inet 192.168.0.31/24 scope global enp3s0
             valid_lft forever preferred_lft forever
          inet6 fe80::4a5b:39ff:feae:d25e/64 scope link
             valid_lft forever preferred_lft forever
      170: br0:  mtu 1500 qdisc noqueue state UP group default qlen 1000
          link/ether 1e:6d:a5:7a:be:41 brd ff:ff:ff:ff:ff:ff
          inet 192.168.0.31/32 scope global br0
             valid_lft forever preferred_lft forever
          inet6 fe80::4a5b:39ff:feae:d25e/64 scope link
             valid_lft forever preferred_lft forever
      171: tap0:  mtu 1500 qdisc fq_codel master br0 state UP group default qlen 1000
          link/ether 1e:6d:a5:7a:be:41 brd ff:ff:ff:ff:ff:ff
          inet6 fe80::1c6d:a5ff:fe7a:be41/64 scope link
             valid_lft forever preferred_lft forever
      

      My routing while running QEMU goes through the bridge interface `br0`

      
      $ ip route
      default via 192.168.0.1 dev br0
      192.168.0.0/24 dev br0 proto kernel scope link src 192.168.0.31
      

      When you close QEMU it should go back to normal.

      1. Before I run QEMU,

        dpremkum@myjunkbox:~$ ip address 
        1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
            link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
            inet 127.0.0.1/8 scope host lo
               valid_lft forever preferred_lft forever
            inet6 ::1/128 scope host 
               valid_lft forever preferred_lft forever
        2: eno1:  mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
            link/ether 50:65:f3:b7:ba:b9 brd ff:ff:ff:ff:ff:ff
            inet 192.168.1.105/24 brd 192.168.1.255 scope global dynamic eno1
               valid_lft 86167sec preferred_lft 86167sec
            inet6 2602:306:8b63:c3c0::30/128 scope global dynamic 
               valid_lft 2591770sec preferred_lft 604570sec
            inet6 2602:306:8b63:c3c0:2bd:5c30:1fc5:f852/64 scope global noprefixroute dynamic 
               valid_lft 2591770sec preferred_lft 604570sec
            inet6 fe80::e61:6d97:1104:e45e/64 scope link 
               valid_lft forever preferred_lft forever
        3: wlo1:  mtu 1500 qdisc mq state DOWN group default qlen 1000
            link/ether 10:08:b1:5e:ef:d1 brd ff:ff:ff:ff:ff:ff
        


        dpremkum@myjunkbox:~$ ip route
        default via 192.168.1.254 dev eno1  proto static  metric 100 
        169.254.0.0/16 dev eno1  scope link  metric 1000 
        192.168.1.0/24 dev eno1  proto kernel  scope link  src 192.168.1.105  metric 100
        


        After running the QEMU,

        dpremkum@myjunkbox:~$ ip address 
        1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
            link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
            inet 127.0.0.1/8 scope host lo
               valid_lft forever preferred_lft forever
            inet6 ::1/128 scope host 
               valid_lft forever preferred_lft forever
        2: eno1:  mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
            link/ether 50:65:f3:b7:ba:b9 brd ff:ff:ff:ff:ff:ff
            inet 192.168.1.105/24 brd 192.168.1.255 scope global dynamic eno1
               valid_lft 85547sec preferred_lft 85547sec
            inet6 2602:306:8b63:c3c0::30/128 scope global dynamic 
               valid_lft 2591149sec preferred_lft 603949sec
            inet6 2602:306:8b63:c3c0:2bd:5c30:1fc5:f852/64 scope global noprefixroute dynamic 
               valid_lft 2591915sec preferred_lft 604715sec
            inet6 fe80::e61:6d97:1104:e45e/64 scope link 
               valid_lft forever preferred_lft forever
        3: wlo1:  mtu 1500 qdisc mq state DOWN group default qlen 1000
            link/ether 10:08:b1:5e:ef:d1 brd ff:ff:ff:ff:ff:ff
        


        The message I get while running the QEMU,

        dpremkum@myjunkbox:~/qemu-raspbian-network-master$ sudo ./qemu-pi.sh 2017-03-02-raspbian-jessie.img 
        [sudo] password for dpremkum: 
        no IP found for eno1
        need tun module
        pulseaudio: set_sink_input_volume() failed
        pulseaudio: Reason: Invalid argument
        pulseaudio: set_sink_input_mute() failed
        pulseaudio: Reason: Invalid argument
        

        1. Somehow I fixed the problem. Apparently the latest ubuntu kernel doesn’t have `tun`. Instead it has `tunctl`.
          There is a issue with the host’s network. Internet doesn’t work in Ubuntu(like web-browsers). Surprisingly, it works inside QEMU raspbian.
          Inside QEMU, I run into this error all the time.
          “`
          pi@rpi00:~ $ cat /etc
          bash: cannot create temp file for here-document: No space left on device
          “`
          I have already expanded the raspbian image to +4G. And my computer has at-least 100Gb of free space.

  4. Hi Nacho, thanks a lot for your scripts!
    See that “qemu-pi.sh” is from end of april. Is that meaning that it runs good on Ubuntu/Mint?
    Specific qemu-arm -version and qemu-arm -cpu-version?
    Thanks a lot.

      1. Hello! Nice job!
        I write only two things I modified to work on my Ubuntu 16.04.2 LTS…
        1) tun is not a module (at least in my distro) so I changed the script in the check:
        #modprobe tun &>/dev/null #original
        #grep -q tun /dev/null || { echo “need tun module” ; NO_NETWORK=1; } #modified
        [if you don’t have tun you have only to create it :
        sudo mkdir /dev/net (if it doesn’t exist already)
        sudo mknod /dev/net/tun c 10 200
        sudo. chmod 0666 /dev/net/tun
        ]
        2) I noticed wlan0 (wireless) is not bridgeable, eth0 (ethernet) yes , I failed so I added a fallback for network with
        “-redir tcp:2222::22” to access ssh from host machine ( ssh -p 2222 pi@localhost )
        Maybe this will help somebody else.

  5. Hi,

    Worked like a charm! 🙂 Many thanks! However, my main interest in the emulator is to use Mathematica and the image
    2017-04-10-raspbian-jessie.img (which works fine) comes with one. The problem is, I don’t have a product key. Do you have a key or a hint about activating Mathematica you might share? Thanks a lot!

    1. This website is all about do it yourself and open source.

      Propietary software discussions and very specifically pirating licensed work are not encouraged, nor welcome here.

      1. No piracy here I’m afraid. To the best of my knowledge, Raspbian comes with a bundled copy of Mathematica. I had another Raspbian version (wheezy) whose copy of Mathematica worked out of the box. No activation key needed. I downloaded jessie waiting, in good faith, that it would work similarly (and legally). As I said jessie comes with Mathematica but this time an activation key is required. Beats me. Why is it different from wheezy? I thought you might know.

        I may be misinformed about a (possibly) new policy with regard to Raspbian & Mathematica, but you don’t have to be anal about that. You don’t know me after all. Once again, thanks for the neat set of instructions. They worked beautifully.

        1. I apologize, I totally read that wrong.

          I don’t know anything about that license change, sorry.

          Thank you for your words and positive feedback

  6. Hi Nachoparker!! Thank you very much for your tutorial, it was very useful to start a Raspbian emulation easily (sorry about my English).
    I am new on this, and I want to know how I can use your script with Kernel 4.9.28-v7+. I think I have to cross-compile the Kernel sources (downloaded from kernel.org). Is this the right way?
    I have never cross-compiled anything so I will appreciate if you can guide me with the process.
    Regards from Argentina.

  7. Hi! Thank you for the tutorial and script! I followed everything ang to my Raspbian running, but I cannot have internet access in it.

    `ping http://www.google.com` gets me Temporary failure on name resolution.

    I’m using Manjaro KDE. Installed both `qemu` and `qemu-arch-extra`.
    `qemu-arm –version` returns version 2.11 (the last one on pacman), not the 2.8 that you say is required.
    I used your script, changing `IFACE=enp7s0`. I also used the kernel on your repository.
    For the image, I used the `2018-04-18-raspbian-stretch.img`.

    Here is my `ip address` before running
    “`
    1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
    valid_lft forever preferred_lft forever
    2: enp7s0: mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 78:2b:cb:ed:92:b3 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.26/24 brd 192.168.0.255 scope global dynamic noprefixroute enp7s0
    valid_lft 604683sec preferred_lft 604683sec
    inet6 2804:14c:bba6:56d4:7a2b:cbff:feed:92b3/128 scope global dynamic noprefixroute
    valid_lft 59sec preferred_lft 29sec
    inet6 2804:14c:bba6:56d4:22d0:60d3:9ff6:9e9b/64 scope global dynamic noprefixroute
    valid_lft 86375sec preferred_lft 71975sec
    inet6 fe80::7429:4bed:2e0e:b712/64 scope link noprefixroute
    valid_lft forever preferred_lft forever
    3: wlp6s0: mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 90:48:9a:ee:d4:31 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.13/24 brd 192.168.0.255 scope global dynamic noprefixroute wlp6s0
    valid_lft 604753sec preferred_lft 604753sec
    inet6 2804:14c:bba6:56d4:9248:9aff:feee:d431/128 scope global dynamic noprefixroute
    valid_lft 58sec preferred_lft 28sec
    inet6 2804:14c:bba6:56d4:f72a:8a4d:8789:7e6e/64 scope global dynamic noprefixroute
    valid_lft 86375sec preferred_lft 71975sec
    inet6 fe80::3b12:1fb3:5c90:8e5a/64 scope link noprefixroute
    valid_lft forever preferred_lft forever
    4: br-8aab5c5dc584: mtu 1500 qdisc noqueue state DOWN group default
    link/ether 02:42:15:a2:e1:57 brd ff:ff:ff:ff:ff:ff
    inet 172.18.0.1/16 brd 172.18.255.255 scope global br-8aab5c5dc584
    valid_lft forever preferred_lft forever
    5: docker0: mtu 1500 qdisc noqueue state DOWN group default
    link/ether 02:42:5b:99:4e:73 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
    valid_lft forever preferred_lft forever
    “`

    `ip route` before running
    “`
    default via 192.168.0.1 dev enp7s0 proto dhcp metric 100
    default via 192.168.0.1 dev wlp6s0 proto dhcp metric 20600
    172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1 linkdown
    172.18.0.0/16 dev br-8aab5c5dc584 proto kernel scope link src 172.18.0.1 linkdown
    192.168.0.0/24 dev enp7s0 proto kernel scope link src 192.168.0.26 metric 100
    192.168.0.0/24 dev wlp6s0 proto kernel scope link src 192.168.0.13 metric 600
    “`

    Then, I run `sudo ./qemu-pi.sh 2018-04-18-raspbian-stretch.img`

    `ip address` while running
    “`
    1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
    valid_lft forever preferred_lft forever
    2: enp7s0: mtu 1500 qdisc fq_codel master br0 state UP group default qlen 1000
    link/ether 78:2b:cb:ed:92:b3 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.26/24 brd 192.168.0.255 scope global dynamic noprefixroute enp7s0
    valid_lft 604404sec preferred_lft 604404sec
    inet6 2804:14c:bba6:56d4:22d0:60d3:9ff6:9e9b/64 scope global dynamic noprefixroute
    valid_lft 86200sec preferred_lft 71800sec
    inet6 fe80::98c:2bd2:16a6:f094/64 scope link
    valid_lft forever preferred_lft forever
    inet6 fe80::aa0b:d104:ff88:df39/64 scope link
    valid_lft forever preferred_lft forever
    inet6 fe80::7429:4bed:2e0e:b712/64 scope link noprefixroute
    valid_lft forever preferred_lft forever
    3: wlp6s0: mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 90:48:9a:ee:d4:31 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.13/24 brd 192.168.0.255 scope global dynamic noprefixroute wlp6s0
    valid_lft 604474sec preferred_lft 604474sec
    inet6 2804:14c:bba6:56d4:9248:9aff:feee:d431/128 scope global dynamic noprefixroute
    valid_lft 49sec preferred_lft 19sec
    inet6 2804:14c:bba6:56d4:f72a:8a4d:8789:7e6e/64 scope global dynamic noprefixroute
    valid_lft 86379sec preferred_lft 71979sec
    inet6 fe80::3b12:1fb3:5c90:8e5a/64 scope link noprefixroute
    valid_lft forever preferred_lft forever
    4: br-8aab5c5dc584: mtu 1500 qdisc noqueue state DOWN group default
    link/ether 02:42:15:a2:e1:57 brd ff:ff:ff:ff:ff:ff
    inet 172.18.0.1/16 brd 172.18.255.255 scope global br-8aab5c5dc584
    valid_lft forever preferred_lft forever
    5: docker0: mtu 1500 qdisc noqueue state DOWN group default
    link/ether 02:42:5b:99:4e:73 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
    valid_lft forever preferred_lft forever
    6: br0: mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 36:42:54:e1:aa:31 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.26/32 scope global br0
    valid_lft forever preferred_lft forever
    inet6 2804:14c:bba6:56d4:3442:54ff:fee1:aa31/64 scope global dynamic mngtmpaddr
    valid_lft 86379sec preferred_lft 71979sec
    inet6 fe80::3442:54ff:fee1:aa31/64 scope link
    valid_lft forever preferred_lft forever
    7: tap0: mtu 1500 qdisc fq_codel master br0 state UP group default qlen 1000
    link/ether 36:42:54:e1:aa:31 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::3442:54ff:fee1:aa31/64 scope link
    valid_lft forever preferred_lft forever
    “`

    `ip route` while running
    “`
    default via 192.168.0.1 dev br0 proto dhcp metric 100
    default via 192.168.0.1 dev wlp6s0 proto dhcp metric 600
    default via 192.168.0.1 dev enp7s0 proto dhcp metric 20100
    172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1 linkdown
    172.18.0.0/16 dev br-8aab5c5dc584 proto kernel scope link src 172.18.0.1 linkdown
    192.168.0.0/24 dev br0 proto kernel scope link src 192.168.0.26 metric 100
    192.168.0.0/24 dev enp7s0 proto kernel scope link src 192.168.0.26 metric 100
    192.168.0.0/24 dev wlp6s0 proto kernel scope link src 192.168.0.13 metric 600
    “`

    `ifconfig` inside the VM is ok, listing `eth0` with
    “`
    inet 169.254.138.61
    netmast 255.255.0.0
    broadcast 169.254.255.255
    “`

    But I can’t connect to any website or ping, or clone git repos. Any idea what it can be?

Leave a Reply to Chris M Balz Cancel reply

Your email address will not be published. Required fields are marked *