Posted on

Seamless Raspberry Pi SD Card Duplication: A Step-by-Step Guide for Flawless Backups

The Raspberry Pi is a fantastic mini-computer, but its reliance on microSD cards for storage can be both a blessing and a curse. While convenient, microSD cards are prone to wear and tear, making reliable backups crucial. If you’ve ever had a Pi suddenly stop working due to a corrupted card, you know the frustration.

This article details a straightforward and effective method to create a full, byte-for-byte backup of your Raspberry Pi’s microSD card and then duplicate it onto a new card. I’ll also share a common observation about one of the tools that often confuses users.


Why Back Up Your Raspberry Pi’s SD Card?

 

  • Prevent Data Loss: Protect your projects, configurations, and custom scripts.
  • Disaster Recovery: Quickly restore your Pi to a working state if the original card fails.
  • Duplication: Easily create identical copies of your setup for multiple Pis or future use.
  • Testing: Experiment with new software or configurations without risking your primary setup.

The Tools You’ll Need:

 

  1. Original Raspberry Pi MicroSD Card: The card you want to back up.
  2. New MicroSD Card: The card you want to copy to (must be equal to or larger than the original).
  3. SD Card Reader: To connect the microSD cards to your Windows PC.
  4. Win32 Disk Imager: A free, open-source tool for reading/writing disk images on Windows.
  5. Raspberry Pi Imager: The official tool for flashing Raspberry Pi OS images, which we’ll use for restoration.

Step 1: Creating the Disk Image Backup with Win32 Disk Imager

 

This is the crucial first step where we turn your live Raspberry Pi installation into a single, comprehensive .img file on your computer.

  1. Insert the Source MicroSD Card: Place your Raspberry Pi’s operational microSD card into your Windows PC’s card reader.
  2. Launch Win32 Disk Imager: Open the application.
  3. Select the Device (Source): On the right side of the Win32 Disk Imager window, you’ll see a dropdown menu labeled “Device.” Carefully select the drive letter corresponding to your Raspberry Pi’s microSD card. Double-check this to ensure you don’t accidentally select another drive.
    • My Observation: This is where the interface can be a bit counter-intuitive. Many users, myself included, expect the “source” to be on the left and the “destination” on the right. In Win32 Disk Imager, the “Device” (your actual SD card, the source for a backup) is on the right, while the “Image File” (your backup file, the destination) is on the left.
  4. Define the Image File (Destination): On the left side, next to the “Image File” field, click the folder icon (📁). Navigate to where you want to save your backup file (e.g., your Desktop or a dedicated “Raspberry Pi Backups” folder).
    • Crucially, type a name for your backup file and add the .img extension. For example: my_pi_backup_2023-10-27.img.
    • Click “Save.”
  5. Hash Selection: If prompted for an “Hash” selection, you can safely choose “None.” Generating a hash is typically for verifying downloads, not for creating local backups where you’re simply replicating existing data.
  6. Initiate the Read Operation: With the Device selected on the right and the Image File path defined on the left, click the “Read” button (NOT “Write”).
    • Expect it to take a while! This process copies every single bit of data from your microSD card, including empty space. The time taken depends on the total size of your card (e.g., a 64GB card will take longer than a 16GB card, even if only 5GB are used), the card’s speed, and your card reader’s speed. Be patient.

Once completed, you’ll have a perfect, bootable .img file of your Raspberry Pi’s entire operating system and data.


Step 2: Restoring the Image to a New MicroSD Card with Raspberry Pi Imager

 

Now that you have your backup image, let’s flash it onto a fresh card. While Win32 Disk Imager can also write, Raspberry Pi Imager is often preferred for its user-friendly interface and robust writing capabilities.

  1. Insert the Destination MicroSD Card: Place your new (or target) microSD card into your PC’s card reader.
  2. Launch Raspberry Pi Imager: Open the official Raspberry Pi Imager application.
  3. Choose OS (Operating System): Click the “CHOOSE OS” button.
  4. Select “Use custom”: Scroll down the list of operating systems until you find and select “Use custom” (or “Custom”).
  5. Locate Your Backup Image: A file explorer window will open. Navigate to where you saved your .img backup file (from Step 1) and select it.
  6. Choose Storage: Click the “CHOOSE STORAGE” button. Carefully select your new microSD card from the list. Ensure you pick the correct one, as this process will erase all data on the selected card.
  7. Initiate the Write Operation: Click the “WRITE” button. Confirm any warnings about erasing data.

Raspberry Pi Imager will now write your custom .img file onto the new microSD card. This process will also take some time, similar to the read operation, as it’s copying all the data (including empty space) from the image file to the physical card.


Conclusion

By following these steps, you’ve successfully created a robust backup of your Raspberry Pi’s microSD card and learned how to effortlessly duplicate it onto a new one. This method provides peace of mind against card failures and simplifies the deployment of identical Raspberry Pi setups. Despite Win32 Disk Imager’s slightly unconventional interface layout, it, combined with the user-friendly Raspberry Pi Imager, offers a powerful and reliable solution for managing your Raspberry Pi’s storage.

Happy Pi-ing!

Posted on

Nakivo : Pre and Post Job Scripts on Linux Appliance

NAKIVO Backup & Replication provides you with the ability to run a script before a job begins (a pre-job script) and after the job has been completed (a post-job script)

SSH Login

Unsing, for example Putty, you have to login Nakivo Director :

Default ssh port for the Nakvo Director is 2221.

Login to nakivo appliance using this credential :

Username: nkvuser
Password: QExS-6b%3D

cd /opt

sudo su

you have to insert password again

mkdir backup

Change new folder permission

chmod 777 backup

Upload file script

Using for example WinSCP with the same above configuration (port and credential) , browse to the new folder /opt/backup and upload here your scripts sh.

Using putty give execution permission to files :

cd backup

chmod +x ./your_file.sh

Take note of the full path of the script file : /opt/backup/your_file.sh

Config Pre and Post script

Using nakivo portal appliance now you have to implement your scripts on job execution. You need to use this guide :

https://prev-helpcenter.nakivo.com/User-Guide/Content/Backup/Creating-VMware-Backup-Jobs/Backup-Job-Wizard-for-VMware-Options.htm#Pre

 

 

Posted on

How to fix read-only file-system on Ubuntu

When you have this error, it means that your system has by default, a line in /etc/fstab which indicates that if there is an error in the file system, that it should go into read-only mode, to prevent further corruption or dataloss.

You could use lsblk to determine the partition name.

Use the command

sudo fsck -f /dev/sdxx

where “sdxx” is the partition of the hard drive that Linux resides on

Posted on

Cron job su raspberry

I cron job sono operazioni pianificate che possiamo fare eseguire autonomamente ad un certo orario al nostro raspberry.

Log di Cron

Se non siamo esperti di Cron un buon metodo per capire se in nostri job vengono eseguiti correttamente o se incorrono in errori è quello di abilitare il log dei Cron. Questi non è abilitato in installazione. Per farlo, dovete editare il file /etc/rsyslog.conf.

sudo nano /etc/rsyslog.conf

Togliete il segno di commento alla riga

# cron.* /var/log/cron.log

Dovete riavviare il raspberry. Cron.log è il vostro file di log

Operazioni di utente e operazioni di sistema

Il file Crontab contiene le vostre operazioni. Esiste un file crontab per ciascun utente. Per editarlo :

crontab -e

Se però volete fare eseguire una operazione pianificata che impatta sul sistema, come per esempio un riavvio ad una certa ora, dovete editare il file crontab dell’utente root

sudo crontab -e

Impostazione del job

Nel crontab ogni riga è l’impostazione di una operazione pianificata. Ogni operazione pianificata è composta da 5 numeri più il comando che si vuole inserire. I numeri in sequenza sono minuti (0-59), ore (0-23, 0 = mezzanotte), giorno (1-31), mese (1-12), giorno della settimana (0-6, 0 = domenica). Il simbolo * (asterisco) in una delle posizioni dice di non considerare quel determinato filtro.

Esempi :

30 3 * * * /usr/script/miocomando.sh

Il comando sopra deve essere eseguito ogni giorno alle 3.30

15 * * * * /usr/script/miocomando.sh

Il comando sopra deve essere eseguito al 15esimo minuto di ogni ora, per sempre. Quindi viene eseguito 24 volte in un giorno.

Impostazione del comando

Nel nostro esempio non stiamo eseguendo un comando linux , bensì uno script, una lista di comandi contenuti nel file miocomando.sh. Se, per esempio, vogliamo eseguire un reboot dentro al nostro file avremo la riga sudo reboot now.

Dobbiamo però dire al sistema operativo quale programma usare per interpretare i comandi quando lo script viene eseguito. Per farlo aggiungiamo all’inizio del nostro script una particolare riga, chiamata shebang.

#!/bin/bash
sudo reboot now

Ricordate, infine, che per essere eseguito, un comando deve avere i permessi di esecuzione.


Approfondimento : https://hackerstribe.com/2015/raspberry-pi-crontab-e-cronjob/

Posted on

raspberry: i comandi che non ricordo

Riavvio

sudo shutdown -r now

oppure

sudo reboot

Spegnimento

sudo shutdown -h now

oppure

sudo halt

Lancio di un comando (sh)

Andare nella cartella in cui si trova il file sh (es. comando.sh) e digitare

.\comando.sh

Lancio di un comando da ssh che rimanga in esecuzione dopo la chiusura

Dopo aver lanciato un comando con il metodo precedente, chiudendo ssh, termineremo il comando lanciato. Se si desidera che il comando sia persistente bisogna lanciarlo in questo modo :

.\comando.sh & disown

 

Posted on

Guida Chromium Kiosk

In questa guida andremo a illustrare i passaggi per creare un chiosco multimediale sfruttando Chromium e un Raspberry Pi 3.

interfaccia di rete

Innanzitutto, per facilitare le connessioni ssh da remoto, andremo ad impostare un IP statico al nostro Raspberry. Apriamo quindi un terminale e digitiamo il seguente comando:

sudo nano /etc/dhcpcd.conf

ora, cercare all’interno del file i seguenti campi:

interface eth0
static ip_address=192.168.0.4/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1

e per ognuno di essi, andremo ad impostare i nostri valori. Riavviamo il Raspberry e procediamo con la creazione dello script per il Kiosk.

chiosco multimediale

Andiamo dentro al disco del Raspberry, e all’interno del nostro profilo, creare la cartella Scripts, dentro la quale metteremo tutti i componenti necessari per costruire ed eseguire il nostro chiosco.

Partiamo col creare il nostro file Kiosk.sh, inizialmente vuoto.

(Da terminale o da sessione ssh, per creare la cartella ci basta inserire il comando: mkdir “nome della cartella”, senza apici, ne singoli ne doppi. Per creare e scrivere il file Kiosk.sh ci basta digitare: nano “nome file”, sempre senza apici, ne singoli ne doppi.)

All’ interno del nostro file Kiosk.sh, inseriamo il seguente comando:

xargs -rd’n’ /usr/bin/chromium-browser –no-sandbox –noerrdialogs –disable-infobars –kiosk < /home/mecdata/Scripts/pagine.txt

Andiamo ora ad analizzare la struttura di tale comando:

“xargs”: rappresenta il comando di Debian per poter sfruttare argomenti passati come input per poter essere eseguiti da un comando all’ interno dello script.

“-rd’\n’”: rappresenta il tipo di limitatore di riga che viene considerato, in questo caso il valore rappresenta un “a capo”.

“/usr/bin/chromium-browser”: rappresenta il comando che invoca il lancio di Chromium.

“–no-sandbox”: istruzione necessaria per poter lanciare Chromium come root di sistema.

“–noerrdialogs”: impedisce a Chromium di mostrare alcun messaggio/popup/schermata di errore.

“—disable-inforbars”: disabilita le barre delle info.

“–kiosk”: serve, in pratica, per eseguire chromium a schermo intero.

< “/percorso/dello/script.sh”: rappresenta il percorso del file dal quale raccogliere i valori da sfruttare come parametri.

avvio e stop da remoto

Per poter permettere allo script di essere lanciato da remoto e in modo più facile anche da locale, andremo a creare uno script nominato “Start.sh”. All’ interno di questo script, inseriamo i comandi necessari per poter eseguire lo script Kiosk.

#/bin/bash
export DISPLAY=:0
sh /home/mecdata/Scripts/kiosk.sh

“/bin/bash”: dice alla shell quale programma usare per interpretare lo script quando eseguito.

“export DISPLAY=:0”: setta la variabile d’ambiente $DISPLAY con il valore specificato, questo caso 0.

“sh /home/mecdata/Scripts/kiosk.sh”: comando che si occupa di invocare ed eseguire lo script kiosk.sh precedentemente creato.

Allo stesso modo, andremo a creare lo script “Stop.sh”, ed è estremamente semplice.

Il comando da inserire è: “pkill -o chromium”

Questo comando termina completamente ogni processo con la parola chromium al suo interno, terminando correttamente il nostro chiosco.

(per lanciare da ssh remoto il nostro script start.sh, ci serve un comando aggiuntivo: “screen”. In questo caso, lo scopo del comando screen, associato ai parametri “-d” e “-m”, previene la visualizzazione dello schermo del server, in questo caso il nostro Raspberry, sul client e permette l’esecuzione dello script sullo stesso. Quindi la sintassi finale del comando sarà: screen -d -m ./start.sh)

tab multiple

Per permettere la visualizzazione di tutte le tab che useremo nel nostro chiosco, andiamo ad installare un estensione che ci permetterà di navigare automaticamente fra le nostre pagine.

Apriamo questo link  e installiamo l’estensione: https://chrome.google.com/webstore/detail/tabcarousel/ddldimidiliclngjipajmjjiakhbcohn?hl=it

avvio automatico

Il nostro sistema è pronto, ora dobbiamo solo scrivere un ultimo script, che renderà il nostro chiosco, pronto e in funzione non appena avremo eseguito il login sul nostro Raspberry. Ovviamente, per rendere il tutto più fluido e senza interruzioni, abbiamo impostato l’autologin, in maniera molto semplice: da ssh, ci basta inserire il comando “sudo raspi-config”, quindi selezionare la voce “boot options”, quindi la voce “desktop/CLI”, e infine la voce “Desktop Autologin”. Ora ci basterà uscire dallo script e avremo l’autologin abilitato.

Torniamo al nostro script, e per rendere le operazioni di scrittura più veloci, apriamo un terminale e digitiamo il comando: “sudo nano /etc/xdg/autostart/ChromiumPanel.desktop”, e premiamo invio. Verrà aperto un file, nel quale dovremo inserire questi comandi:

[Desktop Entry]
Version=1.0
Type=Application
Name=ChromiumPanel
Exec=/home/mecdata/Scripts/start.sh

Una volta inseriti i comandi nel file, premete ctrl+x, digitate y e premete invio. Il file verrà salvato automaticamente e verrà eseguito ogni volta non appena verrà eseguito il login, in questo caso, automaticamente.

Ruotare lo schermo

Vedi : https://www.raffaelechiatto.com/ruotare-lo-schermo-con-il-raspberry/?fbclid=IwAR0O7r8eT7wGJquTZqdMvmtBGUeh3T3MDIlZTJt44KE65O_bdZeXVg-D_O0