Install xmr-stak 2.2 in a machine with NVIDIA video card under Ubuntu 16.04 LTS

This is simple “how to” to get started mining crypto currency with explanations using cryptonight algorithm like monero, electroneum, intensecoin and more. Just follow the simple steps and you’ll have an optimized GPU and CPU miner for cryptonight crypto currencies:

STEP 1) Download latest CUDA from NVDIA site.

Open your favorite browser and go to

http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/

and search for copy the link

cuda-repo-ubuntu1604-

in our case the latest version of CUDA 9.1.85 is

http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_9.1.85-1_amd64.deb

There is also

cuda-repo-ubuntu1604_8.0.44-1_amd64.deb 4.0KB 2017-09-22 22:08
cuda-repo-ubuntu1604_8.0.61-1_amd64.deb 4.0KB 2017-09-22 22:08
cuda-repo-ubuntu1604_9.0.176-1_amd64.deb 4.0KB 2017-09-22 22:09
cuda-repo-ubuntu1604_9.1.85-1_amd64.deb 4.0KB 2017-12-02 01:29

you could try them to see if you have a better performance for your video card with some of the older CUDA platform.
So now we download the file with wget just execute

cd ~
wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_9.1.85-1_amd64.deb

STEP 2) Install the NVIDIA CUDA repository in you UBUNTU with

sudo dpkg -i /root/cuda-repo-ubuntu1604_9.1.85-1_amd64.deb
* If you encounter error

The public CUDA GPG key does not appear to be installed.
To install the key, run this command:
sudo apt-key adv –fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub

Just execute the command it says and then again, so in our case:

sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub
dpkg -i /root/cuda-repo-ubuntu1604_8.0.61-1_amd64.deb

STEP 3) Install repository for your proprietary drivers of NVIDIA video cards

sudo add-apt-repository -y ppa:graphics-drivers/ppa

STEP 4) Update all repositories to download the latest package lists

sudo apt-get update -y

STEP 5) Install the dependencies for the xmr-stak, NVIDIA video driver and NVIDIA CUDA platform5).

Install the dependencies for the xmr-stak, NVIDIA video driver and NVIDIA CUDA platform

sudo apt-get -y install libboost-all-dev libleveldb-dev libcurl4-openssl-dev libmicrohttpd-dev libminiupnpc-dev libgmp-dev  cuda nvidia-opencl-dev libmicrohttpd-dev libssl-dev cmake build-essential

You probably will see how you packet manager downloads around 851 packets and installs them all, at last you must see no errors and probably there will be double “done”

done.
done.

STEP 6) now reboot the machine to load the NVIDIA proprietary driver.

At the time of this howto we the NVIDIA driver is 390.30 (nvidia-390 (390.30-0ubuntu1)), but you can list older ones and install them to see if they are better than the last. It happens frequently an older driver (but not much old) to be slightly better in performance than the latest driver, so you can experiment with other older drivers if you like.

sudo reboot

STEP 7) Check to see if your driver is loaded properly

Execute command

dmesg|grep nvidia

Here is example output

[   14.300894] nvidia: module license 'NVIDIA' taints kernel.
[   14.310623] nvidia: module verification failed: signature and/or required key missing - tainting kernel
[   14.324753] nvidia-nvlink: Nvlink Core is being initialized, major device number 248
[   14.472502] nvidia-modeset: Loading NVIDIA Kernel Mode Setting Driver for UNIX platforms  390.30  Wed Jan 31 21:32:48 PST 2018
[   14.478643] [drm] [nvidia-drm] [GPU ID 0x0000001e] Loading driver
[   19.717917] nvidia-uvm: Loaded the UVM driver in 8 mode, major device number 247

So we finished the first stage, the preparation of your machine to install the xmr-stak. Now we move to the actual installation of the gpu mining software (and cpu mining, of course):

STEP 8)* Tune screen for better support of your scrolling history, because usually you execute the xmr-stak in screen (this step is not required for proper working of xmr-stak)

echo "termcapinfo xterm* ti@:te@" > /root/.screenrc

STEP 9) Start screen and clone the xmr-stak repository

git clone https://github.com/fireice-uk/xmr-stak

STEP 10) Compile xmr-stak with “native” optimizations for the compiler gnu gcc.

Using the -march=native ensures you have the best optimization options for processor, because the gnu gcc will autodetect all options sutable for your processor. Now there is one trick if you do not know your CUDA_ARCH, which is supported by your Nvidia video card you could skip “-DCUDA_ARCH=37” in the cmake line and to execute only “cmake ../” (most of the time this works, autodetect, but you can experiment) and after successful compiltion and execute the xmr-stak and if you get error with mismatch gencodes saying this compilation is for other sm architure, the error will output the right architecture for you, then you can recompile and rerun with “cmake -DCUDA_ARCH=../”

mkdir -p ./xmr-stak/build
cd ./xmr-stak/build
export CFLAGS="-O2 -march=native -msse3 -fomit-frame-pointer -pipe"
export CHOST="x86_64-pc-linux-gnu"
export CXXFLAGS="${CFLAGS}"
export LDFLAGS="-Wl,-O1"
#cmake -DCUDA_ARCH=37 ../
cmake ../
make -j 4

STEP 11) Execute xmr-stack, but before you must execute some tuning exports for the GPU and the linux kernel

sysctl -w vm.nr_hugepages=128
export GPU_FORCE_64BIT_PTR=0
export GPU_MAX_HEAP_SIZE=100
export GPU_USE_SYNC_OBJECTS=1
export GPU_MAX_ALLOC_PERCENT=100
export GPU_SINGLE_ALLOC_PERCENT=100
cd ./xmr-stak/build/bin
./xmr-stak 

STEP 12) When executing xmr-stak for the first time and you’ll be asked couple of questions (only the first run).

Just enter your monero (or other cryptocurrency using cryptonight algorithm like Electoneum, Intensecoin and so on), follow the questions and in our case are shown below, the question start with “-” line and my answers are the next lines, yours will be different, especially in the part of the “Pool address”, which is the address of the pool you use, the username, which is the crypto currency public address you have (now, there is a fake address, DO NOT USE IT, you’ll mine and use your resources for nothing!!! Check your public address and put it there!), the Password, which is blank or your email (some pools’ software shows better statistics with your email, not required in most cases)

Please enter:
- Currency: 'monero' or 'aeon'
monero
- Pool address: e.g. pool.usxmrpool.com:3333
11.22.33.44:7777
- Username (wallet address or pool login):
etn111111111111111111111111111111111111111111111111111111111111111111111
- Password (mostly empty or x):
mining@example.com
- Does this pool port support TLS/SSL? Use no if unknown. (y/N)
N
- Do you want to use nicehash on this pool? (y/n)
n
- Do you want to use multiple pools? (y/n)
n
Configuration stored in file 'config.txt'
-------------------------------------------------------------------
xmr-stak 2.2.0 2ae7260

Brought to you by fireice_uk and psychocrypt under GPLv3.
Based on CPU mining code by wolf9466 (heavily optimized by fireice_uk).
Based on NVIDIA mining code by KlausT and psychocrypt.
Based on OpenCL mining code by wolf9466.

Configurable dev donation level is set to 2.0%

You can use following keys to display reports:
'h' - hashrate
'r' - results
'c' - connection
-------------------------------------------------------------------
[2018-02-14 02:19:20] : Start mining: MONERO
[2018-02-14 02:19:22] : Starting NVIDIA GPU thread 0, no affinity.
[2018-02-14 02:19:22] : WARNING: No AMD OpenCL platform found. Possible driver issues or wrong vendor driver.
[2018-02-14 02:19:22] : WARNING: backend AMD disabled.
[2018-02-14 02:19:22] : Starting 2x thread, affinity: 0.
[2018-02-14 02:19:22] : hwloc: memory pinned
[2018-02-14 02:19:22] : Starting 2x thread, affinity: 1.
[2018-02-14 02:19:22] : hwloc: memory pinned
[2018-02-14 02:19:22] : Starting 2x thread, affinity: 2.
[2018-02-14 02:19:22] : hwloc: memory pinned
[2018-02-14 02:19:22] : Starting 2x thread, affinity: 3.
[2018-02-14 02:19:22] : hwloc: memory pinned
[2018-02-14 02:19:22] : Starting 2x thread, affinity: 4.
[2018-02-14 02:19:22] : hwloc: memory pinned
[2018-02-14 02:19:22] : Starting 2x thread, affinity: 5.
[2018-02-14 02:19:22] : hwloc: memory pinned
[2018-02-14 02:19:22] : Starting 2x thread, affinity: 6.
[2018-02-14 02:19:22] : hwloc: memory pinned
[2018-02-14 02:19:22] : Starting 1x thread, affinity: 7.
[2018-02-14 02:19:22] : hwloc: memory pinned
[2018-02-14 02:19:22] : Starting 1x thread, affinity: 8.
[2018-02-14 02:19:22] : hwloc: memory pinned
[2018-02-14 02:19:22] : Starting 1x thread, affinity: 9.
[2018-02-14 02:19:22] : hwloc: memory pinned
[2018-02-14 02:19:22] : Starting 1x thread, affinity: 10.
[2018-02-14 02:19:22] : hwloc: memory pinned
[2018-02-14 02:19:22] : Starting 1x thread, affinity: 11.
[2018-02-14 02:19:22] : hwloc: memory pinned
[2018-02-14 02:19:22] : Starting 1x thread, affinity: 12.
[2018-02-14 02:19:22] : hwloc: memory pinned
[2018-02-14 02:19:22] : Starting 1x thread, affinity: 13.
[2018-02-14 02:19:22] : hwloc: memory pinned
[2018-02-14 02:19:22] : Starting 1x thread, affinity: 14.
[2018-02-14 02:19:22] : hwloc: memory pinned
[2018-02-14 02:19:22] : Starting 1x thread, affinity: 15.
[2018-02-14 02:19:22] : hwloc: memory pinned
[2018-02-14 02:19:22] : Fast-connecting to 11.22.33.44:7777 pool ...
[2018-02-14 02:19:22] : Pool 11.22.33.44:7777 connected. Logging in...
[2018-02-14 02:19:23] : Difficulty changed. Now: 100001.
[2018-02-14 02:19:23] : Pool logged in.
[2018-02-14 02:19:29] : Difficulty changed. Now: 100001.
[2018-02-14 02:19:29] : New block detected.
[2018-02-14 02:19:55] : New block detected.
[2018-02-14 02:20:01] : Result accepted by the pool.

2 thoughts on “Install xmr-stak 2.2 in a machine with NVIDIA video card under Ubuntu 16.04 LTS”

Leave a Reply

Your email address will not be published. Required fields are marked *