Just plug in the storage and power to run the Raspberry Pi (Ubuntu Server Edition)

Introduction

Continuation of https://qiita.com/sinnsa233048/items/7651deab6a5461a6b23e

It's a hassle to connect a display and keyboard just for setup to use the Raspberry Pi as a server! Tips to eliminate such annoyance

menu

This time we will look at the setup of the following patterns.

Ubuntu Server setup

Change the settings of the board loader

If you want to boot Ubuntu Server from USB memory on Raspberry Pi 4, you need to change the boot loader settings. Please refer to the following documents https://www.raspberrypi.org/documentation/hardware/raspberrypi/booteeprom.md

Burning discs with Raspberry Pi Imager

This procedure is common to SD cards and USB memory.

OS selection

Select Ubuntu Server 20.04.1 LTS (64bit) スクリーンショット 2021-01-06 23.17.07.png

Disc selection

Insert the boot disk into the terminal and select from the selection screen スクリーンショット 2021-01-06 23.17.12.png

writing

Press WRITE to write. After the writing is completed, the disc will be unmounted, so reinsert it.

Creating a wifi connection configuration file

About connection setting file

The connection setting file for Ubuntu Server is netplan -like description. Please prepare the following template with {SSID} and {WPA key} filled in. (Save it with the file name network)

On Ubuntu Server, the mDNS service does not start by default at startup and cannot be accessed with [hostname] .local. Therefore, it is recommended to assign a fixed IP.

Changing the settings of the fixed IP and default gateway

# This file contains a netplan-compatible configuration which cloud-init
# will apply on first-boot. Please refer to the cloud-init documentation and
# the netplan reference for full details:
#
# https://cloudinit.readthedocs.io/
# https://netplan.io/reference
#
# Some additional examples are commented out below

version: 2
wifis:
  wlan0:
    dhcp4: true
    optional: true
    access-points:
      {SSID}:
        password: "{WPA key}"

Transfer the configuration file to SD card/USB memory

Place the network file created earlier in the root directory of the SD card/USB memory.

The procedure on mac is as follows


$ ls network
network
$ cp network /Volumes/system-boot/
$ ls -1 /Volumes/system-boot/network
/Volumes/system-boot/network

Those who boot from the SD card should use ** ssh to fly to the Raspberry Pi connection **.

Change settings to boot from USB memory

** Here is the production **

The content spoken here is at https://www.raspberrypi.org/forums/viewtopic.php?t=278791.

After that, all the steps will be taken from mac. (Please forgive me because I don't have a Win terminal at hand.)

Kernel decompression

We will decompress the kernel compressed with gz.

$ cd /Volumes/system-boot/
$ pwd
/Volumes/system-boot/
$ ls vmlinuz
vmlinuz 
$ sudo dd if=vmlinuz bs=1 | zcat > vmlinux
$ ls vmlinux
vmlinux

It seems that you can also answer with zcat vmlinuz> vmlinux, but since an error occurred on your mac terminal, follow the above procedure.

Change boot settings

In /Volumes/system-boot/config.txt

config.txt


[pi4]
kernel=uboot_rpi_4.bin
max_framebuffers=2

To

config.txt


[pi4]
max_framebuffers=2
dtoverlay=vc4-fkms-v3d
boot_delay
kernel=vmlinux
initramfs initrd.img followkernel

Please replace with.

Creating an automatic kernel decompression configuration file

Update the kernel with apt and place the auto-decompression setting script so that it will start normally after rebooting.

$ pwd
/Volumes/system-boot/
$ touch auto_decompress_kernel
$ vi auto_decompress_kernel

Describe the following contents

#!/bin/bash -e

#Set Variables
BTPATH=/boot/firmware
CKPATH=$BTPATH/vmlinuz
DKPATH=$BTPATH/vmlinux

#Check if compression needs to be done.
if [ -e $BTPATH/check.md5 ]; then
	if md5sum --status --ignore-missing -c $BTPATH/check.md5; then
	echo -e "\e[32mFiles have not changed, Decompression not needed\e[0m"
	exit 0
	else echo -e "\e[31mHash failed, kernel will be compressed\e[0m"
	fi
fi

#Backup the old decompressed kernel
mv $DKPATH $DKPATH.bak

if [ ! $? == 0 ]; then
	echo -e "\e[31mDECOMPRESSED KERNEL BACKUP FAILED!\e[0m"
	exit 1
else 	echo -e "\e[32mDecompressed kernel backup was successful\e[0m"
fi

#Decompress the new kernel
echo "Decompressing kernel: "$CKPATH".............."

zcat $CKPATH > $DKPATH

if [ ! $? == 0 ]; then
	echo -e "\e[31mKERNEL FAILED TO DECOMPRESS!\e[0m"
	exit 1
else
	echo -e "\e[32mKernel Decompressed Succesfully\e[0m"
fi

#Hash the new kernel for checking
md5sum $CKPATH $DKPATH > $BTPATH/check.md5

if [ ! $? == 0 ]; then
	echo -e "\e[31mMD5 GENERATION FAILED!\e[0m"
	else echo -e "\e[32mMD5 generated Succesfully\e[0m"
fi

#Exit
exit 0

I'll give you execute permission just in case

$ sudo chmod +x auto_decompress_kernel

Raspberry Pi connection with ssh

Insert the USB memory/SD card and turn on the power.

I'm sorry to write the article without knowing the cause, but for some reason the NIC does not assign an IP at the first startup, and an event that cannot be accessed by ssh may occur. In that case, turn on the power and wait about 5 minutes before removing/reinserting the power. (The basis for 5 minutes is the time when cloud-init processing is completed at the first startup + a margin of several minutes.)

Access with ssh

You can access it with ssh ubuntu @ [IP of Raspberry Pi]. (PW is ubuntu. Forced PW reset runs at login, so follow the prompts.)

** This is the end for those who boot with an SD card **

Set to kick kernel auto-decompression script when running apt

Set the automatic decompression script created on the USB memory to start.

$ sudo vi /ect/apt/apt.conf.d/999_decompress_rpi_kernel

Describe the following contents

/ect/apt/apt.conf.d/999_decompress_rpi_kernel


DPkg::Post-Invoke {"/bin/bash /boot/firmware/auto_decompress_kernel"; };

Grant execution authority

$ sudo chmod +x 999_decompress_rpi_kernel

After setting up to this point, restart and check that the kernel starts. If the settings are not correct, you should be stopped with the (initramfs) prompt at startup.

Finally

It's a long sentence, but thank you for reading. I felt that there are many scenes where the DISK I/O of the SD card becomes a bottleneck for Raspberry Pi, so I hope this article will be useful. If you have any inconsistencies/questions, please comment.

Reference material

Recommended Posts

Just plug in the storage and power to run the Raspberry Pi (Ubuntu Server Edition)
The key to running Docker on Raspberry Pi 4 (Ubuntu server 20.04)
How to run React and Rails on the same server
How to install the language used in Ubuntu and how to build the environment
Install Ubuntu20.04 on RaspberryPi 4 and build Kubernetes to run the container
Now, put "InfluxDB + Telegraf + Chronograf" in CentOS8 and try to control the temperature of multiple Raspberry pi4.
Serially connect to Ubuntu on Raspberry Pi
Ubuntu 18 is the OS that adds a NIC to a server instance in Sakura's cloud and assigns a local IP.
raspberry pi 4: Both Raspberry Pi OS and ubuntu boot with just a USB hard disk
I wanted to start the AP server and debug with just the Maven command
Run chromium in kiosk mode from Ubuntu Server
When the server fails to start in Eclipse
[Raspberry Pi] Try to link Apache2 and Tomcat
Introduced GROWI to Raspberry Pi 4 Model B (Ubuntu)
How to run javafx with Raspberry Pi Posted on 2020/07/12
Java classes and instances to understand in the figure