Optimizing your Gridcoin Raspberry Pi experience
gridcoin·@scalextrix·
0.000 HBDOptimizing your Gridcoin Raspberry Pi experience
I have posted articles about how to [install](https://steemit.com/gridcoin/@scalextrix/how-to-install-gridcoinboinc-on-a-raspberry-pi), [control](https://steemit.com/gridcoin/@scalextrix/how-to-control-your-gridcoin-wallet-with-command-line) and [upgrade](https://steemit.com/gridcoin/@scalextrix/upgrading-your-gridcoin-raspberry-pi-node) a Raspberry Pi with BOINC/Gridcoin. If you are anything like me, after doing all that you have twitchy fingers and dont really like just looking at your Pi, whizzing away quietly making you a Gridcoin millionaire, how dull :) **WARNING: Many of these tips are on the edge of what your Pi can handle, for gods sake [backup](https://www.raspberrypi.org/forums/viewtopic.php?p=239331) your SD card and your wallet before you do these steps!!!!** **WARNING: Im just a guy who cant stop tinkering and learning as I go, if you screw it up, I might not be able to help you sort it out, this guide comes with no warranty!!!!** So what additional mischeif can we get ourselves into, here's what: # Security Your Raspberry Pi runs on Linux which is already pretty secure, but as we have currency involved we may want to go a step further. If you didnt already, please make sure you change the default password for accessing your R-Pi > sudo raspi-config  Apart from that a firewall to help stop internet nasties getting into your Pi is a good idea, there is an easy command line tool UFW that we can install > sudo apt-get install ufw Ill give you the basic commands to add rules but its worth reading [this guide](https://www.digitalocean.com/community/tutorials/how-to-setup-a-firewall-with-ufw-on-an-ubuntu-and-debian-cloud-server) Add a rule to allow you to SSH to your Pi (**if you dont add this then you will lose access to remote into your Pi!**) > sudo ufw allow 22/tcp To add the port for Gridcoin p2p > sudo ufw allow 32749/tcp To enable ufw > sudo ufw enable If you didnt screw up you still have access to your Pi and gridcoinresearchd is still connected to the blockchain. # Overclocking In my experience with Raspberry Pis, BOINC and Gridcoin, overclocking is risky and often causes more problems than it solves. However we can make sure our R-Pi is operating within its maximum parameters. To check the clock speed your Pi is running at > vcgencmd measure_clock arm  You see in that clip my Pi3 is running at 970Mhz, but in fact its capable of 1.2Ghz at maximum operation, so whats going wrong? The Pi is designed to be low power and getting it to boost to maximum CPU frequency is tricky in its default settings, you may see yours is even lower often around 600Mhz. To convince the Pi to work harder we need to change a setting that tells the CPU how to scale, the so called [scaling govenor](https://www.kernel.org/doc/Documentation/cpu-freq/governors.txt) which you can read about and play with if you like but I have found the 'conservative' setting works best (I will highlight why later). The problem with the scaling govenor is it cant be permanently changed, if you reboot the Pi the setting will be lost, but dont worry we can use the magic of 'cron' to tell the Pi to set the scaling govenor each reboot > sudo crontab -e And add this text at the bottom '@reboot echo conservative > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor' so it looks like this  CTRL X to save, now reboot your Pi, login and do > vcgencmd measure_clock arm And you should see the CPU frequency much higher (if nothing happened check that BOINC and Gridcoin are running). Now you need to be careful of your Pi overheating, the Pi3 can get very hot > vcgencmd measure_temp  I like to keep my Pi lower than 70 degrees C, in my opinion thats quite hot already. You can set a teperature limit in > sudo nano /boot/config.txt Add a line > temp_limit=70 CTRL X to save changes and reboot Now when you log back in your scaling govenor and temp limit settings should be working together nicely to strike a balance between CPU clocks and temperatures (this is why I feel the 'conservative' scaling govenor is best). I have also drilled a hole in my Raspberry Pi case and added some active cooling, as well as heat sinks which you can google for and buy cheaply online  # Improving Random Number Generation Cryptography requires random numbers to help stop things becoming predictable, in cryptocurrency this might be new key generation which effects your wallet addressing for example. Computers arent very good at generating random numbers and the Raspberry Pi is no exception, it does have a random number generator (understand more about it all [here](http://fios.sector16.net/hardware-rng-on-raspberry-pi/)) but we can help it along by installing a code that selects properly randomized numbers and keeps a pool to use: > sudo apt-get install rng-tools # Recompiling Gridcoin with custom flags OK so this is experimental, and your milage may vary or not even be detectable, but we can try to improve the overall performance of gridcoinresearchd by changing the way it compiles, what we are doing here is telling the code to be built in a manner that uses only the features available specifically on your Raspberry Pi > sudo systemctl stop griscoinresearchd.service > cd /var/lib/boinc-client > boinccmd --quit > cd > cd Gridcoin-Research/src > sudo nano makefile.unix Scroll down until you find a section xCXXFLAGS =  We can change the first argument from '-O2' to '-Ofast' and add '-mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s' so it now looks like this  CTRL X to save Then if you read the recompiling guide, we do > sudo make -f makefile.unix clean > sudo make -f makefile.unix -e PIE=1 If the re-compilation is successful > strip gridcoinresearchd > sudo install -m 755 gridcoinresearchd /usr/bin/gridcoinresearchd Now reboot your R-Pi and hopefully you have a stable, and slightly more efficient gridcoinresearchd # Move the blockchain files to an external USB drive Your Raspberry Pi uses an SD card to store everything, they can and do fail from time to time, but we can reduce the wear and tear on the SD card by storing the blockchain files on a USB drive. Insert an empty USB drive into your Pi and mount it (if you have a desktop version of raspian, you dont need to mount the drive) > sudo fdisk -l In the output look for the last entry, something like /dev/sda1  > sudo mkdir /media/disk1 > sudo mount /dev/sda1 /media/disk1 > sudo nano /etc/fstab Add the following underneath the rows already present '/dev/sda1 /media/disk1 auto defaults 1 2' :  **NOTE: My screen grab is wrong here, copy the text, not the picture** Now we need to stop Gridcoin, copy over the directory with the block-chain files and symlink (make a shortcut) so Gridcoin can find the files > sudo systemctl stop gridcoinresearchd.service > mv .GridcoinResearch /media/disk1 > ln -s /media/disk1/.GridcoinResearch .GridcoinResearch If everything went right, on rebooting your Pi it should all work. If your Pi appears not to restart properly, its probably a problem in /etc/fstab, plug your Pi into a screen via HDMI with a USB keyboard and mouse and restart it, you may see it gets stuck and goes into a recovery mode. # Well thats about all I really have not figured out any further optimizations for Raspberry Pi BOINC/Gridcoin, but if you have some, please come and share.