Recently I’ve been back experimenting with cryptocurrencies. I was interested in whether or not I could use a Raspberry Pi to help me – in particular I wondered whether it would be of any use for CPU or hard disk mining. To test this theory I thought I’d create my own cross-platform hard disk miner for Burstcoin.
Microsoft released DotNet Core a couple of years ago – basically a really cut-down version of the .Net Framework that would run on MacOS and Linux as well as Windows without the need for Mono. This was excellent but the current beta of version 2 is even more exciting as cross-architecture support is now supported meaning we can write the same code for ARM, x86 and x64 platforms. This opens up Linux ARM devices (such as the Raspberry Pi) and pretty much everything that runs Windows 10 IOT and even Windows 8 ARM tablets as well as MacOS, Linux and Windows itself. Pretty cool especially considering how much I like the .Net Framework.
Since there isn’t much written yet about getting your Raspberry Pi up and running with .Net I thought I’d do this quick run-through.
First you need to get your Raspberry Pi an image. To do this we want to download an Ubuntu image. Whilst Raspbian will work it’s a bit more fiddly and we want to get this up and running quickly – so grab an Ubuntu image from https://ubuntu-pi-flavour-maker.org/download. I downloaded Ubuntu Classic Server 16.04 for a Raspberry Pi 3.
Whilst that’s downloading insert your memory stick into your machine (I’ll assume you’re on Linux here – plenty of guides for writing images from Windows and MacOS exist). Just open up a console and check the kernel log.
This should show you a log from the kernel and towards the bottom you should see which disks have been attached.
[ 5369.614159] sd 5:0:0:0: Attached scsi generic sg2 type 0 [ 5369.614379] sd 5:0:0:1: Attached scsi generic sg3 type 0 [ 5371.062654] sd 5:0:0:0: [sdc] 15523840 512-byte logical blocks: (7.95 GB/7.40 GiB) [ 5371.063394] sd 5:0:0:0: [sdc] Write Protect is off [ 5371.063397] sd 5:0:0:0: [sdc] Mode Sense: 2f 00 00 00 [ 5371.064153] sd 5:0:0:0: [sdc] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA [ 5371.065744] sd 5:0:0:1: [sdd] Attached SCSI removable disk [ 5371.070755] sdc: sdc1 sdc2 [ 5371.072948] sd 5:0:0:0: [sdc] Attached SCSI removable disk
From the above I can see the disk I’ve inserted is called “sdc”. We need to remember that.
Now change to the folder that you downloaded the image to (for example in our default Downloads folder):
Then we extract the Ubuntu image (assuming you downloaded the same image as me)
Once that’s done we’re ready to take the image and write it to the disk. In this command we take the Ubuntu image as the input file (if) and set the disk from the previous step (sdc in my example) as the output file.Make sure you use the right output file here otherwise you could have seriously bad consequences and remove the entire contents of one of your other harddisks – you have been warned!
sudo dd if=ubuntu-16.04-preinstalled-server-armhf+raspi3.img of=/dev/sdc bs=1M
Once that completes pop the memory card into the Raspberry Pi and boot it. You’ll be able to login with the username ubuntu and the password ubuntu. The first thing it will do is prompt you to change your password – so do that now.
If you want to SSH in to your Raspberry Pi to continue configuration you’ll want to grab the IP address now
You will get output like the below which, in this example, indicates the IP address is 10.0.1.101
3: eth: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 34:97:f6:5b:ff:56 brd ff:ff:ff:ff:ff:ff inet 10.0.1.101/24 brd 10.0.1.255 scope global enp6s0 valid_lft forever preferred_lft forever
The first thing we want to do on our freshly installed Raspberry Pi is to update the package list to the latest version
sudo apt-get update
Once that completes we want to install all of the packages that DotNet Core requires. I’m also installing wpasupplicant here as you’ll need this if you want to configure WiFi – although it’s completely optional.
sudo apt-get install htop wpasupplicant libunwind8 libunwind8-dev gettext libicu-dev liblttng-ust-dev libcurl4-openssl-dev libssl-dev uuid-dev
If when you run either of the above statements you get any errors about unable to gain a lock for package installation it means the Pi is auto-updating. At this point I’d grab a cup of tea as it can take up to half an hour and you may as well let it complete.
Once everything is installed we’ll want to download the latest version of the .Net runtime. The link below is for the ARM version for a Raspberry Pi but if you swap “arm” to “x64“ you can follow all these instructions on your Ubuntu desktop as well to get DotNet installed
cd ~ wget "https://dotnetcli.blob.core.windows.net/dotnet/Runtime/release/2.0.0/dotnet-runtime-latest-linux-arm.tar.gz"
We now want to create a directory to extract this to and then extract our DotNet download to this folder
sudo mkdir /opt/dotnet-2.0.0 cd /opt/dotnet-2.0.0 sudo tar -xzf ~/dotnet-runtime-latest-linux.arm.tar.gz
For good measure I tend to delete my downloads
rm -f ~/dotnet-runtime-latest-linux-arm.tar.gz
Finally I want to be able to run DotNet Core from anywhere without modifying my path so to do that I’ll link the executable into a common system path
sudo ln -s /opt/dotnet-2.0.0/dotnet /usr/local/bin/dotnet
With that you’re done and you can now run DotNet Core applications on your Raspberry Pi. Let’s assume you’ve uploaded helloworld.dll which you’ve built – all you need to do to run it is
And it will run exactly the same on your Raspberry Pi as it would on MacOS, Linux x64 or Windows.
With that we’re done and DotNet Core is fully working on a Pi. With more than 75% of NuGet packages now compatible with DotNet core and a huge amount of the .Net Framework SDK running under DotNet Core the possibilities are endless – from using Pis as tiny servers that can run as micro-services in part of your infrastructure to home automation. I’ve even recently worked on the start of a GUI framework that means DotNet core will be able to give you a cross platform UI – even for ARM devices that don’t run X11/Wayland. The options are pretty limitless and all of this can be developped in the comfort of Visual Studio. The remote debugger works excellently as well – allowing you to attach to your Raspberry Pi and debug it the same way you would on Windows.
I always loved Mono for letting me run .Net under Linux and on a Pi – but the integration in to Microsoft’s software development tools really makes the Pi a first-place contender now.