OrzMiku

Dzの窝

山无陵,江水为竭,冬雷震震,夏雨雪,天地合,乃敢与君绝。
github
bilibili
modrinth
email

How to Burn System to Raspberry Pi with a Mobile Phone

Warning: This blog post was written during my high school years and contains very immature content. However, the method should still be feasible.

Disclaimer#

Your phone needs to have a third-party recovery (such as TWRP) installed!!!
This article contains a large amount of personal opinions, which are based on personal experience and may not be accurate. The understanding of the related operations may also be biased. If there are any errors, please point them out in a timely manner.

During the pandemic, I had nothing to do at home. When I was organizing my closet, I found a Raspberry Pi that was collecting dust. So I thought about using it to pass the time. Since I didn't bring my computer home and the neighborhood was locked down, I couldn't go out. Is it possible to install a system on the Raspberry Pi using my phone?

Tutorial#

Step 1: Prepare the materials#

You will need a phone with TWRP installed and an SD card.

If your phone does not support an SD card, you will also need a card reader and an OTG adapter.

Step 2: Download the necessary files#

Download the system image you want to flash. If it is in IMG format, you can use it directly. If it is not in IMG format, open the compressed file and extract the IMG file for later use.

For the purpose of this article, let's assume the file name is sys.img.

Remember the path of the file.

For the purpose of this article, let's assume the path is /sdcard/Download/sys.img.

Step 3: Open the terminal and check the partition status#

Restart your phone and enter TWRP. Go to "Advanced -> Terminal" and enter the following command to check the partition status:

df -h

The result will be something like this (example):

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda1        64G   32G   32G  50 /sdcard

Now insert the SD card and enter the command again to check the partition status:

df -h

The result will be something like this (example):

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda1        64G   32G   32G  50 /sdcard

/dev/sdg1        32G   1kb  32G   0 /sdcard1

You will notice an additional line, which represents the SD card. Remember the file system of the SD card.

For the purpose of this article, let's assume the SD card is located at "/dev/sdg1".

Step 4: Flash the system#

Now we can start flashing the system:

dd bs=1024000 if=/sdcard/Download/sys.img of=/dev/sdg

Note 1: This process may take a long time and may appear to be stuck. Please be patient.
Note 2: "if" refers to the path of the system image.
Note 3: "of" is not the file system of the SD card! Pay attention to this. In this example, the file system of the SD card is /dev/sdg1, but the "of" parameter is /dev/sdg without the number. If your SD card is "/dev/sdh114514", then the "of" parameter should be "/dev/sdh" without the number.

Once the command is executed successfully, the system has been flashed. Now remove the SD card, insert it again, and go to the TWRP home page. There will be a "Mount" option. Enter it and remount the SD card. Then go to the TWRP file manager and navigate to the SD card. You will see the file you flashed (the boot partition).

Step 5: Configure SSH and network (using the official Raspberry Pi system as an example, different systems may have different methods)#

In the TWRP file manager, create a file named "ssh" in the root directory of the SD card. This will enable SSH.

In the TWRP file manager, create a file named "wpa_supplicant.conf" in the root directory of the SD card and edit it:

country=CN
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
    ssid="Wifi Name"
    psk="Password"
    key_mgmt=WPA-PSK
    priority=1
}

Save the changes and remove the SD card. Insert it into the Raspberry Pi and power it on. It should be ready to go.

Step 6: SSH into the Raspberry Pi#

After powering on the Raspberry Pi, you can check the IP address in the router's settings. If you cannot access the router's settings or if you are using a hotspot to provide network to the Raspberry Pi, you can use the Termux app with the nmap command to scan the local network IP addresses.

Once you find the IP address of the Raspberry Pi, you can use an SSH client to connect to it.

Default credentials for the Raspberry Pi:
Username: pi
Password: raspberry

Common Issues#

The "bs" parameter in the dd command in the Android Shell does not support units#

bs=1024000 # The default unit is bytes, so 1024000 is 1MB.
bs=1M # This format is not supported in the Android Shell.

Why do we need to use the TWRP terminal instead of the dd command in Termux?#

I'm not sure. In theory, Termux should work, but in my case, Termux couldn't recognize the partition where the SD card was located, while TWRP could. Later, I found a tutorial online that used a different shell software (not Termux), which should work (requires root access to install BusyBox).

To be continued...#

Journey of Exploration#

At first,#

I wanted to run a Linux version of the flashing tool through Termux. I searched online and found some tools, but they were only available for x86 and x64 platforms, while my phone was ARM64 (some phones are ARMHF, and x86 and x64 phones are rare). Then I thought about emulating an x86 environment to run the flashing tool, but it turned out that the software couldn't recognize the SD card since it couldn't be brought into the emulated environment. So this plan was basically abandoned.

Plan B,#

I asked in a QQ group, and a group member gave me an idea: use the Android version of Wine to run the Windows version of the flashing tool. I thought it should work and downloaded the latest version of Wine for Android from the official website. However, it was not compatible with my Android version, so I couldn't try this method.

Then,#

I was about to give up because I couldn't see any hope (and also because I couldn't find any related tutorials online, no one had done this before). So I went to chat in a group. But then, a group expert said something that woke me up. The Android Shell has the dd command, right! The dd command can be used to flash a system. (But I hadn't really used this command before, so I started learning about it online.)

Finally,#

After reading a lot of information, I finally understood how to use the dd command and started practicing. Basically, it involved formatting the partition where the SD card was located and then using the following command to flash the system:

dd bs=1024000 if=image_path of=sd_card_partition_path

I encountered some minor issues, which are mentioned in the common issues section.

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