Showing posts with label raspbian. Show all posts
Showing posts with label raspbian. Show all posts

Tuesday, June 12, 2018

Set date and time in raspbian

Problem

My new installation of raspbian stretch had its time off. The easiest way of setting this right I found was using timedatectl.

timedatectl
      Local time: Tue 2018-06-12 18:27:41 UTC
  Universal time: Tue 2018-06-12 18:27:41 UTC
        RTC time: n/a
       Time zone: Etc/UTC (UTC, +0000)

Network time on: yes
NTP synchronized: yes

RTC in local TZ: no

The date was correct but the actual time was off. Checking the output of timedatectl, the time zone was here off, so that was the obvious problem.

Solution

Checking the help of timedatectl quickly led to a resolution.

timedatectl -h
timedatectl [OPTIONS...] COMMAND ...

Query or change system time and date settings.

  -h --help                Show this help message
     --version             Show package version
     --no-pager            Do not pipe output into a pager
     --no-ask-password     Do not prompt for password
  -H --host=[USER@]HOST    Operate on remote host
  -M --machine=CONTAINER   Operate on local container
     --adjust-system-clock Adjust system clock when changing local RTC mode

Commands:
  status                   Show current time settings
  set-time TIME            Set system time
  set-timezone ZONE        Set system time zone
  list-timezones           Show known time zones
  set-local-rtc BOOL       Control whether RTC is in local time
  set-ntp BOOL             Enable or disable network time synchronization

  1. List the available timezones that can be set with,
    timedatectl list-timezones
    and scroll through the list to find the correct one.
  2. Set your current timezone with,
    timedatectl set-timezone Zone/City
No reboot is required, changes take effect right away.

Monday, April 7, 2014

Install Raspberry Pi without Monitor, Keyboard or Mouse

This guide walks you through how to set up your Raspberry Pi without connecting a TV or computer monitor to it at all only by the means of using an ssh tunnel and a computer. This guide is tailored for using Ubuntu linux, however other operating systems can do the same in a slightly different way.

This method can be very useful for those who do not have access to a HDMI TV or computer monitor where they could do the initial configuration for their Raspberry Pi.

This guide is based on using Raspbian Wheezy OS version 2013-12-20.

Installing on an SD Card

The steps are described at elinux.org nicely, however I would like to point out a few things here.

  1. Obtain a copy of the latest (or desired) version of raspbian.img from
    http://downloads.raspberrypi.org/raspbian/images/
    In this article I will be referring to 2013-12-20-wheezy-raspbian.zip
  2. wget  http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-12-20/2013-12-20-wheezy-raspbian.zip
  3. unzip 2013-12-20-wheezy-raspbian.zip
  4. Note: for me the SDcard was /dev/sdb. You can check yours by e.g. running gparted with

    sudo gparted

    and checking the devices. Makes absolutely sure you are using the correct one!
  5. WARNING! The command "dd" will be used here that can cause major data loss if used incorrectly. "of=/dev/sdb" must be correctly given as output destination. If you choose the wrong drive, it may overwrite everything on your computer's hard disk. In my case the command was

    sudo dd bs=1M if=2013-12-20-wheezy-raspbian.img of=/dev/sdb

    dd -calls dd file copying formatting tool
    bs=1M - Tells what block size to use. This is important!
    if=xxx - Input file
    of=xxx - Output file (again where the command will write)
  6. Flush write cache with

    sudo sync 

WARNING!
When using "dd" please make sure what you are doing. Selecting an incorrect device will lead to data loss.


Note that I have used the second latest Raspbian image as I had issues with the 2014 version with libc6, so I have decided to downgrade. You may try the latest version of course.

At this point you should be done and read to boot your Raspberry Pi for the first time. However, I would like to show how you can set up internet access right away without the need to connect the Pi to a screen. This will allow you to ssh into the device at first boot and configure from there.

Configuring Internet Access

This part depends on whether you want ethernet or wifi internet access. First, mount the newly formatted SD card's 2'nd partition, sdb2 in my case, so

sudo mkdir -p /mnt/raspberry
sudo mount /dev/sdb2 /mnt/raspberry

Open the network configuration file with

sudo nano /mnt/raspberry/etc/network/interfaces

And make it look similar to this

auto lo

#Wired interface, ethernet connection
iface lo inet loopback
iface eth0 inet static
#address 192.168.0.25
#netmask 255.255.255.0
#gateway 192.168.0.1

#Wireless interface (Wi-Pi)
auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.0.25
netmask 255.255.255.0
gateway 192.168.0.1
wpa-ssid YOURWIFISSID
wpa-psk YOURWIFIPASSWORD

#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

iface default inet dhcp

Save file with CTRL+O and exit with CTRL+X.

Explanation

These settings give a static local IP address to your Pi both to the ethernet (cable/wired) and wireless interface. A static address is useful as this will let you connect to the device always with the same IP address instead of having to search for it on the local network. If you have your Pi connected to your home router with a cable and do not use WiFi, then you don't need to configure the WiFi configuration part.

Assuming you have WPA2-PSK WiFi encryption the wpa-ssid and wpa-psk fields are correct and should be filled in with your network's credentials [2]. If you have other type of WiFi encryption on your local network, please refer to https://wiki.debian.org/WiFi/HowToUse to find the correct settings.

Of course, if your home network is different then you have to adjust the appropriate fields. The above settings are just a sample that you can use.

You are done with the most important configuration part, now the SD card can be inserted into the Pi and booted for the first time. Remove the card from your computer with

sudo sync
sudo umount /mnt/raspberry

Remove SD card and plug it into the Pi.

First Boot

If you did everything correctly, your Raspberry should boot without a problem. Wait about a minute before you would try to ssh. Then you can

ssh pi@192.168.0.25

(192.168.0.25 based on the interfaces configuration file I posted above)

Now you are presented with the terminal login. Log in with the default username and password:
username: pi
password: raspberry

The first thing you probably want to do is open raspberry config and do a few things. You can do this over an ssh tunnel with

sudo raspi-config

Raspi-config screen over an ssh tunnel

Based on what you want to do with your raspberry you can set up a range of things. What I have set up for mine:
  • Set custom hostname
  • Set GPU memory allocation to 16 as I will use the device without GUI and therefore won't need much RAM for the GPU
  • Expand partition (The image file copied to the SDcard is sized for smaller 2-4 GB card. So if your card is bigger, you should expand the partition on it to make it usable)

Add a new user instead of the default pi with

sudo adduser YOURUSERNAME

Give the password twice and fill out the additional information. Then give root permissions to this user by editing the following file

sudo nano /etc/sudoers

And look at the end of the file and append the line

#includedir /etc/sudoers.d
pi ALL=(ALL) NOPASSWD: ALL
YOURUSERNAME ALL=(ALL) NOPASSWD: ALL
This pretty much sums up the most important steps you should take when installing new a Raspberry Pi. The rest is up to you what you want to do with your device.

I like this method, because it spares me the hassle of connecting my Raspberry to a TV, attaching keyboard etc. to configure it. I also keep a second SD card installed as a backup that is just a clean install with ssh access. I had problems before with file system corruption and a quick SD card swap has saved  a lot fo problems for me.

References

[1] - http://elinux.org/RPi_Easy_SD_Card_Setup
[2] - https://wiki.debian.org/WiFi/HowToUse

Thursday, January 16, 2014

Raspberry Pi for Block Erupter Bitcoin Mining

Previously I have written about setting up Bitcoin mining with the Block Erupter in Ubuntu, however a more efficient way to mine can be to use of a Raspberry Pi to control the Block Erupter(s). The major benefit to this is the greatly reduced power consumption, provided by the Raspberry Pi compared to a desktop computer or a laptop.

Controlling the mining of a Block Erupter does not require huge amounts of system resources, so the Pi can also be used for other tasks at the same time (ssh tunnelling, small webserver and so on).

Initial Requirements and Expected Outcome

Hardware

  • Raspberry Pi (preferably model B)
  • Block Erupter (as used in this guide, but other miners should also work if connectable)
  • Powered USB hub
  • Small fan (cooling the miner, necessary for Block Erupter)

Software

  • Raspbian Wheezy (OS running on the Raspberry Pi)
  • screen
  • bfgminer 3.9 [1]

Expectation

  • Steady, reliable mining speed of 300-330 MH/s
  • Low HW errors, definitely under 1%, but better in the range of 0.4-0.6%
  • Continuous running without the need of reboot or maintenance of any sort
  • No "hungs" of the Raspberry Pi, mining and configuration to be done without physical access to the hardware after initial setu
  •  Remote access and configuration (reach the Raspberry Pi through ssh)

Installation

Installing bfgminer

I have installed the latest version (as of December 2013) of bfgminer 3.9.0. This will be the reference in this guide. If you choose to install another version, please change the commands accordingly.

  1.  ssh into the Raspberry Pi. You will need root privileges.

    ssh user@raspberrypi
  2. Installing dependencies

    sudo apt-get install build-essential autoconf automake libtool pkg-config libcurl4-gnutls-dev libjansson-dev uthash-dev libncursesw5-dev libudev-dev libusb-1.0-0-dev libevent-dev libmicrohttpd-dev hidapi libmicrohttpd-dev
  3.  Download bfgminer

    wget http://luke.dashjr.org/programs/bitcoin/files/bfgminer/3.9.0/bfgminer-3.9.0.zip
  4. Unzip

    unzip bfgminer-3.9.0.zip
  5. Cd to directory

    cd bfgminer-3.9.0
  6. Configure. Note that by default all miner configuaations are enabled, so no extra argumetns are required if building for Block Erupters. (If you would like to disable some miners because you will not be using them, check out the README file that comes with bfgminer)

    ./configure
  7. And finally make

    sudo make
Technically it is done and bfgminer can be run.Navigate to the directory and

sudo ./bfgminer -o pool:port -u usrname -p password -S erupter:all

Where "-S erupter:all"  is important as it tells bfgminer to search for all connected Block Erupters and use them for mining.

The problem of running bfgminer like this is that it is only running until you have the ssh tunnel open. Once you close it, bfgminer shuts down. Hence one would need to have a computer running 24/7 in order to keep the ssh tunnel open and contiue mining. To overcome this problem, screen will be used. [2]

Running bfgminer "as a service" with screen 

"Screen is a full-screen window manager that multiplexes a physical terminal between several processes." [3] Technically it allows to run a command in a virtual terminal window in the background, which allows running the miner in the background too without the need of a live ssh connection to the Raspberry pi.

Simply install screen with
sudo apt-get install screen

After that, running bfgminer with screen goes as the following.

Start Bfgminer
sudo screen -dmS miner ./bfgminer -o pool:port -u usrname -p password -S erupter:all

Note: that this assumes you are in the directory of bfgminer. If you want to make a general command append the route to before ./bfgminer.

This will start bfgminer in a new screen session, detached, so no output will be shown on the screen, you will be returned to the command line. Here is a short explanation what the parts of the above command do.

  • screen: start a new screen sessions
  • -dm : Start screen in "detached" mode. This creates a new session but doesn’t attach to it. This is useful for system startup scripts.
  • -S: Session name. When creating a new session, this option can be used to specify a meaningful name for the session. As above I named the session "miner", one may choose a more specific name as well.


Switch to the Screen Session 

sudo screen -dR miner

This will switch to the screen session where bfgminer is running. Here you can monitor the miner, accepted shares, stales and so on. Once you checked the miner is running OK, exit the screen session properly, without interrupting the miner!

Stop Screen Sessions

CTRL+A+D

This will properly detach the screen session, without interrupting the miner. Note if you exit the screen session with CTRL+C or exit the miner with "q", the mining will stop.

Observations

Choice of Miner

Originally I tried to make mining work with cgminer as that was more familiar to me and have been using it for quite a while. However, I have encountered several problems that I could not overcome.
I tried virtually every version of cgminer from 2.8 until the latest version to see which one works best, but none could perform reliably. Hardware errors (HW) were in the 10% range (!) which is far above the expected value. First I feared that I bought a somehow faulty chip and this was the reason for getting so many HW errors.
The miner was also somehow unstable and caused the Raspbery Pi to hung after about ~20h of running and required a maanual reboot. This was definitely not what I was looking for.

All this might not be caused by cgminer as I find it a great software for mining (works great on my computer), however I could not get it to work the way I wanted to with he raspberry Pi.

Bfgminer seems to have solved all these issues. The miner runs steady with a low ~0.50% HW error and it did not get hung so far after some extensive testing. Configuration is easy and it works pretty much "out of the box".

Pool

Some pools implement a high stratum difficulty which means that a 330MH/s miner will have a hard time submitting shares at all. I found this issue with quite a few pools. Triplemining on the other hand has a stratum difficulty of 1 and I am submitting a share about every 30-40 seconds.

Cooling and Hardware

As mentioned before in my setting up Bitcoin mining with the Block Erupter in Ubuntu article, the Block Erupter requires some cooling. Initially I wanted to add some small copper heat sinks, however this plan failed due to delayed delivery of the heat sinks. Hence I am only using a small fan directed over the Block Erupter and somewhat creating a slight air movement over the rasoberry Pi as well. See some pictures below. Not a masterpiece for sure, but runs fine and was a nice experiment!

Complete setup contained in a plastic basket

Block Erupter and the USB hub

Small USB fan (partially disassembled)
Bfgminer stats after running for 7 days


References