Difference between revisions of "Bering-uClibc 7.x - User Guide - Advanced Topics - Setting Up a Raspberry PI"

From bering-uClibc
Jump to: navigation, search
(now for the Linux console)
(Accessing your PI)
(29 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
===Raspberry PIs installation of tarballs images===
 
===Raspberry PIs installation of tarballs images===
  
We will use:
+
The simplest way of doing that is to use:
  
 
* a HDMI Television or a computer monitor with an HDMI input
 
* a HDMI Television or a computer monitor with an HDMI input
Line 7: Line 7:
 
* for the PI Zero we will need a [https://www.adafruit.com/products/2819 mini to standard HDMI adapter] and a [https://www.adafruit.com/products/1099 USB OTG micro B to A cable].
 
* for the PI Zero we will need a [https://www.adafruit.com/products/2819 mini to standard HDMI adapter] and a [https://www.adafruit.com/products/1099 USB OTG micro B to A cable].
  
====partition and format your SD card====
+
There are other ways too, but you have to know your way around... for instance, with the SD card mounted on the external PC, you could enable the console on /dev/ttyAMA0 by including a special [https://github.com/jeanrocco/LEAF/blob/main/RPI%20Zero/configdb.lrp configdb.lrp] file in the tarball alongside the other *.lrp files. This special file will be automatically loaded by LEAF even if it is not specified in leaf.cfg. This file is normally created when you do '''save''' on LEAF but you can make one manually... 
 +
 
 +
====Partition and format your SD card====
  
 
We assume the PI will use an SD card for LEAF. As we said before the PI becomes very reliable when running LEAF so there is no appreciable gain to use a so called "more reliable" USB key.  
 
We assume the PI will use an SD card for LEAF. As we said before the PI becomes very reliable when running LEAF so there is no appreciable gain to use a so called "more reliable" USB key.  
Line 42: Line 44:
 
  sudo tar -xvzf ~/Download/Bering-uClibc/7.0.1/Bering-uClibc_7.0.1_raspberry-rpi3.tar.gz
 
  sudo tar -xvzf ~/Download/Bering-uClibc/7.0.1/Bering-uClibc_7.0.1_raspberry-rpi3.tar.gz
  
Note: that this assumes the downloaded file is located in your <code class="filename">$HOME/Download</code> directory.
+
Note: this assumes the downloaded file is located in your <code class="filename">$HOME/Download</code> directory.
  
 
  sudo umount /dev/mnt
 
  sudo umount /dev/mnt
Line 48: Line 50:
 
Insert the SD card in your PI.
 
Insert the SD card in your PI.
  
====prepare your Raspberry PI====
+
====Prepare your Raspberry PI====
  
 
Connect your PI to your HDMI monitor and USB keyboard, and power it up ...  
 
Connect your PI to your HDMI monitor and USB keyboard, and power it up ...  
Line 91: Line 93:
 
Doing so insures that the serial interface conveniently becomes '''/dev/ttyAMA0''' for all PIs in LEAF.  
 
Doing so insures that the serial interface conveniently becomes '''/dev/ttyAMA0''' for all PIs in LEAF.  
  
======now for the Linux console======  
+
======Now for the Linux console======  
  
The Linux console is simply enabled by touching 2 files:
+
The Linux console is simply enabled by editting 2 files:
  
 +
''in:''
 
  /etc/inittab
 
  /etc/inittab
  add:  
+
  ''add:''
 
  ...
 
  ...
 
  # Example how to put a getty on a serial line (for a terminal)
 
  # Example how to put a getty on a serial line (for a terminal)
Line 102: Line 105:
 
  ttyAMA0::respawn:/sbin/getty -L ttyAMA0 115200 vt100
 
  ttyAMA0::respawn:/sbin/getty -L ttyAMA0 115200 vt100
 
  ...  
 
  ...  
and
+
and:
 +
''in:''
 
  /etc/securetty
 
  /etc/securetty
  ... add at the end of the file:
+
  ... ''add at the end of the file:''
 
  ttyAMA0
 
  ttyAMA0
 +
  
 
The serial interface is available on the PI's GPIO pins 14(TX) and 15(RX). You can use any suitable converter to connect to it as long as it uses 3.3 volts DC.  
 
The serial interface is available on the PI's GPIO pins 14(TX) and 15(RX). You can use any suitable converter to connect to it as long as it uses 3.3 volts DC.  
  
Here are examples of a USB to TTL 3.3 volts converter: '''pins 14, 15 and ground'''...<u>do not connect +3.3V</u>.
+
Here are examples of a USB to TTL 3.3 volts converter: '''pins 14, 15 and ground'''...'''<u>do not connect +3.3V</u>'''.
  
 
[[File:PI2_ttl_USB.jpg]] [[File:20210413 165052.png]]
 
[[File:PI2_ttl_USB.jpg]] [[File:20210413 165052.png]]
Line 121: Line 126:
  
  
To display your console on your external PC screen using a USB converter run:
+
If you are using a USB converter, before rebooting your PI, run on your external PC:
 +
 
 
  picocom -b115200 /dev/ttyUSB0
 
  picocom -b115200 /dev/ttyUSB0
 +
  
 +
After rebooting your PI, if you have both HDMI and serial displays still enabled, you should now see on both the console boot messages and logging prompts.
  
and reboot your PI.
+
''You might be wondering what the push-button and the blue led are doing on the PI2 header ... they are leftovers for other OSs that are not as safe as LEAF regarding the SD card corruption on power failure, have a look [https://github.com/jeanrocco/PI-shutdown-push-button here] ...''
reboot
+
  
If you have separate displays, you should now see both the HDMI display and the picocom terminal giving you the console boot messages and a logging prompt.
+
=====Web browser method=====
 +
You could have a look [[Bering-uClibc_7.x_-_User_Guide_-_Basic_Configuration_-_Booting_for_the_First_Time#Connecting_to_your_target_system|here]] at how LEAF now allows a secure web browser access on '''eth1''' on platforms that have more than one NIC. The PIs (1,2,3,and 4) all have a single NIC, which will default to '''eth0''', on LEAF. To ease and force a similar kind of access for your PI, from your local network, you should first <u>temporarily</u> remove the <code class="filename">shorwall</code> entry from the LRP=" list " in <code class="filename">leaf.cfg</code> file:
  
You might be wondering what the push-button and the blue led are doing on the PI2 header ... they are left over for other OS that are not as safe as LEAF, have a look [https://github.com/jeanrocco/PI-shutdown-push-button here] ...
+
On your external PC, with the SD card in the '''/mnt''' directory, edit the <code class="filename">leaf.cfg</code> file with
 
+
=====web browser method=====
+
You could have a look [[Bering-uClibc_7.x_-_User_Guide_-_Basic_Configuration_-_Booting_for_the_First_Time#Connecting_to_your_target_system|here]] at how LEAF now allows a secure web browser access on '''eth1''' on platforms that have more than one NIC. The PIs (1,2,3,and 4), on the other hand, all have a single NIC, which will default to '''eth0''', on LEAF. To facilitate and enjoy the same kind of access for your PI, when it will be connected on your local network, you should first temporarily remove the <code class="filename">shorwall</code> entry from the LRP=" list " in <code class="filename">leaf.cfg</code> file:
+
 
+
while still in the '''/mnt''' directory, from the previous steps, edit the <code class="filename">leaf.cfg</code> file with
+
 
  sudo nano leaf.cfg
 
  sudo nano leaf.cfg
 
find the line
 
find the line
Line 142: Line 145:
 
and remove the <code class="filename">shorwall</code> entry ... save and exit nano, run sync and un-mount the SD card.
 
and remove the <code class="filename">shorwall</code> entry ... save and exit nano, run sync and un-mount the SD card.
  
====accessing your PI====
+
======Accessing your PI======
 
+
Now insert the SD card in your PI, connect it to your local network, and power it up. Count to 100 :-)..., your local network DHCP server should assign an IP address to your PI. You can then access the PI from a web browser running on your external PC at http://dhcp.assigned.addr with admin:admin. To find out the IP address, use '''fing''' on Android or look in <code class="filename">/var/lib/misc/dnsmasq.leases</code> if you're already running a LEAF firewall local net.
+
  
You can always add other NICs with a suitable HAT add-on or a dongle, to your PI and use it more like the intended LEAF box router, but remember to restore the <code class="filename">shorwall</code> entry. The PI's might not be the best routers firewalls, but in these cases and for other networking purposes they become a very robust platform once loaded with LEAF since the code is then executed in rams only and no potentially destructive writes to SD card will ever happen while running.  
+
Now insert the SD card in your PI, connect it to your local network, and power it up... your local network DHCP server should assign an IP address to your PI. You can then access the PI from a web browser running on your external PC at http://dhcp.assigned.addr with admin:admin. To find out the IP address, use '''fing''' on Android or run the command: ip addr.
  
As of this writing, a naked '''PI Zero''' can only be access with the serial console, using GPIO 14 and 15 and a ttl-usb converter, since there is no NIC... The console have to be enabled by adding the file [https://github.com/jeanrocco/LEAF/raw/main/RPI%20Zero/configdb.lrp configdb.lrp] to the media files.
 
  
The '''PI zero W''' is an interesting one, as it can be accessed thru WIFI... There is an example of it's use [[Bering-uClibc_7.x_-_User_Guide_-_Advanced_Topics_-_Raspberry_PI_Zero_W_direct_WIFI_logon|here]] which does not use the serial console.
+
You can always add other NICs with a suitable HAT add-on or a dongle to your PI and use it more like the intended LEAF box router design, but remember to restore the <code class="filename">shorwall</code> entry. The PI's might not be the best routers firewalls, but in these cases and for other networking purposes they become a very robust platform once loaded with LEAF since the code is then executed in rams only and no potentially destructive writes to SD card will ever happen while running.

Revision as of 03:03, 3 June 2021

Raspberry PIs installation of tarballs images

The simplest way of doing that is to use:

There are other ways too, but you have to know your way around... for instance, with the SD card mounted on the external PC, you could enable the console on /dev/ttyAMA0 by including a special configdb.lrp file in the tarball alongside the other *.lrp files. This special file will be automatically loaded by LEAF even if it is not specified in leaf.cfg. This file is normally created when you do save on LEAF but you can make one manually...

Partition and format your SD card

We assume the PI will use an SD card for LEAF. As we said before the PI becomes very reliable when running LEAF so there is no appreciable gain to use a so called "more reliable" USB key.

On an external PC running Linux, insert your SD card, and run:

dmesg 
or
sudo fdisk -l

to see which device your SD card is assigned to (let's assume we get /dev/sdb)...

Start the fdisk utility to partition your SD card.

sudo fdisk /dev/sdb

The safest approach is to delete any existing partition. To delete a partition type "d", to create a new partition type "n", choose "p" for a new primary partition, "1" for the partition number, accept the default values for First and Last Sector. To change the partition system id to W95 FAT32, choose "t" and "b".

You may have a look before writing the changes to your SD with the command "p". It should show something like this:

Device      Boot      Start         End           Blocks      Id         System
/dev/sdb1             2048        524287         261120        b         W95 FAT32

Save your changes with the command "w".

Format the SD card:

sudo mkfs.vfat -r 1024 /dev/sdb1

Mount the SD card:

sudo mount /dev/sdb1 /mnt
cd /mnt

Extract your tarball: extract the contents of your PI(n) downloaded file with a command like the following

sudo tar -xvzf ~/Download/Bering-uClibc/7.0.1/Bering-uClibc_7.0.1_raspberry-rpi3.tar.gz

Note: this assumes the downloaded file is located in your $HOME/Download directory.

sudo umount /dev/mnt

Insert the SD card in your PI.

Prepare your Raspberry PI

Connect your PI to your HDMI monitor and USB keyboard, and power it up ...

You will get a display on your HDMI screen just like on a VGA display and the keyboard will act like the Linux tty1 standard input device.

From here on you can configure everything on the PI. Let's look at some interesting and desirable setups...

Enabling the PI Linux serial console

As usual, there is a small catch 22 waiting for us... just have a look at the Raspberry Pis documentation on the UARTS here and you will find out that all PIs are not born equal... The important thing is that for LEAF the PI's /dev/ttyAMA0 should be the first PL011 (UART0).

... extracted from the PI's documentation:

By default, only UART0 is enabled. The following table summarises the assignment of the first two UARTs:
Model first PL011 (UART0) mini UART
Raspberry Pi Zero primary secondary
Raspberry Pi Zero W secondary (Bluetooth) primary
Raspberry Pi 1 primary secondary
Raspberry Pi 2 primary secondary
Raspberry Pi 3 secondary (Bluetooth) primary
Raspberry Pi 4 secondary (Bluetooth) primary

This means that for the PIs Zero W, 3 and 4, you will have to add dtoverlay=disable-bt at the end of the file config.txt to reassign UART0 as the primary UART .

mount /dev/mmcblk0p1 /mnt
cd /mnt
edit config.txt
... and add at the end dtoverlay=disable-bt

Doing so insures that the serial interface conveniently becomes /dev/ttyAMA0 for all PIs in LEAF.

Now for the Linux console

The Linux console is simply enabled by editting 2 files:

in:
/etc/inittab
add: 
...
# Example how to put a getty on a serial line (for a terminal)
#
ttyAMA0::respawn:/sbin/getty -L ttyAMA0 115200 vt100
... 

and:

in:
/etc/securetty
... add at the end of the file:
ttyAMA0


The serial interface is available on the PI's GPIO pins 14(TX) and 15(RX). You can use any suitable converter to connect to it as long as it uses 3.3 volts DC.

Here are examples of a USB to TTL 3.3 volts converter: pins 14, 15 and ground...do not connect +3.3V.

PI2 ttl USB.jpg 20210413 165052.png


and an RS232C to TTL 3.3 volts converter: pins 14,15, +3.3V and ground

Rs232 ttl rpi2 APU2C2.jpg


If you are using a USB converter, before rebooting your PI, run on your external PC:

picocom -b115200 /dev/ttyUSB0

After rebooting your PI, if you have both HDMI and serial displays still enabled, you should now see on both the console boot messages and logging prompts.

You might be wondering what the push-button and the blue led are doing on the PI2 header ... they are leftovers for other OSs that are not as safe as LEAF regarding the SD card corruption on power failure, have a look here ...
Web browser method

You could have a look here at how LEAF now allows a secure web browser access on eth1 on platforms that have more than one NIC. The PIs (1,2,3,and 4) all have a single NIC, which will default to eth0, on LEAF. To ease and force a similar kind of access for your PI, from your local network, you should first temporarily remove the shorwall entry from the LRP=" list " in leaf.cfg file:

On your external PC, with the SD card in the /mnt directory, edit the leaf.cfg file with

sudo nano leaf.cfg

find the line

LRP="license root nano dhcpcd keyboard shorwall dnsmasq dropbear lighttpd webconf patch"

and remove the shorwall entry ... save and exit nano, run sync and un-mount the SD card.

Accessing your PI

Now insert the SD card in your PI, connect it to your local network, and power it up... your local network DHCP server should assign an IP address to your PI. You can then access the PI from a web browser running on your external PC at http://dhcp.assigned.addr with admin:admin. To find out the IP address, use fing on Android or run the command: ip addr.


You can always add other NICs with a suitable HAT add-on or a dongle to your PI and use it more like the intended LEAF box router design, but remember to restore the shorwall entry. The PI's might not be the best routers firewalls, but in these cases and for other networking purposes they become a very robust platform once loaded with LEAF since the code is then executed in rams only and no potentially destructive writes to SD card will ever happen while running.