Sunday, 4 August 2013

How to Build CPUMINER from Source Code in Debian


cpuminer is a miner program for Litecoin and Bitcoin cryptocurrencies. It runs on CPUs (it does not need a graphic card to run).

By default it uses scrypt algorithm, but it can be configured to use SHA-256 one.


Build cpuminer from source code:


In order to build cpuminer from source code we will download its source code from its repository:
$ sudo aptitude install git
$ git clone https://github.com/pooler/cpuminer
$ cd cpuminer
$ less README

Next we install some dependencies to be able to build it.
$ sudo aptitude install automake
$ sudo aptitude install pkg-config
$ sudo aptitude install gcc
$ sudo aptitude install make

NOTE: without this package: "possibly undefined macro: AC_MSG_ERROR" error appears
$ sudo aptitude install libcurl3-gnutls-dev


Create configure and Makefile files:
$ ./autogen.sh
configure.ac:15: installing './compile'
configure.ac:4: installing './config.guess'
configure.ac:4: installing './config.sub'
configure.ac:6: installing './install-sh'
configure.ac:6: installing './missing'
Makefile.am:12: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
Makefile.am: installing './INSTALL'
Makefile.am: installing './depcomp'



Build the sources:
$ ./configure CFLAGS="-O3"

$ make

A minerd binary file appears:
$ file minerd
minerd: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=dfab35e6312ee764f4ab73e9e10e991aa998d930, not stripped


Launch minerd program:


By default it mines using scrypt algorithm:

NOTE: minerd options
-o : pool to connect to
-u : your worker name in that pool
-p : password for that worker

$ ./minerd -o stratum+tcp://stratum.give-me-ltc.com:3334 -u your_worker -p your_passwd


As an example of performance in my system:

$ grep bogo /proc/cpuinfo
bogomips : 4255.53
bogomips : 4255.90
bogomips : 4255.91
bogomips : 4255.91


4 Gigabyte of RAM.

$ uname -a
Linux debSOne 3.2.0-3-amd64 #1 SMP Mon Jul 23 02:45:17 UTC 2012 x86_64 GNU/Linux



It gets a total: 10.54 khash/s

[2013-07-01 23:09:46] Stratum detected new block
[2013-07-01 23:09:46] thread 2: 35100 hashes, 2.55 khash/s
[2013-07-01 23:09:46] thread 0: 36972 hashes, 2.69 khash/s
[2013-07-01 23:09:46] thread 1: 37452 hashes, 2.72 khash/s
[2013-07-01 23:09:46] thread 3: 35688 hashes, 2.58 khash/s


Debug option: We could supply debug option -D if we wanted to obtain more information.

$ ./minerd -o stratum+tcp://stratum.give-me-ltc.com:3334 -u worker -p password -D
+tcp://stratum.give-me-ltc.com:3334 -u foo -p bar -D
[2013-07-01 23:12:27] Binding thread 3 to cpu 3
[2013-07-01 23:12:27] Starting Stratum on stratum+tcp://stratum.give-me-ltc.com:3334
[2013-07-01 23:12:27] Binding thread 0 to cpu 0
[2013-07-01 23:12:27] Binding thread 1 to cpu 1
[2013-07-01 23:12:27] 4 miner threads started, using 'scrypt' algorithm.
[2013-07-01 23:12:27] Binding thread 2 to cpu 2
[2013-07-01 23:12:27] Stratum session id: 5048f950607f00001
[2013-07-01 23:12:27] Stratum difficulty set to 16
[2013-07-01 23:12:28] DEBUG: job_id='1372720337 724' extranonce2=00000000 ntime=51d20cd1
[2013-07-01 23:12:29] thread 3: 4104 hashes, 2.79 khash/s
[2013-07-01 23:12:29] thread 0: 4104 hashes, 2.73 khash/s
[2013-07-01 23:12:29] thread 1: 4104 hashes, 2.58 khash/s
[2013-07-01 23:12:30] thread 2: 4104 hashes, 2.38 khash/s


REFERENCE


cpuminer source code:
https://github.com/pooler/cpuminer

More optimized version of cpuminer:
https://github.com/pooler/cpuminer

8 comentarios:

Anonymous said...

Great instructions. I compiled it on a RaspberryPi under Raspbian, and get 227 khash/sec.

Not really useful at all, but interesting to tinker with.

Vicente Hernando said...

Good to know! I also have a Raspberry Pi, someday it will be fun to run cpuminer on it. :)

Michael NA said...

To the auther: Thanks for this guide I now have mining on an old Android phone running Linux that was otherwize incompatible with the apps on the market place :-D

To all that may read this that have an Android device or two and want to mine on them: First it's really not time efective on older devices and it requires "root" permissions on Android; the way I do it.
I use the "Debian Kit" app that is free on the marketplace on all my devices which provides; squeeze, wheezy and ubuntu flavors of Linux in a very friendly hybrid filesystem instead of chroot segrogated file trees. I also use the "LilDebi" app for some of my devices because it offers "hard float" Linux for compatible ARM CPUs which has some great advantiges over normal "soft float" options offered by (I think) all other similar Android apps curently out for download.

I have tested mining with a free Android app on two devices;
Sero 7" Pro (a quad core 1+ Ghrtz ARM) and received one shair after less than an hour of running 3 out of 4 of the CPUs :-) and averaged about 700 Khps
Epic 4G (a single core 1 Ghrtz ARMv7) no shaires after an hour and avareged 600 Khps
HTC myTouch 3G (a single core 600-800 Mhtz ARMv6) using Linux and the above posted guide to install minrd, no shaires just yet with an average of less than 1 Khps

I've been working on mounting USB devices to Linux running on Android so I belive it to be more than possible for anyone to up-cycle an old Android phone to run as a controller much like the Raspberry Pi comunity is doing now.

You can contact me on G+ under the name of "Michael NA" or at XDA forums or github under the name of "S0AndS0" if you nead help with Android based mining. Furthermore I write scripts for RPi and Android Linux setup of Java, Nodejs, NoFlo, Bramble, OpenStack, and others.

Thanks again for this guide. One question; are there any options in minerd to choose which processor is used and are there any tools already available to monitor CPU temp and put a "sleep/waite" on mining for a bit to cool off?


Vicente Hernando said...

Hi Michael,

thank you for your interesting comment!

Looking at cpuminer source code

It automatically detects the processor(at compilation time) and uses some assembler code to compute the algorithm.

The usage options:
-a, --algo=ALGO specify the algorithm to use
-o, --url=URL URL of mining server
-O, --userpass=U:P username:password pair for mining server
-u, --user=USERNAME username for mining server
-p, --pass=PASSWORD password for mining server
--cert=FILE certificate for mining server using SSL
-x, --proxy=[PROTOCOL://]HOST[:PORT] connect through a proxy
-t, --threads=N number of miner threads (default: number of processors)
-r, --retries=N number of times to retry if a network call fails
(default: retry indefinitely)
-R, --retry-pause=N time to pause between retries, in seconds (default: 30)
-T, --timeout=N timeout for long polling, in seconds (default: none)
-s, --scantime=N upper bound on time spent scanning current work when
long polling is unavailable, in seconds (default: 5)
--no-longpoll disable X-Long-Polling support
--no-stratum disable X-Stratum support
--no-redirect ignore requests to change the URL of the mining server
-q, --quiet disable per-thread hashmeter output
-D, --debug enable debug output
-P, --protocol-dump verbose dump of protocol-level activities
-S, --syslog use system log for output messages
-B, --background run the miner in the background
--benchmark run in offline benchmark mode
-c, --config=FILE load a JSON-format configuration file
-V, --version display version information and exit.
-h, --help display this help text and exit.

It does not appear anything about the temperature. You will have to monitor it using other ways and stop the app or whatever.

Michael NA said...

Wow, thanks for the speedy/informitive responce :-D
Here's a link to a G+ post I did a wile back on the fetures I've worked on for Android Linux and RPi
https://plus.google.com/109122627771394663675/posts/Kusytsxzhyt

I work part-time for a living so the fetures listed are constently being expanded and I write new posts on G+ when there's a magior update of fun things to play with.

Oh and no wories on the miner not tracking temps I found a few commands that I can "grep" up into a script that "pauses" spicific CPUs for a given amount of time and then duble checks the temp again befor allowing the miner to us it again.
Curently I found the "screen" comandline program to offer running and killing processes in the background wile still alowing the active user to perform other tasks or even connect into the task that "screen" is prossessing. However I'm running into issues with starting and killing tasks in one line so I'll be going over the "man" pages for that because I didn't notice any change in workflow on mining when running it through screen; well so long as I didn't do much with the device ;-)

One odd thing I've noticed so far; the device seems to be chugging along but when I check my pool acount on deepbit (I gave it a good amount of time to update befor checking) I don't see any connected workers. However when I use an Android app directly for mining I see workers connected almost emediatly... odd but not disturbing just yet... I'm using your example with my own info without any other options and like I said the device is happy.

I'll be working on editing my curent installer to include the directions in your guide (only guide to have worked so far is yours) so I can implimint on my other devices swiftly and then get to work on a script to monitor CPU temp; which if I'm really good should work on PC, RPi, and Android/Linux.

One more question for future script fetures: Is there a way to install all with apt-get or is "make" the only option for cpuminer?

MF said...

get

pt@storage01:~/cpuminer$ ./minerd --url http://work.mmcpool.com --user rWSdVd7P2T9918p -p x --threads 1
[2014-05-11 02:19:14] 1 miner threads started, using 'scrypt' algorithm.



[2014-05-11 02:19:14] JSON-RPC call failed: {
"message": "method not getwork",
"code": -1
}
[2014-05-11 02:19:14] getblocktemplate failed, falling back to getwork

[2014-05-11 02:19:14] Long-polling activated for http://work.mmcpool.com:8880/LP
[2014-05-11 02:19:14] thread 0: 12 hashes, 3.23 khash/s
[2014-05-11 02:19:14] thread 0: 12 hashes, 4.01 khash/s


AND THEN


[2014-05-11 02:25:20] JSON-RPC call failed: {
"message": "upstream RPC error",
"code": -4
}
Does anyone know whats wrong?

Vicente Hernando said...

Hi Michael NA,

I do not see any cpuminer package in debian repository. Probably it is not in ubuntu repo either.

In that case you could try to find someone who has already built a debian cpuminer package on his own.

May be this link (I have not tested it) suits you:
https://launchpad.net/~tuxsoul/+archive/ppa

Vicente Hernando said...

Hello Michael NA,

about the getwork issue, cpuminer only supports getwork protocol for pools.

If pool only supports stratum protocol you will probably need a proxy.

http://bitcoin.stackexchange.com/questions/13002/cpuminer-problem-empty-reply-from-server

https://bitcointalk.org/index.php?topic=193354.msg2287148#msg2287148