The time has come to move my Chia farm from a Windows desktop PC to another system. (NOTE: Any links here are Amazon affiliated links to help support the website). I chose the Raspberry Pi 4 Model B 4GB because I wanted to save more power with the farm. This model is also the minimum recommendation from the Chia Team. Their recommendation was updated recently in their Dust Storm Postmortem, an event where a flood of transactions came through the network, which stress tested it. Currently, my Windows farming system uses more energy and generates more heat than a Pi4 would. I also only have USB HDDs, so this is an easy option to switch to.
With the Pi4, I also purchased the Smraza kit in order to have a case with active cooling and heat sinks. The case is not one piece, it is actually a stack of acrylic layers that you put together. It was easy to follow the directions and assemble the case with the Pi4 inside it. I put the fan in low power mode since that should be enough and was not too loud. I also placed the fan outside of the case as opposed to inside like the directions show.
The last piece of hardware I needed was a 256GB MicroSD card, which I also purchased. I started with a 32GB but had to restart because currently the blockchain database for Chia is around 32GB. (NOTE: In the Postmortem document linked above, the Chia team now recommends running the Chia files and databases from a USB SSD instead of the onboard MicroSD. The onboard MicroSD does not have to be big if going this route. That is why I crossed out the last sentence.) Since I already purchased the 256GB MicroSD, I kept using it.
With the Pi4 assembled, the next step is to load the operating system. For this I chose Ubuntu. I won’t have a display monitor hooked up to mine, I plan to just remote into it so I do not need Ubuntu Desktop, I only need Ubuntu Server. The server image must be flashed onto the MicroSD card and then inserted into the Pi4. I followed the instructions on the Ubuntu website located here: https://ubuntu.com/tutorials/how-to-install-ubuntu-on-your-raspberry-pi#1-overview
Installing Ubuntu Server
With the tutorial I linked, I was able to flash the SD card with 64-bit Ubuntu Server 20.04.3 LTS. The operating system was a little bit hidden in the imager software. When the imager software opens, Click the CHOOSE OS button and in the new window go to: Other general purpose OS->Ubuntu->Ubuntu Server 20.04.3 LTS (RPi 3/4/400). Make sure you pick 64-bit! 32-bit will not work with Chia. I chose LTS (Long Term Support) so that security patch support lasts for while. Once the SDcard is imaged, Windows will try to open the two partitions on it. One partition cannot be read by Windows and will ask if you want it formatted. Do not format it, just cancel and close the window.
With the SDcard imaged, I needed to setup WiFi. Configuring the WiFi was simple in section 3 of the tutorial. On your Windows machine, navigate to the
system-boot partition of the SD card. Then, open the
network-config file and replace
myhomewifi and the
password with the name of your WiFi and the password for it. Make sure to keep the quotes around the password. You also need to remove the # symbols for the correct lines. It should match what is shown below:
Save the file, then remove the SD card from the Windows machine. Connect keyboard, monitor and power to the Pi4 with the HDMI cable and power cable from the kit. Then, put the SD card in the Pi4 and turn it on. It should boot automatically when turned on.
You’ll need to enter the standard credentials when you first sign in, which are
ubuntu. It will make you change the password when you first sign in. While doing this you may see a lot of “cloud-init” lines printed on screen while you’re signing in and changing the password, this is normal. Let it complete before doing any rebooting.
Once signed in, reboot the system with the command
reboot. This reboot is necessary in order for the WiFi to begin to work. Once it reboots, sign in again. Now we can go ahead and update Ubuntu Server to the latest security patches. Enter the commands below:
$ sudo apt update $ sudo apt upgrade
If you get an error that begins with: “Waiting for cache lock…” and ends with “unattended-upgr” then that means the auto updater is updating some software. I like the automation of security patch installs and will leave this option on. Leave the Pi4 running for about 5 minutes then try
sudo apt upgrade command again. It should go ahead and install all the remaining updates. Now is also the time to change the hostname and username if you want. Enter
sudo nano /etc/hostname in order to change the hostname.
Since I’m using the 4GB model, a swap partition needs to also be created per the instructions on the Chia Wiki. Follow these steps to do this:
$ sudo dd if=/dev/zero of=/swap bs=1M count=1024 $ sudo chmod 600 /swap $ sudo mkswap /swap $ sudo swapon /swap
The dd command will take a little bit to complete. Next, make sure to add a line to
/etc/fstab so that swap is available on reboot.
$ sudo nano /etc/fstab /swap swap swap defaults 0 0
reboot command and proceed with the next section.
Format and Mount the USB SSD
Before installing Chia, we need to first mount the USB SSD. Remember that we need to mount the USB SSD that will run the Chia files and databases. I purchased a 500GB Micron Crucial X6 SSD for this, but you can use any drive you wish as long as its an external SSD. Connect the drive to one of the USB 3.0 ports on the Pi4 and then run the command
sudo parted -l to list the name of the external drive. The command should return something similar to this image of my drive:
Here, my disk is located at
/dev/sdm. We need to format the drive next. EXT4 is the format of choice for this. I only needed to format the second partition, so here was the command I used:
$ sudo mkfs.ext4 /dev/sdm2
Then, I used these commands to make the mount location folder, mount the USB drive, and change the permissions to the ubuntu user:
$ sudo mkdir /media/chia_ssd $ sudo mount /dev/sdm2 /media/chia_ssd/ $ sudo chown ubuntu:ubuntu /media/chia_ssd/
mount command to ensure that the drive is mounted. Next, the drive needs to be added to
/etc/fstab in order to mount on boot. But this time, since there are multiple partitions on the SSD, we need to specify the UUID of the partition we want. You can see this by entering the command:
$ sudo blkid|grep sdm2
This will display the UUID that you will need to copy and paste into the
fstab. (NOTE: This is not the PartUUID). It should look like the below:
Here you can see that you have to first list the UUID, then the folder you want it mounted to, the filesystem type and then
defaults 0 0. Now with the drive configured, we can take the time now to ensure we are getting the advertised USB Transfer rate. Enter these commands to do the benchmark:
$ cd /media/chia_ssd/ $ dd if=/dev/zero of=./largefile bs=1M count=1024
This command will take a while, but it should provide you with a transfer speed. If the speed is slow then you will need to search the internet for a solution with your drive. With the USB SSD ready to go, we can continue the installation of Chia.
Installing the Chia Software
This section installs the Chia software and necessary support software. At the time of writing, the Chia software version was 1.2.11. Enter this command to install the packages that Chia needs:
$ sudo apt install build-essential python3-dev
These are packages that the Chia installer needs to function. Once installed, enter these commands to get the chia software:
$ cd /media/chia_ssd $ mkdir git $ cd git $ git clone https://github.com/Chia-Network/chia-blockchain.git -b latest
This will download the latest version of the Chia blockchain software into the git folder that was made. Next, run these commands to run the installer:
$ cd chia-blockchain $ sh install.sh
More packages will be installed. Once finished, Chia will be ready to run. I will be using a nested terminal to run the Chia Node with the preinstalled software called
byobu. This is so that when I SSH into the Pi4 and disconnect, the Chia node will continue to function. Chia runs in a virtual environment (aka venv) which is why it needs to be activated first before running chia. Run these commands to start the nested terminal and to start Chia inside of it:
$ byobu $ cd ~/git/chia-blockchain $ . ./activate (venv)$ chia init
After entering byobu, the terminal will change. This is normal. Once chia is running, it will say that there no keys present, which is fine. Run
chia keys show to make sure no keys are installed. If you get a warning about an unprotected SSL file, just run
chia init --fix-ssl-permissions to fix the issue.
Since we’re migrating a farm, run
chia keys add and add the 24-word mnemonic phrase to restore your farming keys. Once complete, run
chia start farmer in order to start farming. You can view the status of the farmer by running
chia show -s -c. You should see FARMER, WALLET and FULL_NODE connections. Chia is now running on the Pi4. Keep checking the status until you see the height start to increase. Once that happens, go ahead and stop the Chia node with
chia stop -d all. We need to migrate the existing database from the Windows Farmer.
Moving the Existing Blockchain Database
Normally, you would have to wait to sync the blockchain before you can start farming. But, since we’re moving an existing farm, the blockchain database can be copied from your current farm. The steps in this section will do just that.
On Ubuntu, Chia will install the database files in your home directory — a folder named
.chia. We will need to move this folder to the USB SSD and then create a “shortcut” to the SSD from the home directory. Perform these commands in order to do this:
$ cd ~ $ mv .chia /media/chia_ssd/ $ ln -s /media/chia_ssd/.chia .
ln -s is the command that creates a symbolic link to the location on the SSD. You can research more how these links work if you wish, but just know that the .chia folder in the home directory now points to the .chia folder on the SSD. Now we can go ahead and copy the database from the Windows machine.
First, log into your Windows Chia Farmer and shut down the Chia farming software so that the connection to the blockchain files close. Next, download WinSCP and install it on the machine. This software will help transfer the database file from windows to the Pi4. Accept all the defaults during installation of WinSCP. After installation, WinSCP will open and a login window will appear. For Host name, enter the IP address of the Pi4. Enter your username then click the save button. Next, click the login button. A Warning window will appear asking to trust the host, press the Yes button here.
Finally, WinSCP should be connected to the Pi4. The left window displays files from the Windows machine. The right window displays files from the Pi4. Below is a table of the files you need to transfer from the windows machine to the Pi4. Before starting, press CTRL+ALT+H so that WinSCP shows hidden files. In both windows, navigate to both paths first, then drag the file from the left window to the right window. An Upload window will open, press OK. Then, press YES to overwrite the file on the Pi4.
|Files to move||From: Windows Path||To: Pi4 Path|
NOTE: Depending on the speed of your WiFi, the transfer rate may be very slow like mine was. If it is, then there are a couple of options — Connect an Ethernet cable or plug the MicroSD to the Windows machine and transfer via USB. I connected an Ethernet cable at this point and then connected WinSCP to the Ethernet IP address of the Pi4.
NOTE: Now is also the time to fix any port forwarding on your network router to the new Pi4.
With the files moved over, close WinSCP from the Windows machine. On the Pi4, with the byobu terminal, enter these commands:
$ cd ~/git/chia-blockchain $ . ./activate (venv)$ chia start farmer
Starting Chia this time will take longer to do. It will need to validate the database files that were moved over. For the full node and the wallet. Since there is no GUI, you can’t really see the progress. Wait about 5-10 minutes for it to catch up then do a
chia show -s -c. You should now see that the height number is much larger. This means the transfer was successful. Now is a good time to shut down the chia farm and the Pi4 in order to move it to the location where you plan to keep it with all the drives. Run
chia stop -d all , then
exit on the byobu terminal, then
shutdown -h now on the normal terminal window.
Moving the USB Hard Drives
Phew, we’ve arrived at the last step of the move. Go ahead and move all of your USB hard drives and connect them to the Pi4. Don’t forget to also move any USB Hubs. With it all connected, go ahead and power the Pi4. For my farm, all of my drives are formatted NTFS. These next steps take that into account.
With the Pi4 back online, open two SSH windows to it. Then in one of the windows, enter the command
sudo blkid. This should display all the USB drives and their partition names. If you labeled your USB drives in Windows, their names will show up here. In the second SSH window, navigate to your
/media folder and make a folder for every USB drive you have, like below:
$ cd /media $ mkdir usbdrive1 $ mkdir usbdrive2 $ mkdir usbdrive3 $sudo chown ubuntu:ubuntu *
With these commands complete , we are ready to add them to the fstab file. Enter the command
sudo nano /etc/fstab. This will open the fstab file like before. For each USB drive you will need to enter a line into the file. For Example:
UUID=09349B40449B3400 /media/usbdrive1 ntfs-3g defaults,nls=utf8,umask=000,dmask=027,fmask=137,uid=1000,gid=1000,windows_names 0 0
First, this fstab configuration is for NTFS formatted drives. Everything after ntfs-3g is needed to mount the drive. If you changed your user ID and Group ID from the default, you will need to change it here too. Second the UUID listed here is the UUID of the partition on the drive you want to mount. This UUID should be listed in your first SSH window that shows the
Every USB drive will need a line like this in the fstab. Once complete, save the fstab file. Then execute a
sudo mount -a command. If you did everything right, all the USB Drives should mount. You can enter the
mount command to view all the mounted drives.
With every drive mounted, you can now add the directories to your chia farm. Here are the commands that are needed:
$ byobu $ cd ~/git/chia-blockchain $ . ./activate (venv)$ chia start farmer (venv)$ chia plots add -d /media/usbdrive1/plots (venv)$ chia plots add -d /media/usbdrive2/plots (venv)$ chia plots add -d /media/usbdrive3/plots (venv)$ chia plots check
chia plots add -d for each directory you need to add. Then, the
chia plots check is only so that you can see if your directories are being recognized. You can cancel the command after it goes through all the drives.
That should be it. The Pi4 should now be farming all the plots that were moved over. If you want to see how progress is going, enter
chia show -s -c. If you want to see how the farm is doing, enter
chia farm summary. From here, you can observe the chia logs to ensure that everything is running smoothly, or employ a log monitor like chiadog. This was a long post that took a lot of time to make, if there are any mistakes, please let me know in the comments below. Thanks all.