User Tools

Site Tools


raspberrypi

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

raspberrypi [2020/10/19 14:43] (current)
Line 1: Line 1:
 +====== Raspberry PI 4 as Server ======
  
 +{{:rapsberrypi4.jpg|}}
 +
 +===== CPU bugs =====
 +[[https://en.wikipedia.org/wiki/Spectre_(security_vulnerability)|Spectre V1 & V2]] and 
 + Variant 4 [[https://en.wikipedia.org/wiki/Speculative_Store_Bypass|Speculative Store Bypass]]
 +
 +===== GPIO =====
 +[[https://www.raspberrypi.org/documentation/usage/gpio/|RPi pinout]]
 +
 +===== Basic Info =====
 +2x USB2.0 connected to VL805 (wire savings - USB3 wires not connected)\\
 +2x USB3.1 Gen 1 5Gbit - VL805 connected via PCIe 2.0 1x (5Gbit)\\
 +1x Gigabit Ethernet connected via PCIe 1.0 1x (2Gbit)\\
 +VideoCore VI running on [[https://en.wikipedia.org/wiki/ThreadX|ThreadX]]\\
 +Power approx 3-8Watts\\
 +iperf3 944Mbit/s\\
 +\\
 +==== SAMBA Performance ====
 +912 Mbit/s = 114 MB/s read and write\\
 +ASM1352R FW:B5_20_60 UASP and vl805_fw_0137ab.bin (raw read/write 358/159 MB/s)
 + 
 +[[https://www.raspberrypi.org/downloads/raspbian/|Raspbian Buster Lite]]\\
 +
 +==== Encryption ====
 +ChaCha20-Poly1305 is fastest so it can be preferred (approx. **323 MB/s** 2GHz)\\
 +AES-128-CBC max. 113 MB/s
 +<code>ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305</code>
 +
 +===== config.txt =====
 +<code>
 +# For more options and information see
 +# http://rpf.io/configtxt
 +# Some settings may impact device functionality. See link above for details
 +
 +arm_freq=1200
 +arm_freq_min=266
 +disable_splash=1
 +gpu_freq=100
 +gpu_freq_min=100
 +v3d_freq=100
 +gpu_mem=64
 +over_voltage=-1
 +temp_limit=80
 +arm_64bit=1
 +</code>
 +==== Overclock ====
 +Add some fan!
 +<code>
 +arm_freq=1750
 +over_voltage=2
 +-- or --
 +arm_freq=2000
 +over_voltage=5
 +</code>
 +===== SSH on headless mode =====
 +Insert file named "ssh" in /boot dir
 +
 +===== Network =====
 +<code>
 +ethtool -K eth0 rx on tx on gso on
 +</code>
 +===== SD Card care =====
 +Recommended SD card with MLC (Samsung Pro, SanDisk High Endurance, etc)
 +<code>defaults,noatime,nodiratime,commit=1800</code>
 +
 +/etc/fstab (move most active locations to RAM)
 +<code>
 +tmpfs /tmp                      tmpfs    defaults,noatime,nosuid,size=100m   0 0
 +tmpfs /var/tmp                  tmpfs    defaults,noatime,nosuid,size=30m    0 0
 +tmpfs /var/log                  tmpfs    defaults,noatime,nosuid,mode=0755,size=100m  0 0
 +tmpfs /var/cache/minidlna       tmpfs    defaults,noatime,nosuid,size=100m    0 0
 +tmpfs /var/spool/mqueue         tmpfs    defaults,noatime,nosuid,mode=0700,gid=12,size=30m 0 0
 +tmpfs /var/lib/logrotate        tmpfs    defaults,noatime,nosuid,mode=0755,size=10m 0 0
 +tmpfs /var/lib/samba            tmpfs    defaults,noatime,nosuid,mode=0755,size=10m 0 0
 +tmpfs /var/lib/nginx            tmpfs    defaults,noatime,nosuid,mode=0755,size=100m 0 0
 +tmpfs /var/lib/php/sessions     tmpfs    defaults,noatime,nosuid,mode=1733,size=10m 0 0
 +tmpfs /var/lib/systemd/timers   tmpfs    defaults,noatime,nosuid,mode=0755,size=1m 0 0
 +tmpfs /var/lib/systemd/timesync tmpfs    defaults,noatime,nosuid,mode=0755,uid=100,gid=102,size=1m 0 0
 +</code>
 +
 +==== Create folders in RAM ====
 +create file /usr/lib/tmpfiles.d/ramdisk.conf
 +
 +<code>
 +d /var/log/samba 0755 - - -
 +d /var/log/exim4 0755 110 117 -
 +d /var/lib/samba/private 0755 - - -
 +d /var/lib/samba/usershares 1700 - - -
 +d /var/log/nginx 0755 - - -
 +d /var/log/mysql 0755 112 119 -
 +</code>
 +
 +==== Remove fake hwclock ====
 +<code>
 +sudo apt-get remove fake-hwclock
 +sudo rm /etc/cron.hourly/fake-hwclock
 +sudo update-rc.d -f fake-hwclock remove
 +sudo rm /etc/init.d/fake-hwclock
 +sudo rm /etc/fake-hwclock.dat
 +</code>
 +
 +==== Trim SD Card ====
 +<code>sudo ionice -c 3 fstrim -v /</code>
 +
 +==== Disable smartd ====
 +If installed disable smartd
 +<code>sudo systemctl disable smartd</code>
 +
 +Info about SD card\\
 +/sys/bus/mmc/devices/mmc0:0002
 +
 +===== VCGENCMD =====
 +
 +==== Check Temperature ====
 +
 +<code>/opt/vc/bin/vcgencmd measure_temp
 +/opt/vc/bin/vcgencmd measure_temp | awk '{ print substr($1,6,length($1)-9) }'</code>
 +
 +==== Check GPU Memory ====
 +
 +<code>vcgencmd get_mem gpu</code>
 +
 +==== Check Clock ====
 +
 +<code>vcgencmd measure_clock xxx</code>
 +xxx = **arm, core, h264, isp, v3d, uart, pwm, emmc, pixel, vec, hdmi, dpi**
 +
 +==== Check Voltage ====
 +
 +<code>vcgencmd measure_volts xxx</code>
 +xxx = **core, sdram_c, sdram_i, sdram_p**
 +
 +==== Other ====
 +<code>vcgencmd bootloader_version</code>
 +
 +<code>vcgencmd get_config int</code>
 +===== Check time status =====
 +
 +<code>timedatectl status</code>
 +
 +===== SAMBA =====
 +More on [[linux:samba|SAMBA]] article for CentOS / RedHat
 +
 +===== ffmpeg h264 =====
 +<code>ffmpeg -vcodec h264_mmal -i input.mkv -s 1920x1080 -c:v h264_omx -b:v 6000k output.mkv</code>
 +h264 accelerated decode and encode sample\\
 +hevc_v4l2m2m\\
 +===== Power Save =====
 +##turn on/off wifi
 +<code>
 +dtoverlay=disable-wifi
 +</code>
 +
 +==== Turn off HDMI / Headless ====
 +<code>/usr/bin/tvservice -o</code>
 +
 +Status
 +<code>/usr/bin/tvservice -s</code>
 +
 +===== sysctl =====
 +<code>fs.inotify.max_user_watches=524288</code>
 +
 +===== HDD Care =====
 +
 +Best stable settings are 
 +  * autosuspend=-1
 +  * hdparm
 +  * wake script
 +
 +==== USB Autosuspend 1 hour ====
 +Prevent external USB from 20s sleep by adding this into **/boot/cmdline.txt**
 +<code>
 +usbcore.autosuspend=3600
 +</code>
 +
 +==== Change disk sleep 1 hour ====
 +<code>sudo hdparm -S 241 /dev/sda</code>
 +
 +==== Install hd-idle ====
 +Download compiled deb package
 +<code>https://janforman.org/files/Linux/hd-idle_1.05_armhf.deb</code>
 +OR
 +<code>
 +sudo apt-get install build-essential fakeroot debhelper -y
 +wget https://janforman.org/files/Linux/hd-idle-1.05.tgz
 +tar -xvf hd-idle-1.05.tgz
 +cd hd-idle
 +dpkg-buildpackage -rfakeroot -uc -us
 +sudo dpkg -i ../hd-idle_*.deb
 +</code>
 +
 +sudo nano /etc/default/hd-idle
 +<code>HD_IDLE_OPTS="-i 0 -a sda -i 3600 -a sdb -i 3600"</code>
 +
 +==== Disable UASP for specific device ====
 +Insert device ids into **/boot/cmdline.txt**
 +<code>usb-storage.quirks=152d:8561:u</code>
 +
 +==== Hack to permanently wakeup disk ====
 +Run this in background
 +<code>
 +while [ 1 ]
 +do
 +hdparm -C /dev/sda >/dev/null
 +sleep 120
 +done
 +</code>
 +
 +===== Install general things =====
 +
 +<code>sudo apt install mc samba minidlna ffmpeg hostapd bridge-utils smartmontools</code>
 +
 +
 +===== HostAP =====
 +
 +sudo nano /etc/hostapd/hostapd.conf
 +<code>
 +interface=wlan0
 +driver=nl80211
 +ssid=janforman.com
 +hw_mode=a
 +channel=40
 +wmm_enabled=0
 +macaddr_acl=0
 +auth_algs=1
 +ignore_broadcast_ssid=0
 +wpa=2
 +wpa_passphrase=AardvarkBadgerHedgehog
 +wpa_key_mgmt=WPA-PSK
 +wpa_pairwise=TKIP
 +rsn_pairwise=CCMP
 +</code>
 +
 +===== Mount FS =====
 +sudo mount -t fs_type -o rw,lazytime,noatime,nodiratime,commit=600 device /path/to/dest/fs
 +
 +===== Disable swap =====
 +
 +<code>sudo systemctl disable dphys-swapfile.service</code>
 +
 +===== Format external drive =====
 +<code>
 +mkfs.ext4 -b 4096 -i 131072 -I 128 /dev/sda1
 +tune2fs -i0 -c -1 /dev/sda1
 +tune2fs -o journal_data_writeback /dev/sda1
 +tune2fs -m 0 /dev/sda1
 +</code>
 +===== How to format 8TB SMR Drive =====
 +<code>
 +mkfs.f2fs -s64 -o0 -t0 -a0 /dev/sda1
 +mount -t f2fs -onoinline_data,noatime,flush_merge,no_heap,extent_cache,noacl,active_logs=2 /dev/sda1 /mnt
 +</code>
 +
 +===== Revert RPI-UPDATE =====
 +<code>sudo apt-get update; sudo apt-get install --reinstall raspberrypi-bootloader raspberrypi-kernel</code>
raspberrypi.txt · Last modified: 2020/10/19 14:43 by Jan Forman