Raspberry Pi Setup

Setup SD Card on another linux machine to install headless

I use minimal Raspian distro. This is tested on a Pi Zero and a Pi 4 in Feb 2020.

# find the sd card device
lsblk -p | grep -v loop
# sdb      8:16   1  29.7G  0 disk 
# unmount your sd if necessary
umount /dev/sdb

# flash it
wget https://downloads.raspberrypi.org/raspbian_lite_latest
unzip 2019-09-26-raspbian-buster-lite
dd bs=4M if=2019-09-26-raspbian-buster-lite.img of=/dev/sdb conv=fsync

# mount boot and root file system to /media/sdcard1,2
sudo mount /dev/sdb1 /media/sdcard1 # boot parition,
sudo mount /dev/sdb2 /media/sdcard2 # root

# wifi settings
sudo cp wpa_supplicant.conf /media/sdcard1/
# vim /media/sdcard1/wpa_supplicant.conf # edit using use format here

# add ssh
touch /media/sdcard1/ssh
mkdir /media/sdcard2/home/pi/.ssh/
cp ~/.ssh/authorized_keys /media/sdcard2/home/pi/.ssh/ # ssh *to* it

# optional
cp ~/.ssh/id_rsa /media/sdcard2/home/pi/.ssh/ # if you want to ssh *from* it
cp ~/.bashrc /media/sdcard2/home/pi/ 

# finish on linux pc
sudo umount /dev/sdc1
sudo umount /dev/sdc2

# boot it up 
#scp .ssh/authorized_keys pi@raspberrypi.local:.
# remove old host keys
ssh-keygen -f "/home/bbeeson/.ssh/known_hosts" -R "raspberrypi.local"
# ssh and go!
ssh pi@raspberrypi.local
#mkdir .ssh
#mv authorized_keys .ssh

Setup Basics

sudo apt-get update && sudo apt-get upgrade -y
# change password!
# get nslookup
sudo apt-get install dnsutils vim
sudo raspi-config
# change hostname, timezone, 

Kiosk Mode


Backup and Restore SD Cards

# insert sd, copy whole (incl. partitions) to a file. Will be the SIZE OF THE WHOLE SD CARD!
sudo dd bs=4M if=/dev/sdc of=original-`date +%d%m%y`.img
# optionally, shrink it http://www.aoakley.com/articles/2015-10-09-resizing-sd-images.php

# alternatively set bs to 1M and use "count" to set megabytes
# see detail https://superuser.com/questions/568236/can-i-use-dd-to-clone-a-larger-sd-card-to-a-smaller-sd-card-if-the-actual-partit
# or just round up Gb using using "df -h"
# also can use "dcfldd" (dd with status). eg for 2Gb:
sudo dcfldd if=/dev/sdc of=original-`date +%d%m%y`.img bs=1M count=2048
# chk the img file with and compare to mounted sd card:
sudo fdisk -l /dev/sdc # check sectors, etc
file original.img      # against this

Leave a Reply

Your email address will not be published. Required fields are marked *