Category Archives: Raspberry_PI

Disclaimer: Raspberry PI is using the Micro SD Card to keep the OS files (I’m using Raspbian Jessie) and unfortunately the card storage solution isn’t 100% reliable because of card data corruption. It’s happening rarely, but is happening. Details how to minimize the risks here. All my important files are stored on an external 3.5 HDD with own power source.

Initial steps

Insert a new Micro SD Card into your computer and write the Raspbian image to your card. I’m using OSX so the quick steps are:

Shell

1

2

3

sudo diskutil list->identity your disk#

sudo ddbs=1mif=2017-04-10-raspbian-jessie-lite.imgof=/dev/rdisk2

sudo touch/Volumes/boot/ssh->enable ssh on your raspberry pi

We’re ready to unmount the card from your computer and install it in the raspberry pi. Please make sure you connected the network (I prefer wired but wireless is available too) and your Raspberry Pi is powered by min 2.5A (I’m using a cell phone quick charger and that could explain why I’m having card corruption issues). You can find a genuine power supply here.

We’re ready to ssh on our raspberry pi. I’m using a static IP based on MAC address so it’s easy for me to ssh on that IP. There are plenty of tools to scan your network and find the ip of your raspberry pi (a quick one is to use nmap -v -sn 192.168.0.0/24). My IP is 192.168.0.112.

I’m connecting to my raspberry pi and first I change the default password and create a new user. Then I run raspi-conf to customize the current installation (eg. timezone, setting hostname, set locale (en_US.UTF-8), expand the boot partition)

Shell

1

2

3

4

ssh pi@192.168.0.112(defaultpassword:raspberry)

passwd->change pi password

sudo adduser iulian->confirm the details

sudo raspi-config

I’m adding my user to sudo group

Shell

1

sudo usermod-aG sudo iulian

Fix mirror for apt-get (Optional)

If apt mirror is causing issues when doing the update the quick workaround I’m applying is:

1.Open /etc/hosts file with sudo rights $sudo nano /etc/hosts

2.Paste the following lines at the end of /etc/hosts file.

Shell

1

2

93.93.128.193mirrordirector.raspbian.org

93.93.128.191archive.raspbian.org

The next step is to ssh with my new user, update my apt repos and start installing packages.

Shell

1

2

3

4

ssh iulian@192.168.0.112

sudo apt-getupdate-y

sudo apt-getupgrade-y

sudo apt-getinstall vim

Updating Firmware (Optional)

Your Raspbian installation also included a pretty recent copy of the Raspberry Pi firmware. However, sometimes there are important updates, so I recommend to use the latest firmare version:

Shell

1

2

3

sudo apt-getinstall rpi-update-y

sudo rpi-update

sudo reboot

Mount external drive

In order to achieve the goal #1 we’ll need to opt for an external HDD drive (I’m using a 2 TB drive, external power supply) formatted as ext4. You can find your external drive by running below command:

Mount entry in the “/etc/fstab” file shall make this mount permanent across reboot. Reboot and to check if the external disk is mounted in the /nas location.

Shell

1

2

3

4

sudo reboot

sudo lsblk-f-oNAME,LABEL,SIZE,FSTYPE,MOUNTPOINT

df

sudo mount-a

Now we have assigned a fixed mount point for the external disk drive, which is available under “/nas” directory in our raspberry pi device.

In case our external connected usb disk takes a long time to initiate this automount might fail and you may need to initiate the system mount at a later time. Adding an entry to /etc/rc.localcan do the trick. Add below lines before exit line:

Shell

1

2

3

sleep30

sudo mount-a

exit

Install and configure samba

Shell

1

2

sudo apt-getinstall samba-y

sudo apt-getinstall samba-common-bin-y

We’ll use the folder “/nas” where our 2TB external drive is mounted. We’ll share “/nas” using samba. To do this, we need a samba account in our raspberry Pi. We’ll use the user account “iulian” in this case. Enter the following command and type in a password to set the samba password for “iulian” user:

Shell

1

sudo smbpasswd-aiulian

The password you set for your samba share will not affect your login to Raspberry Pi over ssh.

Let’s backup the original smb.config file.

Shell

1

2

sudo cp/etc/samba/smb.conf/etc/samba/smb.conf.orig

sudo vim/etc/samba/smb.conf

Add the following section in the smb.conf file:

Shell

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

security=user

//your shared definition

[nas]

comment=Nas share

path=/nas

browseable=yes

writeable=yes

only guest=no

create mask=0777

directory mask=0777

public=no

readonly=no

force user=root

Restart samba service:

Shell

1

sudo/etc/init.d/samba restart

Check if samba service is enabled on startup, so that the service starts on reboot (usually it is)

Shell

1

2

3

4

5

sudo service--status-all|grepsamba

pi@nas:~$sudo service--status-all|grepsamba

[+]samba

[+]samba-ad-dc

The “[ + ]” indicates the service is active on startup.

You can mount your /nas folder to your local computer and check if the share works as you expect.

Installing nginx and configure reverse proxy

Nginx is a light and modern web server and fits perfectly our raspberry pi configuration.

Shell

1

2

sudo apt-getinstall nginx

sudo/etc/init.d/nginx start

You should be able to see nginx is up and running by opening your local browser with http://192.168.0.112 (raspberry pi assigned ip).

Install PHP 7 (optional)

Raspbian being based on Debian Jessie ships with PHP 5.6 by default. But we want to run the latest PHP version. To install PHP 7 on Raspbian we must switch to the testing branch of Raspbian, commonly known by the codename stretch.

By adding this all installs or updates will default to use the newer versions of files available in the stretch release which is not considered 100% stable. To prevent that, we’ll pin all packages to use the jessie release with a higher priority by default. To do this create a preferences file: