raspiblitz icon indicating copy to clipboard operation
raspiblitz copied to clipboard

[RPi5] Migrate Option from external SSD to NVMe base

Open rootzoll opened this issue 1 year ago • 11 comments

On recover with a fresh sd card if a Pi5+NVMe detects an external SSD with the name "BLOCKCHAIN" it could offer an automated data migration.

This could be used to migrate from an old external SSD used on a RPi4 or legacy RPi5 setup to an Pimoroni style NVMe base.

Or when moving from an 1TB NVMe to a 2TB NVMe later by connecting the old NVMe thru a cheap USB adapter like this one: Bildschirmfoto 2024-01-17 um 21 26 37

rootzoll avatar Jan 17 '24 20:01 rootzoll

Can somebody test if on the RaspberryPi5 with the Pimoroni NVMe Base an additional connected USB SSD (the one we used before or such an USB NVMe adapter) can still copy lots of dummy data correctly without drops in power?

rootzoll avatar Jan 17 '24 20:01 rootzoll

Yes, kind of, I am in the fortunate position of owning two Pi 5s, allowing me to use one for testing purposes. I will receive a Pineberry Pi HatDrive! Top tomorrow. A few weeks later, I'm expecting the Pimoroni NVMe Base. I believe their performance will be comparable.

My initial step involves creating a copy of my current productive RaspiBlitz USB SSD. Following that, on the test device, I plan to install the latest 1.11.pre dev version on the NVMe. Then, using an SD card loaded with the most recent Pi OS, I'll proceed to copy the blockchain onto the NVMe partition. If the synchronization has already started, I delete the blocks that have already been synchronized.

I intend to replicate the blockchain multiple times, utilizing various tools and settings such as cp, rsync, and dd, to compare their outcomes. My anticipation is that cp will offer the fastest performance, rsync the most reliability, and dd the slowest speed.

I am very much open to suggestions regarding this setup.

neversleep404 avatar Jan 17 '24 22:01 neversleep404

First off, copying the productive USB SSD onto the test USB SSD with rsync has already worked without any problems on the Pi 5. Following are the results: sent 732,594,025,718 bytes received 721,296 bytes 295,103,624.17 bytes/sec total size is 732,412,654,771 speedup is 1.00

real 41m21.883s user 0m1.202s sys 0m2.873s

neversleep404 avatar Jan 18 '24 12:01 neversleep404

The performance was initially good when copying the blockchain data (400MB/s) but dramatically dropped after 1000 blocks. I think the NVMe SSD might have overheated, which is more likely a problem with the small 2230 format, but it could also be an issue with the Pimoroni Base due to its compact design. Interestingly, the transfer was faster with the parameter "dtparam=pciex1_gen=3" than without. I had expected that the NVMe SSD would stay cooler without the parameter and that the overall transfer rate would be better, which was not the case.

However, the system ran very stable and, in total, copying 675GB in just under 2 hours is still not bad:

sent 675.20G bytes received 715.47K bytes 98.53M bytes/sec total size is 675.15G speedup is 1.00

real 114m11.946s user 0m1.182s sys 0m3.020s

pine2 Pine1

neversleep404 avatar Jan 19 '24 08:01 neversleep404

cooling

Copying the blockchain over USB or LAN is unfortunately not possible without temporary cooling eg. using a fan.

neversleep404 avatar Jan 31 '24 17:01 neversleep404

TODO: To prevent overheating we might have to pause the copy process ....

ps aux | grep rsync
kill -STOP <PID>
kill -CONT <PID>

and maybe monitor temp of NVME with:

[email protected]:~ ₿ sudo smartctl -A /dev/nvme0n1p1
smartctl 7.3 2022-02-28 r5338 [aarch64-linux-6.1.0-rpi7-rpi-v8] (local build)
Copyright (C) 2002-22, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF SMART DATA SECTION ===
SMART/Health Information (NVMe Log 0x02)
Critical Warning:                   0x00
Temperature:                        35 Celsius
Available Spare:                    100%
Available Spare Threshold:          5%
Percentage Used:                    0%
Data Units Read:                    1,584,859 [811 GB]
Data Units Written:                 1,666,195 [853 GB]
Host Read Commands:                 8,999,684
Host Write Commands:                18,183,834
Controller Busy Time:               54
Power Cycles:                       66
Power On Hours:                     205
Unsafe Shutdowns:                   3
Media and Data Integrity Errors:    0
Error Information Log Entries:      0
Warning  Comp. Temperature Time:    0
Critical Comp. Temperature Time:    0
Temperature Sensor 1:               35 Celsius

rootzoll avatar Jan 31 '24 18:01 rootzoll

Overheating is really an issue. Here's an optimized script. I recommend not sorting the files and also consider using an external fan for cooling the NVMe SSD. If your blockchain is located on another Raspberry Pi, it's best to use SSHFS to mount the remote drive. It's quite simple

#!/bin/bash

# NVMe Temperature Monitoring and Blockchain Copy Script for Raspberry Pi
# This script copies the Bitcoin blockchain data from one drive to another,
# while monitoring the temperature of the NVMe SSD. The source files will
# not be deleted after copying.

# Set the source and destination directories
SOURCE="/mnt/source/bitcoin/blocks" # Replace with the path to the source directory
DEST="/mnt/target/test"             # Replace with the path to the destination directory

# Set the NVMe device. Example: /dev/nvme0n1
NVME_DEVICE="/dev/nvme0n1"          # Replace with your NVMe device

# Set the maximum allowed temperature (in Celsius)
MAX_TEMP=50

# Temporary files
TO_COPY_FILE="/tmp/to_copy.txt"
COPIED_FILES="/tmp/copied_files.txt"

# Delete temporary files if they exist
[ -f "$TO_COPY_FILE" ] && rm "$TO_COPY_FILE"
[ -f "$COPIED_FILES" ] && rm "$COPIED_FILES"

# Create a new empty file for tracking copied files
> "$COPIED_FILES"

# Main loop
while true; do
    # Read the temperature of the NVMe SSD
    TEMP=$(sudo smartctl -A $NVME_DEVICE | grep "Temperature:" | awk '{print $2}')

    # Check if the temperature is within the acceptable range
    if [ "$TEMP" -le "$MAX_TEMP" ]; then
        # Find new files to copy, excluding those already copied
		cd $SOURCE
        find . -type f | sed 's|^\./||'| grep -xvFf "$COPIED_FILES" | head -n 100 > "$TO_COPY_FILE"
                
        # Check if there are new files to copy
        if [ ! -s "$TO_COPY_FILE" ]; then
            echo "Copying complete"
            break
        fi

        # Copy the files with absolute paths
        rsync -av --progress --files-from="$TO_COPY_FILE" "$SOURCE/" "$DEST/"


        
        # Add copied files to the list of copied files
        cat "$TO_COPY_FILE" >> "$COPIED_FILES"
    else
        # Count the remaining files
        cd $SOURCE
        REMAINING_FILES=$(find . -type f | sed 's|^\./||'| grep -xvFf "$COPIED_FILES" | wc -l)

        # Pause if the temperature is too high
        echo "Pausing due to high temperature ($TEMP°C). $REMAINING_FILES files remaining to copy."
        sleep 60 # Wait for 60 seconds
    fi
done

# Cleanup
rm "$TO_COPY_FILE" "$COPIED_FILES"

# End of script

neversleep404 avatar Feb 02 '24 14:02 neversleep404

Bildschirmfoto 2024-02-02 um 15 29 10

neversleep404 avatar Feb 02 '24 14:02 neversleep404

Bildschirmfoto 2024-02-02 um 15 30 22

neversleep404 avatar Feb 02 '24 14:02 neversleep404

What do you think about displaying the NVME temperature alongside the CPU temperature on the dashboard?

TrevorPhilipsBR avatar Feb 03 '24 02:02 TrevorPhilipsBR

What do you think about displaying the NVME temperature alongside the CPU temperature on the dashboard?

The heat problem should only occur when transferring large amounts of data, eg. the blockchain. In later operation, the NVMe hardly has anything to do.

neversleep404 avatar Feb 04 '24 06:02 neversleep404