preface

The Raspberry PI is a card computer released by the Raspberry PI Foundation in the UK. The bare board is only the size of a credit card, with low cost and power consumption. However, it can install and run the Linux system with complete functions. From 2013 to 2019, the Raspberry PI Foundation has released several versions of the raspberry PI. They typically support 1GB of ram, cost $35, consume less than 15W of power, and can be turned on 24/7.

On June 25, 2019, the Raspberry PI Foundation officially launched the PI 4B at $35, $45, and $55 for 1GB, 2GB, and 4GB, followed by an 8GB version at $65. And just a few days ago, on October 20, 2021, Raspberry PI has officially announced a price hike for the raspberry PI 4B series. Due to a chip shortage, the price of the Raspberry PI series has increased for the first time in history.

As early as March 2020, I bought the RASPberry PI 4B 4G ram version, but after playing with it for a while, I left it to eat dust. At least 400 RMB, I’d better use it. However, as a software programmer, I couldn’t get the most out of the Raspberry PI. After all, I couldn’t play with the hardware and sensors, and the only things I liked were “low power” and “Full Linux”.

The raw materials

The title note
Raspberry sent 4 b There was a TypeC power port hardware bug with raspberry PI 4B when it first quitFixed in 4GB memory version, hardware version 1.2, the actual purchase should pay attention to distinguish.
The shell It is recommended to use Pi4B with fan, Pi4B has high heat, please note that the 4B version is marked when buying.Previous versions of the shell were not compatible.
Sd card The official requirement is at least 8G, 8G is recommended,Speed above C10the
U disk Size 16G or above, USB3.0 or above protocol. Raspberry PI 4B has two USB3.0 ports and two USB2.0 ports,The USB flash drive can be used as a system disk.
Electrical source The official recommendation is to use a 5V 3A charger.
The power cord Thick 5A power cables with USB-TypeC ports are recommended.
Other peripherals Depending on the situation youmayYou also need a computer (to write system images), monitor, andmicroHDMILine (first start network configuration), keyboard (first start network configuration)

Install the system

I used raspberry PI official PiOS, and then the USB disk was broken. It was really broken when I was using it. At that time, SSH was still connected, and suddenly the whole system became read-only. But the USB disk is also obsolete, physical damage, need a new USB disk, redo the system.

For the new system this time I chose Ubuntu Server 20.04.3LTS. There are two ways to install the operating system. One is to use the official system write tool. After installing the operating system on the PC, you can write the system to the SD card by selecting the SD card and the system to be installed.

I chose a different approach.

  1. Download the Ubuntu Server image from the Ubuntu official website
  2. useWin32diskimager toolsWrite the downloaded operating system image to the SD card.
  3. After the image is written, go to disk management and delete the second partition of the SD card.
  4. Modify the network-config configuration file of SD card partition 1 to prewrite wifi information so that the system automatically connects to wifi for the first time.
  5. The SD card is ejected, and the usb flash drive is inserted. Repeat step 2 to write the same image to the USB flash drive. Then repeat Step 3 to delete the first partition of the USB flash drive.
  6. Insert THE SD card and USB disk into the corresponding interface of raspberry PI, power on and start.
  7. After the system starts for the first time, it takes some time to automatically expand partitions. After about five minutes, unplug the power supply and reconnect the system.
  8. On the router page, you can see that raspberry PI is connected to the network. The MAC address of Raspberry PI 4B starts with DC: A6:32.If you do not have permission to access the router page, use this commandThe official methodCheck the IP address of raspberry PI.
  9. If none of the above schemes is available, or the raspberry PI device cannot be found, you need to connect the monitor and the keyboard and mouse device to restart and check the running status of the Raspberry PI. The raspberry PI 4B used ordinary HDMI for video interface, while the raspberry PI 4B uses two microHDMI, smaller in size, and the one close to the power port is enabled by default.
  10. After obtaining the RASPberry PI IP address, you can use the SSH client program to log in to the Raspberry PI system. The initial user name and password are both Ubuntu. You need to change the password upon the first login.
  11. After logging in to the Raspberry PI system with the new password, you can use sudo permission to run the apt-get update && apt-get upgrade commands to update the system.

At this point, the Raspberry PI system has been installed and the USB flash drive has been automatically mounted to the root partition. If the above steps are correctly configured and operated, it is completely unnecessary to connect peripheral keys, mice and screens to the raspberry PI.

Modify the code

The default coding of raspberry PI is C.UTF-8, which often involves Chinese characters (either file names or code comments) in China. Therefore, it is recommended to use zh_cn.utF-8 encoding set. To set the encoding, install the corresponding encoding first, and then run the export command to set environment variables.

ubuntu@ubuntu:~$ sudo locale-gen zh_CN.UTF-8
Generating locales (this might take a while)...
  zh_CN.UTF-8... done
Generation complete.
ubuntu@ubuntu:~$ export LANG=zh_CN.UTF-8
Copy the code

You can use the locale command to view the effect.

In this case, although the encoding set has been successfully modified, it is only valid for the current session. After connecting to a new session, you will find that the encoding set is still the original C. utf-8. In this case, you can change the content of the file to LANG= zh_cn.utf-8 by vim /etc/default/locale. After login with any account will be zh_CN. Utf-8 encoding.

Set the time zone

By default, the raspberry PI uses UTC (0 time zone) after installing ubuntu Server. When using the date command to check the time, you need to add 8 hours to the domestic time. To change the time zone, run the dpkg-reconfigure tzdata command. Press the arrow key on the keyboard to select Asia (Asia) and enter, then select Shanghai (Shanghai) and enter.

The above is to set the time zone in interactive mode. After entering the command, you need to continue to use the keyboard to interact with the shell, otherwise it will always be blocked. This method is not suitable for ordinary scripts.