Difference between revisions of "Install Raspberry Pi"

From xPL
Jump to: navigation, search
(Links)
(Operating system)
 
(45 intermediate revisions by one user not shown)
Line 6: Line 6:
 
This wiki bases on the console version of Raspbian.
 
This wiki bases on the console version of Raspbian.
  
== Prepare an SD card ==
+
== Operating system ==
  
On a Linux computer, download it:
+
A [https://www.raspberrypi.org/downloads/raspbian/ disk image]
su
+
can be downloaded and copied to the SD card
cd /tmp
+
with the help of [https://etcher.io/ Etcher].
wget https://downloads.raspberrypi.org/raspbian_lite_latest
+
  unzip ~/Downloads/etcher-1.1.2-linux-x86_64.zip -d /tmp/
mv raspbian_lite_latest raspbian_lite.zip
+
  /tmp/etcher-*.AppImage &
  unzip raspbian_lite.zip
+
  mv *-raspbian-*-lite.img raspbian-lite.img
+
  
Insert a card reader with the SD card you wish to use and write the image:
+
Place the SD card on the board and power it.
  fdisk -l
+
Attach a keyboard and a screen and wait for the boot process to terminate.
  RPI_DISK='/dev/sdb'
+
Login as <code>pi</code> with username <code>raspberry</code>.
  umount $RPI_DISK*
+
  raspi-config
  dd if=raspbian-lite.img of=$RPI_DISK
+
  sudo su
 +
  passwd
 +
  apt update
 +
apt upgrade
 +
 
 +
Check OS version:
 +
uname -a
 +
The result can be compared to the [https://en.wikipedia.org/wiki/Raspberry_Pi_OS#Version_history Raspberry Pi OS version history].
 +
 
 +
With <code>raspi-config</code>, one can:
 +
* change the keyboard layout
 +
* edit the host name
 +
* enable <code>ssh</code> (from <code>Interfacing Options</code>)
 +
* disable predictable interface names (keep to <code>eth0</code> and <code>wlan0</code>)
 +
* set the wi-fi region
 +
 
 +
Enable root SSH by changing in <code>/etc/ssh/sshd_config</code>:
 +
PermitRootLogin yes
  
With [http://gparted.org/ GPartEd], add a 1&nbsp;GB partition for the swap
+
Disable the [https://en.wikipedia.org/wiki/Bluetooth Bluetooth] related services:
and format the rest of the card as [https://en.wikipedia.org/wiki/Ext4 ext4] for the user data.
+
systemctl disable hciuart.service
 +
systemctl disable bluetooth.service
  
Eject the SD card reader.
+
Disable loading the Bluetooth kernel modules by adding in <code>/boot/config.txt</code>:
 +
# Disable Bluetooth
 +
dtoverlay=pi3-disable-bt
  
== Change root password ==
+
== Change root settings ==
  
 
Insert the SD card in the Raspberry Pi and boot it.
 
Insert the SD card in the Raspberry Pi and boot it.
Line 33: Line 51:
 
  sudo su
 
  sudo su
 
  passwd
 
  passwd
  apt-get update
+
  apt update
 +
apt upgrade
  
== Swap space ==
+
Setup aliases:
 +
nano .bashrc
 +
source .bashrc
  
Create a swap file:
+
Specify what to do with pageUp/Down keys:
  dd if=/dev/zero of=/root/swapfile bs=1M count=1024
+
  nano /etc/inputrc
chmod 600 /root/swapfile
+
mkswap /root/swapfile
+
  
Enable the swapfile:
+
Allow ssh:
  swapon /root/swapfile
+
  nano /etc/ssh/sshd_config
  swapon -s
+
  # change: PermitRootLogin yes
  free -k
+
  service ssh restart
  
To enable at reboot, edit <code>/etc/fstab</code>:
+
== Perl ==
/root/swapfile    swap    swap    defaults    0 0
+
  
== Locales ==
+
Specify locales by editing <code>/etc/default/locale</code>:
 +
LANG=C.UTF-8
 +
LC_ALL=C
  
Install locales (for PERL and others):
+
Test it:
  su
+
  perl -e exit
locale-gen en_US.UTF-8
+
  
Then edit <code>~.bashrc</code> and add:
+
Install the necessary package for the documentation of [https://www.perl.org/ Perl] scripts:
  export LC_ALL=C
+
apt install perl-doc
 +
 
 +
== Swap partition ==
 +
 
 +
Add a 1&nbsp;GB swap partition
 +
cfdisk /dev/mmcblk0
 +
swaplabel -L swap /dev/mmcblk0p3
 +
 
 +
Edit <code>/etc/fstab</code> and add:
 +
  LABEL=swap    none    swap    sw    0 0
 +
 
 +
Remove the default swapfile:
 +
update-rc.d -f dphys-swapfile remove
 +
swapoff -a
 +
rm /var/swap
 +
 
 +
Reboot and check:
 +
swapon -s
  
 
== Ethernet ==
 
== Ethernet ==
  
 
Check the Ethernet connection:
 
Check the Ethernet connection:
  ifconfig | grep inet
+
  ifconfig | grep 'inet '
  ping google.com
+
  ping -c 4 google.com
 
+
Connect to the BeagleBone via SSH to continue working (on a larger window).
+
ssh root@192.168.1.165
+
  
 
Change host name:
 
Change host name:
  nano /etc/hosts
+
  raspi-config
  change: "127.0.1.1 ubuntu-armhf" to: "127.0.1.1 beagleBoneHostname"
+
nano /etc/hostname
+
  
Set up a [http://en.wikipedia.org/wiki/Bonjour_(software) bonjour] discovery:
+
Give a static IP address:
  apt-get install avahi-daemon libnss-mdns
+
nano /etc/dhcpcd.conf
 +
Add the following lines:
 +
# Set a static IP address
 +
interface eth0
 +
static ip_address=192.168.1.18/24
 +
  static routers=192.168.1.1
 +
static domain_name_servers=192.168.1.3
  
Give a static address:
+
Restart the machine and re-enable SSH:
  nano /etc/network/interfaces
+
  reboot
  iface eth0 inet static
+
  raspi-config
  address 192.168.1.14
+
  ifconfig | grep 'inet '
  gateway 192.168.1.1
+
  netmask 255.255.255.0
+
  dns-nameservers 192.168.1.1
+
  /etc/init.d/networking restart
+
  
 
Set-up Apple FileProtocol (AFP) sharing:
 
Set-up Apple FileProtocol (AFP) sharing:
  apt-get install netatalk
+
  apt install netatalk
 
  nano /etc/netatalk/AppleVolumes.default
 
  nano /etc/netatalk/AppleVolumes.default
  
== Command-line editing ==
+
= Users =
  
Enable history search and bash tab autocompletion:
+
Removing the default user can close security gaps:
  nano .bashrc
+
  userdel -r pi
nano /etc/inputrc
+
apt-get update && apt-get install bash-completion
+
  
Install manuals:
 
apt-get install man-db
 
  
== Programming tools ==
+
Add a data partition for the users' home
 +
cfdisk /dev/mmcblk0
 +
mke2fs -t ext4 -L data /dev/mmcblk0p4
  
Install compilation tools (make, gcc, …):
+
Edit <code>/etc/fstab</code> and add:
  apt-get install build-essential
+
  LABEL=data    /home    ext4    defaults,noatime    0 1
  
Install Perl documentation reader:
+
Reboot the machine:
  apt-get install perl-doc
+
  reboot
 +
lsblk -o name,label,mountpoint
  
== Local time ==
+
Add the <code>control</code> user:
 +
useradd -m -g users -G users,dialout,audio -s /bin/bash control
 +
passwd control
  
Set local time:
+
= Backup =
ls -lr /usr/share/zoneinfo/Europe/
+
rm /etc/localtime
+
ln -s /usr/share/zoneinfo/Europe/Zurich /etc/localtime
+
  
[https://help.ubuntu.com/community/UbuntuTime#Time_Synchronization_using_NTP Update time] on a daily basis
+
Zeroing unused blocks on the SD card should be better for later compression:
with the help of the script <code>/etc/cron.daily/ntpdate</code> containing:
+
  apt install secure-delete
  #!/bin/sh
+
  lsblk -o name,label,mountpoint
  ntpdate ntp.ubuntu.com
+
  
Make the script executable:
+
Zero fill unused blocks of the data partition:
  chmod 755 /etc/cron.daily/ntpdate
+
  sfill -lzv /home/
  
= Control user =
+
Zero fill unused blocks of the system partition:
 +
umount /home
 +
sfill -lzv /
  
== Create user ==
+
Zero the swap partition:
 +
swapoff /dev/mmcblk0p3
 +
dd if=/dev/zero of=/dev/mmcblk0p3
 +
mkswap -L pi-swap /dev/mmcblk0p3
  
Add the <code>control</code> user:
+
Stop the machine:
  useradd -m -g users -G users,dialout,audio -s /bin/bash control
+
halt
  passwd control
+
 
 +
Extract the SD card, insert it in a reader and plug it in a Linux PC.
 +
 
 +
Save the whole disk:
 +
lsblk -o name,label,fstype,size,mountpoint
 +
RPI_DISK='/dev/sdb'
 +
RPI_BACKUP_FILE='/home/<i>user</i>/Desktop/rpi.img.bz2'
 +
  umount $RPI_DISK*
 +
dd if=$RPI_DISK status=progress | bzip2 -9f >$RPI_BACKUP_FILE
 +
ls -lh $RPI_BACKUP_FILE
 +
  eject $RPI_DISK
 +
 
 +
Restore the whole disk:
 +
bunzip2 -dc $RPI_BACKUP_FILE | dd of=$RPI_DISK status=progress
  
 
= Checks =
 
= Checks =
Line 158: Line 206:
 
  done
 
  done
 
  ps ax -o nice,pid,user,args | grep -v ' grep ' | grep -i xpl-
 
  ps ax -o nice,pid,user,args | grep -v ' grep ' | grep -i xpl-
 
== Upstart daemons ==
 
 
Check the status of init daemons:
 
initctl list
 
initctl list | grep xpl-
 
  
 
= Links =
 
= Links =
Line 170: Line 212:
 
* [https://narcisocerezo.wordpress.com/2014/06/25/create-a-robust-raspberry-pi-setup-for-24x7-operation/ create a robust Raspberry Pi setup for 24x7 operation]
 
* [https://narcisocerezo.wordpress.com/2014/06/25/create-a-robust-raspberry-pi-setup-for-24x7-operation/ create a robust Raspberry Pi setup for 24x7 operation]
 
* [https://raspberrypi.stackexchange.com/questions/47773/disable-auto-file-system-expansion-in-new-jessie-image-2016-05-10 removing automatic filesystem expansion at boot]
 
* [https://raspberrypi.stackexchange.com/questions/47773/disable-auto-file-system-expansion-in-new-jessie-image-2016-05-10 removing automatic filesystem expansion at boot]
 +
* [https://raspberrypi.stackexchange.com/questions/48056/login-as-root-not-possible enabling root ssh]
 +
* [https://www.modmypi.com/blog/how-to-give-your-raspberry-pi-a-static-ip-address-update setting a static IP address]
 +
* [https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md setting-up WiFi]
  
 
[[Category: all]] [[Category: Install]]
 
[[Category: all]] [[Category: Install]]

Latest revision as of 11:36, 29 January 2021

The xPL protocol is light enough to run on simple machines such as the Raspberry Pi.

Install Raspbian

Several distributions are available for the Raspberry Pi. This wiki bases on the console version of Raspbian.

Operating system

A disk image can be downloaded and copied to the SD card with the help of Etcher.

unzip ~/Downloads/etcher-1.1.2-linux-x86_64.zip -d /tmp/
/tmp/etcher-*.AppImage &

Place the SD card on the board and power it. Attach a keyboard and a screen and wait for the boot process to terminate. Login as pi with username raspberry.

raspi-config
sudo su
passwd
apt update
apt upgrade

Check OS version:

uname -a

The result can be compared to the Raspberry Pi OS version history.

With raspi-config, one can:

  • change the keyboard layout
  • edit the host name
  • enable ssh (from Interfacing Options)
  • disable predictable interface names (keep to eth0 and wlan0)
  • set the wi-fi region

Enable root SSH by changing in /etc/ssh/sshd_config:

PermitRootLogin yes

Disable the Bluetooth related services:

systemctl disable hciuart.service
systemctl disable bluetooth.service

Disable loading the Bluetooth kernel modules by adding in /boot/config.txt:

# Disable Bluetooth
dtoverlay=pi3-disable-bt

Change root settings

Insert the SD card in the Raspberry Pi and boot it.

sudo su
passwd
apt update
apt upgrade

Setup aliases:

nano .bashrc
source .bashrc

Specify what to do with pageUp/Down keys:

nano /etc/inputrc

Allow ssh:

nano /etc/ssh/sshd_config
# change: PermitRootLogin yes
service ssh restart

Perl

Specify locales by editing /etc/default/locale:

LANG=C.UTF-8
LC_ALL=C

Test it:

perl -e exit

Install the necessary package for the documentation of Perl scripts:

apt install perl-doc

Swap partition

Add a 1 GB swap partition

cfdisk /dev/mmcblk0
swaplabel -L swap /dev/mmcblk0p3

Edit /etc/fstab and add:

LABEL=swap    none    swap    sw    0 0

Remove the default swapfile:

update-rc.d -f dphys-swapfile remove
swapoff -a
rm /var/swap

Reboot and check:

swapon -s

Ethernet

Check the Ethernet connection:

ifconfig | grep 'inet '
ping -c 4 google.com

Change host name:

raspi-config

Give a static IP address:

nano /etc/dhcpcd.conf

Add the following lines:

# Set a static IP address
interface eth0
static ip_address=192.168.1.18/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.3

Restart the machine and re-enable SSH:

reboot
raspi-config
ifconfig | grep 'inet '

Set-up Apple FileProtocol (AFP) sharing:

apt install netatalk
nano /etc/netatalk/AppleVolumes.default

Users

Removing the default user can close security gaps:

userdel -r pi


Add a data partition for the users' home

cfdisk /dev/mmcblk0
mke2fs -t ext4 -L data /dev/mmcblk0p4

Edit /etc/fstab and add:

LABEL=data    /home    ext4    defaults,noatime    0 1

Reboot the machine:

reboot
lsblk -o name,label,mountpoint

Add the control user:

useradd -m -g users -G users,dialout,audio -s /bin/bash control
passwd control

Backup

Zeroing unused blocks on the SD card should be better for later compression:

apt install secure-delete
lsblk -o name,label,mountpoint

Zero fill unused blocks of the data partition:

sfill -lzv /home/

Zero fill unused blocks of the system partition:

umount /home
sfill -lzv /

Zero the swap partition:

swapoff /dev/mmcblk0p3
dd if=/dev/zero of=/dev/mmcblk0p3
mkswap -L pi-swap /dev/mmcblk0p3

Stop the machine:

halt

Extract the SD card, insert it in a reader and plug it in a Linux PC.

Save the whole disk:

lsblk -o name,label,fstype,size,mountpoint
RPI_DISK='/dev/sdb'
RPI_BACKUP_FILE='/home/user/Desktop/rpi.img.bz2'
umount $RPI_DISK*
dd if=$RPI_DISK status=progress | bzip2 -9f >$RPI_BACKUP_FILE
ls -lh $RPI_BACKUP_FILE
eject $RPI_DISK

Restore the whole disk:

bunzip2 -dc $RPI_BACKUP_FILE | dd of=$RPI_DISK status=progress

Checks

CPU usage

Check CPU usage:

ps -eo pcpu,user,args | sort -k 1 -r | head -10
echo && ps -eo pcpu,user,args | grep -v ' 0.0 ' | grep -v '%CPU' | sort -k 1 -r | sed 's/[ ^I]\/.*\/perl//' | sed 's/.pl[ ^I].*/.pl/'

Process priorities

Check process priorities:

ps ax -o nice,pid,user,args | grep -v ' NI ' | sort

The lowest numbers correspond to the highest priorities.

Change the priority level of xPL devices:

ps ax -o nice,pid,user,args | grep -v ' grep ' | grep -i xpl-

USER='control'
NEW_LEVEL=-10
SYSTEM_IFS=$IFS; IFS=$'\n'; 
task_list=(`ps ax -o pid,user,args | grep -v ' grep ' | grep -i '/xpl-'`)
IFS=$SYSTEM_IFS
for item in "${task_list[@]}" ;  do
  task_id=`echo "${item}" | sed "s/$USER.*//"`
# echo $task_id
  renice $NEW_LEVEL -p $task_id >/dev/null
done
ps ax -o nice,pid,user,args | grep -v ' grep ' | grep -i xpl-

Links

Here some interesting pages for the installation process: