This shows you the differences between two versions of the page.
Previous revisionNext revision | |||
— | fuss:raspberry_pi [2020/07/21 05:52] – [Running a One-Off Script on First Machine Boot] office | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Enable UART Serial Communication ====== | ||
+ | |||
+ | Edit ''/ | ||
+ | < | ||
+ | enable_uart=1 | ||
+ | </ | ||
+ | |||
+ | to the end of the file and reboot. | ||
+ | |||
+ | ====== Disable Wifi Power Management ====== | ||
+ | |||
+ | When receiving large amounts of output over SSH the Raspberry Pi might render the console inoperable and the connection will time out in a few seconds. | ||
+ | |||
+ | The following command adds some module options to the wifi kernel module to disable power management which is apparently responsible for the former issue. | ||
+ | |||
+ | < | ||
+ | echo " | ||
+ | </ | ||
+ | |||
+ | ====== Enable SSH on (First) Boot ====== | ||
+ | |||
+ | Create a blank file named '' | ||
+ | |||
+ | ====== Check if Hardware Decoders are Enabled ====== | ||
+ | |||
+ | < | ||
+ | vcgencmd codec_enabled MPG2 | ||
+ | vcgencmd codec_enabled WVC1 | ||
+ | </ | ||
+ | |||
+ | Note that the Raspberry Pi 4 does not have hardware decoders such that the commands will most likely state '' | ||
+ | |||
+ | ====== Change Audio Output ====== | ||
+ | |||
+ | Issuing: | ||
+ | <code bash> | ||
+ | amixer controls | ||
+ | </ | ||
+ | |||
+ | will yield the controls available on the Raspberry Pi: | ||
+ | <code bash> | ||
+ | # amixer controls | ||
+ | numid=3, | ||
+ | numid=2, | ||
+ | numid=1, | ||
+ | </ | ||
+ | |||
+ | The Raspberry Pi 2,3 and 4 can commute between sending sound through the $3.5mm$ audio jack: | ||
+ | <code bash> | ||
+ | amixer cset numid=3 1 | ||
+ | </ | ||
+ | or the HDMI output: | ||
+ | <code bash> | ||
+ | amixer cset numid=3 2 | ||
+ | </ | ||
+ | respectively, | ||
+ | <code bash> | ||
+ | amixer cset numid=3 | ||
+ | </ | ||
+ | to set the sound selection to autodetect where the jack will be used only if the HDMI cable is not connected. | ||
+ | |||
+ | ====== Fixing Various Network Issues ====== | ||
+ | |||
+ | Any of the following symptoms are to be detected? | ||
+ | * SSH connections drop, | ||
+ | * issuing commands with large output over SSH makes the SSH session hang, | ||
+ | * connection issues toward package repositories on Raspbian | ||
+ | |||
+ | They may all boil down to a non-uniform MTU setting across the network. | ||
+ | |||
+ | ====== Logging-in via SSH over USB ====== | ||
+ | |||
+ | The Raspberry Pi when connected to a PC can configure itself as an USB gadget and start a network over USB. A RNDIS network adapter is needed in most cases and can be downloaded from here: | ||
+ | |||
+ | * {{fuss: | ||
+ | |||
+ | In order to log into the Raspberry Pi over SSH via the USB port, edit '' | ||
+ | < | ||
+ | dtoverlay=dwc2 | ||
+ | </ | ||
+ | |||
+ | Next, edit '' | ||
+ | < | ||
+ | modules-load=dwc2, | ||
+ | </ | ||
+ | |||
+ | Finally, add a blank file named '' | ||
+ | |||
+ | The Raspberry can now be connected to a PC via its USB port (not the USB port marked '' | ||
+ | |||
+ | When the RNDIS interface is brought up, if Apple bonjour is installed and running on the machine that the Raspberry Pi is connected to, then the Raspberry Pi is supposed to register the DNS address '' | ||
+ | |||
+ | The first attempt would be to try connecting via the assigned DNS address: '' | ||
+ | |||
+ | ===== Connecting to a Bridge Automatically ===== | ||
+ | |||
+ | In order to connect the Raspberry Pi to a bridge as it is connected to a server, [[fuss/ | ||
+ | |||
+ | The only changes required on the Raspberry Pi is to edit ''/ | ||
+ | < | ||
+ | auto usb0 | ||
+ | iface usb0 inet dhcp | ||
+ | </ | ||
+ | |||
+ | and save the file. This will make sure that when the Raspberry Pi boots, an IP address will be requested over the '' | ||
+ | |||
+ | ====== Enabling Monitor Mode via Nexmon Drivers ====== | ||
+ | |||
+ | Some Raspberry Pi devices such as the Raspberry Pi Zero W can operate in monitor mode in order to sniff wireless traffic. Up to this date, there is no official way to get monitor mode working for the Raspberry SoC except for using alternative Nexmon drivers that replace the '' | ||
+ | |||
+ | Here is a short guide on how to build the nexmon drivers for Raspberry Pi W and substitute the kernel module in order to enable monitor mode. | ||
+ | |||
+ | Install required packages to compile the drivers: | ||
+ | <code bash> | ||
+ | apt-get install subversion raspberrypi-kernel-headers git libgmp3-dev gawk qpdf bison flex make autoconf automake build-essential libtool libisl10 | ||
+ | </ | ||
+ | |||
+ | Change directory to a compile space: | ||
+ | <code bash> | ||
+ | cd /usr/src | ||
+ | </ | ||
+ | |||
+ | and check out the source (official): | ||
+ | <code bash> | ||
+ | git clone https:// | ||
+ | </ | ||
+ | |||
+ | or from Wizardry and Steamworks: | ||
+ | <code bash> | ||
+ | svn co http:// | ||
+ | </ | ||
+ | |||
+ | Set variables: | ||
+ | <code bash> | ||
+ | export NEXMON_ROOT=/ | ||
+ | </ | ||
+ | |||
+ | and load the provided environment: | ||
+ | <code bash> | ||
+ | source setup_env.sh | ||
+ | </ | ||
+ | |||
+ | Now compile the nexmon package from the top-level: | ||
+ | <code bash> | ||
+ | make | ||
+ | </ | ||
+ | |||
+ | Now build the kernel module and firmware: | ||
+ | <code bash> | ||
+ | cd patches/ | ||
+ | </ | ||
+ | where: | ||
+ | * '' | ||
+ | |||
+ | <code bash> | ||
+ | make | ||
+ | </ | ||
+ | |||
+ | Now generate a backup of the original firmware file and install the patched firmware: | ||
+ | <code bash> | ||
+ | make backup-firmware | ||
+ | make install-firmware | ||
+ | </ | ||
+ | |||
+ | Compile '' | ||
+ | <code bash> | ||
+ | cd utilities/ | ||
+ | make install | ||
+ | </ | ||
+ | |||
+ | Now to make the Raspberry load the modified kernel module after reboot it, the existing module is simply substituted for the module that was compiled at the previous step: | ||
+ | <code bash> | ||
+ | PATH_OF_DEFAULT_DRIVER_AT_REBOOT=$(modinfo brcmfmac | grep -m 1 -oP " | ||
+ | mv " | ||
+ | cp patches/ | ||
+ | </ | ||
+ | |||
+ | Finally, generate module dependencies: | ||
+ | <code bash> | ||
+ | depmod -a | ||
+ | </ | ||
+ | |||
+ | In order to set up the Wifi monitoring interface on boot, create the file ''/ | ||
+ | < | ||
+ | auto mon0 | ||
+ | iface mon0 inet manual | ||
+ | pre-up iw wlan0 interface add mon0 type monitor | ||
+ | wireless-mode monitor | ||
+ | |||
+ | </ | ||
+ | |||
+ | and restart the Raspberry Pi. | ||
+ | |||
+ | ====== Running a One-Off Script on First Machine Boot ====== | ||
+ | |||
+ | To execute a script unconditionally edit ''/ | ||
+ | < | ||
+ | init=/ | ||
+ | </ | ||
+ | |||
+ | that will end up executing ''/ | ||
+ | |||
+ | The contents of ''/ | ||
+ | <code bash> | ||
+ | # Boot | ||
+ | mount -t tmpfs tmp /run | ||
+ | mkdir -p / | ||
+ | mount / -o remount,rw | ||
+ | # Ensure the script does not run again. | ||
+ | sed -i 's| init=.*||' | ||
+ | |||
+ | # Run | ||
+ | |||
+ | # Insert custom commands. | ||
+ | / | ||
+ | / | ||
+ | |||
+ | # Reboot | ||
+ | sync | ||
+ | umount /boot | ||
+ | mount / -o remount,ro | ||
+ | sync | ||
+ | echo 1 > / | ||
+ | echo b > / | ||
+ | sleep 5 | ||
+ | </ | ||
+ | |||
+ | ====== Downgrade or Upgrade to Specific Kernel Version ====== | ||
+ | |||
+ | Pick a commit from the '' | ||
+ | <code bash> | ||
+ | rpi-update HASH | ||
+ | </ | ||
+ | where: | ||
+ | * '' | ||
+ | |||
+ | |||
+ | |||