Raspberry Pi basics

Installing from scratch

Download Raspberry Pi OS or use the Balena Etcher to write it to an SD card.

Get raspberry PI Hardware version

cat /proc/cpuinfo

Backup an image

Copy sd card content to a file source

dd bs=4096 if=<source file or device> | pv | dd of=<dest file or device>

dd bs=4096 if=/dev/sdc | pv | dd of=~/tmp/output-pi-image-backup.img`
wget https://raw.githubusercontent.com/Drewsif/PiShrink/master/pishrink.sh
chmod +x pishrink.sh
sudo mv pishrink.sh /usr/local/bin/
sudo pishrink.sh ~/tmp/output-pi-image-backup.img 

Old disk drives

Automatic spinning drives down, jut install hdparm - default settings should work just fine.

sudo apt-get install hdparm

More on that, and fine tuning:

hdparm -S 120 /dev/sda

Get current status: hdparm -C /dev/hdX

Autostart apps

symbolic link ide: ln -s /etc/init.d/start_my_app /etc/rc.d/

exec 2> /tmp/rc.local.log  # send stderr from rc.local to a log file
exec 1>&2 # send stdout to the same log file
set -x
sudo hdparm -S 100 /dev/sda
sudo service alarisb.sh start

Autologin to terminal

Run: sudo raspi-config
Choose option: 1 System Options
Choose option: S5 Boot / Auto Login
Choose option: B2 Console Autologin
Select Finish, and reboot the Raspberry Pi.

Networking

Auto connect to WiFi

bootfs/wpa_supplicant.conf or rootfs/etc/wpa_supplicant/wpa_supplicant.conf

country=US # replace with your country code
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

network={
ssid="WIFI_NETWORK_NAME"
psk="WIFI_PASSWORD"
key_mgmt=WPA-PSK
}

Restarting network manager without reboot:

sudo systemctl restart wpa_supplicant.service 
sudo systemctl restart dhcpcd.service

Enable SSH with creating the file bootfs/ssh

Find device on network

Use arp | grep -v incomplete or nmap -sn $(ip route | awk '/default/ {print $3}')/24 -p 22 (note that it looks for open ports 22)

Uncomplicated FireWall

install ufw - more on linux security here.

Network problems?

My pi4 consistently had a hard time with my wireless interface. I do a fresh install with the Imager for a headless, create the wpa_supplicant.conf file, add the ssh on the bootfs partition, and no luck. So I had to connect it to a monitor, add default username/pass - and STILL the network would not connect... I tried to scan for wireless connections:

sudo iwlist wlan0 scan

got Network is down error. Well, if it's down, let's make it up!

sudo ifconfig wlan0 up

Now the first useful clue came: Operation not possible due to RF-kill.

So let's list it:

rfkill list all
0: phy0: Wireless LAN
Soft blocked: yes
...

I do not know which step I missed, or if it did that due the power supply, but this was the first thing that came with the latest RPI install.

Disable Wifi on Pi Zero W

Edit boot/config.txt Add dtoverlay=pi3-disable-wifi