Update the Firmware on a Raspberry Pi

Updating the Raspberry Pi firmware is easy thanks to a nice utility called rpi-update included by default in Raspbian but I’ve also included an extra step for those of us who use other distributions for the Raspberry Pi like Minibian(my favorite), Kali Linux, etc… Understand that rpi-update is automated and once executed it will download and install the firmware without any user input. Upgrading the firmware takes less than a minute, however the install might take longer depending on your Internet connection.

The three steps below are included because rpi-update is not included by default in other distributions. Update and upgrade the system. First update and upgrade the OS.

sudo apt-get update
sudo apt-get upgrade

Install rpi-config from the repository.

sudo apt-get install rpi-update

Update the Firmware

Rpi-update is automated and once executed it will download and install the firmware without any user input. Upgrading the firmware takes less than a minute, however the install might take longer depending on your Internet connection. Sit back and watch the process.

root@raspberrypi:~# sudo rpi-update

*** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
*** Performing self-update
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 9823 100 9823 0 0 1837 0 0:00:05 0:00:05 --:--:-- 34346
*** Relaunching after update
*** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
*** We're running for the first time
*** Backing up files (this will take a few minutes)
*** Backing up firmware
*** Backing up modules 3.18.7-v7+
*** Downloading specific firmware revision (this will take a few minutes)
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 168 0 168 0 0 419 0 --:--:-- --:--:-- --:--:-- 585
100 46.1M 100 46.1M 0 0 448k 0 0:01:45 0:01:45 --:--:-- 565k
*** Updating firmware
*** Updating kernel modules
*** depmod 3.18.11+
*** depmod 3.18.11-v7+
*** Updating VideoCore libraries
*** Using HardFP libraries
*** Updating SDK
*** Running ldconfig
*** Storing current firmware revision
*** Deleting downloaded files
*** Syncing changes to disk
*** If no errors appeared, your firmware was successfully updated to 5b0cbedacf45e111f02d925fa5b1cec9041fb279
*** A reboot is needed to activate the new firmware

Reboot the Raspberry Pi for the new firmware to take effect.

root@raspberrypi:~# sudo reboot

Let’s check again to see what the Raspberry Pi has to say about the new firmware.

root@raspberrypi:~# sudo rpi-update

*** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
*** Performing self-update
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 9823 100 9823 0 0 54727 0 --:--:-- --:--:-- --:--:-- 79861
*** Relaunching after update
*** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
*** Your firmware is already up to date

Your Raspberry Pi in now running the latest firmware.

Expand the Root Partition in Kali Linux for the Raspberry Pi

By default when Kali Linux for the Rapsberry Pi is installed the file system will only expand to occupy 3GB of storage, in my case I have a 16GB Micro SD card in my Raspberry Pi 2 with most of its capacity unused. One can easily expand the file system by making use of a script that automatically does the job for you.

File system after install.

root@kali:~# df -h

Filesystem      Size  Used Avail Use% Mounted on
rootfs          2.9G  1.5G  1.2G  56% /
/dev/root       2.9G  1.5G  1.2G  56% /
devtmpfs        460M     0  460M   0% /dev
tmpfs            93M  468K   93M   1% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           186M     0  186M   0% /run/shm

I should note I did not create the script and found it at the following address http://www.raspberryvi.org/wiki/doku.php/raspi-expand-rootfs but it has proven useful.

Download the script into the boot directory. Locally hosted.

root@kali:~# wget -O /boot/raspi-expand-rootfs.sh http://dl.linhost.info/file1/raspi-expand-rootfs.sh

Now we make the script executable.

root@kali:~# chmod +x /boot/raspi-expand-rootfs.sh

And execute the script. Don’t be scared by the output.

root@kali:~# sh /boot/raspi-expand-rootfs.sh
Command (m for help):
Disk /dev/mmcblk0: 15.9 GB, 15931539456 bytes
4 heads, 16 sectors/track, 486192 cylinders, total 31116288 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000697c0

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1               1      125000       62500    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          125001     6143999     3009499+  83  Linux

Command (m for help): Partition number (1-4):
Command (m for help): Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): Partition number (1-4, default 2): First sector (125001-31116287, default 125001): Last sector, +sectors or +size{K,M,G} (125001-31116287, default 31116287): Using default value 31116287

Command (m for help):
Disk /dev/mmcblk0: 15.9 GB, 15931539456 bytes
4 heads, 16 sectors/track, 486192 cylinders, total 31116288 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000697c0

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1               1      125000       62500    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          125001    31116287    15495643+  83  Linux

Command (m for help): The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
update-rc.d: using dependency based boot sequencing
update-rc.d: warning: default start runlevel arguments (2 3 4 5) do not match resize2fs_once Default-Start values (2 3 4 5 S)
update-rc.d: warning: default stop runlevel arguments (0 1 6) do not match resize2fs_once Default-Stop values (none)
Root partition has been resized. The filesystem will be enlarged upon the next reboot

It is necessary to reboot the OS for the changes to take effect.

root@kali:~# reboot

Once again us the df command to verify the file system successfully expanded.

root@kali:~# df -h

Filesystem      Size  Used Avail Use% Mounted on
rootfs           15G  1.5G   13G  11% /
/dev/root        15G  1.5G   13G  11% /
devtmpfs        460M     0  460M   0% /dev
tmpfs            93M  468K   93M   1% /run
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           186M     0  186M   0% /run/shm

If you like you can remove the script from the /boot directory.

root@kali:~# rm /boot/raspi-expand-rootfs.sh

Auto Mount USB Drives in Raspbian

Update and upgrade the Raspbian installation.

sudo apt-get update && sudo apt-get upgrade

Install the package necessary to automatically mount USB drives.

sudo apt-get install usbmount

Now plug a USB drive and issue the df command to view all volumes. My USB drive was recognized /dev/sdb and mounted as /media/usb0 by the system.

df -hT
pi@raspberrypi ~ $ df -hT
Filesystem     Type      Size  Used Avail Use% Mounted on
rootfs         rootfs    2.9G  2.6G  215M  93% /
/dev/root      ext4      2.9G  2.6G  215M  93% /
devtmpfs       devtmpfs  460M     0  460M   0% /dev
tmpfs          tmpfs      93M  256K   93M   1% /run
tmpfs          tmpfs     5.0M     0  5.0M   0% /run/lock
tmpfs          tmpfs     186M     0  186M   0% /run/shm
/dev/mmcblk0p1 vfat       56M   15M   42M  26% /boot
/dev/sdb1      vfat      2.0G  200M  1.8G  11% /media/usb0

To un-mount a volume make use of the df command above to discover the USB drive mount point and issue the unmount command as follows.

sudo umount /media/usb0

Upgrade Ubuntu 14.10 to 15.04

You can view your version of Ubuntu with the following command.

lsb_release -a
user@ubuntu:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.10
Release:        14.10
Codename:       utopic

Update and upgrade the system.

sudo apt-get update
sudo apt-get upgrade

If not already installed, then install the update-manager-core package from the repository.

sudo apt-get install update-manager-core

Start the upgrade tool.

sudo do-release-upgrade

Now follow the prompts to complete the upgrade to Ubuntu 15.04. Read the instructions carefully.

Verify the upgrade was successful with the help of the lsb_release command.

lsb_release -a
user@ubuntu:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 15.04
Release:        15.04
Codename:       vivid

Wget Ignore Invalid SSL Certificates

This is more of a note to my self since I tend to easily forget how to tell Wget to skip certificate checks on self signed addresses.

The added parameter below is self explanatory, it tell Wget to ignore the cert check and go ahead.

wget --no-check-certificate https://ididntpayforacert.ca/file.gz

If you frequently work with self-signed certificates then you can make a change to the Wget config file to let you work with self-signed certificates without resulting in an error.

nano $HOME/.wgetrc

And add the following parameter to the bottom of the config file.

check_certificate=off

Ubuntu Server 14.04 Static IP configuration

In order to set up static IP configuration in Ubuntu 14.04 you need to edit the /etc/network/interfaces file.

sudo nano /etc/network/interfaces

You can remove the content referring to the previous DHCP configuration and add the parameters below. Change the addresses below to fit your needs.

# 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 primary network interface
auto eth0

# Static IP configuration
iface eth0 inet static
address 192.168.1.5
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
dns-nameservers 8.8.4.4

You don’t have to restart the system instead restart the networking service.

sudo service networking restart

Ubiquiti EdgeRouter Firmware Upgrade

EdgeOS firmware can be downloaded from the Ubiquity download page. First we need to see the installed version.

admin@ubnt:~$ show version
Version:      v1.2.0
Build ID:     4574253
Build on:     06/26/13 12:48
Copyright:    2012-2013 Ubiquiti Networks, Inc.
HW model:     EdgeRouter Lite 3-Port
HW S/N:       -------------
Uptime:       14:53:51 up  4:00,  2 users,  load average: 0.00, 0.02, 0.00

I like EdgeOS because you can pull the image directly into the router via HTTP. Alternatively you can download the image into a local webserver(like I did) and install from there. After the download is complete installation will begin.

admin@ubnt:~$ add system image http://192.168.1.5/ER-e100.v1.5.0.4677648.tar
Trying to get upgrade file from http://192.168.1.5/ER-e100.v1.5.0.4677648.tar
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 68.9M  100 68.9M    0     0  7837k      0  0:00:09  0:00:09 --:--:-- 6334k
Download suceeded
Checking upgrade image... Done
Preparing to upgrade... Done
Copying upgrade image... Done
Removing old image... Done
Checking upgrade image... Done
Finishing upgrade... Done
Upgrade completed

The image has been installed but its not running yet, we need to reboot the router for the new image to become the default.

admin@ubnt:~$ show system image
The system currently has the following image(s) installed:

v1.5.0.4677648.140620.1301     (default boot)
v1.2.0.4574253.130626.1248     (running image)

A reboot is needed to boot default image

Simply reboot and the new image will become the default boot.

admin@ubnt:~$ reboot
Proceed with reboot? [confirm]

Verify the router is running the recently installed image.

admin@ubnt:~$ show version
Version:      v1.5.0
Build ID:     4677648
Build on:     06/20/14 13:01
Copyright:    2012-2014 Ubiquiti Networks, Inc.
HW model:     EdgeRouter Lite 3-Port
HW S/N:       -------------
Uptime:       15:01:36 up 1 min,  1 user,  load average: 0.78, 0.30, 0.11

Optional commands

EdgeOS can store two images in the event you need to revert to a previous version.

admin@ubnt:~$ show system image
The system currently has the following image(s) installed:

v1.5.0.4677648.140620.1301     (running image) (default boot)
v1.2.0.4574253.130626.1248

You can also delete one of the image.

delete system image

Download Test Files

While this isn’t a definitive test of available bandwidth it should help you form an idea of what an Internet link throughput is. wget -O /dev/null avoids skewed results caused by disk performance limitations.

CacheFly
Location: CDN

wget -O /dev/null http://cachecefly.cachefly.net/100mb.test

SoftLayer
Location: USA and Amsterdam

wget -O /dev/null http://speedtest.dal01.softlayer.com/downloads/test100.zip
wget -O /dev/null http://speedtest.sea01.softlayer.com/downloads/test100.zip
wget -O /dev/null http://speedtest.ams01.softlayer.com/downloads/test500.zip

Linode
Location: USA, UK, and Japan

wget -O /dev/null http://speedtest.tokyo.linode.com/100MB-tokyo.bin
wget -O /dev/null http://speedtest.london.linode.com/100MB-london.bin
wget -O /dev/null http://speedtest.newark.linode.com/100MB-newark.bin
wget -O /dev/null http://speedtest.atlanta.linode.com/100MB-atlanta.bin
wget -O /dev/null http://speedtest.dallas.linode.com/100MB-dallas.bin
wget -O /dev/null http://speedtest.fremont.linode.com/100MB-fremont.bin

Leaseweb
Location: USA and Netherlands

wget -O /dev/null http://mirror.nl.leaseweb.net/speedtest/1000mb.bin
wget -O /dev/null http://mirror.us.leaseweb.net/speedtest/1000mb.bin

FDCServer
Location: USA

wget -O /dev/null http://lg.denver.fdcservers.net/100MBtest.zip

OVH

Location: France

wget -O /dev/null http://proof.ovh.net/files/100Mb.dat

Automatically Mount A USB Drive In Ubuntu Server

USB drives can be easily and automatically mounted on Ubuntu Server with the help of USBmount which is available from the Ubuntu and Debian repositories. Fortunately, USBmount requires little configuration in order to work. The following was tested in Debian 7 Wheezy and Ubuntu 13.04.

Installation and Configuration

Make sure you run apt-get update/upgrade before starting the tutorial.

sudo apt-get update
sudo apt-get upgrade

Now install USBmount from the repositories.

sudo apt-get install usbmount

USBmount mounts all USB drives in /media/usb*.

Now plug a USB drive and wait for it to be detected and mounted. As long as the host OS supports the File System it should be mounted.

To verify whether the USB drive was mounted correctly you can use df -h to view all available drives and their respective mount points. My 4GB USB drive is accessible from the /media/usb0 mount point.

user@debian:~$ df -h
Filesystem                                              Size  Used Avail Use% Mounted on
rootfs                                                   49G   18G   29G  38% /
udev                                                     10M     0   10M   0% /dev
tmpfs                                                   100M  432K  100M   1% /run
/dev/disk/by-uuid/af874479-b4ee-4d83-a3da-d2fdb48511ea   49G   18G   29G  38% /
tmpfs                                                   5.0M     0  5.0M   0% /run/lock
tmpfs                                                   404M     0  404M   0% /run/shm
/dev/sdb1                                               138G   14G  118G  11% /media/hdd1
/dev/sdc1                                               3.8G  6.6M  3.8G   1% /media/usb0

To un-mount a drive you can use umount.

sudo umount /media/usb0

Conclusion

USBmount is quite handy for mounting USB drives with no effort.