XMRig

From LinuxReviews
Jump to navigationJump to search
Currency-icon.png

XMRig is a crypto currency mining program for crypto currencies like Monero (XMR). Many anti-virus scanners consider it to be malware. If you have found it on your system and you are wondering what it is malware then it is likely a part of a malware infection. Xmrig supports mining using the RandomX, CryptoNight, AstroBWT and Argon2 algorithms. It can mine using both the CPU and the GPU depending on what algorithms is used.

XMRig is free software under the GNU GPL v3. It is available for Linux and Windows..

Is XMRig Malware?[edit]

XMRig itself is not malware. It is a legitimate program for mining cryptocurrencies such as Monero (XMR). You would know if you downloaded it and installed it yourself because you actually want to mine crypto currency.

Many malware creators, operators of large botnets and others with a slightly defective moral compass bundle a variation of the xmring binary or build it into their malware in order to use other peoples computers to mine cryptocurrency without their permission. Most commonly used anti-virus software consider XMRig to be malware because of the large amounts of computers that are infected with malware bundling it in the wild. Many host blacklist files include cryptocurrency mining pools for the exact same reason.

If you have wound a xmring binary on your machine and you are wondering what it is and you think it may be malware then the answer is yes, it is a part of hostile malware and you should get rid of it. You will not randomly find xmrig on your machine for any legitimate reason (you would know what it is if you installed it yourself).

Do note that xmring is just a cryptocurrency mining program some malware bundle to use your computer for mining purposes. Removing the xmring binary will not remove or solve the actual malware infection, the unexpected presence of xmrig is only a symptom. You need to identify and eradicate the actual malware binaries to solve your underlying problem.

Features[edit]

XMRig can be used to mine any currency using one of these algorytms:

  • AstroBWT
  • Argon2
  • CryptoNight
  • KawPow
  • RandomX

XMRig supports mining using both the CPU and, on non-Linux platforms, the GPU (using OpenCL). It is not possible to mine all the currencies it supports on the GPU. Most will work on Windows. XMRig does not support the popular ROCm OpenCL implementation that is widely used on GNU/Linux. It will also not work with the Clover OpenGL implementation that comes with Mesa since Clover is limited to OpenCL 1.1. Do not expect to be able to use XMRig to do anything with your GPU.

Installation[edit]

Most distributions do not have XMRig in their repositories. Building it from the source found at github.com/xmrig/xmrig.git is quite easy. You will need to install a few dependencies. These can be installed on Fedora with:

sudo dnf -y install git cmake gcc-c++ libuv-devel libmicrohttpd-devel hwloc-devel libstdc++-static

The build process is a very strait forward standard cmake process once you have the dependencies:

git clone https://github.com/xmrig/xmrig.git
cd xmrig;mkdir build;cd build
cmake ..
make

The only binary you need will be xmrig created in the build/. You can simply copy that to $HOME/bin or somewhere else in your $PATH.

Do note that XMRig 6.10.0 will, by default, donate 1% of your mining revenue to the developers (it used to be 5% and README.md still says it is 5%). How much CPU-time XMRig donates to the developers can be configured with the --donate-level option but it can not be set to 0% unless you change the header file src/donate.h. You can set a zero donation rate with --donate-level 0 if you change kDefaultDonateLevel and kMinimumDonateLevel in src/donate.h before you compile:

File: src/donate.h
constexpr const int kDefaultDonateLevel = 0;
constexpr const int kMinimumDonateLevel = 0;

Both of those values are, by default, set to = 1;.

Mining Monero (XMR) with XMRig[edit]

Xmrig-5.11.2.jpg
XMRig mining Monero currency.

Mining a currency like Monero with XMRig is fairly easy. You will have to specify a mining pool with -o, specify the number of threads you want with -t, specify a user-name or payment address with -u and optionally ask it to send keep-alive pings with -k. Most pools will also require you to use --tls. You can use --rig-id to give a string you can use to identify individual computers when you look at mining pool statistics.

Many major pools, like the Monero minexmr.com mining pool, ask you to use a payment address as your user-name. This avoids having to register any user-account with the mining pool.

XMRig has a special option called --cpu-affinity which specifies what CPU cores should be used if you limit the number of threads with -t. Ryzen processors on GNU/Linux will have their real cores as the first available threads and shared threads as the last. "Cores" 0-5 will be real cores on a Ryzen CPU while 6-11 will be threads on cores 0-5. Specifying --cpu-affinity 0xFF says that the first cores should be used, not randomly chosen cores. Adding -t 6 --cpu-affinity 0xFF will make XMRig use 6 total threads with one thread on each actual CPU core. XMRig does not benefit from using all available system threads, it performs best if it only uses one thread per real CPU core.

Processors with real cores sharing integer cores, like the AMD A8-7600 Radeon R7, perform best sith "--cpu-affinity 0x5". That value specifies that every other CPU core is used (0x5 means cores 0,2,4,6, 0xF means cores 0,1,2,3)

You can use mpstat to check what CPU cores are actually used by a program like XMRig with mpstat -P ALL 1

Putting that together, if you placed xmrig in $HOME, gives this command that could be used to CPU-mine Monero with the minexmr.com mining pool:

$HOME/bin/xmrig --donate-level 1  -t 6 --cpu-affinity 0xFF -o pool.minexmr.com:443 -u 8756rMjt954avBzXXR1rh9HtGij1vPmNC2KymseuuL8xaiimYTgjqEgBkwMo7YavvdVqAU9nF45Q6BiCH7dbR3FHCW5zXQA --rig-id Rainbox -k --tls

All of the above could, instead, be placed in a simple script like this:

File: bin/mine-xmrig-monero.sh
#!/bin/bash

POOL=" pool.minexmr.com:443"
PAYTO="8756rMjt954avBzXXR1rh9HtGij1vPmNC2KymseuuL8xaiimYTgjqEgBkwMo7YavvdVqAU9nF45Q6BiCH7dbR3FHCW5zXQA"
RIG="keumjo"
CPUS="2"
EXTRA="--cpu-affinity 0xFF"

if [ "$1" == "" ]; then
  THREADS=${CPUS}
else
  THREADS=${1}
fi

$HOME/bin/xmrig --donate-level 1  -t ${THREADS}  ${EXTRA} \
  -o ${POOL} -u ${PAYTO} --rig-id ${RIG} -k --tls

Make sure you change payment address to something you control. You may also want to change the mining pool.

You can use the amount of CPU cores you want (ab)used by specifying a number to the above script. This is useful if you want to limit it to 2 cores when you are using the computer and switch to 5 or 6 when you are not.

Increasing The Hashrate With Huge Pages[edit]

XMRig performs better when it has huge memory pages available to it. Linux users can make them available by specifying a vm.nr_hugepages=X where X is the number of huge memory pages you want to reserve. Enough for XMRig can be temporary be created with:

sudo sysctl -w vm.nr_hugepages=1536

Huge pages can be made permanently available with:

echo "vm.nr_hugepages=1280" > /etc/sysctl.d/60-hugepages-for-xmrig.conf

Increasing The Hashrate By Changing MSR Registers[edit]

XMRig will try to change some MSR registers when it launches. These changes will only be applied if it is ran as root. It will otherwise print out a message saying:

FAILED TO APPLY MSR MOD, HASHRATE WILL BE LOW

if it fails to apply model-specific registers (MSR) on the CPU it detects. This warning can be grossly misleading, the hashrate will, in fact, not be low without the "MSR MOD" applied if you have a AMD Ryzen CPU. It can make a difference on some Intel CPUs, but the hashrate will not be "low" there either.

The average hash rate over a 10 hour period shows that the MSR MOD does give a slight improvement, but it is very small.

Ryzen 2600 with vm.nr_hugepages=1280
-t 7 --cpu-affinity 0xFF

There is a small improvement if you run xmrig as root and the MSR mod is applied, but the difference isn't huge. It is a stretch to call the barely smaller hash rate without the MSR mod "low" on Ryzen CPUs - though the difference may be bigger on Intel chips.

Hardware Requirements[edit]

XMRig can be used on any old computer but it will not be profitable. Newer machines and faster computers will generally give you a higher hashrate and, more importantly, more hashes per watt.

Some mining algorithms have special requirements. The randomX algorithm used to mine Monero requires 2 MB cache per CPU thread for anything but dismal performance. This requirement is more important than the CPU clock speed of other factors when XMRig uses the randomX algorithm. As an example, the Ryzen 5 2400G is only equipped with 2 MB L2 cache and a tiny 4 MB L3 cache. That limitation equals horrible performance when it is used to mine randomX with four threads, even though the CPU has four cores and eight threads. Mining randomX using four cores on a Ryzen 1600X (3.0 MB L2 cache and 16.0 MB L3 cache) gives a hash rate of about 2398.7 H/s while the 2400 G will produce only 1038.3 H/s even though the 2400 G is running at higher clocks. The 2 MB per thread cache requirement is specially important if you want to mine using a high core count Xeon CPU, those chips tend to have less than 2 MB cache per core. You will likely want to use a lower number of cores than the total on those chips.

Mining using randomX is hugely faster if the processor has AVX2 instructions available.

xmrig mining RandomX hashrate H
CPU Cores/Threads L2/L3 CPU Cache -t 2 -t 4 -t 6 -t 12
Athlon II x3 3 1.5M/0 190.0 273.7 271.0
AMD A8-7600 4(*) 4M/0 656.4 810.1 796.5
Ryzen 5 2600G 4/8 2M/4M 683.8 1049.6 1176.5 1196.8
Ryzen 5 1600X 6/12 3M/16M 1201.3 2324.1 3225.5 2294.8
Ryzen 5 2600 6/12 3M/16M 1241.1 2535.7 4205.0 2841.7
Intel i7-5500U 2/4 0.5M/4M 879.1 706.8 807.9
(*) The AMD A8-7600 has 4 cores, but there is only 1 integer core per 2 cores so it is kind of like a processor with 2 cores and 4 threads.

There are three important points to learn from the above table:

  • The hash rates produced by a processor mining Monero with the randomX algorithm is largely dependent on the CPU cache, and
  • Using more threads than the actual number of CPU cores available reduces the hash rate (with the Ryzen 5 2600G being an exception, but the increase by going from 4 to 6 or 12 threads is very small)
  • Mining on old hardware like the Athlon II x3, a 95W TDP CPU, is pointless. The hashrate is extremely low and the electricity cost per hash is more than 10x that of a modern CPU.

The hardware requirements, and hardware advantages and disadvantages, will differ depending on the mining algorithm. XMRig supports a lot more than just RandomX, and the RandomX requirements do not apply if you are using Argon2 or AstroBWT or something else.

Profitability[edit]

The simple truth is that cryptcurrency mining is, as of mid-2020, not at all profitable. You can expect it to barely generate enough revenue to cover the additional electricity cost and it may not even make enough to do that if you are in an area with high electricity prices. You will absolutely not get any return on your investment (ROI) if you buy a new high-end computer just to mine a currency like Monero. The equation is different if you already have a computer and you are considering using it to mine when it is not otherwise used.

Mining with a low number of threads (say 2 of 6 CPU cores) when you are not using your computer to do anything that utilizes all CPU cores (games, compiling, video encoding, etc) is something worth considering if you are interested in cryptocurrencies and you want to learn how it works and experiment with mining. This will, again, not be profitable.

Mining with a hash rate of 4200H/s (A Ryzen 2600 using 6 cores) produces 0.004 XMR/day or 0.12 XMR per month. That equals, at the current price (cryptowat.ch: BINANCE:XMR-USDT) of $72.5 per XMR, $8.7. With a system power draw of 180W the $8.7 revenue may or may be enough to cover the additional electricity cost, nothing more.

The only barely good reason to mine cryptocurrency would be speculating in rising prices in the future. If you actually believe the price of the currency you mine will rise ten-fold and you plan to save the currency you mine until that happens then crypto currency mining may be for you. You will, of course, not get reimbursed if a future price rise fails to materialize.

See also[edit]

Links[edit]

The XMRig source is at github.com/xmrig/xmrig.

The developer has a Twitter account at twitter.com/xmrig_dev.


Add your comment
LinuxReviews welcomes all comments. If you do not want to be anonymous, register or log in. It is free.