LJason

LJason

野生程序猴子
twitter
github
nintendo switch
steam
bilibili
email

Getting Started with Raspberry Pi 01 - Initialization

I am a severe procrastinator, always finding various reasons and excuses to delay things (to be honest, I really wish someone would force me to do things T_T).

It's been so long since I last wrote a blog post, I almost forgot how to write.

Recently, I bought a Raspberry Pi, and I absolutely love it. This little guy has created endless possibilities for me.

Now, let's write something about Raspberry Pi.

Installing the System#

Requirements:#

  1. One Raspberry Pi
  2. SD card (at least 8GB, the speed of the SD card affects system performance, it is recommended to use Class 10 or higher)

First, go to the Raspberry Pi official website to download the latest image. It is recommended for beginners to use Raspbian Buster Lite.

00

(2023.08.30: Now Raspberry Pi has a 64-bit system, which can be installed on 3B and above)

After downloading, extract the file and you will get an image file in img format.

Windows#

Download and install the tool Win32DiskImager.

Insert the SD card into your computer and open Win32DiskImager.

01

Click the folder icon to select the image file, then select the drive letter of the SD card, and click Write. Wait a few minutes (the writing time depends on the speed of the SD card). When prompted with "Write Successful," it means the process is complete. Exit Win32DiskImager.

(2023.08.30: Now there is official software for Raspberry Pi)

Linux#

Download the tool balenaEtcher.

Insert the SD card into your computer and open balenaEtcher.

The operation is similar to Win32DiskImager.

(2023.08.30: Now there is official software for Raspberry Pi)

Pre-configuration before booting#

Since the system updated on November 25, 2016, SSH is disabled by default. You can enable it by creating an empty file named ssh (without extension) in the boot partition.

For detailed instructions, you can refer to the official blog post A SECURITY UPDATE FOR RASPBIAN PIXEL.

Now, remove the SD card, insert it into the Raspberry Pi, and power it on.

Initialization#

Since I don't have an HDMI cable, I didn't connect a monitor, which means the Raspberry Pi must be configured using an Ethernet cable.

After connecting the Ethernet cable, the Raspberry Pi will obtain an IP address from the router (assuming the router is set to automatically assign IP addresses).

If you cannot log in to the router, you can use your phone to download NetX to scan and obtain the IP address of the Raspberry Pi.

02

Then, download and install Xshell 5 as an SSH client (use JuiceSSH on your phone).

Open Xshell 5, create a new session with a custom name, leave the protocol as default, enter the Raspberry Pi's IP address in the host field, leave the port number as default, and click OK. Select the session and click Connect. (If an SSH security warning pops up, click Accept)

03

The username for the new system is usually pi.

04

Then enter the password, which is usually raspberry by default.

05

Now you have successfully logged into the Raspberry Pi remotely.

Enable the root account#

The first thing I usually do is to enable the root account. Run the following command:

sudo passwd root

Enter the password twice. If you see the message passwd: password updated successfully, it means the root password has been changed successfully. Then run:

sudo passwd --unlock root

Update the system#

sudo apt -y update
sudo apt -y upgrade
sudo apt -y dist-upgrade
sudo apt -y --purge autoremove
sudo apt -y autoclean
sudo rpi-update
sudo reboot

Update vim#

The default vi editor in the system is vim-common, which is not very useful. So, uninstall it and reinstall it:

sudo apt -y purge vim-common
sudo apt -y --purge autoremove
sudo apt -y install --no-install-recommends vim

Disable root login#

sudo vi /etc/ssh/sshd_config

Find PermitRootLogin without-password and change it to PermitRootLogin no, then save the file.

Modify swap file size#

The default swap file size on Raspberry Pi is too small for my usage, so I increased it:

sudo vi /etc/dphys-swapfile

Find the CONF_SWAPSIZE option and change it to 1024. Then restart the service with sudo systemctl restart dphys-swapfile.service.

Install common software#

sudo apt -y --no-install-recommends install git gcc screen

Mounting a hard drive#

Mounting NTFS#

My USB drive is formatted as NTFS, and mounting NTFS requires NTFS-3G. I found out that most systems come with NTFS-3G, so there is no need to download the source code and compile it again. If your system is too old and does not have NTFS-3G, please Google the installation method. (You can check by typing ntfs and pressing Tab twice to see if ntfs-3g appears)

06

To view NTFS partitions, run the following command:

fdisk -l | grep NTFS

07

You will get /dev/sda1. Run the following command:

mkdir /mnt/storage
ntfs-3g /dev/sda1 /mnt/storage

If you see the message Mount is denied because the NTFS volume is already exclusively opened., unmount it first and then remount it:

umount /dev/sda1
ntfs-3g /dev/sda1 /mnt/storage

Now NTFS is successfully mounted. If you want it to be automatically mounted at boot, edit /etc/fstab and add the following line:

/dev/sda1 		/mnt/storage 	ntfs-3g silent,umask=0,locale=zh_CN.utf8 0 0

08

Mounting ext4#

It's 2019, and my storage device has upgraded from the NTFS formatted USB drive to a 2TB hard drive (using a USB extender with its own power supply). For convenience, I formatted it as ext4.

Temporary mount:

sudo fdisk -l
sudo mount /dev/sda1 /mnt

Automount at boot:

echo "UUID=$(ls -l  /dev/disk/by-uuid/ | grep sda1 | awk '{print $9}') /mnt ext4 defaults 0 0" | sudo tee -a /etc/fstab

Configure Raspberry Pi#

If you want to use Chinese, you can install Chinese fonts before configuring. Run the following command:

sudo apt -y --no-install-recommends install fonts-wqy-zenhei fonts-wqy-microhei fonts-droid-fallback

raspi-config is the system configuration tool for Raspberry Pi. Run the following command:

sudo raspi-config

Select:

  • Localisation Options
    • Change Locale
      Remove en_GB.UTF-8 UTF-8, select es_US.UTF-8 UTF-8, zh_CN.GBK GBK, zh_CN.UTF-8 UTF-8, and press Tab to OK. Set the default system language to zh_CN.UTF-8.
    • Change Timezone
      Asia-Chongqing.
  • Interfacing Options
    • SSH
      Yes.
  • Advanced Options
    • Expand Filesystem
      Make full use of the SD card.

<Finish>, press Enter, and then restart.

Connect to WiFi#

Since I have a Raspberry Pi 3, which comes with Bluetooth and Wi-Fi, I can use Wi-Fi without any additional devices. There are two methods to connect to Wi-Fi. One is through the graphical interface, which can be accessed by clicking on the Wi-Fi icon in the top right corner and setting it up. It's too simple, so I won't explain it here.

Let's focus on the second method.

Edit /etc/wpa_supplicant/wpa_supplicant.conf and add:

network={
	ssid="WiFi name"
	psk="12345678"
}

You can refer to the /data/misc/wifi/wpa_supplicant.conf file on your phone. After adding it, restart the network to connect to Wi-Fi:

sudo systemctl restart networking.service

Now you can unplug the Ethernet cable and go anywhere.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.