The Raspberry Pi can be used to create a system from scratch or to work with an existing system. Beginners will definitely start with an existing system. Later on, you can compile the kernel, debug the kernel, and build your own root filesystem. I will also introduce some basic commands, learning while using. Additionally, I will share some knowledge about Linux that I have learned. Please point out any mistakes.
To facilitate learning about the Raspberry Pi and Linux, and to communicate with some devices using the Raspberry Pi, I have installed Ubuntu on my PC (please don’t criticize me for not installing Debian).
I am using Ubuntu 14.04 version. I previously installed 16.x but found that some things like scripts or Python were incompatible, so I reverted back. Don’t install a version that is too new.
To work with an existing system, the first step is to install the official Raspberry Pi system. You don’t need to deal with too much hardware. The system is flashed onto an SD card. The SD card is connected to the PC through a USB card reader.1. Download the img image from the official website https://www.raspberrypi.org/downloads/ There are many pre-compiled IMG options available, including the official NOOBS and Raspbian. Below are third-party images.I chose Raspbian, which is the preferred option. The system is similar to my PC Ubuntu, and the commands can be used interchangeably. Raspbian also has a full version and a lightweight (lite) version.I chose the full version, which is the first option. The compressed file is quite small. After decompression, the image file is over 4GB. The version I downloaded is 2016-03-18-raspbian-jessie. After downloading, remember to verify the sha1. The sha1 is provided below the image. If the image is incorrect, burning it onto the SD card may fail. The verification is for the compressed file, which is the one downloaded, not the decompressed one. The command for verification is #sha1sum filename2 Prepare to burn the system
First, understand that the image file after extraction should be an img file. This img file mainly consists of two parts: the first part is the boot partition, formatted in FAT32. It contains the Linux kernel, device tree, command line, and configuration files. This partition can be recognized and modified under Windows, and we can operate and modify these files for Raspberry Pi configuration. The second part is the ext4 formatted rootfs, which is the root filesystem. Double-clicking this img file will help Ubuntu recognize and mount it.You can also use the fdisk command to check: #fdisk -l 2016-03-18-raspbian-jessie.imgDisk 2016-03-18-raspbian-jessie.img: 4033 MB, 4033871872 bytes 255 heads, 63 sectors/track, 490 cylinders, total 7878656 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x8f1eafaf
The Raspberry Pi is an open-source development board, but it is not completely open-source. The initial boot part is fixed in ROM and cannot be modified. Therefore, unless the hardware is damaged, the Raspberry Pi is unlikely to be bricked.
It is necessary to understand the basic boot process of the Raspberry Pi to understand the basic functions of various files: CPU power on -> initial boot ROM code -> mount the first FAT32 boot partition -> load bootcode.bin -> call start.elf
start.elf reads config.txt for initial initialization, such as allocating memory for the GPU based on the configuration in config.txt, and then loads kernel.img, which is the Linux kernel, passing the kernel command parameters in cmdline.txt to start the kernel. The kernel finds the rootfs based on parameters and starts the entire system. The code in ROM and start.elf are not open-source, provided in the firmware available on the official website, which is a point of contention for those who prefer pure open-source solutions.
After understanding the system boot process, we can look back at some files in the first part
-
overlays are device tree files for some extended devices.
-
dtb files are device trees for different versions of Raspberry Pi boards.
-
Bootcode.bin is used to start start.elf.
-
Start.elf is used by the Raspberry Pi to load the kernel and perform basic initialization.
-
Kernel.img is the image of the Linux kernel (zImage + dtb boot file. I haven’t looked at this in detail. The official tools can create kernel.img from zImage).
-
cmdline.txt contains the parameters for starting the Linux kernel.
-
Config.txt is the configuration file for the Raspberry Pi, such as how much memory to allocate to the GPU and what mode to use for display output. If configured improperly, the display may not work correctly when connected.
Different files are just to adapt to different boards; not all files are necessary. For example, my Raspberry Pi Model B only needs bcm2708-rpi-b.dtb bootcode.bin cmdline.txt config.txt kernel.img start.elf to boot.
3 Preparing to start burning the system
Insert the SD card into the card reader and connect it to the PC.
How to find your device on Ubuntu? Before inserting the card reader, use ls to check the local devices.Linux disk devices use sd[a-z][1-9] [a-z] indicates the number of disks [1-9] indicates the number of partitions here is /dev/sda /dev/sdb /dev/sdc indicating that I have three hard drives (why three? One SSD 250G mini SSD and two 1T mechanical drives, one for hard drive and one for optical drive). Next, insert the SD card. Use ls /dev/sd* again: /dev/sda /dev/sda5 /dev/sdb2 /dev/sdc2 /dev/sdc5 /dev/sdc8 /dev/sdd2 /dev/sda1 /dev/sdb /dev/sdc /dev/sdc3 /dev/sdc6 /dev/sda2 /dev/sdb1 /dev/sdc1 /dev/sdc4 /dev/sdc7 /dev/sdd1 found that /dev/sdd is newly added. This indicates that the newly inserted SD card is /dev/sdd. This step is very important. Ensure that you have identified the correct device for the SD card. Do not burn it to another drive. Next, use the dd command to burn the img to the device: #sudo dd if=2016-03-18-raspbian-jessie.img of=/dev/sdd bs=65536 and wait indefinitely… dd does not provide feedback. Do not unplug the device during the process. Wait until it is finished. The parameters are if=input filename, of=output filename, and bs indicates the byte size for each read or write operation. Here, a higher value does not mean faster; I usually set it to 64KB. The final result5.7MB/S is quite slow. This is just a demonstration with a regular SD card. On Windows, it is much simpler.
Using Win32DiskImager, select your drive letter and img. Click write, and you can see the progress. This is better than Linux.
If everything goes well, after burning is complete, insert the SD card into the Raspberry Pi slot. Power on the Raspberry Pi (a regular phone charger will do), and your Raspberry Pi should boot up.Image: Power supply and SD card4 Check the status
Currently, we do not have any display to check the boot status. The only thing we can observe is the indicator light on the Raspberry Pi.
If the green light flashes intermittently during the process, it indicates that the SD card is being read. This should be OK. At this point, we can connect the network cable, or connect the network cable before powering on, which also works. If the orange LNK light is on, it indicates that there is a network connection. Wait for two minutes, and when the system is stable, check the status. The ACT light should flash occasionally, and generally, it should not be lit. The other four lights should be steady on.The effect is not clear, but it is still visible that all four lights are lit. At this point, the ACT light is off. I log into the router to see if an IP has been assigned. Alternatively, I can scan using nmap: #nmap 192.168.1/24 according to your local area network. Mine is 192.168.1.x, results as shown in the image.192.168.1.1 is the router, 192.168.1.4 is my PC Ubuntu, and 192.168.1.9 is definitely the Raspberry Pi. Directly logging into the router to check the IP is the easiest way. My device has already been recognized.nmap can check that port 22 (ssh) is open by default. Let’s log in and see the default username is pi and the password is raspberry. The command is ssh username@ip #ssh [email protected] and it prompts to trust this connection. Type yes to continue.Enter the password raspberry (note that when entering a password in Linux, there is no visible feedback. Just enter and press enter to confirm).
OK, login successful.
Look at Kanxue Testing: http://ce.kanxue.com
Kanxue Forum: http://bbs.pediy.com/
—– WeChat ID: ikanxue —–
Kanxue Security Continuously focusing on security for 16 years, dedicated to serving you!
Leave a Comment
Your email address will not be published. Required fields are marked *