you're reading...
Debian, Raspbian

Raspbian DevBox

I recently purchased a Raspberry PI to build a wifi access point to replace my dd-wrt WRT54G.

Setting up a Raspberry Pi as a WiFi access point

While I’m waiting on the kit, I figured it would be good to start getting familiar with Debian, and Raspbian in particular.

After search around, trying a VirtualBox OVA, and trying CentOS Qemu ARM, I decided I would just build a Debian VirtualBox VM and run Qemu there.

These are the notes/steps I have from that build, seems to work well, I can VNC or SSH directly to Raspbian.

First, install Debian in a VirtualBox VM (1GB ram, 8GB Disk), after you have that, and can connect (I port forward 22+IP Last Octet, so is 2215)

First, fix SSHd to not use DNS, this will speed up the login process greatly:

# Add UseDNS=no
echo "UseDNS=no" >>/etc/ssh/sshd_config 
/etc/init.d/ssh restart

Next update and install packages:

apt-get update
apt-get install qemu-user-static
apt-get install debootstrap
apt-get install sudo
apt-get install vim
apt-get install xorg
apt-get install fluxbox xterm
apt-get install xterm
apt-get install unzip
apt-get install openvpn
apt-get install bridge-utils
apt-get install vim-gtk
apt-get install tightvncserver

I personally like Vi instead of Nano or Emacs, so set whatever you prefer, default is Nano:

echo "export EDITOR=/usr/bin/vim" >> /etc/profile
echo "export VISUAL=/usr/bin/vim" >> /etc/profile

Setup a bridged interface for Qemu to use:

cat >/etc/network/interfaces<<EOF
# The loopback network interface
auto lo
iface lo inet loopback

# The bridge network interface(s)
auto br0
  iface br0 inet static
  bridge_ports eth0
  bridge_fd 9
  bridge_hello 2
  bridge_maxage 12
  bridge_stp off

Setup the Qemu ifup and ifdown scripts:

cat >/etc/qemu-ifup<<EOF 
echo "Executing /etc/qemu-ifup"
echo "Bringing up $1 for bridged mode..."
sudo /sbin/ifconfig $1 promisc up
echo "Adding $1 to br0..."
sudo /sbin/brctl addif br0 $1
sleep 2

cat >/etc/qemu-ifdown<<EOF
echo "Executing /etc/qemu-ifdown"
echo "Bringing down  $1"
sudo /sbin/ifconfig $1 down
echo "Removing $1 from br0..."
sudo /sbin/brctl delif br0 $1
sleep 2

You can either just grant your user account certain sudo rights, or take a sledge hammer approach and grant all.

cat >>/etc/sudoers<<EOF
Cmnd_Alias      QEMU=/sbin/ifconfig, /sbin/brctl

### OR ####

sed -i 's/%sudo.*/%sudo ALL=(ALL:ALL) NOPASSWD: ALL/' /etc/sudoers
usermod -a -G sudo koaps

Next set of commands are run as the user account:

Get a copy of Raspbian and the kernel qemu:

wget http://xecdesign.com/downloads/linux-qemu/kernel-qemu
wget http://downloads.raspberrypi.org/images/raspbian/2013-07-26-wheezy-raspbian/2013-07-26-wheezy-raspbian.zip

unzip 2013-07-26-wheezy-raspbian.zip
rm 2013-07-26-wheezy-raspbian.zip

You will want to bump up the size of the raspbian image with the Qemu Image command:

qemu-img resize 2013-07-26-wheezy-raspbian.img 3.7G

Now you can start Raspbian:

cat >start.sh<<EOF

sudo /usr/bin/qemu-system-arm \
  -cpu arm1176 \
  -kernel kernel-qemu \
  -name 'builder-raspi' \
  -hda 2013-07-26-wheezy-raspbian.img \
  -m 256 \
  -M versatilepb \
  -no-reboot \
  -serial stdio \
  -append "root=/dev/sda2 panic=0 ro" \
  -net nic,vlan=0 \
  -net tap,vlan=0,ifname=tap0,script=/etc/qemu-ifup \
  -clock dynticks \
  -vnc :1
chmod +x start.sh

However that will fail, the disks aren’t sda, but mmcblk0, so we need to fix that:

cat >first.start.sh<<EOF

sudo /usr/bin/qemu-system-arm \
  -cpu arm1176 \
  -kernel kernel-qemu \
  -name 'builder-raspi' \
  -hda 2013-07-26-wheezy-raspbian.img \
  -m 256 \
  -M versatilepb \
  -no-reboot \
  -serial stdio \
  -append "root=/dev/sda2 panic=0 ro single" \
  -vnc :1
chmod +x first.start.sh

Not you should have a single user prompt on Raspbian, but root is mounted readonly so need to fix that, then fix the disk names in fstab:

mount / -o remount,rw

cat >/etc/fstab<<EOF
proc    /proc    proc    defaults    0 0
/dev/sda1    /boot    vfat    defaults    0 0
/dev/sda2    /       ext4    defaults    0 0
/dev/sda3    none    swap    sw    0 0

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



Next you will get the rasp-config tool screen.
You can change the password, turn on boot to desktop, and change anything else you want there. Probably want to goto Advanced Options and turn on the SSH server.

Hit finish and it will reboot, which will be a shutdown for us because we have the -no-reboot option set.

Now you run start.sh and bring up Raspbian, it should create a tap0 interface that’s added to br0 so networking can work.

Now to connect to the desktop, you use VNC, I have a script to start vnc server for me:

cat >vnc.sh<<EOF

if [ -z "$cmd" ];then echo "No command given";exit 1;fi

if [ "$cmd" == "start" ]; then
  vncserver :0 -geometry 800x600 -depth 16 -pixelformat rgb565
elif [ "$cmd" == "stop" ]; then
  vncserver -kill :0
  echo "Don't know what you want"
chmod +x vnc.sh

Should ask you for a password and start running.

Now you just need to create a VirtualBox port forward for 5900 and you can VNC to Raspbian. You can also add a rule for SSH.

That’s it. Have Fun 🙂

QEMU Emulating Raspberry Pi the easy way
How To: Emulate Raspberry Pi on Windows 7
Raspberry Pi under QEMU
Working with QEMU
QEMU – Debian – Linux – TUN/TAP – network bridge



No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s