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
This time we will look at the setup of the following patterns.
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
This procedure is common to SD cards and USB memory.
Select Ubuntu Server 20.04.1 LTS (64bit)
Insert the boot disk into the terminal and select from the selection screen
Press WRITE
to write.
After the writing is completed, the disc will be unmounted, so reinsert it.
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}"
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 **.
** 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.)
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.
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.
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
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.)
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 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.
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.
Recommended Posts