28 January 2018

Mining Magi Coin on the Raspberry Pi Model B Revision 1

This is how I did it. Disclaimer, I'm very new to this. Some info might be incorrect.

Setup the Pi

Download and install Raspbian Lite (Raspian without the GUI).

Add a file called ssh (no extension) to the root of the SD card. This will enable SSH at boot.

Connect the rp to a client PC over ssh.

  • Boot the rp, but don't connect anything yet
  • In the Network settings of your client PC, select Edit connections (click the network icon to access these settings)
  • Select Add
  • Select Ethernet
  • Change the connection name to something like Pi.
  • In the IPv4 Setting, set the Method to Shared to other computers
  • In the IPv6 Setting, set the Method to Ignore
  • Click Save
  • Run sudo apt-get install arp-scan on the client PC.
  • Uncheck Enable Wifi in network settings, or however you connect to the internet.
  • Plug the ethernet cable into the rp (directly connecting it to the PC client)
  • Select Pi from network tab. A confirmation message Connected to Pi should appear
  • Run sudo arp-scan -l to get the network address of the rp
  • In case you get an error (ioctl: No such device) you might have to choose your network device manually, get a list of all devices installed with this command ifconfig. Depending on this info you maybe have to specify something like eth2 Do this by altering the above command with the --interface option like this sudo arp-scan --interface eth2 -l

Now follow the security procedure here https://www.raspberrypi.org/documentation/configuration/security.md

Make other rp configurations sudo raspi-config. Select boot to console. Reduce the GPU to 16MB.

Run locale to see output from the locale list. If the first two items are missing their values, in ~/.bashrc (at the end of the script) add

LANG=en_GB.UTF-8
LANGUAGE=en_GB 

Or whatever your preferred language is. You can now connect the rp to the internet, although I ssh into it over the local network and don't open any ssh ports for external access. Run sudo apt-get update && sudo apt-get upgrade to make sure everything is updated. Reboot sudo shutdown -r now. You may also want to statically set the address of the rp on the router.

Install the cpu miner.

Modified from this guide (this guy is using a RP2): https://www.novaspirit.com/2017/10/19/crypto-mining-sbc/

Satisfy any dependencies.

sudo apt-get install automake autoconf pkg-config libcurl4-openssl-dev libjansson-dev libssl-dev libgmp-dev make g++ git libgmp-dev

Clone the git source.

git clone https://github.com/novaspirit/wolf-m7m-cpuminer

Compile the miner.

cd wolf-m7m-cpuminer 
./autogen.sh

Run the rp model B rev 1 compiler specific flags.

CFLAG="-O2 mfpu=vfp" ./configure

Modify 2 make files with rp model B rev 1 compiler specific flags

nano Makefile

Do Ctrl + w and search for march. Replace -march=native with -mcpu=arm1176jzf-s for manual cpu detection.

nano m7/Makefile

Do Ctrl + w and search for march. Replace -march=native with -mcpu=arm1176jzf-s for manual cpu detection.

Run make to build the miner.

The miner is now installed. Once you have joined a mining pool, you can run something like the the following

./minerd -a m7mhash -o urlofpool:5678 -u pool_username.worker_name -p worker_password

But I prefer to create a file called miner.sh in the home directory.

cd ~/
touch miner.sh
chmod +x miner.sh
nano miner.sh

Add (replace the tcp address and credentials with your pool's info)

#!/bin/bash 
nohup ./wolf-m7m-cpuminer/minerd -a m7mhash -o stratum+tcp://xmg.suprnova.cc:7128 -u pool_username.worker_name -p worker_password &

Using nohup <command> & allows you to log out of the ssh session and keep the miner running. Save and close the file. In .bashrc, add the alias alias magi='miner.sh', alias magi-mon='tail -f nohup.out' and alias magi-kill='pkill minerd'

You can now run the miner with magi, and monitor the miner with magi-mon, or magi-kill to end the miner process during any session. To quit magi-mon (tail output), call Ctrl + c

Get the wallet

To get a wallet receiving address (to receive mined or donated coin), you will need a wallet. For magi coin, a wallet is an application you need to install. Get it here http://www.m-core.org/download/

After installing the wallet application, you will need to get something called the blockchain to have the wallet application create your receiving address. This is a very big file and the app will try and download it by default when you launch it. However, there is a much quicker way to get this.

  • Backup wallet.dat to a safe place.
  • Download fairly recent block-chain data from here: http://m-core.org/bin/block-chain
  • Delete all of the contents in the ~/.magi folder, except for wallet.dat and magi.conf
  • Unzip the block-chain file and copy the folders under "m-block-chain" into the .magi (unix-like system) or Magi (OS X or Windows) folder
  • Launch the new wallet.

This will quickly get you a complete (but old) block-chain so the app can create you a receiving address. The app will now attempt to catch up to the latest version of the block-chain, which will help you get your latest mined coins (those coins exist on the block-chain). You can now find the receiving address in the Received tab of the wallet application.

Join a pool

The recommended way to mine magi coin is with a mining pool. Here is a list of pools https://poolinfo.systms.org I heard it's best to join a pool with a high hashrate, which is what I did. Register with one of these pools, and check out the settings in My Account > Edit Account.

Next you will need to create a worker (My Account > My Workers). Fill in the required fields and make a note of the details for the next step (the pool address). Back when we created the miner, there was some parameters you had to pass

./minerd -a m7mhash -o urlofpool:5678 -u pool_username.worker_name -p worker_password

Go to Help > Getting Started and check "Configure your miner" on that page of the pool site, and edit your miner parameters to reflect how you execute your miner on the rp.

Mine looks like

nohup ./wolf-m7m-cpuminer/minerd -a m7mhash -o stratum+tcp://xmg.suprnova.cc:7128 -u pool_username.worker_name -p worker_password &

Finishing up

Using a Raspberry Pi Model B Revision 1, I managed to get about 0.34 khash/s. For comparison, I hear a rp 2 get's about 5 khash/s and I think it even uses less power! I haven't done the math yet, but I don't think this is profitable or fast enough to be worthwhile. It has been a fun learning experience though.

No comments:

Post a Comment