Raspberry Pi Developer's Guide: Setup


Install the Image


To install a Raspberry Pi operating system image on an SD card.

Download the image


Download Raspbian Buster Lite: Minimal image based on Debian Buster

Installing operating system images on Linux


  • Check the current block devices
  • 
      lsblk -p
    
  • Find the SD card's information
  • The new device that has appeared is your SD card
    
      lsblk -p
    
    /dev/sdb      8:16   1  14.9G  0 disk 
    ├─/dev/sdb1   8:17   1    20M  0 part /media/jerry/B24B-E3F4
    └─/dev/sdb2   8:18   1   256M  0 part /media/jerry/57f8f4bc-abf4-655f-bf67-946fc
    
    
  • Copying the image to the SD card
  • In a terminal window, write the image to the card with the command below, make sure the output device name is the name of the whole SD card as described above, not just a partition.
    
    sudo dd bs=4M if=2019-09-26-raspbian-buster.img of=/dev/sdb conv=fsync
    
    
  • Login using SSH client
  • SSH can be enabled by placing a file named ssh, without any extension, onto the boot partition of the SD card. When the Pi boots, it looks for the ssh file. If it is found, SSH is enabled and the file is deleted.
    
    $ touch /media/jerry/boot/ssh
    
    The default for all versions of Raspbian: User: pi Password: raspberry
    
    ssh pi@192.168.0.11
    

Setup


config.txt


The Raspberry Pi uses a configuration text file named config.txt.
This is read by the GPU before the ARM CPU and Linux are initialised. It must therefore be located on the first (boot) partition of your SD card, alongside bootcode.bin and start.elf. This file is normally accessible as /boot/config.txt from Linux, and must be edited as root.
The config.txt file is read by the early-stage boot firmware.
Any changes will only take effect after you have rebooted your Raspberry Pi.




raspi-config


raspi-config is the Raspberry Pi configuration tool


sudo raspi-config


If you are using the Raspberry Pi desktop then you can use the graphical Raspberry Pi Configuration application from the Preferences menu to configure your Raspberry Pi.


Servers

Telnet

You start the process of installing Telnet by using the command

sudo apt-get install telnetd

After Telnet has been installed, you will need to get the service starts.
You can do it by using the command

 sudo /etc/init.d/openbsd-inetd restart


or by rebooting the RPi.
Once you have the service ready, you can verify this by using the netstat -a command.
You should see something like this from the RPi


pi@raspberrypi:~$ netstat -a | grep telnet (with no telnet session on RPi active)


tcp 0 0 *:telnet *:* LISTEN

In a production environment, you should limit who can access the RPi via Telnet. You can do so with the /etc/hosts.allow file.
Using this example (changing the ip address for the address of the workstation you are testing from) will block access to that workstation on Telnet: add a line like this to /etc/hosts.allow to block a specific host:

in.telnetd : 192.168.15.161 : deny


Finding the name of the process to put in the hosts.allow file involved looking at the /var/log/syslog file to identify the running process involved.
That is what told me that I needed to use in.telnetd instead of telnet or telnetd that I had first tried. Anytime that you make a change to the hosts.allow file, you will need to restart the inetd process

sudo /etc/init.d/openbsd-inetd restart



If you want to allow only a specific workstation to get in via Telnet and block all others, you would use something like this


in.telnetd : 192.168.15.162 : allow
in.telnetd : 192.168.15. : deny


Using only 192.168.15. acts like a wildcard and blocks all workstations that didn’t match on the earlier rule.

If you want to remove Telnet, you will use sudo apt-get remove telnet.

Apache

Apache is a popular web server application you can install on the Raspberry Pi to allow it to serve web pages.
On its own, Apache can serve HTML files over HTTP, and with additional modules can serve dynamic web pages using scripting languages such as PHP.

Install Apache
First install the apache2 package by typing the following command in to the Terminal:
sudo apt-get install apache2 -y
Test the Web Server
By default, Apache puts a test HTML file in the web folder. This default web page is served when you browse to http://localhost/ on the Pi itself, or http://192.168.1.10 (whatever the Pi's IP address is) from another computer on the network. To find the Pi's IP address, type hostname -I at the command line (or read more about finding your IP address).
CHANGING THE DEFAULT WEB PAGE

This default web page is just a HTML file on the filesystem. It is located at /var/www/html/index.html.
Note: The directory was /var/www in Raspbian Wheezy but is now /var/www/html in Raspbian Jessie

As you can see, by default the html directory and index.html file are both owned by the root user. In order to edit the file, you must gain root permissions. Change the owner to your own user with sudo chown pi index.html before editing.
Try editing this file and refreshing the browser to see the web page change.
Your Own WEB Site
If you know HTML you can put your own HTML files and other assets in this directory and serve them as a website on your local network.

VNC


The latest Raspbian provided raspi-config .
You can enable VNC Server at the command line using raspi-config:

sudo raspi-config

In this submenu ""Interfacing Options", you enable/disable VNC server.

For the legacy Raspbian, install the VNC server manually:

sudo apt-get install tightvncserver


Change it to be started automatically:

$ cd /home/pi
$ cd .config
$ mkdir autostart
$ cd autostart
$ nano tightvnc.desktop

[Desktop Entry]
Type=Application
Name=TightVNC
Exec=vncserver :1
StartupNotify=false



Type ctrl-X and then Y to save the changes to the file.
That is all there is to it. The next time you reboot the VNC server will restart automatically.

Now, change the password it:

/usr/bin/tightvncpasswd

Execute

/usr/bin/tightvncserver 

Development Tools



APT

Some Python packages can be found in the Raspbian archives and can be installed using APT.

sudo apt-get update

This is the preferred method of installing software, as it means that the modules you install can be kept up to date easily with the usual sudo apt-get update and sudo apt-get upgrade commands.

Python


Python packages in Raspbian which are compatible with Python 2.x will always have a python- prefix. So, the picamera package for Python 2.x is named python-picamer.
Python 3 packages always have a python3- prefix. So, to install picamera for Python 3 you would use:

sudo apt-get install python3-picamera

Uninstalling packages installed via APT can be accomplished as follows:

sudo apt-get remove python3-picamera


They can be completely removed with purge:

sudo apt-get purge python3-picamera


PIP

Not all Python packages are available in the Raspbian archives, and those that are can sometimes be out-of-date.
If you can't find a suitable version in the Raspbian archives, you can install packages from the Python Package Index (PyPI). To do so, use the pip tool.

pip is installed by default in Raspbian Jessie (but not Raspbian Wheezy or Jessie Lite). You can install it with apt:

sudo apt-get install python3-pip


To get the Python 2 version:

sudo apt-get install python-pip
pip3 installs modules for Python 3, and pip installs modules for Python 2.

For example, the following command installs the Unicorn HAT library for Python 3:

pip3 install unicornhat

The following command installs the Unicorn HAT library for Python 2:

pip install unicornhat

Note: In Raspbian Wheezy, the command for managing Python 3 packages was pip-3.2, not pip3.

Uninstall Python modules with pip3 uninstall or pip uninstall.

WiringPi



System


Create RAM filesystem


#!/bin/bash
sudo mkdir -p /mnt/ram
sudo mount -t tmpfs -o size=10m tmpfs /mnt/ram

Networking


Installing the FTP server



sudo apt install proftpd

Then, enable the changes by running the command:

sudo service proftpd reload



Delete a default route



sudo del -net default gw 192.168.0.1


USB


USB stick


Create an ext4 partition in your USB stick, then, add this line in /etc/fstab:

/dev/sda1 /media/USBdrive ext4 defaults,nofail,x-systemd.device-timeout=1,noatime 0 0


WiFi


Installation

The Edimax EW-7811Un 150 Mbps Wireless 802.11bgn USB Adapter is a popular choice for use with the Raspberry Pi.
The latest Raspian distribution (Raspbian “wheezy” 2012-09-18) already includes the drivers for this adapter pre-installed.

Insert the Edimax USB adapter into your Raspberry Pi's USB port. Next, lets make sure that the Raspberry Pi recognizes the device. Use the following command to verify that the Pi "sees" the Edimax WiFi adapter.

lsusb

Bus 001 Device 004: ID 7392:7811 Edimax Technology Co., Ltd EW-7811Un

You should see the Edimax EW-7811Un device listed in the output.
Now that we have verified that the Edimax adapter is recognized, lets check to make sure the kernel driver is loaded. Use the following command to list the kernel modules:


lsmod

You should see the "8192cu" kernel module loaded. If not, try removing and re-inserting the Edimax USB adapter.
As a final validation check to make sure that the Edimax is ready to use, send the "iwconfig" command to display a listing of the current wireless network configuration.

iwconfig

We are just looking to ensure that the "wlan0" adapter is present.
Now we are ready to move on to the configuration steps.

Configuration


One you have installed the adapter, verified the kernel driver is loaded, and confirmed that a wireless network interface ("wlan0") is available, you will need to configure the wireless connection settings to securely connect to your wireless network.

The following error will be in the system log messages when the WiFi is not configured correctly:


[ 69.643226] IPv6: ADDRCONF(NETDEV_UP): wlan0: link is not ready 
[ 69.751025] usb 1-1.2: USB disconnect, device number 4 
[ 69.758622] rtw_cmd_thread: DriverStopped(0) SurpriseRemoved(1) break at line 482

  • Raspi model 3
  • Setting WiFi up via the command line:
    • Using raspi-config
    • sudo raspi-config
      
      Note that raspi-config does not provide a complete set of options for setting up wireless networking
    • To scan for WiFi networks
    • sudo iwlist wlan0 scan
      
    • /etc/wpa_supplicant/wpa_supplicant.conf
    • Go to the bottom of the file and add the following:
      network={
          ssid="testingSSID"
          psk="testingPasswordPhrase"
      }
      
  • Raspi model B+
  • Modify /etc/network/interfaces
    • Find this block in the file
    • 
      allow-hotplug wlan0
      iface wlan0 inet manual
          wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
      
    • Then change it to this
    • 
      auto wlan0
      allow-hotplug wlan0
      iface wlan0 inet dhcp
          wpa-ssid “YOUR NETWORK SSID HERE”
          wpa-psk “YOUR NETWORK PASSPHRASE HERE”
          
      
    Then, re-start the networking service
    sudo /etc/init.d/networking restart

The above is the way I used to bring up my WiFi and connected to the AP.


The following are suggested in the Book and Internet and can't bring up my WiFi.
After modifying the network interface configuration file, we need to create the wireless configuration file.
Now let's setup the WiFi connection and passkey.
ow we create a pass phrase using a tool that was installed with wpa_supplicant the syntax is as follows:



    wpa_passphrase ssid pass phrase

Where ssid is the name you gave the router and pass phrase is the phrase you used to secure your router.(If you don’t know or never have secured your router then this is the time to do so).




wpa_passphrase myrouter thisisalongpassphrasesonobodycanguess

Edit the file etc/wpa_supplicant/wpa_supplicant.conf.
Add this to the end:



network={
  ssid="myrouter"
  #psk="thisisalongpassphrasenobodycanguess"
  psk=fd50e5fb2b66493702338dd5175241d2e8dd7dd42fc292bbb7c56b01f9e9fdc0
  proto=RSN
  key_mgmt=WPA-PSK
  pairwise=CCMP
  auth_alg=OPEN
}

Once the configuration files are complete, use the following command to restart the wireless adapter / interface.



sudo ifup wlan0


This command will restart the network interface and use the newly defined interface and wireless settings to establish a wireless network connection. Assuming the configuration is correct, the wlan0 interface should connect and acquire an IP address.

For connection verification and an alternate way to see your assigned IP address, use the following command to list the network configuration:



ifconfig wlan0




Commands

  • ncdu
  • dpkg -l

SETTING UP A RASPBERRY PI AS AN ACCESS POINT IN A STANDALONE NETWORK


留言

熱門文章