Posts Tagged Raspberry

How to run Raspberry Pi from a USB hard drive

Raspberry Pi - USB Hard drive

I had been using my Raspberry Pi with a 4 GB – class 4  SD card Kingston until it decided to die (since I burn the image the first time that SD card was a little problematic). Because I didn’t have another 2GB or higher SD card, I decided to do a research to check if I could use the first partition as boot and another partition from an external USB hard drive of 320 GB. Effectively it can be done and I describe the needed steps on this article.

Raspbian Image

I decided to use the Raspbian image Raspbian 2013-02-09-wheezy-raspbian.img, but first I had to do a trick: dump the image to a 8 GB pen drive to be able separate the /boot partition and the remaining file system.

Dumping Raspbian to the pen drive

Just dump the Raspbian image as it were a SD card, but instead of  using /dev/mmcblk0 do it on your  pen drive:

# dd bs=4M if=/home/lgallard/Projects/RaspberryPi/2013-02-09-wheezy-raspbian.img of=/dev/sdb

Extracting the boot image

In order to extract the Raspbian’s boot image just dump the first partition of the pen drive:

# dd if=/dev/scb1 of=/home/lgallard/Projects/RaspberryPi/2013-02-09-wheezy-raspbian.boot.img

Extracting the operating system

Do the same to extract the file system where the operating systems resides:

# dd if=/dev/sdc2 of=/home/lgallard/Projects/RaspberryPi/2013-02-09-wheezy-raspbian.fsext4.img

Partition /boot on SD card

You will still need a SD card to boot your Rasberry, but it not longer need to be 2GB, in fact it could be much less, even 64 MB (I use a 1 GB SD card I found). To do so, you need to make a partition with GParted of about 60 MB as show in the next picture:

GParted - SD Card

Now copy the content of the first image you dumped previously:

# dd if=/home/lgallard/Projects/RaspberryPi/2013-02-09-wheezy-raspbian.boot.img of=/dev/sdb1

Once you have copied the data you must mount that partition and then edit file /media/usb0/cmdline.txt  (change /media/usb0 according to the mounting point), and put the following:

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/sda1 rootfstype=ext4 elevator=deadline rootwait

Here is important to put root=/dev/sda1  so the Raspberry uses the first partition of the external USB hard drive as the root partition, I mean, the “/” directory at boot.

Partitioning the external USB hard drive

Connect the hard drive to a PC and make the partitions as shown in the next picture. The first partition will content the file system  and the second one will be used for saving data (you can define later that in the /etc/fstab of your the RaspBerry Pi).

GParted - hard drive

File system partition “/”

Now you can dump the Raspian image you got to the first partition of the USB hard drive. To do so type this:

# dd if=/home/lgallard/Projects/RaspberryPi/2013-02-09-wheezy-raspbian.fsext4.img of=/dev/sdc1

Fixing the size partition

As you can see in the last picture, the partition was created of 9 GB size, but if you mount the partition it will report it as only 2 GB because the Raspian image has that size by default.  To fix this you must umount the partiton and and resize the file system:

# umount /dev/sdc1
# e2fsck -f /dev/sdc1
e2fsck 1.42.5 (29-Jul-2012)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
Raspbian: 66488/114688 files (0.1% non-contiguous), 346538/458240 blocks
# resize2fs /dev/sdc1
resize2fs 1.42.5 (29-Jul-2012)
Resizing the filesystem on /dev/sdc1 to 2304000 (4k) blocks.
The filesystem on /dev/sdc1 is now 2304000 blocks long.

After that check the available space. It should report something like this:

# df -h
/dev/sdc2 285G 191M 271G 1% /media/Data
/dev/sdc1 8.7G 1.3G 7.0G 16% /media/Raspbian

If you follow these steps, your Rasberry Pi will boot from a USB hard drive.

Final notes

  • It’s a fact that a hard drive have a higher price than a SD card but you have to consider the later will suffer more, specially a file system with journal can kill the SD card, so it’s not crazy to think in an external USB hard drive.
  • This hard drive and keyword are powered by the Rasberry Pi without problems. But if I connect something more, for instance a mouse, it can’t handle all and the device reboots.
  • Using a hard drive can solve the SD card compatibility issue (recommended class 6 type). In my case I used a Sandsik of 1 GB, class 4 and it worked perfectly.
  • Probably you can use dd and extract the /boot and file system partitions, but due I didn’t know the exact size and because I was a little lazy a decide to dump the Rasbian image on a pen drive and extract the images that way.

, , , ,


XBMC on Rasberry Pi with Raspbian

XBMC - Raspbian

If you want to install XBMC on your Raspberry Pi using  Raspbian and got dependency problems, you can download it from this repo by adding the following line to /etc/apt/sources.list

# XBMC Repo
 deb wheezy contrib

Then update and install XBMC:

# aptitude update
 # aptitude install xbmc

After that, you can start it on boot and increase the priority level by editing file /etc/default/xbmc with these parameters:

# Set this to 1 to enable startup
# The user to run XBMC as
# Adjust niceness of XBMC (decrease for higher priority)

Remember to disable the LXDE or XFCE start on boot (you can ue rasp-config). Enjoy it!

Reference: XBMC for Raspberry Pi

, , ,


Unboxing the Raspberry Pi

Raspberry board

My Raspberry Pi has arrived…and sooner than expected (they say in three weeks). I would say it just took one week to ship it to Venezuela. In my case I bought it at RS Raspberry Pi Store and the shipment was direct to Venezuela. And yes, IPOSTEL shipments do arrive.


Here  I leave some picture of the unboxing…

Raspberry Delivery Raspberry box

Unboxing the Raspberry Raspberry Quick Start

Raspberry Case AC adaptors
American AC wire

I just need a SD card, which must be class 4…at the moment I continue experimenting with the QEMU image as I mentioned in my last post.

, ,


Emulating Raspberry Pi with QEMU

XFCE4 - Raspberry Pi

I bought a Raspberry Pi but it will take three weeks until it arrives (add three more weeks thanks to the postal service) so I decided to see what I can read about the Raspberry. Then it occur to me the idea of trying to emulate the Raspberry Pi and it came to my mind QEMU, because the Raspberry Pi has a ARM1176 processor. Doing a quick research I found this blog where explains how to do it. But I didn’t want to use the Rasberry project’s image but one of the Raspbian variations, in particular the Hexxeh image. Finally, and because I wanted to do some tests without the need of a graphic interface, I did a research to make a bridge on QEMU. Then I set the image as suggested by the Raspbian page, because it comes too plain, so I uninstall LXDE in favor of XFCe with Slim. Here I explain how to do so:

Hexxhex image

I downloaded the  Raspbian Hexxeh image and applied the changes sugested:

  • I installed the  SSH server and regenerated the keys (you have to do this because everybody downloads that image and the keys must be unique). Just to this:
# rm /etc/ssh/ssh_host_*
# dpkg-reconfigure openssh-server
  • I upgraded the package list
  • I installed XFCE and Slim (login manager)  and uninstall LXDE because I thinks it’s ugly an heavier than XFCE.
  • I updated the timezone to Caracas, and set the time with ntp.
  • I set the locales to US_us UTF8
  • I set the keyboard layout to Latin American Spanish.

If you want custom this image as above follow the steps explained at the Raspbian Hexxeh web page.

Raspbian on QEMU

Now to run Raspbian on QEMU you must follow these steps:

  1. Download the kernel for this proccesor:
    $ wget
  2. Extract the Raspbian image downloaded. I put the Hexxeh image as example, but you can try any other image:
    $ unzip
  3. Run QEMU with the following options:
    $ qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2" -hda raspbian-r3/raspbian-r3.img

Keep in mind that is an emulation  so no all the Raspberry’s hardware is supported. For example when booting the image you can see that the first partition is not loaded, which corresponds to the /boot partition, which is supplied by the downloaded kernel .

Setting the briged on QEMU

Another thing I wanted to do was to be able to access the emulation from a remote computer. The idea behind this is not to depend on a graphic environment but to be able to access the Raspberry image with ssh to, for example, be able to install packages with aptitude. To do so I had to make a bridge as explained next:

Installing the needed packages

First, you must download these packages:

# aptitude install bridge-utils uml-utilities

Granting permissions with sudo

In order add the network interfaces to the bridge you have to grant permissions to the user who launch the virtual machine. To do so you have to set sudo using the visudo command:

# This file MUST be edited with the 'visudo' command as root.
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
# See the man page for details on how to write a sudoers file.
Defaults env_reset
Defaults mail_badpass
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
# Host alias specification
# User alias specification
# Cmnd alias specification
Cmnd_Alias QEMU=/sbin/ifconfig, \
# User privilege specification
# Allow members of group sudo to execute any command

# See sudoers(5) for more information on "#include" directives:
#includedir /etc/sudoers.d

In this case lgallard is the user that is allowed to run ifconfig and brctl.

Setting the bridge

You have to set the file /etc/network/interfaces to bring up the bridge automatically . To do so you must disable the interfaces to be added to the bridge (for instance, ifdown eth0) and define just the bridge as explained below:

# This file describes the network interfaces available on your system
 # and how to activate them. For more information, see interfaces(5).
# The loopback network interface
 auto lo
 iface lo inet loopback
# The bridge network interface(s)
auto br0
iface br0 inet dhcp
 bridge_ports eth0
 bridge_fd 9
 bridge_hello 2
 bridge_maxage 12
 bridge_stp off

After this you can bring up the bridge by typing this:

# ifup br0

QEMU init script (/etc/eqemu-ifup)

This script let you bring up the network interfaces and the bridge with QEMU. To do so you have to edit /etc/qemu-ifup with the following info:

#sudo -p "Password for $0:" /sbin/ifconfig $1

echo "Executing /etc/qemu-ifup"
echo "Bringing up $1 for bridged mode..."
sudo /sbin/ifconfig $1 promisc up
echo "Setting tap0"
sudo tunctl -t tap0 -u lgallard
echo "Adding $1 to br0..."
sudo /sbin/brctl addif br0 $1
sleep 2


Here I leave some screenshots with the QEMU emulation:

Raspberry Pi - Hexxeh image

Raspberry Pui - Slim

Raspberry Pi - SSH

Rasbperry Pi basic

As you can see in the last screenshot, not all is installed on the image, so if something doesn’t work you have to download it. In this case you can install midory browser:

# aptitude install midory

Or any other browser you prefer.