Archive for the ‘Running cgminer’ Category

Getting cgminer on an RPi

Friday, July 19th, 2013

Last updated: 15-Jul-2014

Use arch linux, get it here: Downloads. I’ve tried:

  • and

Follow the RPi SD setup/install instructions: RPi_Easy_SD_Card_Setup to create an SD ready to boot
Make sure you use a Class 10 SD card of at least 4GB
I’ve used SanDisk Ultra SDHC’s and Sony SDHC USH-I’s and so far (touch wood) had no problems with them
I’ve had plenty of trouble with Class 6 SD cards

Booting will get a DHCP IP address (check your router to find out what it got)
Login with ssh root@IP (or on windows: Putty – download ‘here’)
Login: root
Password: root
Change the password with
and remember it.

The ArchLinux install guide is here:
You can skip most of that if you want, however you should set the timezone as explained at:
Initial_Installation -> “Modify System Files”

You now want to increase the size of the system partition since it will only have about 800MB left free.
You’ll first need to work out the SD disk layout of the version of Arch you have. To see the layout:
fdisk -l

Layout “A”: ArchLinuxARM-2014.06, ArchLinuxARM-2014.01 and archlinux-hf-2013-07-22 have 1 primary, 1 extended and 1 logical partition – with the system partition being the logical partition, so it looks like 3 partitions:

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            2048      186367       92160    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          186368     3667967     1740800    5  Extended
/dev/mmcblk0p5          188416     3667967     1739776   83  Linux

Layout “B”: archlinux-hf-2013-06-06 has a layout with 2 primary partitions – the 2nd one is the system partition. It looks like:

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1   *        2048      186367       92160    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          186368     3667967     1740800   83  Linux

For Layout “A” you want to extend the “3rd” partition to the full size of the SD card, so you must also increase the size of the extended partition first then recreate the system logical partition inside the extended partition.
fdisk /dev/mmcblk0
In fdisk, just so you know, if you wish to quit without changing anything:
First look at the layout and remember the start of /dev/mmcblk0p5 (as I highlighted in red above) e.g. It may be 188416
Now delete both /dev/mmcblk0p5 and /dev/mmcblk0p2
Still in fdisk, create the new larger extended partition ‘2’ using the previous + all unused space:
Then recreate the system logical partition inside that to use all the space, starting at the same place where it did before (which will probably be the default value):
Save the changes and exit fdisk

For Layout “B” you want to extend the 2nd partition to the full size of the SD card:
fdisk /dev/mmcblk0
In fdisk, just so you know, if you wish to quit without changing anything:
To view the parition layout:
Then delete the main system partition ‘2’:
Still in fdisk, create the new larger primary partition ‘2’ using the previous + all unused space:
Save the changes and exit fdisk

Now for both Layout “A” and Layout “B”: Reboot:
(N.B. this can take a minute or 2 – be patient)

And finally log back in and resize it.
Layout “A”: resize2fs /dev/mmcblk0p5
Layout “B”: resize2fs /dev/mmcblk0p2

When editing files on linux there are a few text editors.

Two common ones people use are vi and nano.
Using vi:
Using nano:

Arch uses pacman as the package management tool: Pacman

Update the package list:
pacman -Syy

Install screen – always useful:
pacman -S screen

Install git to get cgminer:
pacman -S git

Install build tools (this will also install gcc):
pacman -S base-devel
N.B. you want the default ‘all’
“base-devel” may download around 30MiB or more of package data, so it may take a while depending upon your internet connection

Install cgminer dependencies:
Update ncurses and curl:
pacman -S ncurses curl
curl versions just below v7.34.0-3 can give an error when you use the ‘git clone’ command, so make sure it is updated. I found I had to reboot after the curl update, to fix it completely
You’ll see near the end of the pacman output “upgrading curl” if it was updated.

Install Java (non-GUI version) for the cgminer API:
pacman -S jre7-openjdk-headless

Get and build cgminer:
git clone
cd cgminer
You don’t need to have all the USB devices compiled in, but this is a useful list:
CFLAGS=”-g -W -Wall” ./ -enable-icarus -enable-gekko
Also note that the autogen command will take about 20 minutes to run on an RPi
make clean

Lastly to see that it actually runs:
./cgminer -n
will report all your recognised USB mining devices.

Now to set the RPi to always start cgminer when it starts or if the cgminer process disappears, restart it, see my git for the files and settings to do that:

If you want to use miner.php to view the status of cgminer from any web browser:
pacman -S apache php-apache

Copy miner.php from the (current) cgminer directory:
cp miner.php /srv/http/

Setup is also required after the apache install:

Edit /etc/httpd/conf/httpd.conf
About 60 lines down there is a whole selection of LoadModule commands.
At the end of the LoadModules add one more:
LoadModule php5_module modules/
Also, towards the bottom of the file is a bunch of Includes
At the top of the Includes add:
Include conf/extra/php5_module.conf

Edit /etc/php/php.ini
Search for Date and below that edit date.timezone to match your time zone and also remove the semicolon at the front, like:
e.g. date.timezone = “Australia/Perth”
The list of time zones is here: List of Supported Timezones
Search for and make sure it isn’t commented out with a semi-colon “;” in front of it.
i.e. remove the “;” if it is there at the front of the line

Enable apache to run at boot time:
systemctl enable httpd.service -system
Then start apache:
systemctl start httpd.service
If you get an error starting the web server e.g.
Job for httpd.service failed. See …:
Recently Arch decided to screw up the install of PHP and Apache so that they are two versions that no longer work together.
The fix is:
Edit /etc/httpd/conf/httpd.conf
Around line 153? search for:
LoadModule mpm_event_module modules/
and change it to:
LoadModule mpm_prefork_module modules/
Then again:
systemctl start httpd.service

To view the web page:
where of course RPiIPAddress is the IP Address of the RPi
If you’re not sure what it is, you can also get it when logged into root using:
It will be the IP address on the 2nd line after inet

You must of course start cgminer at least with -api-listen
Read API-README for more details about miner.php and the API