Search

Lazy Man Joe's Ramblings

Category

Raspbian

GardenPi – a garden watering solution built on Raspberry Pi, MQTT and Home-Assistant.io [Part 4/4]

Following on from PART 3

Now that Home Assistant is aware of the Garden Zones, we can “program” some automations in Node-Red.

For now I’ve only implemented a rudimentary little flow:

  • I have 4 different flows to handle each of the zones separately, but I do make sure (manually) that they’re not conflicting with each other (i.e. 1 zone’s start-time is AFTER the end-time of the previous zone, etc.)
  • As it’s winter at the moment here in South Africa, I’ve opted to only water the garden 2 x a week and for only 10 minutes in each zone.

 

My flows looks like this:

GardenPi_NodeRed

And the schedule is as follows (currently Mondays and Thursdays):

GardenPi_Zone1_Schedule

And to make it easier for me, I used a “switch”-node to split the flow based on some logic (if the payload is “on” or “off” then go route 1 or 2)

GardenPi_Zone1_SwitchNode

For the “ON” payload, I use the “call service”-node to call the switch and switch it ON (Home-Assistant handles the mqtt messaging in the background):

GardenPi_Zone1_SwitchOn

At the end of the flow I have a “msg”-node for debugging purposes, which I will probably remove in future.

GardenPi_Zone1_Debug

So a bit of a long-winded 4-part post, but wanted to capture all the aspects of the process.

Future work will include adding some “intelligence” like checking the probability of rain, possible sensors in the ground to check humidity, etc.

Anyways – it’s been LOTS of fun and a great learning experience.

 

Advertisements

GardenPi – a garden watering solution built on Raspberry Pi, MQTT and Home-Assistant.io [Part 3/4]

Continued from PART 2

With all the puzzle pieces in place, now we can make Home-Assistant aware of the Garden Zone “switches”, so we can program and use the in automations.

In the switches.yaml file (remember I split the configuration for switches out into their own file), under the platform: mqtt section I added the Garden Zones / Switches:

platform: mqtt
name: "Garden Zone 1"
command_topic: "lazyhome/garden/output/zone1/set"
state_topic: "lazyhome/garden/input/zone1"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: true
- platform: mqtt
name: "Garden Zone 2"
command_topic: "lazyhome/garden/output/zone2/set"
state_topic: "lazyhome/garden/input/zone2"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: true
- platform: mqtt
name: "Garden Zone 3"
command_topic: "lazyhome/garden/output/zone3/set"
state_topic: "lazyhome/garden/input/zone3"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: true
- platform: mqtt
name: "Garden Zone 4"
command_topic: "lazyhome/garden/output/zone4/set"
state_topic: "lazyhome/garden/input/zone4"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: true

You can name the switch anything you want, as this will be the user-friendly name in the Home-Assistant homepage.
The important bits are the command_topic and state_topic sections – these need to align to the configuration you have on your Raspberry Pi with it’s mqtt listener.

I also created some “Groups” (groups.yaml) for Home Assistant to group my different switches into logical sections:

Geysers:
name: Geysers
entities:
- switch.bedroom_geyser
- switch.upstairs_geyser
Garden:
name: Garden
entities:
- switch.Garden_Zone_1
- switch.Garden_Zone_2
- switch.Garden_Zone_3
- switch.Garden_Zone_4

Please note that the switches have “_” to replace the spaces in the names

After updating the configuration, restart HASS and your switches should show up in it’s own group 🙂

GardenPI_Zones

And that’s it !

Home Assistant is now aware of the switches AND you can switch them using the on-screen toggles (which kicks off some mqtt messages in the background, which the Raspberry Pi picks up, switching the relevant GPIO pin, which in turn switches the relay !)

Phew !

😀

GardenPi – a garden watering solution built on Raspberry Pi, MQTT and Home-Assistant.io [Part 2/4]

So in GardenPi – PART 1 I covered the hardware & software configs to get going, but that’s not all yet 🙂

We now have a Raspberry Pi running MQTT and we can switch the GPIO pins by sending messages on the queue.

Next steps:

Connect the pins from GPIO to the relay board

This was fairly easy as the 8 port relay board I used had small pins I could connect directly via small cables from the GPIO pins
As the board also make use of 5V, I used the PWR connector (PIN 2 [5V] and PIN 6 [GND] on the Raspberry Pi) to power the relay board.
I would only be using 1 of the relays at a time, so the power usage will be minimal to draw power directly from the Raspberry Pi.

gardenpi-test-before-boxing.jpg

Make sure MQTT starts at power-on of the Raspberry Pi

To make sure we have a consistent experience, we need to make sure MQTT is started on power-on / reboot of the Raspberry Pi.
I used Supervisor for this as it makes it much easier to set up items which need to start when the Raspberry Pi is restarted.
They cover the configuration of Supervisor in the Pi-MQTT-GPIO setup instructions and I followed it – except I DID NOT set up a virtual environment, as my Raspberry Pi will be dedicated to it’s job.
Basically you install Supervisor;
Then create a /etc/supervisor/conf.d/pi-mqtt-gpio.conf file with your config information for pi-mqtt-gpio [/home/pi/config.yml].
My pi-mqtt-gpio.conf looks like this:

[program:pi_mqtt_gpio]
command = /usr/bin/python -m pi_mqtt_gpio.server /home/pi/config.yml
directory = /home/pi
redirect_stderr = true
stdout_logfile = /var/log/pi-mqtt-gpio.log

and my config.yml file looks like this:

mqtt:
host: 192.168.xxx.xxx
port: 1883
user: “xxx”
password: “xxx”
topic_prefix: lazyhome/garden

gpio_modules:
- name: raspberrypi
module: raspberrypi

digital_outputs:
- name: zone1
module: raspberrypi
pin: 5
on_payload: "ON"
off_payload: "OFF"
initial: low

- name: zone2
module: raspberrypi
pin: 6
on_payload: "ON"
off_payload: "OFF"
initial: low

- name: zone3
module: raspberrypi
pin: 13
on_payload: "ON"
off_payload: "OFF"
initial: low

- name: zone4
module: raspberrypi
pin: 19
on_payload: "ON"
off_payload: "OFF"
initial: low

digital_inputs:
- name: zone1
module: raspberrypi
pin: 5
on_payload: "ON"
off_payload: "OFF"
pullup: yes
pulldown: no

- name: zone2
module: raspberrypi
pin: 6
on_payload: "ON"
off_payload: "OFF"
pullup: yes
pulldown: no

- name: zone3
module: raspberrypi
pin: 13
on_payload: "ON"
off_payload: "OFF"
pullup: yes
pulldown: no

- name: zone4
module: raspberrypi
pin: 19
on_payload: "ON"
off_payload: "OFF"
pullup: yes
pulldown: no

4 Zones, each with settings for digital_output and digital_input.

OK – so now hardware connected and Raspberry Pi will start the PI-MQTT-GPIO listener on power-up / reboot.

Connecting the sprinklers

As I was basically replacing the controller for the sprinklers I already had in the garden, all I did was connect each of the Zones’ solenoids/valves to the relay board.
It’s fairly straightforward as you just have to remember the relay is a switch and you need to see whether you’re going to use the “Normally Open” [NO] or “Normally Closed” [NC] side of the relay. (Normally Open would mean that the switch is NOT switched on by default and when you trigger the relay, it will close the circuit; i.e. switch things ON – for Normally Closed it’s the other way round 🙂 )
I used “Normally Open” side of the relay as I wanted the Raspberry Pi to actually switch the solenoid on, which will open the valve and let the water through.
The solenoids make use of 24V AC and I already had a transformer to power them – so re-used that.

rainbird_hv

End result was enclosing the Raspberry Pi and relay board in a small housing, connected to the sprinklers in the garden.

GardenPi-Endresult

Next part we go to Home-Assistant to set up & config.

GardenPi – a garden watering solution built on Raspberry Pi, MQTT and Home-Assistant.io [Part 1/4]

We currently have an off-the-shelf garden watering solution [Hunter], but I’d like to have more control of when, etc. the irrigation is switched on.

I used the following items in my solution:

Hardware:

  • Raspberry Pi 2 B+ [using a 16GB SD card]
  • Raspberry Pi Wifi Dongle
  • 8 Port Relay board

Software:

SETUP

OS

I first started prepping my Raspberry Pi and because I’ll be running it as a headless solution, I used the latest Rasbian Lite OS [download here] (Raspbian Stretch) which doesn’t have the UI and you configure all via the command-line

  1. Using Etcher, I wrote the image onto the 16GB SD card
  2. Take your SD card and boot up the Raspberry Pi
    1. Although I am going headless, I used a keyboard and screen to configure the base OS – I need a way to configure the Wifi and the easiest is when you use raspi-config.
  3. I configured the following once the 1st boot-up was done:
    1.  sudo raspi-config 
    2. Configure your locale, timezone and keyboard layout [I use the en_ZA.UTF-8 locale settings and US keyboard layout]
    3. Also configure your Wifi settings (SSID & Password, Wifi Country)
    4. Change the network name of your Raspberry Pi (mine’s called GardenPi)
    5. I also updated the password for the default pi user (default password is “raspberry” & it’s a good idea to change it 🙂 )
    6. I then forced an update in the locale file (I’ve had some issues in the past and found if you force it, things work better)
      1.  sudo nano /etc/default/locale 
      2. Add the following:
        1. LANG=en_ZA.UTF-8
          LC_ALL=en_ZA.UTF-8
          
LANGUAGE=en_ZA.UTF-8
 
    7. I also enabled SSH as I will be using SSH to manage the RaspberryPi in future.
  4. Reboot your Raspberry Pi, log in using the pi user and the new password you configured.
  5. Check your ip address
    1.  ifconfig 
    2. My result showed my wlan0 adapter on IP 192.168.2.150
  6. You can now make this IP address (192.168.2.150) static on your router to ensure you can easily “find” your raspberry pi when you want to manage it using ssh
  7. I tested my ssh configuration from my Macbook
    1.  ssh pi@192.168.2.150 
  8. As a last step, I always check whether the latest updates are installed on my raspberrypi
    1. sudo apt-get update
      sudo apt-get upgrade

Now you can move on to the software installation !

Software

Python

OK, we 1st need python installed

sudo apt install python-pip 

PI-MQTT-GPIO

Once python is installed, you can install PI-MQTT-GPIO (it will install MQTT as part of the setup] (more details here)

pip install pi-mqtt-gpio 

As I already have MQTT running as part of the rest of my Home-Assistant.io setup, I will now only have to configure pi-mqtt-gpio to publish/subscribe to the MQTT messages.

Update your config.yml file with the necessary info, my info below (with some passwords hidden 🙂 )

NOTE – I’m only showing Zone 1 & Zone 2 settings (output & input)

mqtt:
host: mqtt-host-ip-address
port: 1883
user: "*******"
password: "*****"
topic_prefix: lazyhome/garden

gpio_modules:
- name: raspberrypi
module: raspberrypi

digital_outputs:     #used to send commands to the GPIO pins
- name: zone1
module: raspberrypi
pin: 5       #GPIO pin number - not the board pin, but the GPIO pin
on_payload: "ON"
off_payload: "OFF"
initial: low # This optional value controls the initial state of the pin
retain: yes # This option value controls if the message is retained.

- name: zone2
module: raspberrypi
pin: 6
on_payload: "ON"
off_payload: "OFF"
initial: low

digital_inputs:     #used to read status from GPIO pins
- name: zone1
module: raspberrypi
pin: 5
on_payload: "ON"
off_payload: "OFF"
pullup: yes
pulldown: no

- name: zone2
module: raspberrypi
pin: 6
on_payload: "ON"
off_payload: "OFF"
pullup: yes
pulldown: no

The GPIO pins are referenced as per the following layout:

gpiopinout

So to test PI-MQTT-GPIO, you can run it in console mode (running it from the /home/pi folder):

 python -m pi_mqtt_gpio.server config.yml 

It should show you connecting to the MQTT server, and then subscribing to the messages, etc.

Quick checklist:

  • Raspberry Pi running Rasbian Stretch Lite, with wifi dongle
  • PI-MQTT-GPIO installed (using python & pip)

In PART 2 we’ll bring is all together in Home Assistant.

 

Home-Assistant.io – Grouping your entities / switches in a logical fashion

While adding more & more switches into my Home Assistant setup, I’ve needed to group the items together in a logical manner.

I have switches controlling our geysers, general “playground” switches and I’m also implementing a solution to control our garden irrigation [details to follow soon].

I first split out the switch configuration into their own switches.yaml file:


- platform: mqtt
name: "Bedroom Geyser"
command_topic: "cmnd/Sonoff1/power1"
state_topic: "stat/Sonoff1/POWER1"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: true
- platform: mqtt
name: "Upstairs Geyser"
command_topic: "cmnd/Sonoff1/power2"
state_topic: "stat/Sonoff1/POWER2"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: true
- platform: mqtt
name: "Switch3"
command_topic: "cmnd/Sonoff2/power1"
state_topic: "stat/Sonoff2/POWER1"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: true
- platform: mqtt
name: "Switch4"
command_topic: "cmnd/Sonoff2/power2"
state_topic: "stat/Sonoff2/POWER2"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: true
- platform: mqtt
name: "Garden Zone 1"
command_topic: "lazyhome/garden/output/zone1/set"
state_topic: "lazyhome/garden/input/zone1"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: true
- platform: mqtt
name: "Garden Zone 2"
command_topic: "lazyhome/garden/output/zone2/set"
state_topic: "lazyhome/garden/input/zone2"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: true
- platform: mqtt
name: "Garden Zone 3"
command_topic: "lazyhome/garden/output/zone3/set"
state_topic: "lazyhome/garden/input/zone3"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: true
- platform: mqtt
name: "Garden Zone 4"
command_topic: "lazyhome/garden/output/zone4/set"
state_topic: "lazyhome/garden/input/zone4"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: true

I then created a groups.yaml file with the following:

Geysers:

name: Geysers
entities:
- switch.bedroom_geyser
- switch.upstairs_geyser

Garden:
name: Garden
entities:
- switch.Garden_Zone_1
- switch.Garden_Zone_2
- switch.Garden_Zone_3
- switch.Garden_Zone_4

Finally I added the following to my configuration.yaml file:

# Add switch config in separate file
switch: !include switches.yaml
# Add group config in separate file
group: !include groups.yaml

The end result looks great !

Groups.png

More info on the Home-Assistant.io GROUP option here – https://www.home-assistant.io/components/group/

Running your own Home VPN Server from a Raspberry Pi (PiVPN)

I recently installed Pi-Hole as an ad-blocking service on our home network – it’s working quite well and I’m truly impressed!

While on holiday recently I thought it would be quite “cool” to have VPN access to our network at home and came across the following article – “How to turn your Raspberry Pi into a Home VPN Server using PiVPN” using PiVPN.

Installing PiVPN on the same Raspberry Pi I’m running Pi-Hole on seemed like a good idea (and it IS a supported installation).

So needless to say, once we got back from holiday I had a quick look at the article and followed the instructions. Within a very short period of time I had a PiVPN (OpenVPN) server running on our network and just had to configure our router for port-forwarding.

I’ve also signed up for the free option from noip.com to make it easier for us to connect to our VPN at home.

NOTE: One tweak I added to our configuration was to edit the /etc/dnsmasq.conf file to ensure that when I connect to the VPN that my clients would also have ad-blocking enabled 🙂

For more detail on this, refer to the FAQ for the PiVPN software.

Installation was quick & easy!

Have fun !

Network-wide ad-blocking using a Raspberry Pi and “Pi-hole(tm)”

Ad-blocking seems to be quite a “thing” these days and I have to say that sometimes the amount of ads on web pages just gets too much !

I do understand it’s a way to get your product noticed, but some web pages have way too many ads on it 😦 and most of the time not really related to me [sorry Google/whoever for profiling me 🙂 ]

I’ve been looking around for an easy and cost-effective solution and found “Pi-hole(tm) : A black hole for Internet advertisements” 🙂

The idea is not to “hide away” (i.e. get some privacy), but rather to block ads so we don’t see them anymore.

I had a Raspberry Pi 2+ available (using it for some home automation testing) and I thought I’d give Pi-hole a go.

Pi-hole essentially runs as a DNS server on your network and block requests for known ad-serving addresses/domains.

Pi-hole can also be used as a DHCP server and in my configuration, I decided to utilize this feature as well (main reason being that my router’s configuration limits me from specifying my own DNS settings). Using DHCP on the Raspberry Pi, I can serve out IP addresses on the network and as part of the configuration, the Pi-hole server is specified as the DNS server !

Installation is very easy:

  • Install a unix based OS on your Raspberry Pi
    • I opted for the latest Raspbian Lite version (Jessie) found here
  • Once you have the basic configuration going, with your Raspberry Pi on your network and connected to the internet, you need to start the installation.
  • I used the following command (although you can get the code from GitHub & run the installer locally as well)
    • curl -sSL https://install.pi-hole.net | bash
    • This connects to the latest Pi-hole installation and runs the scripts to install it on your Raspberry Pi
  • Basically follow the instructions
    • Select the IP address you want to use (your Pi-hole server needs a static address, as you want to ensure your network clients point to it even after restarts, etc.)
    • Once installed, the installer will tell you which IP address to connect to for the web configuration and the password to use (192.168.x.x/admin)
      • It’s important to note the password as it’s only given to you once
      • If you loose it for some reason, you can only change it via command line (see notes below)
    • Configure your router DNS to point to the Pi-hole server to ensure it uses it for your network traffic OR as in my case, configure DHCP on the Pi-hole to serve the IP addresses with the DNS information.
    • Use the web interface to check the DHCP configuration, etc. and rest of the configuration (very easy to follow)

The dashboard view gives you a quick overview of the DNS blocking, requests, etc. as well as access to the settings page to configure DHCP, etc.

Pi-Hole-Dashboard_1

That’s essentially it !

Some notes:

The Web interface password is only given to you ONCE at the end of the installation – if you don’t make a note of this, you will have to use the command line on your Raspberry Pi to reset the password.

Use the following command from the command line to reset your password:

  • “pihole -a -p somepasswordhere”
  • You can also remove the password using the following command – “pihole -a -p”

Have fun !

BTW – this is an interesting article as well … “Ad-blockers might actually make it easier for advertisers to track you” – TNW

 

 

Installing a NAS on a Raspberry PI (OpenMediaVault)

It seems I’ve been on a roll the last couple of weeks/days 🙂

Recently my DROBO died and then I installed NAS4Free on my Home Server to serve our storage needs at home.

Well, we’re going on holiday soon and we need to take some of the media content we have with us !

So I had the following hardware available:

  • Raspberry Pi 3+
  • 2.5″ 500GB external drive (powered)
  • Apple TV
  • iPads
  • MacBook Air

What to do, what to do ?

🙂

Well, I tried installing Plex on the Raspberry Pi and although it worked “okay” it could not keep up with the transcoding process 😦

So I had a couple of options:

  • transcode ALL the content to something usable [very time consuming]
  • have the content available on the network and do the transcoding ON the device you’re using
    • iPad
    • OSX
    • Windows 10
    • etc.

Well, I opted for the latter (well – it’s a proof of concept at the moment)

Looking around I found the following NAS software for the Raspberry Pi (OpenMediaVault)

OpenMediaVault runs on Debian Linux (Jessie) and they have a Raspberry Pi 3 image to download (here)

Installation is fairly simple:

  • download the image
  • write it to your SD card (I recommend Etcher)
  • Boot up the Raspberry Pi and let the configuration complete
  • The setup will then tell you which IP address to connect to (in my instance it was 192.168.1.10) [I forced the Router to have a static IP address for the Raspberry Pi – makes it easier in the long-run]
  • Using your browser, connect to the IP address specified
  • Use admin/openmediavault (remember to change the password)
    • OpenVault_Login
  • Use the Web Interface to add your devices (I have an external USB drive (500GB), which I mounted)
    • OpenMediaVault_Drives
  • Once mounted, you have need to SHARE this drive on the network
  • Under Services ->SMB/CIFS you need to enable the service
  • Once enabled, go to Shares and configure the Share (defaults are fine)
    • I allowed GUEST access to make it easier and it’s contained to my local network
    • OpenMediaVault_Shares
  • That’s it !

OpenMediaVault_Stats

The plan for the holiday is to have the Raspberry Pi connected to our 3G/LTE router and use the router as a local WiFi hotspot.

With the Raspberry Pi connected directly to the router, we won’t have WiFi lag, but then we’ll be able to connect to the NAS over WiFi and AirPlay from our iPads or MacBooks to our Apple TV (3rd Gen), or lie in bed in the evening and catch-up on some series on our iPads (I recommend VLC Mobile).

We’ll use AirPlay as it looks like to easiest option at the moment to play content on the TV.

OpenMediaVault has quite a couple of plug-ins you can enable on it – one of which is a Plex Media Server.

My initial tests showed me what I suspected – the Raspberry Pi 3+ (although more powerful than previous iterations) just can’t keep up with the transcoding process – so I disabled that feature again 😦 [especially when the content is 720p or 1080p]

There are a lot of plug-ins to choose from and as I need more time to investigate, I’ll have to report back on my findings in future.

For now it seems we’re set for an OpenMediaVault-RaspberryPi-NAS configuration to stream our content to which-ever device we want 🙂

Like always – HAVE FUN !

How to install and run Raspbian Jessie from a USB stick on Raspberry Pi

UPDATE (May 2017):
This article focus on using a Raspberry Pi 2 & USB. 
If you however have a Raspberry Pi 3 and the latest version of Rasbian (Jessie April 2017 or later) then you can natively run from USB – See the documentation here on Raspberrypi.org (https://www.raspberrypi.org/documentation/hardware/raspberrypi/bootmodes/msd.md)


I have been playing around with my Raspberry Pi 2 lately and read that if you want to run some write-intensive code on the Pi (MySQL, etc.) and you have an SD card, you’re probably heading for trouble. SD cards have improved over the years, but they still suffer from having a limited write-cycle (eventually they stop working).

USB stick/drives on the other hand are quite cheap and have a much better write-cycle.

So my next “project” was trying to figure out how to run Raspbian Jessie from a USB stick.

Currently there is no way to boot directly from a USB stick on the Raspberry Pi, but this is solved by using a small SD card to bootstrap the process and point the boot-up manager to boot from the USB stick.

The following article gave me most of the information I needed, but I adapted it to my own set-up which I am documenting in this post – Install & Run Raspbian from a USB Flash Drive

My set-up:

Step 1 – Download Raspbian

Download Raspbian from the RaspberryPi website – https://www.raspberrypi.org/downloads/raspbian/

I downloaded the Raspbian Jessie Lite version as I’m planning on running a non-GUI, head-less installation.  This process will work for the full version as well.

Unzip the downloaded file to get the .img file ready to use.

Step 2 – Install Raspbian on your USB stick

I use ApplePi-Baker to make this process quick and easy.

Open ApplePi-Baker, supply your admin password (required as ApplePi-Baker needs root access behind the scenes to write the .img file, etc.)

First off, I “prep” the USB stick by formatting it

  • Select the drive (under the Pi-crust option)
  • Click on “Prep for Noobs” (basically ensuring the partitioning and formatting is done)
  • Wait for the prep to finish

Now you want to write the image file to the USB stick

  • Select the .img file (under the Pi-ingredients section)
  • Click on the “Restore Backup” option – this will write the .img file to the USB stick and may take a while to complete (5-10 mins depending on speed of USB stick)

ApplePi-Baker_1

Your USB stick is now prepped BUT you still need to configure the MicroSD card to ensure the Raspberry Pi boots from the correct drive.

Step 3 – Configure the MicroSD card

Use ApplePi-Baker to prep the SD card as well

  • Select the card in the Pi-Crust section
  • Click on “Prep for NOOBS” to partition and format it

Once formatted, you should see this drive mounted on your desktop as “RASPBERRY”

Copy all the files from the USB stick to the SD Card.

Step 4 – Change the boot path on your MicroSD card

Once you’ve completed step 3, you now need to tell the Raspberry Pi to boot from the USB stick. You do this by changing the boot path setting in the cmdline.txt file in the root of the MicroSD card.

Open the file using TextEdit and change the following:

  • root=/dev/mmcblk0p2

    to

  • root=/dev/sda2

Save the changes and eject the USB stick and MicroSD card.

Step 5 – Boot up your Raspberry Pi

Plug your MicroSD card in the slot in the Raspberry Pi and the USB stick in one of the USB ports.

Add power and wait for the Raspberry Pi to boot up 🙂

Step 6 – Housekeeping (utilising all the space on the USB stick)

To utilise all the space on the USB stick, we need to expand the partition. Normally you would make use of the raspi-config utility to expand the file system, but this does not work on USB sticks.

Log in to the Raspberry Pi (standard username: pi, password: raspberry  [change this in future :-)])

Start FDISK with the following command:

sudo fdisk /dev/sda

Press p to see all the partitions. You should have only 2.

We need to delete the 2nd partition and recreate it – BUT we need to note the start position for the sda2 partition. (write down the start position number – for me it was 131072)

Press d and then 2, then ENTER. [this will delete the partition]

Now we need to create the partition again.

Press n, then p, then 2 and then ENTER.

Provide the start position (first sector) for partition 2. (for me it was 131072)

For the end position, just hit ENTER to use the full partition.

Press w to commit the changes. You will see a message about the table being in use, etc. but don’t worry about it.

Reboot the system to start using the updated partition info.

sudo reboot

Once rebooted, we need to resize the partition to use the full amount of space.

sudo resize2fs /dev/sda2

Once it’s done, reboot your Raspberry Pi again.

Confirm that the changes have taken effect by checking the space allocated using:

df -h

That’s it !

You are now running Raspbian Jessie from a USB stick (using the SD card to inform the Raspberry Pi to boot from the USB stick :-))

Have fun !

Create a free website or blog at WordPress.com.

Up ↑