Raspberry Pi Pitfall Memorandum - Using Linux

2019年12月15日 64点热度 0人点赞 1条评论
内容目录

Table of Contents

 1. To do a good job, one must first sharpen one's tools

2. Essentials for Startup

3. Updating apt-get sources and software search

4. Installing .NET Core

5. File Transfer

6. Searching and Installing Software

7. Commonly Missing xxx.so

8. Tips and Tools

1. To do a good job, one must first sharpen one's tools

1. Downloading the System

Raspberry Pi official system download address

https://www.raspberrypi.org/downloads/

Note:

Besides the three systems listed below, all others are third-party systems. These three are Raspberry Pi's own Linux systems.

NOOBS is a system installer and also a system. It is suitable for beginners and allows for custom installations, but it is quite large.

Don't rush to download; first, see the next tip.

2. CPU and System

The above-listed systems from Raspberry Pi are all 32-bit. Note, 32-bit! This means whether your Raspberry Pi CPU is 32 or 64 bit, the system is 32-bit! Raspberry Pi 3 has been around for a while, yet there is still no 64-bit system; reasons will not be explained here.

ARM and X86 refer to CPU instruction sets (ARM: simple instruction set, X86: complex instruction set), not to CPU model nor to 32-bit/64-bit. Most chips in the embedded field use the ARM instruction set.

Moreover, the Raspberry Pi system released on 2018-11-13 is Stretch, based on Debian 9, with Openssl 1.1.1, while the version from 2016 is Jessis, based on Debian 8, with Openssl 1.0.0.

Old version system download address http://blog.lxx1.com/raspberrypi-jingxiang

3. Flashing the System

Win32DiskImager is probably the most popular, but the author recommends using rufus.

After flashing, if you find that the allocated storage space is insufficient, you can use the DiskGenius tool to extend the storage. Sometimes, during the system flash, only a few GB of storage is used, leaving the rest unallocated.

fdisk -l        #View system storage space

4. Viewing System Information

uname -a        #View system version and Linux kernel information
cat /etc/os-release        #View system version code, official website, etc.
getconf LONG_BIT        #Check if the system is 32-bit or 64-bit
gcc -v                           #gcc version

2. Essentials for Startup

1. Account and Password

Raspberry Pi default account and password

pi
raspberry

Note: There is no root by default.

2. Adding Root

Since there is no root by default, you need to add it yourself.

sudo passwd root

Then you will be asked to enter the password twice.

Since you are not root by default, you cannot log in directly as root when using ssh for remote access. You must first log in as the pi user.

To switch to the root user

su root

3. Enabling Remote SSH Functionality

/etc/init.d/ssh start    #If not root user, use sudo

Check the computer's IP

ifconfig

4. Startup on Boot

SSH may not start automatically on boot; you can make software start at boot as well. Other software that needs to start can also be added here.

nano /etc/rc.local

Before the exit 0 line, enter  /etc/init.d/ssh start, then

Ctrl + O, Enter, Ctrl + X

The above three steps are the methods to save, edit, and exit edit mode. Of course, you can also use vi/vim, and adding it will make the service start automatically when booting.

5. Updating Time

Use the shell command

date    #Check system time

If the displayed time is not the same as your local time, first set the timezone (Shanghai)

cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

6. Using Wi-Fi

Considering the need to use Wi-Fi, it has been added.

If it's an Orange Pi board, you can use

nmtui      # Pop up network manager
# The rest is UI interface operations.

If it's a Raspberry Pi

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf  #Modify the network configuration file

Then add the following:

network={
    ssid="Wi-Fi name, case-sensitive"
    psk="Wi-Fi password, case-sensitive"
}
#Note: There should be no spaces around the equal sign

Restart the network

sudo /etc/init.d/networking restart

Use ifconfig to get the network status or curl baidu.com to check whether there is a response to determine if you have connected to Wi-Fi.

If you are not connected, restart the machine.

# The following commands can all reboot, need root
reboot
shutdown -h now

3. Updating apt-get Sources and Software Search

 1. Updating

apt-get update        # Update apt list
apt-get upgrade        # Update the system

The above commands are for spare use.

2. Modifying apt Sources

For spare use! Generally, no need to modify!

nano /etc/apt/sources.list

You can use either nano or vi/vim.

If your source starts with https://, it is recommended to change it to http://

If your system is Debian

deb http://ftp.debian.org/debian sid main   # Official source

Debian, Raspbian system source - official documentation  https://docs.saltstack.com/en/latest/topics/installation/debian.html

163 open-source Debian mirror source (very comprehensive, i386, amd64, source architecture)   http://mirrors.163.com/.help/debian.html

For issues regarding apt software installation, source updates, system updates errors, or problems with HTTPS, please refer to the author's other article

https://www.cnblogs.com/whuanle/p/10540584.html

4. Installing .NET Core

The author is learning .NET!

1. Downloading .NET Core

Open  https://dotnet.microsoft.com/download to obtain the download address for the appropriate version.

The ARM version of the .NET Core SDK/Runtime has a .tar.gz suffix.

On your Linux system, open the /var directory and create a directory for dotnet (for installing .NET Core). Actually, the installation directory can be arbitrary, but the author suggests placing it under /var.

Note: In some special cases or applications, the .NET Core SDK/Runtime directory needs to be placed under /usr/share/, for example, OpenCvSharp.

mkdir /var/dotnet
cd /var/dotnet

Download the software package (the following is Runtime 2.2.3, replace the download address based on actual needs)

wget https://download.visualstudio.microsoft.com/download/pr/280390c7-10ab-46bc-bd62-886751517624/b6b98756380556e39a6a96a920aa4b67/aspnetcore-runtime-2.2.3-linux-arm.tar.gz

PS: If wget indicates that it cannot download files from https links, add the parameters  --no-cookie --no-check-certificate

wget --no-cookie --no-check-certificate https://address

The author's other article: Issues encountered in embedded development boards with Linux updates, software installation, and resource downloads

https://www.cnblogs.com/whuanle/p/10540584.html

2. "Installing" .NET Core

On ARM (development boards), whether it is SDK or Runtime, it is not considered a real installation. Instead, it places the dotnet script command into the system. .NET Core does not reside in the background; it only appears when you use the dotnet command, and it does not consume any resources when idle.

Extract the .NET Core package

tar -vxf xxxxxx the name of the compressed packagexxxxxx.tar.gz

If the name is too long, you can type the first few letters and press Tab for auto-completion. A little trick: The Tab key can auto-complete commands, directory/file names, etc.

ls    # View directory files
      # Or use
ls -lah

You can see a dotnet file in the directory; link this file to /usr/bin.

ln -s /var/dotnet/dotnet /usr/bin/dotnet -f
#Note: Develop the habit of using absolute paths in some places

Test if it was successful

dotnet
dotnet --info

If it fails, check if there are any path issues; first, delete the created soft link and try creating it again.

rm /usr/bin/dotnet        # Remove the created link

Another Installation Method

export DOTNET_ROOT=/var/dotnet/dotnet
export PATH=$PATH:/var/dotnet/dotnet
# The above commands create environment variables

Then try entering the dotnet command to test.

However, variables created using the export command can only be used in the current terminal; they do not persist after re-connection, reboot, or switching accounts; they are temporary.

This method can automatically execute the export command

nano ~/.bashrc
# Or
vim ~/.bashrc

Add the following:

export DOTNET_ROOT=/var/dotnet/dotnet
export PATH=$PATH:/var/dotnet/dotnet

Thus, only the current user can use dotnet.

To make it effective globally for all users: you can edit the  /etc/bashrc file.

5. File Transfer

1. Cross-screen file transfer

Install ZMODEM

apt-get update    # Update apt list, should be updated frequently
apt-get install lrzsz    # Install cross-screen transfer software

This software can be used on any Linux system; simply drag the necessary files into the terminal (they will be stored in your current working directory in the terminal), and you can drag multiple files.

So, how can we retrieve files from Linux?

sz filename

After executing the command, a prompt to save the file will appear. The following commands can be used to conveniently download multiple files:

sz *        #All files in the current directory
sz *.zip    #All files ending with .zip in the current directory

Isn't it convenient? Give some likes to the editor!

 Six, Searching and Installing Software

Input

apt-get search xxx
# For example
apt-get search openssl

to search for a software package by name.

This might look a bit inconvenient.

Debian official address:  https://packages.debian.org/index

Searching in there allows you to get the names of software packages for different CPUs, operating systems, and versions, and you can also see software descriptions!

To install, input apt-get install xxx.

Additionally, you may often encounter missing xxx.so files or dependency issues like missing xxx. You can search on this site to determine which software is causing the issue.

 

For some beginners, a reminder here. There are many Linux distribution versions, and methods for installing software include apt, rpm, yum, etc. Debian and Ubuntu use apt for installation, while CentOS uses the yum command.

Some users have tried many tutorials online for installing software and ended up saying: "Can't find the yum command..."

 Seven, Common Missing xxx.so Files

1. Openssl

root@instance:/tmp# ldd /usr/bin/openssl
    linux-vdso.so.1 =>  (0x00007ffe94bc0000)
    libssl.so.1.0.0 => /lib/x86_64-linux-gnu/libssl.so.1.0.0 (0x00007f62aacf4000)
    libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007f62aa8b0000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f62aa4e6000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f62aa2e2000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f62aaf5d000)

When installing or compiling certain software, it may prompt that libssl.so.1.x or libcrypto.so.1.x is missing.

openssl version            # Check openssl version
ldd /usr/bin/openssl        # Check its dynamic link library files
# Sometimes even after installing openssl, a missing file error appears, which may be due to different versions~ You can check using the above commands.

View the installation directory of openssl

which openssl

Uninstall openssl

Use

apt remove openssl  # Uninstall openssl
rm -rf /etc/ssl # Delete configuration files 

Alternatively,

apt-get purge openssl    # Uninstall openssl
rm -rf /etc/ssl # Delete configuration files 

Install the latest openssl

apt-get update
apt-get-install openssl

Install a specific version of openssl:

The download address for a specific version of openssl is https://oomake.com/download/openssl

After downloading, place it somewhere in Linux; it's suggested to place it in a specific directory.

#tar zxvf openssl.tar.zip   # Rename the compressed package
cd xxxxx              # Open the decompressed directory

Create an openssl directory

mkdir /usr/local/openssl
# This directory is used to store the compiled openssl files

Configure openssl source code

This will place the compiled files and generated dynamic link libraries in the specified directory.

./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl -Wl,-rpath,/usr/local/openssl/lib shared

Install openssl

make
make install

Create a symlink

ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl

Use  ldd /usr/bin/openssl to check if it's functioning correctly. The presence of libssl.so.1.x and libcrypto.so.1.x indicates that it is normal.

 

Eight, Tips and Tools

1. ZMODEM

As mentioned in section five, it will not be listed here.

2. tree

apt-get install tree

This command will list directories in tree format; try entering the tree command.

To specify the number of "tree" layers to list:

#tree -L N ,N represents the number of layers
tree -L 1
Result:
. ├── aspnetcore
-runtime-2.2.3-linux-arm.tar.gz ├── dotnet ├── host ├── LICENSE.txt ├── shared └── ThirdPartyNotices.txt

 3. alias

Suppose I have created a .NET Core application, and to run this project, I need to navigate to the respective directory and run dotnet xxx.dll.

If I want something more stylish, for branding purposes, I can do this:

alias command_name='dotnet /xxxx.dll'

Note that there should be no spaces around the equals sign. For example:

alias xfan='dotnet /var/test/ConsoleApp1.dll'

Then, I can simply type xfan in the terminal to start the project. If you don’t understand the purpose of alias, Linux users can understand the following contents:

alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'

It should be noted that alias is temporary and only valid for the current session; it will not persist upon the next login.

To make it persistent:

nano ~/.bashrc

In that file, you can add your alias commands, for example, alias xfan='dotnet /var/test/ConsoleApp1.dll'.

Then, refresh the file for immediate effect:

source ~/.bashrc
# or
. ~/bashrc

Note that ~ refers to the current user's directory path and is only valid for that user.

To make it global and effective for all users: you can edit the  /etc/bashrc file.

4. Update gcc/gcc++ for ARM development boards | Debian update gcc without compilation.

You can refer to the author's other article:  https://www.cnblogs.com/whuanle/p/10546634.html

5. Raspberry Pi pin distribution

 6. Check CPU, Memory, and Other Consumption

top

This will show the system resource consumption of processes.

#top -p PID
# For example
top -p 1236

You can view a specific process.

Press the f key to add or remove displayed items.

  • Press the space bar to select or deselect a displayed item.
  • Press Esc to return to the monitoring interface.

In the monitoring interface, press the e key to change the display units: k, m, g, t, p. The default unit is k.

7. Shutdown, Restart, Terminate Commands, Background Execution

logout          # Logout
exit            # Logout
shutdown -h now     # Shutdown immediately
shutdown -r now     # Restart immediately
reboot              # Restart

Ctrl + C to terminate the current command.

Ctrl + Z to run the current command in the background (multiple commands can run in the background).

Input fg in the terminal to bring a background command to the foreground (provided that the command is still running).

When multiple background commands exist, enter fg n (where n is the sequence number) to bring a specific background command to the foreground.

8. Mounting a USB Drive

Insert the USB drive into the Linux device; it needs to be mounted before use.

。The following commands are for the FAT file system on USB drives.

Check the USB drive number and note the "Device", such as /dev/sda1 

fdisk -l

Mount the USB drive (modify the red part according to the actual situation)

#mount -t vfat Device_string Mount_directory
mount -t vfat /dev/sda1 /mnt/usb

9. Life Decompression Tips

rm -rf /* 

This command, once used, will completely relax you and relieve fatigue!

rm -rf /* &  # Adding & for background running, unaware

To show off to those who don’t know computers:

# On Windows
dir /s
# On Linux
find / *

The two commands above list all files on the computer, with a bunch of strings appearing quickly, which are actually harmless.

cd /&& tree

List all files in a tree format; it'll take some time~ you can show off


The author's laptop is broken, sent it to the vendor for repair, and this is the only article published this week~

  • How to use the Raspberry Pi's GPIO pins? Connecting LEDs, sensors?
  • How to light up an LED and use sensors in VS 2017?
  • How to create a project in VS 2017 and debug on the Raspberry Pi?
  • How to conduct embedded development (small lights) with .NET Core?
    Stay tuned for the next issue...

Personal experience is limited; please criticize if there are any mistakes, and I will correct them immediately~

If you encounter any other pitfalls, feel free to contact the author to add them~

痴者工良

高级程序员劝退师

文章评论