May 162013
 

So lately, I’ve been trying to use one of my Raspberry Pis as a WiFi bridge.
That is connecting the Pi to a WiFi network, and sharing it out via the ethernet port.
I was trying to do that with the RT5370 USB sticks that I was also using to broadcast hotspots.

With the default drivers in Raspbian however, trying to add wlan0 to a bridge results in this message

can't add wlan0 to bridge br0: Operation not supported

According the the drivers, wlan0 can’t do it.
The only way to add the RT5370 NIC to a bridge is to activate 4addr (4 address frame) mode.

iw wlan0 set 4addr on

However, once 4addr mode is on, traffic between the WiFi device and the AP seemed to stop altogether.

The solution to this issue, is to use the RALink drivers. The vendor drivers does not seem to use the Linux WiFi stack however, which means that those drivers can not be used to broadcast a hotspot using hostapd. So if you’re using a Pi as a WiFi repeater, you may have issues there, though that will be something I’m going to experiment with later as well.

Preparation

Before we can actually compile the drivers, we’re going to need to grab the kernel sources.
I’m using Raspbian Server Edition, which uses the 3.6.11+ kernel. We’ll need the matching source from github.
We’ll change to the /usr/src directory first, then wget the sources from github, and then untarball it with these commands.

*Note* I’m doing it as root, so you can either prepend sudo to these commands, or run sudo bash before running these commands.

cd /usr/src
wget https://github.com/raspberrypi/linux/archive/rpi-3.6.y.tar.gz
tar -xvzf rpi-3.6.y.tar.gz

Once the source is extracted, we’ll need to copy the current kernel configuration into the source directory.

cd linux-rpi-3.6.y
gzip -dc /proc/config.gz > .config

And then we need to create the files and symlinks neccesary for compiling external modules

make modules_prepare
ln -s /usr/src/rpi-3.6.y /lib/modules/3.6.11+/build

Compiling the Vendor drivers

In order to use the Vendor drivers, first we’ll need to get them.
The drivers can be found here.
Download the ones for the RT5370 and transfer it to the Pi as we’ll need to compile the drivers ourselves.

Once we have the drivers on the Pi, we’ll move them to /usr/src and untar them to keep things nice and neat. Assuming the drivers are in /home/pi
*Note* Again I’m doing everything as root.

mv /home/pi/2011_0719_RT3070_RT3370_RT5370_RT5372_Linux_STA_V2.5.0.3_DP0.bz2 /usr/src
cd /usr/src
tar -xvjf 2011_0719_RT3070_RT3370_RT5370_RT5372_Linux_STA_V2.5.0.3_DP0.bz2
cd 2011_0719_RT3070_RT3370_RT5370_RT5372_Linux_STA_V2.5.0.3_DP0

Once it’s untarred, we’ll need to edit the file ‘os/linux/config.mk’ to enable WPA support and to allow network managers to control the device.
So find these lines, and change the n to y, then save and close the file.

HAS_WPA_SUPPLICANT=n
HAS_NATIVE_WPA_SUPPLICANT_SUPPORT=n

Now, we should still be in the /usr/src/2011_0719_RT3070_RT3370_RT5370_RT5372_Linux_STA_V2.5.0.3_DP0/ directory.
Time to compile the drivers !
To compile them, we just need to run the ‘make’ command in the drivers directory as root.
It took me just shy of 12 minutes to compile the drivers on a Class 4 SD Card on a non-overclocked pi.
Once they are compiled, running ‘sudo make install’ will install the drivers into the right spot

To make sure the drivers are installed properly, we’ll load the module to make sure no errors come up.
*Note* Run this as root again

modprobe rt5370a

If no errors come up, then that’s a good sign. Check that it’s been loaded by running lsmod and checking the output.

root@raspberrypi:/home/pi# lsmod
Module Size Used by

rt5370sta 786186 0

You should see the module rt5370sta in the list there.
Lastly we’ll disable the rt2800 usb module and enable autoloading of the new rt5370sta module.
We’ll need to edit /etc/modprobe.d/raspi-blacklist.conf and add the following line to the end

blacklist rt2800usb

And then we’ll need to edit the /etc/modules file to add the new module we’ve just compiled. Just need to add the module name to the end of the file

rt5370sta

After the file has been modified, reboot the Pi and when it comes back up, run ifconfig -a and you should see something similar to the following -

eth0 Link encap:Ethernet HWaddr b8:27:eb:xx:xx:xx
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:354 errors:0 dropped:0 overruns:0 frame:0
TX packets:181 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:30609 (29.8 KiB) TX bytes:25948 (25.3 KiB)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

ra0 Link encap:Ethernet HWaddr 00:0f:54:xx:xx:xx
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:854641 (834.6 KiB) TX bytes:44800 (43.7 KiB)

Notice the ra0 rather than wlan0. This shows that the Pi is using the new rt5370sta module rather than the old rt2800usb one. You can still use the ra0 interface to connect to wireless networks like normal.

TwitterFacebookGoogle+LinkedInRedditDeliciousDiggShare

Apr 242013
 

Another update to PiParted

Fixed up non-appearing SD Cards
Also added a backup option, at the moment it can only backup ~4GB SD Cards as it reads it to ram for now. Your computer will also need at least 4 GB of ram to backup the SD Card.

Grab it here !

SHA1 Hash – 2fa25e4f9e9260a3612129a1b0291fca3e3fd628 PiParted-0.04.iso

Comments / feedback would be very welcome !

TwitterFacebookGoogle+LinkedInRedditDeliciousDiggShare

Apr 192013
 

Just finished up with PiParted v0.03

Changes -
No longer needs 4 gigs of ram as it will uncompress and image on the fly.
Tested it on a laptop with 1.5 gigs of ram and it worked ok.

Installing from SD Card -
Works with both zip and .gz file, haven’t tested properly with .tar.gz but should still work

Also checks SHA1 hash when downloaded from the Pi site.

Incremental update really.
Download it from here
SHA1 Hash –
f91e53df56aec6cc7d1b27041e0750b0f4763bfd PiParted-0.03.iso

TwitterFacebookGoogle+LinkedInRedditDeliciousDiggShare

Apr 082013
 

After some tweaking, I have improved PiParted.
Please note this is a very early testing version, so some things may break or not work properly.

Download it here !

New features -
Flash OS from zip file on SD Card:
If the SD card only has one partition, and there is one zip file on that partition, the script will use that to flash an OS on.

Reset SD Card:
This will format an SD Card back to defaults, i.e. one vfat partition.

dd will now show it’s status when it’s flashing a SD card.

I’m looking for testers, so if anyone tries this out, please give me some feedback, either on this post or in the forum thread @ http://www.raspberrypi.org/phpBB3/viewtopic.php?f=63&t=39160

TwitterFacebookGoogle+LinkedInRedditDeliciousDiggShare

Apr 022013
 

After going through the forums, I recently had an idea that hopefully will make installing distros onto an SD card much easier.

A lot of issues come from people not knowing how to do it right, e.g. just dropping the img file onto an SD card.
So I’ve customised a GParted LiveCD ISO and written up a custom script to *hopefully* install a distro straight onto an SD card.
This is a very early iteration of this idea, but hopefully will develop into something useful.

At the moment, essentially what it will do is

1. Grab the list of Distros from the RPI Download page
2. Let the user select which distro he wants to install
3. Select the Disk device that he wants to install it onto
4. dd the image onto the disk device.

Later on, I’m hoping to add more functionality including -
resizing image files
resizing sd card partitions
wiping SD cards back to a normal usable (by windows) state
Installing distributions from other sites
auto-resizing of the root partition after installing a distribution

Grab the iso from here

Feedback can be left here or on the forum topic

TwitterFacebookGoogle+LinkedInRedditDeliciousDiggShare

Mar 222013
 

Hi everyone, sorry for the lack of updates !
Been a bit busy at home but I’ll try and post up a few of my ideas in the coming weeks.
I am also running low on bandwidth :( Hopefully my blog will last until the end of the month !

At the moment I have the below ideas on my to-do list of blog posts, if anyone wants anything similar to these, please don’t hesitate to drop me a request in the comments :)

Video ideas -
Mounting a USB stick as the root partition

Post ideas -
Mounting a USB stick as the root partition
Pi as a ADSL router
Pi as a wifi client bridge
Pi as a standalone wifi point with a welcome page
Readonly Pi

I’ll keep this list updated as I think of more ideas, at least in the meantime :D

TwitterFacebookGoogle+LinkedInRedditDeliciousDiggShare

Mar 102013
 

I’ve had a few queries regarding streaming audio as well as video on the Raspberry Pi, so tonight I set up my little Raspberry Pi with a Logitech C110. This webcam also has a microphone integrated which the Pi can use to record audio.
Everything has been setup as per part 3 of my ffmpeg streaming guide.

A little investigation reveals which hardware device the microphone is recognised as.

# arecord -l
**** List of CAPTURE Hardware Devices ****
card 1: C110 [Webcam C110], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0

So the device is recognised as card 1. This comes in later when we are setting up the audio part of the streaming.

I’ve updated the webcam.sh script to reflect the fact that we are now recording sound -

ffserver -f /root/ff.conf & ffmpeg -vcodec mjpeg -v verbose -r 15 -s 176x128 -f video4linux2 -i /dev/video0 -f alsa -ac 1 -i hw:1 http://localhost:81/webcam.ffm

And I also need to update ff.conf with the new streaming settings
The Stream webcam section has now turned into this -
<Stream webcam.avi>
Feed webcam.ffm
Format avi
VideoSize 176x128
VideoFrameRate 15
VideoBufferSize 40
VideoBitRate 64
AudioBitRate 32
AudioChannels 1
AudioSampleRate 11025
VideoQMin 1
VideoQMax 20

With this configuration, I could start ffmpeg with audio and video streaming. However I could not get my laptop with vlc to connect to it for now, so I’ll have to keep investigating that.
Hopefully this helps though.


Please support the continued development of any useful scripts and tutorials that you have found useful !




TwitterFacebookGoogle+LinkedInRedditDeliciousDiggShare

Mar 102013
 

There’s been a few threads recently on the Raspberry Pi forums regarding SD Card images too big to fit on other SD cards.
So I’ve come up with a script to automatically resize SD Cards to the smallest size possible. At the moment it is Linux only unfortunately, but I may release a windows version if there’s demand.

The script can be downloaded from here

or copied and pasted from here

#!/bin/bash
# Automatic Image file resizer
# Written by SirLagz
strImgFile=$1


if [[ ! $(whoami) =~ "root" ]]; then
echo ""
echo "**********************************"
echo "*** This should be run as root ***"
echo "**********************************"
echo ""
exit
fi

if [[ -z $1 ]]; then
echo "Usage: ./autosizer.sh "
exit
fi

if [[ ! -e $1 || ! $(file $1) =~ "x86" ]]; then
echo "Error : Not an image file, or file doesn't exist"
exit
fi

partinfo=`parted -m $1 unit B print`
partnumber=`echo "$partinfo" | grep ext4 | awk -F: ' { print $1 } '`
partstart=`echo "$partinfo" | grep ext4 | awk -F: ' { print substr($2,0,length($2)-1) } '`
loopback=`losetup -f --show -o $partstart $1`
e2fsck -f $loopback
minsize=`resize2fs -P $loopback | awk -F': ' ' { print $2 } '`
minsize=`echo $minsize+1000 | bc`
resize2fs -p $loopback $minsize
sleep 1
losetup -d $loopback
partnewsize=`echo "$minsize * 4096" | bc`
newpartend=`echo "$partstart + $partnewsize" | bc`
part1=`parted $1 rm 2`
part2=`parted $1 unit B mkpart primary $partstart $newpartend`
endresult=`parted -m $1 unit B print free | tail -1 | awk -F: ' { print substr($2,0,length($2)-1) } '`
truncate -s $endresult $1


Please support the continued development of any useful scripts and tutorials that you have found useful !




TwitterFacebookGoogle+LinkedInRedditDeliciousDiggShare

Mar 042013
 

A few people wanted a 1 GB image for Raspbian Server Edition, and I finally got around to putting it together !

It’s the same 2GB image that has been repackaged into a 1GB image.
It has been resized so it should fit any 1GB SD card in existence.

You can Download it here !

SHA1 hash -
74abe17fdea4dc862e0aa6d68a33daa434934cc5 1gbRSEv2.3.img.gz


Please support the continued development of Raspbian Server Edition by donating !




TwitterFacebookGoogle+LinkedInRedditDeliciousDiggShare

Mar 042013
 

**Update**
I have now built a script to do this automatically.
The script will minimise the size as much as possible.
Script can be found here


I recently had to resize a Raspbian Server Edition image into a 1 gigabyte image. As I didn’t actually have a 1 gigabyte SD card to use as a template, I generated my own by resizing the original 2 gigabyte image.

This was done on another computer, but this can also be done on the Pi itself, and you can even flash the resulting image to an SD card if you have a USB SD Card reader on the Pi.

Also, most commands will need to be run as root, or use sudo to run the commands.

Step 1 : Mounting the image

First thing I did was make a copy of the 2gb image to work on, this is not essential if you downloaded the image originally, but I’m working on the original RSE image.

# cp RSEv2.3.img RSE1g.img

Similar to part 1, we need to mount the image via loopback.

# losetup -f --show RSE1g.img

This will mount the image file as a loopback device, and show you which one it was mounted as. By default, it should be /dev/loop0

Step 2: Resizing the Partition

Once the image is mounted, we then need to run parted on the image file, and get it to print out the current partitions.

# parted /dev/loop0
GNU Parted 2.3
Using /dev/loop0
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)

Running the print command will output the current setup.

(parted) print
Model: Loopback device (loop)
Disk /dev/loop0: 2003MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number Start End Size Type File system Flags
1 4194kB 62.9MB 58.7MB primary fat16 lba
2 62.9MB 1940MB 1877MB primary ext4

(parted)

As you can see, the 2nd partition, which is the linux partition, is 1877 megabytes. To resize the partition, we need to remove it, and recreate it with a new size.

Running the command rm 2 will remove the 2nd partition.

(parted) rm 2

To recreate it, we need to use mkpart command, and specify that we will be creating it as a primary partition, starts at 62.9MB, and ends at 900MB to give us a partition of 837 MB.

(parted) mkpart primary 62.9 900

Once the partition has been created, running print again will show us the new setup.

(parted) print
Model: Loopback device (loop)
Disk /dev/loop0: 2003MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number Start End Size Type File system Flags
1 4194kB 62.9MB 58.7MB primary fat16 lba
2 62.9MB 900MB 837MB primary ext4

We will also need to get the amount of sectors in the new partition so we can resize the filesystem to the right size later. To do that, we change the units to sectors, and then run the print command again

(parted) unit s

Now when we run the print command, the partitions will show up with sectors as the units instead

(parted) print
Model: Loopback device (loop)
Disk /dev/loop0: 3911680s
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number Start End Size Type File system Flags
1 8192s 122879s 114688s primary fat16 lba
2 122880s 1757183s 1634304s primary ext4

We’ll need to take a note of the size of the number 2 partition (1634304 sectors) and the sector size (512 bytes), and also the start of the partition (sector 122880).

Step 3: Resizing the Filesystem

Once the partition has been resized, we will then need to resize the filesystem that resides in the partition.

We need to calculate where the partition starts so we can mount the specific partition rather than the whole image. To calculate it, we take the starting sector, and multiply it by the sector size.

I’m using bc to do the calculation here

# echo '122880 * 512' | bc
62914560

So to mount the partition itself, we need to mount the image with an offset. This should mount it on /dev/loop1

# losetup -f --show -o 62914560 RSE1g.img
/dev/loop1

Before we can resize the filesystem, we need to check it for errors first. We’ll need to force it as the filesystem is meant to be clean.

# e2fsck -f /dev/loop1
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
/dev/loop1: 28754/114688 files (0.1% non-contiguous), 153181/458240 blocks

Once the filesystem has been verified as clean, we can then use resize2fs to resize the filesystem.
We will need to calculate the size of the new filesystem to resize it correctly. To do that, we need to take the size of the partition in sectors (1634304), and divide by 8 (4KB blocks divided by 512 bytes/sector), assuming we are using 4KB blocks in the filesystem.

# echo '1634304 / 8' | bc
204288

We can use resize2fs now to resize the filesystem to the correct size.

# resize2fs /dev/loop1 204288
resize2fs 1.42.5 (29-Jul-2012)
Resizing the filesystem on /dev/loop1 to 204288 (4k) blocks.
The filesystem on /dev/loop1 is now 204288 blocks long.

Once the resize is done, we can now remove all loopback devices

# losetup -d /dev/loop0 /dev/loop1

Step 4: Resize the image file

Once the resize is all completed, we just need to lop off the end of the image file that has all the free space.
Since the 2nd partition ends at the 900MB mark, we can lop it off right there with the truncate command

# truncate -s 900M RSE1g.img

The filesize will now be 900 Megabytes which is small enough to fit onto any 1GB SD Card.

TwitterFacebookGoogle+LinkedInRedditDeliciousDiggShare