Guide For Setting Up And Mining Bitcoin BTC On FreeBSD

Bitcoin (BTC) is a cryptocurrency, a virtual currency designed to act as money and a form of payment outside the control of a single person, group, or entity, thereby eliminating the need for third-party involvement in financial transactions. It is awarded to blockchain miners for work done to verify transactions and can be purchased on some exchanges.

Bitcoin was introduced to the public in 2009 by an anonymous developer or group of developers using the name Satoshi Nakamoto. Since its first introduction, Bitcoin has become the most famous cryptocurrency in the world. Its popularity has inspired the development of many other cryptocurrencies. These competitors are trying to replace it as a payment system or be used as a utility or security token in other blockchains and emerging financial technologies.

For the FreeBSD system, we rarely come across articles that review installation, configuration and Bitcoin mining. Bitcoin is discussed more on Linux such as Ubuntu and Debian. We come across lots of articles that explain how to install, configure and mine Bitcoin.

In this article we try to discuss Bitcoin in more depth and detail, especially those related to installation and configuration. This article will guide you in setting up Bitcoin on a FreeBSD system. In this case, the FreeBSD version used is FreeBSD 13.2 Stable.

Yup, let's just start installing and configuring Bitcoin on the FreeBSD 13.2 Stable system.


1. Bitcoin Installation

To run Bitcoin on FreeBSD you must install the Bitcoin application. Before installing Bitcoin, make sure the FreeBSD system has been updated, if not, do the following command.

root@router2:~ # pkg update
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.

root@router2:~ # pkg upgrade -y
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
Updating database digests format: 100%
Checking for upgrades (203 candidates): 100%
Processing candidates (203 candidates): 100%
Checking integrity... done (0 conflicting)
Your packages are up to date.

root@router2:~ #


When the update and upgrade process has been completed, install other supporting applications. This application is very important, because if this application is not installed, then don't expect Bitcoin to be able to run on the FreeBSD system.

root@router2:~ # pkg install autoconf automake boost-libs git libevent libtool pkgconf
root@router2:~ # pkg install libzmq4 miniupnpc norm openpgm python39 sqlite3 db5 gmake

After that, create a user and group with the name "bitcoin".

root@router2:~ # adduser
Username: bitcoin
Full name: bitcoin wallet
Uid (Leave empty for default):
Login group [bitcoin]:
Login group is bitcoin. Invite bitcoin into other groups? []:
Login class [default]:
Shell (sh csh tcsh bash rbash git-shell nologin) [sh]:
Home directory [/home/bitcoin]:
Home directory permissions (Leave empty for default):
Use password-based authentication? [yes]:
no
Lock out the account after creation? [no]:
Username : bitcoin
Password : <disabled>
Full Name : bitcoin wallet
Uid : 1018
Class :
Groups : bitcoin
Home : /home/bitcoin
Home Mode :
Shell : /bin/sh
Locked : no
OK? (yes/no): yes
adduser: INFO: Successfully added (bitcoin) to the user database.
Add another user? (yes/no):
no
Goodbye!

If the Bitcoin user and group have been created, it's time to install Bitcoin. Follow the script below to install Bitcoin. To install Bitcoin, you can copy the complete file from https://github.com/bitcoin/bitcoin.

root@router2:~ # cd /usr/local/etc
root@router2:/usr/local/etc/bitcoin # git clone https://github.com/bitcoin/bitcoin.git
root@router2:/usr/local/etc/bitcoin # cd bitcoin
root@router2:/usr/local/etc/bitcoin # ./autogen.sh
root@router2:/usr/local/etc/bitcoin # ./configure --disable-hardening MAKE="gmake" CFLAGS="-I/usr/local/include" CXXFLAGS="-I/usr/local/include -I/usr/local/include/db5" LDFLAGS="-L/usr/local/lib -L/usr/local/lib/db5"
root@router2:/usr/local/etc/bitcoin # gmake
root@router2:/usr/local/etc/bitcoin # gmake check
root@router2:/usr/local/etc/bitcoin # gmake install


At this point, if there are no errors when executing the gmake syntax, Bitcoin should have been installed on the FreeBSD system, but it cannot be run yet. We continue by configuring Bitcoin


2. Bitcoin Configuration

The first stage in the configuration process is to create a Bitcoin Start Up script. We add the script to the /etc/rc.conf file. Add the following script in the /etc/rc.conf file.

bitcoin_enable="YES"
bitcoin_user="bitcoin"
bitcoin_group="bitcoin"
bitcoin_config="/usr/home/bitcoin/.bitcoin/bitcoin.conf"
bitcoin_datadir="/usr/home/bitcoin/.bitcoin"

The next stage is to create folders and files that are used to store Bitcoin blockchain files.

root@router2:~ # mkdir -p /usr/home/bitcoin/.bitcoin
root@router2:~ # touch /usr/home/bitcoin/.bitcoin/bitcoin.conf
root@router2:~ # touch /usr/home/bitcoin/.bitcoin/debug.log
root@router2:~ # chmod -R +x /usr/home/bitcoin/.bitcoin/debug.log
root@router2:~ # chown -R bitcoin:bitcoin /usr/home/bitcoin/.bitcoin/

Before we continue to the next stage, create a simlink to the /root folder.

root@router2:~ # ln -s /usr/home/bitcoin/.bitcoin /root

Continue by creating the Start Up script rc.d. This script is useful for carrying out commands to start, restart and stop the Bitcoin daemon, not only that, the Start Up rc.d script is also used to load automatically so that the Bitcoin daemon always runs when the server computer is turned off or restarted. Start Up rc.d, we will name the file bitcoind. Follow these steps to create the rc.d script.

root@router2:~ # touch /usr/local/etc/rc.d/bitcoin
root@router2:~ # chmod -R +x /usr/local/etc/rc.d/bitcoin

Type the script below in the file "/usr/local/etc/rc.d/bitcoind".

#!/bin/sh

# PROVIDE: bitcoind
# REQUIRE: LOGIN cleanvar
# KEYWORD: shutdown

#
# Add the following lines to /etc/rc.conf to enable :
# bitcoind_enable (bool): Set to "NO" by default.
# Set it to "YES" to enable bitcoind
# bitcoind_user (str) Set to "bitcoin" by default.
# bitcoind_group (str) Set to "bitcoin" by default.
# bitcoind_conf (str) Set to "/usr/local/etc/bitcoind.conf" by default.
# bitcoind_data_dir (str) Set to "/var/db/bitcoin" by default.
# bitcoindlimits_enable (bool) Set to "NO" by default.
# Set it to "YES" to enable bitcoindlimits
# bitcoindlimits_args Set to "-e -U ${bitcoind_user}" by default


. /etc/rc.subr

name="bitcoind"
rcvar=bitcoind_enable

start_precmd="bitcoind_precmd"
start_cmd="bitcoind_start"
restart_precmd="bitcoind_checkconfig"
reload_precmd="bitcoind_checkconfig"
configtest_cmd="bitcoind_checkconfig"
status_cmd="bitcoind_status"
stop_cmd="bitcoind_stop"
stop_postcmd="bitcoind_wait"
command="/usr/local/bin/bitcoind"
daemon_command="/usr/sbin/daemon"
pidfile="/var/run/${name}.pid"
extra_commands="configtest"


: ${bitcoind_enable:="NO"}
: ${bitcoindlimits_enable:="NO"}

load_rc_config ${name}

: ${bitcoind_user:="bitcoin"}
: ${bitcoind_group:="bitcoin"}
: ${bitcoind_data_dir:="/var/db/bitcoin"}
: ${bitcoind_config_file:="/usr/local/etc/bitcoin.conf"}
: ${bitcoindlimits_args:="-e -U ${bitcoind_user}"}

# set up dependant variables
procname="${command}"
required_files="${bitcoind_config_file}"


bitcoind_checkconfig()
{
echo "Performing sanity check on bitcoind configuration:"
if [ ! -d "${bitcoind_data_dir}" ]
then
echo "Missing data directory: ${bitcoind_data_dir}"
exit 1
fi
chown -R "${bitcoind_user}:${bitcoind_group}" "${bitcoind_data_dir}"

if [ ! -f "${bitcoind_config_file}" ]
then
echo "Missing configuration file: ${bitcoind_config_file}"
exit 1
fi
if [ ! -x "${command}" ]
then
echo "Missing executable: ${command}"
exit 1
fi
return 0
}

bitcoind_cleanup()
{
rm -f "${pidfile}"
}

bitcoind_precmd()
{
bitcoind_checkconfig

pid=$(check_pidfile "${pidfile}" "${procname}")
if [ -z "${pid}" ]
then
echo "Bitcoind is not running"
rm -f "${pidfile}"
fi

if checkyesno bitcoindlimits_enable
then
eval $(/usr/bin/limits ${bitcoindlimits_args}) 2>/dev/null
else
return 0
fi
}

bitcoind_status()
{
local pid
pid=$(check_pidfile "${pidfile}" "${procname}")
if [ -z "${pid}" ]
then
echo "Bitcoind is not running"
return 1
else
echo "Bitcoind running, pid: ${pid}"
fi
}

bitcoind_start()
{
echo "Starting bitcoind:"
cd "${bitcoind_data_dir}" || return 1
${daemon_command} -u "${bitcoind_user}" -p "${pidfile}" -f \
${command} \
-conf="${bitcoind_config_file}" \
-datadir="${bitcoind_data_dir}"
}

bitcoind_stop()
{
echo "Stopping bitcoind:"
pid=$(check_pidfile "${pidfile}" "${procname}")
if [ -z "${pid}" ]
then
echo "Bitcoind is not running"
return 1
else
kill ${pid}
fi
}

bitcoind_wait()
{
local n=60
echo "Waiting for bitcoind shutdown:"
while :
do
printf '.'
pid=$(check_pidfile "${pidfile}" "${procname}")
if [ -z "${pid}" ]
then
printf '\n'
break
fi
sleep 1
n=$((${n} - 1))
if [ ${n} -eq 0 -a -f "${pidfile}" ]
then
printf "\nForce shutdown"
kill -9 $(cat "${pidfile}")
for n in 1 2 3
do
printf '.'
sleep 1
done
printf '\n'
break
fi
done
rm -f "${pidfile}"
echo "Shutdown complete"
}

run_rc_command "$1"


If you have finished creating the rc.d Start Up script, continue by creating a configuration file, we will name it bitcoind.conf. Place the bitcoin.conf file in the /usr/home/bitcoin/.bitcoin folder. The following is the script file /usr/home/bitcoin/.bitcoin/bitcoin.conf.

root@router2:~ # ee /usr/home/bitcoin/.bitcoin/bitcoin.conf

listen=1
port=8333

rpcallowip=192.168.9.3
rpcpassword=jakasetiawan
rpcuser=iwanse1212
rpcport=8332

conf=/usr/home/bitcoin/.bitcoin/bitcoin.conf
daemon=1
server=1

debuglogfile=/usr/home/bitcoin/.bitcoin/debug.log
datadir=/usr/home/bitcoin/.bitcoin
pid=/usr/home/bitcoin/.bitcoin/bitcoin.pid
addnode=seed.bitcoin.sipa.be
addnode=54.38.85.30:8333
addnode=46.19.137.74:8333
addnode=141.98.219.12:8333
addnode=50.107.158.135:8333
addnode=76.150.98.135:8333
addnode=166.70.145.151:8333
addnode=96.74.179.132:8333
addnode=34.75.215.83:8333

IP 192.168.9.3 is the FreeBSD Server LAN IP, you can change the IP according to your FreeBSD server IP. The next stage is to restart/reboot the FreeBSD server.

root@router2:~ # reboot

After the FreeBSD server computer returns to normal, run the Bitcoin daemon.

root@router2:~ # service bitcoin start


3. Mining Bitcoin

To mine Bitcoin, you can use the CPUminer program. cpuminer is a simple daemon that runs Bitcoin or Litecoin. Cpuminer can be used for solo mining or pool mining. Below is how to install cpuminer on a FreeBSD system.

root@ns1:~ # cd /usr/ports/net-p2p/cpuminer
root@ns1:/usr/ports/net-p2p/cpuminer # make install clean

Cpuminer can also be installed with the default FreeBSD pkg package.

root@ns1:~ # pkg install net-p2p/cpuminer

Iwan Setiawan

I Like Adventure: Mahameru Mount, Rinjani Mount I Like Writer FreeBSD

Post a Comment

Previous Post Next Post