Installation Raspberry Pi OS - Version serveur

Mise à jour : Raspi OS 10.6

Dans ce qui suit, on décrit l'installation en version serveur "headless" (sans affichage) de la distribution Raspberry Pi OS. Le système est configuré pour un accès wifi via une connexion SSH. L'installation décrite est identiquesur les différents modèles de Raspberry et a été testée sur les modèles Pi 4et PI zéro W (version avec wifi)

Sommaire

1 - Principe

L'installation s'effectue en trois étapes principales

2 - Préparation de la carte SD

2.1 - Téléchargement de l'image

Dans l'exemple ci-dessous le téléchargement est effectué via un torrent

$ rtorrent -n -p 55718-55718 -s ./ -d ./ -o download_rate=5000,upload_rate=500,check_hash=yes \
https://downloads.raspberrypi.org/raspios_lite_armhf_latest.torrent
$ sha256sum 2020-08-20-raspios-buster-armhf-lite.zip
4522df4a29f9aac4b0166fbfee9f599dab55a997c855702bfe35329c13334668 2020-08-20-raspios-buster-armhf-lite.zip
$ unzip 2020-08-20-raspios-buster-armhf-lite.img.zip
$ ls -lh 2020-08-20-raspios-buster-armhf-lite.img.zip
-rw-r--r-- 1 philippe philippe 1,8G août  20 12:47 2020-08-20-raspios-buster-armhf-lite.img

2.2 - Recopie de l'image sur la carte SD

$ sudo dd if=2020-08-20-raspios-buster-armhf-lite.img of=/dev/mmcblk0 bs=1MiB status=progress conv=fsync
$ sudo parted /dev/mmcblk0 unit GiB print free

Number Start End Size Type File system Flags
0,00GiB 0,00GiB 0,00GiB Free Space
1 0,00GiB 0,25GiB 0,25GiB primary fat32 lba
2 0,25GiB 1,72GiB 1,46GiB primary ext4
1,72GiB 14,8GiB 13,1GiB Free Space
$ lsblk -f /dev/mmcblk0
NAME FSTYPE LABEL UUID FSAVAIL FSUSE% MOUNTPOINT
mmcblk0
├─mmcblk0p1 vfat boot 4AD7-B4D5
└─mmcblk0p2 ext4 rootfs 2887d26c-6ae7-449d-9701-c5a4018755b0

2.3 - Configuration

2.3.1 Mise en place de l'autorisation SSH

$ sudo mount /dev/mmcblk0p1 /mnt
$ sudo touch /mnt/ssh
$ sudo umount /mnt ; sync

2.3.2 Mise en place de la connexion wifi

$ cat <<EOF> wpa_supplicant.conf

country=FR
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ ssid="SSID du réseau"
scan_ssid=1

k
ey_mgmt=WPA-PSK
psk="Mot de passe réseau en clair" }
EOF

Ne pas oublier d'indiquer le pays, nécessaire pour débloquer le wifi

$ sudo iw dev  wlp0s20f3 info |grep ssid
ssid SFR-fcc8_5GHz
$ sudo mount /dev/mmcblk0p1 /mnt
$ sudo cp wpa_supplicant.conf /mnt
$ sudo umount /mnt ; sync

2.3.3 Fichier config.txt simplifié

$ sudo cp /mnt/config.txt /mnt/config.txt.BU
$ cat /mnt/config.txt

[pi4]
# Enable DRM VC4 V3D driver on top of the dispmanx display stack
dtoverlay=vc4-fkms-v3d
max_framebuffers=1

2.3.4 Récupération de la carte

$ sudo umount /mnt

3 - Démarrage et connexion

3.1 - Démarrage

3.2 - Connexion

$ ip route |grep default
default via 192.168.0.1 dev wlp0s20f3 proto dhcp metric 600
$ nmap -n 192.168.0.1/24 -p 22 |grep open -B4
Nmap scan report for 192.168.0.20
Host is up (0.22s latency).

PORT STATE SERVICE
22/tcp open ssh

Dans le cas présent, une machine a été trouvée à  l'adresse 192.168.0.2

$ ssh pi@raspberrypi.local  # ou bien 

$ ssh -l pi 192.168.0.19
$ ssh -l pi 192.168.0.19
The authenticity of host '192.168.0.19 (192.168.0.19)' can't be established.
ECDSA key fingerprint is SHA256:5rOqtg9Y++MtGMTIfN+KcJ3z3xyTfW/zJplWY9t8BU8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.19' (ECDSA) to the list of known hosts.
pi@192.168.0.19's password:
Linux raspberrypi 5.4.51-v7l+ #1333 SMP Mon Aug 10 16:51:40 BST 2020 armv7l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.

SSH is enabled and the default password for the 'pi' user has not been changed.
This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.
pi@raspberrypi:~ $ passwd 
Changing password for pi.
Current password:
New password:
Retype new password:
You must choose a longer password
New password:
Retype new password:
passwd: password updated successfully
$ sudo passwd root
Nouveau mot de passe :
Retapez le nouveau mot de passe :
passwd: password updated successfully
$ sudo parted /dev/mmcblk0 unit GiB print free
Model: SD SMI (sd/mmc)
Disk /dev/mmcblk0: 14.8GiB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number Start End Size Type File system Flags
0.00GiB 0.00GiB 0.00GiB Free Space
1 0.00GiB 0.25GiB 0.25GiB primary fat32 lba
2 0.25GiB 14.8GiB 14.6GiB primary ext4

4 - Mise à jour

4.1 - Mise à jour date, langue, ...

Toujours depuis le PC, via SSH

$ date
Thu 12 Nov 15:50:10 GMT 2020
$ sudo raspi-config
Sélectionner 5 - Localisation Options Puis L1 locale Puis L2 Timezone
etc ...
# Ajouter le français [*] fr_FR.UTF-8 UTF-8 
$ sudo dpkg-reconfigure locales

# Définir le fuseau horaire (Europe - Paris)
$ sudo dpkg-reconfigure tzdata
$ exit
$ ssh -l pi 192.168.0.20

$ date
dimanche 15 novembre 2020, 23:50:48 (UTC+0100)

4.2 - Mise à jour des paquets

$ sudo mv /etc/apt/sources.list.d/vscode.list /etc/apt/sources.list.d/vscode.list.BU
$ sudo apt update

$ sudo apt dist-upgrade
......
The following packages will be upgraded:
base-files bind9-host bluez-firmware firmware-atheros firmware-brcm80211 firmware-libertas
firmware-misc-nonfree firmware-realtek libbind9-161 libdns-export1104 libdns1104
libfreetype6 libfreetype6-dev libisc-export1100 libisc1100 libisccc161 libisccfg163
liblwres161 libraspberrypi-bin libraspberrypi-dev libraspberrypi-doc libraspberrypi0
libx11-6 libx11-data raspberrypi-bootloader raspberrypi-kernel raspberrypi-sys-mods
raspi-config rpi-eeprom tzdata
......
$ sudo apt install aptitude apt-file mlocate speedtest-cli sysstat lsof \
alsa-utils sound-theme-freedesktop

$ sudo apt-file update

Ne pas installer command-not-found : Génération d'une erreur avec le dépôt rpi qui n'est pas pris en charge

4.3 - Mise à jour du chargeur de démarrage

$ sudo rpi-update
*** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
*** Performing self-update
*** Relaunching after update
*** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
#############################################################
WARNING: This update bumps to rpi-5.10.y linux tree
See: https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=288234
'rpi-update' should only be used if there is a specific
reason to do so - for example, a request by a Raspberry Pi
engineer or if you want to help the testing effort
and are comfortable with restoring if there are regressions.

DO NOT use 'rpi-update' as part of a regular update process.

##############################################################
Would you like to proceed? (y/N)

$ sudo raspi-config >>> Advanced Options >> Bootloader version >>

4.4 - Mise à jour de l'EEPROM

$ sudo rpi-eeprom-update
BCM2711 detected
Dedicated VL805 EEPROM detected
BOOTLOADER: up-to-date
CURRENT: jeudi 3 septembre 2020, 12:11:43 (UTC+0000) (1599135103)
LATEST: jeudi 3 septembre 2020, 12:11:43 (UTC+0000) (1599135103)
FW DIR: /lib/firmware/raspberrypi/bootloader/default
VL805: up-to-date
CURRENT: 000138a1
LATEST: 000138a1

5 - Vérifications

5.1 - Noyau

5.1.1 - Version

$ uname -r
5.4.51-v7l+

5.1.2 - Messages d'erreur

$ sudo dmesg -k -l emerg,alert,crit
[ 203.275191] Under-voltage detected! (0x00050005)
[ 215.755665] Under-voltage detected! (0x00050005)
....
$ sudo dmesg -k -l warn
[ 0.000000] Kernel parameter elevator= does not have any effect anymore.
Please use sysfs to set IO scheduler for individual devices.
[   17.422629] brcmfmac mmc1:0001:1: Direct firmware load for brcm/brcmfmac43430-sdio.raspberrypi,model-zero-w.txt failed with error -2
[    5.510483] brcmfmac mmc1:0001:1: Direct firmware load for brcm/brcmfmac43455-sdio.raspberrypi,4-model-b.txt failed with error -2
$ wget https://github.com/openwrt/cypress-nvram/archive/master.zip 
$ unzip master.zip
$ sudo cp cypress-nvram-master/brcmfmac* /lib/firmware/brcm/
$ sudo dmesg -k -l warn |grep error

5.1.3 Ligne de commande

$ sudo dmesg  |grep "Kernel command line"
[ 0.000000] Kernel command line: coherent_pool=1M 8250.nr_uarts=0 snd_bcm2835.enable_compat_alsa=0 snd_bcm2835.enable_hdmi=1 smsc95xx.macaddr=DC:A6:32:C9:70:EB vc_mem.mem_base=0x3ec00000 vc_mem.mem_size=0x40000000 console=ttyS0,115200 console=tty1 root=PARTUUID=90c80064-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait

sont générées à partir

$ cat /boot/cmdline.txt 
console=serial0,115200 console=tty1 root=PARTUUID=90c80064-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait

5.2 - Analyse du démarrage

$ systemd-analyze blame
31.588s dhcpcd.service
1.986s dev-mmcblk0p2.device
1.443s raspi-config.service
1.032s rpi-eeprom-update.service
569ms systemd-udev-trigger.service
.....

5.3 - Logiciel

$ cat /etc/debian_version 
10.8
$ cat /boot/config.txt
[pi4]
# Enable DRM VC4 V3D driver on top of the dispmanx display stack
dtoverlay=vc4-fkms-v3d
max_framebuffers=1

[all]
# Gestion de la carte hifiberryplus
dtparam=i2s=on
dtoverlay=hifiberry-dacplus

# Gestion de la carte alimentation
dtoverlay=gpio-poweroff,gpiopin=22,active_low
dtoverlay=gpio-shutdown,gpio_pin=17,active_low=0,gpio_pull=down

5.4 - Température et tension d'alimentation

$ vcgencmd measure_volts core
volt=0.8688V

$ vcgencmd measure_volts sdram_c
volt=1.1000V
$ sudo dmesg |grep -i voltage
[ 5178.534718] Under-voltage detected! (0x00050005)
[ 5182.694771] Voltage normalised (0x00000000)
$ vcgencmd measure_temp
temp=56.4'C

Annexe 1 - Voyants

Le voyant rouge PWR est absent sur le Pi zéro et présent sur les autres modèles

Indicates that power has been provided to the board. On A+ and later models it will flash if the voltage drops below 4.63V

Indicates SD card activity: flashes when read or write is in progress, otherwise steady ON (on Pi Zero) or OFF. Should flash intensively during boot. This is the only LED present on Pi Zero.

Additionally, ACT is flashed in specific patterns to indicate early boot problems:

Annexe 2 - Réduction consommation

# Disable the LED (to save power)
dtparam=act_led_trigger=none dtparam=act_led_activelow=off dtparam=pwr_led_trigger=none dtparam=pwr_led_activelow=off
$ sudo systemctl disable hciuart.service
$ sudo systemctl disable bluealsa.service
$ sudo systemctl disable bluetooth.service
# Disable Bluetooth
dtoverlay=pi3-disable-bt
$ sudo aptitude purge bluez
$ lsusb |grep hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
$ echo '1-1' |sudo tee /sys/bus/usb/drivers/usb/unbind
$ echo '2-1' |sudo tee /sys/bus/usb/drivers/usb/unbind
$ lsusb -t
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/1p, 480M


$ echo '1-1' |sudo tee /sys/bus/usb/drivers/usb/bind
$ echo '2-1' |sudo tee /sys/bus/usb/drivers/usb/bind

Annexe 3 - Adresse ip fixe

$ sudo nano /etc/dhcpcd.conf

 selon le modèle fourni en exemple, par exemple pour un Raspberry Pi connexion par wifi, adresse fixe 192/168.0.20 sur un réseau privé avec routeur à l'adresse 192.168.0.1

# Adresse statique
interface wlan0
static ip_address=192.168.0.20/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1 8.8.8.8
$ sudo service dhcpcd restart
$ sudo systemctl daemon-reload
$ cat /etc/resolv.conf
# Generated by resolvconf
domain numericable.fr
nameserver 89.2.0.1
nameserver 89.2.0.2

Annexe 4 - Sauvegarde SD card

L'objectif est de disposer d'une image sur PC copie de la carte SD installée, qui puisse être recopiée en cas de besoin sur une carte SD.

$ sudo parted /dev/mmcblk0 unit kiB print 
Model: SD APPSD (sd/mmc)
Disk /dev/mmcblk0: 15360000kiB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number Start End Size Type File system Flags
1 4096kiB 266240kiB 262144kiB primary fat32 lba
2 266240kiB 15360000kiB 15093760kiB primary ext4
$ calc 15360000 - 14680064 	# Réduction à opérer en kiB
679936

$ calc 15093760 - 679936 # Nouvelle taille de la partition en kiB
14413824
$ sudo e2fsck /dev/mmcblk0p2

$ sudo resize2fs /dev/mmcblk0p2 14413824K
...
Le système de fichiers sur /dev/mmcblk0p2 a maintenant une taille de 3603456 blocs (4k).
$ calc 14680064*2-1
29360127

$ sudo parted /dev/mmcblk0 resizepart 2 29360127s
$ sudo parted /dev/mmcblk0 unit GiB print
Model: SD APPSD (sd/mmc)
Disk /dev/mmcblk0: 14,6GiB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number Start End Size Type File system Flags
1 0,00GiB 0,25GiB 0,25GiB primary fat32 lba
2 0,25GiB 14,0GiB 13,7GiB primary ext4

$ sudo e2fsck /dev/mmcblk0p2
$ sudo dd if=/dev/mmcblk0 of=BU.img bs=1MiB count=14336 status=progress conv=fsync iflag=fullblock oflag=direct