Raspberry Pi - Teach, learn, make !

mail

How to get CPU / GPU temperature ?

CPU temperature (source) :

/sys/class/thermal/thermal_zone0/temp has the current value of CPU temperature in degrees Celsius * 1000 :
cat /sys/class/thermal/thermal_zone0/temp
43620
To get the real value :
awk '{print $0 / 1000}' /sys/class/thermal/thermal_zone0/temp
43.62

GPU temperature :

This is available with RaspberryPi OS only.
/opt/vc/bin/vcgencmd measure_temp
temp=39.4'C

Both :

awk '{print "CPU : temp="$0 / 1000"°C"}' /sys/class/thermal/thermal_zone0/temp; echo -n "GPU : "; /opt/vc/bin/vcgencmd measure_temp
mail

Minimal Debian setup on a Raspberry Pi 4

Table of contents

Introduction

Some context data :

"Install" Debian on the SDCard

The steps below are executed on your workstation, you can leave your Raspberry Pi board aside for the moment.
  1. download the Debian image matching your hardware as well as the corresponding SHA256 checksum file
  2. check the downloaded file :
    sha256sum -c 20200909_raspi_4.xz.sha256
    20200909_raspi_4.img.xz: OK
  3. identify the SDCard :
    • Do this before and after plugging the SDCard into your card reader, the device that will appear is the SDCard :
      NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
      sda               8:0    0 111.8G  0 disk
      ├─sda1            8:1    0  55.9G  0 part /
      └─sda2            8:2    0   7.5G  0 part [SWAP]
      sdb               8:16   0   3.7T  0 disk
      └─sdb1            8:17   0   3.7T  0 part
        ├─myLVM-homes 254:0    0     4T  0 lvm  /home
      
      sde               8:64   1  28.9G  0 disk		here it is!
      ├─sde1            8:65   1   299M  0 part
      └─sde2            8:66   1  28.6G  0 part
      
    • Alternate method, as root :
      tail -f /var/log/messages
      
      Sep 14 20:06:52 myWorkstation kernel: [ 9592.290555] sd 8:0:0:0: [sde] 15687680 512-byte logical blocks: (8.03 GB/7.48 GiB)
      Sep 14 20:06:52 myWorkstation kernel: [ 9592.291638] sd 8:0:0:0: [sde] Write Protect is off
      Sep 14 20:06:52 myWorkstation kernel: [ 9592.292758] sd 8:0:0:0: [sde] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
      Sep 14 20:06:52 myWorkstation kernel: [ 9592.319790]  sde: sde1 sde2
      Sep 14 20:06:52 myWorkstation kernel: [ 9592.324091] sd 8:0:0:0: [sde] Attached SCSI removable disk
      
  4. "flash" the image to the SDCard, as root :
    xzcat 20200909_raspi_4.img.xz | dd of=/dev/sde bs=64k oflag=dsync status=progress

Boot your Raspberry Pi

  1. place the SDCard into its slot
  2. connect keyboard + mouse + monitor
  3. plug the AC adapter : the boot starts
  4. the system LED will turn on :
    1. red + green (both solid)
    2. solid red + blinking green
    3. solid red
    4. both off

After the boot

  1. You should get a prompt like :
    Debian GNU/Linux 10 rpi4-20200909 tty1
    
    rpi4-20200909 login: 
    login : root, password : no password (source)
  2. configure the keyboard layout
  3. make everything up-to-date :
    apt update && apt upgrade && apt dist-upgrade
  4. make the SSH configuration very unsecure :
    echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config
    echo 'PermitEmptyPasswords yes' >> /etc/ssh/sshd_config
    sed -i 's/UsePAM yes/UsePAM no/' /etc/ssh/sshd_config
    systemctl restart ssh
    no need to change PasswordAuthentication since it defaults to yes
  5. open an SSH session from another computer :
    ssh -F /dev/null root@ip.address.of.raspberry
    You should be instantly logged in as root with no password prompt.

Make a backup image

This method implies reading the whole SDCard content (including the empty space), meaning up to 32/64/128/GB of data. Restoring means writing that same amount of data. Albeit it works, it is extremely long both ways , and restarting from scratch was actually quicker.
workaround to try the next time : instead of backuping/restoring the full storage /dev/sde, why not working on its "partitions" only /dev/sde1, /dev/sde2, instead ? Even though it's likely that experiments damage the contents of a filesystem (delete / overwrite files), the risk of damaging the filesystem itself (partition table) seems low.

At that time, you may be pretty excited to start playing with your new Raspberry Pi and start building things (manually or with tools like Ansible and the likes).

However, experience proves that sooner or later, you'll try something we'll see if it works and break everything (). The only solution will then be to restart from the beginning :

  1. flash the image on the SDCard
  2. configure the keyboard layout
  3. make the system updates
  4. make the minimal sshd setup
Making an image of the SDCard right now will backup its current state, and should things break bad, you'll just have to "reflash" it and save these manual steps.

dd status=progress bs=64k if=/dev/sde | xz > path/to/myImage.img.xz