6 Ways to Hack a Raspberry Pi via the Boot Partition
Using a Raspberry Pi is great fun. With so many projects to choose from, the $50 computer will keep you busy for months. But setting up a Raspberry Pi can be time consuming.
If you’re not plugging in a keyboard to set up Wi-Fi, you’re struggling to find the right display configuration. Or some other trivial setup option that shouldn’t really take this long to sort out.
But in many cases, you can make these changes easily, and quickly. Here’s how to tweak your Raspberry Pi in the /boot/ partition before you even boot it up.
What Is the Raspberry Pi Boot Partition?
When you set up a Raspberry Pi, you need to install an operating system. This isn’t done in same was on a PC or laptop. Instead, an operating system is installed on a Raspberry Pi by writing it to an SD card.
During this process, the card is split into two or more partitions. One of these has the operating system, formatted with the EXT4 filesystem.
The other is always called “boot” and referred to as /boot/. This features a host of boot data, configurations, and other options, and is formatted with the FAT filesystem. Note that the /boot/ partition is required for every Raspberry Pi distro.
Beyond the fact that you can use /boot/ to tweak the Raspberry Pi’s hardware settings, it’s notable in another way. The /boot/ partition can be accessed on any computer with a card reader. This contrasts with the main OS, which can almost always only be read on a Linux computer.
As such, you can access /boot/ in Windows, macOS, Linux, anything. Importantly, you can also browse to it from the installed operating system on your Raspberry Pi.
So, the /boot/ partition is useful. But what can you do with it? Insert your Raspberry Pi’s SD card in your PC, open /boot/, then read on to find out.
1. Label Your Raspberry Pi Distro
Running multiple projects on your Raspberry Pi can be a little confusing. For example, I maintain a spreadsheet, so I know what each Pi is doing. I also note what hardware is connected, such as a camera, or touchscreen, and which case the Pi is in.
But you might only have one Pi, with multiple microSD cards for easy switching between projects. Even then, however, you might find it difficult to recall what is on each card.
Simply create a text file in the /boot/ partition with a useful name, such as “security cam.txt” or “print server.txt.” You might add more details about the project to the body of the file.
Doing this lets you quickly identify the SD card without booting.
2. Tweak Config.txt for Better Hardware Compatibility
While the Raspberry Pi has no system BIOS as such, it does have the config.txt file, found in /boot/.
This is the home of tweaks for the Raspberry Pi, with options for almost everything you can imagine. The file features a list of settings using the format “property=value” (without quotes), one per line. Note the lack of spaces. Comments can be added using the # character to start a line.
Each section of the config.txt file is clearly marked, with commented lines explaining what each setting does. While this file should only be edited with care, there’s enough information to stop you making changes with serious consequences.
The sort of tweaks you make here will depend on your hardware setup. For example, you might wish to enable the camera module at boot:
start_x=1
Meanwhile, if you’re struggling to get a picture via HDMI out, use
hdmi_safe=1
This setting combines various HDMI settings to create a general, catch-all fix that should force HDMI to work.
One more notable config.txt tweak is rotating the display, using display_rotate. For example, rotate 90 degrees with
display_rotate=1
A 180-degree rotation, meanwhile is
display_rotate=2
And so on.
As you will have gathered, the config.txt is the single most important hardware configuration feature on the Raspberry Pi. While raspi-config is significant, config.txt has a greater impact, allowing for considerable pre-boot configuration.
Consult the elinux.org wiki for more comprehensive details about the config.txt file.
3. Create a Blank File to Enable SSH
Using SSH to remotely access your Raspberry Pi saves a lot of time. For example, you might wish to update the operating system, but be unable to connect the Pi to a TV. The answer is to remotely access your Raspberry Pi and SSH is the quickest way to do this.
However, later versions of the Debian-based Raspberry Pi operating system have SSH disabled by default. This is a security measure that can prove inconvenient to regularly users.
There is a workaround, however. Simply create a special file in the /boot/ partition to enable SSH.
Open the /boot/ partition on your computer and create a new file. Label it ssh and remove the file extension. It’s as simple as that! As quick as it may be, it’s worth keeping an ssh flag file on your PC. This way, all you need to do is drag and drop the file into the /boot/ partition each time you install a Raspberry Pi OS.
This file acts as a flag when the Pi boots up, instructing the operating system to enable SSH.
Note that you’ll be prompted to change the default “pi” user password when you first login.
4. Save Wi-Fi Network Credentials in wpa_supplicant.conf
Another time sink with setting up a Raspberry Pi is getting the device on your wireless network. While plugging it directly into the router can save time here, you may not have enough ports. Or you have the Pi situated too far away.
The answer is wireless networking, which means logging into the Pi’s desktop environment. Setting up with a mouse and keyboard doesn’t take too long. You might set it up in the command line, by editing the wpa_supplicant.conf file, but you can also edit this before the Pi boots.
In the /boot/ partition, create a new file wpa_supplicant.conf. Open it in your PC’s text editor (e.g., Notepad on Windows, or you may prefer Notepad++). Copy and paste the following lines:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=US
network={
ssid="SSID"
psk="PASSWORD"
key_mgmt=WPA-PSK
}
Some edits are required. First, change the country as appropriate (for example, GB for the United Kingdom).
Following this, set the SSID and PASSWORD fields to match those of your wireless network. Save the file, then close it and boot your Pi. The device should shortly connect to your local Wi-Fi. Access your router’s administration page to view the IP address for the Pi.
You should then be able to remotely access the Raspberry Pi over SSH. As with ssh, it’s worth keeping a copy of the wpa_supplicant.conf file on your PC for quick set up.
5. Fix Bugs With the /boot/ Partition
The release of the Raspberry Pi 4 in 2019 featured three iterations with different RAM specifications. While the 1GB and 2GB models run fine, the 4GB Raspberry Pi 4 has a bug. Specifically, this concerns USB port detection in Ubuntu.
The bug prevents the ports from being detected in the 4GB version of the Pi 4, but there is a workaround. Until an official fix is rolled out, you can tweak the amount of RAM available to the OS.
Open /boot/firmware and find the usercfg.txt file. Launch this in a text editor and add:
total_mem=3072
This changes the available RAM from 4GB to 3GB.
Save the file and close, then boot your Raspberry Pi 4. The USB ports should now work. A future update should resolve this fault, so be sure to remove the line in usercfg.txt when this happens.
6. Copy Data From Your PC to Raspberry Pi
If you need to quickly copy data from your PC to your Raspberry Pi, you can use the /boot/ partition. Simply copy the data into a new directory and it will be accessible when you boot the Pi. Note that the size of the /boot/ partition is limited, however.
As such, this is only suitable for small files, like MP3s or images, rather than video files. It’s not an ideal solution, but it works.
Here are more ways to copy data between a PC and a Raspberry Pi.
6 Ways to Use the Raspberry Pi /boot/ Partition
With so many options for configuring your Raspberry Pi in the /boot/ partition, you’ll save time on your next project. To recap, you can do the following in the /boot/ partition:
- Label your SD card
- Tweak config.txt
- Enable SSH
- Pre-load your wireless network credentials
- Fix bugs
- Copy data from PC to Pi
Many of these tweaks speed things up, but you can streamline your Raspberry Pi setup further. Here’s how to save time configuring your Raspberry Pi with PiBakery.
Read the full article: 6 Ways to Hack a Raspberry Pi via the Boot Partition
from MakeUseOf https://ift.tt/37gHeMy
No comments: