# Raspberry Pi 4 Setup notes
###### tags: `linux2021 jserv 1-on-1`
# Steps
* SD card
* Use image writer
* Ubuntu
* [Setup wifi](https://ubuntu.com/tutorials/how-to-install-ubuntu-on-your-raspberry-pi#3-wifi-or-ethernet)
* Raspbian
* [Setup wifi](https://www.tomshardware.com/reviews/raspberry-pi-headless-setup-how-to,6028.html)
* Network side notes
* Scan connected network devices `sudo nmap -sn 192.168.0.1/24`
* `-sn`: run a quick scan of machines in our network without trying to see if any port is open
* can also use `arp -na | grep -i "dc:a6:32"` to find rpi
* OS update
* `sudo apt update`
* `sudo apt install zsh git && sh -c "$(wget https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"`
* `sudo apt upgrade`
* [Locale issue](https://askubuntu.com/questions/162391/how-do-i-fix-my-locale-issue): `sudo locale-gen "en_US.UTF-8" && sudo dpkg-reconfigure locales`
* `sudo apt install build-essential iotop vim`
* [CPU set to performance mode](https://raspberrypi.stackexchange.com/questions/9034/how-to-change-the-default-governor)
* `cd /sys/devices/system/cpu`
* available modes `cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_available_governors`
* check current mode `cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor`
* set to
* rpi
* performance mode: `echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor`
* alternative way `sudo sh -c "echo performance > cpu0/cpufreq/scaling_governor"`
* ondemand mode: `echo ondemand | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor`
* alternative way `sudo sh -c "echo ondemand > cpu0/cpufreq/scaling_governor"`
* Intel NUC
* performance mode: `echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor`
* powersave mode: `echo powersave | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor`
* vimrc
```
set number " Show line numbers
set linebreak " Break lines at word (requires Wrap lines)
set showbreak=+++ " Wrap-broken line prefix
set showmatch " Highlight matching brace
set visualbell " Use visual bell (no beeping)
set hlsearch " Highlight all search results
set smartcase " Enable smart-case search
set ignorecase " Always case-insensitive
set incsearch " Searches for strings incrementally
" set expandtab " For python code indentation to work correctly
set noexpandtab " For linux kernel development
set autoindent " Auto-indent new lines
set shiftwidth=8 " Number of auto-indent spaces
set smartindent " Enable smart-indent
set smarttab " Enable smart-tabs
set tabstop=8 " Number of spaces per Tab
set cursorline " Show underline
set cursorcolumn
set ruler " Show row and column ruler information
set mouse=a
set undolevels=10000 " Number of undo levels
set backspace=indent,eol,start " Backspace behaviour
set splitbelow "New spilt starts below
set splitright "New split starts on the right
set scrolloff=5 "auto scroll on the bottom 5 lines
filetype on "enable file detection
syntax on "syntax highlight
highlight Comment ctermfg=cyan
set showmode
set encoding=utf-8
set fileencoding=utf-8
scriptencoding=utf-8
```
* Wireguard
* Install on both raspberry pi and VPS lightsail server
* `sudo apt install wireguard resolvconf`
* `wg genkey | tee wg-private.key | wg pubkey > wg-public.key`
* [Edit wiregurd file](https://henrybear327.github.io/blog/post/sideprojects/vpn-using-home-ip/)
* Expose UDP port number $x$ on lightsail control panel (otherwise the port will be blocked)
* Setup both machine's wireguard IP
* Setup crontab on raspberry pi
* `@reboot sudo wg-quick up /home/ubuntu/wg/wg0.conf`
* [Fix](https://www.globo.tech/learning-center/sudo-unable-to-resolve-host-explained/) `sudo: unable to resolve host ubuntu: Name or service not known`
* Run `hostname` to get your hostname
* Add `127.0.0.1 [your hostname]` to your `/etc/hosts` file
* git
* `git config --global core.editor "vim"`
* `ssh-keygen -t ed25519 -C "henrybear327@gmail.com"`
* watch
* temp `watch -n 1 cat /sys/class/thermal/thermal_zone0/temp`
* freq
* rpi: `sudo watch -n 1 cat /sys/devices/system/cpu/cpu*/cpufreq/cpuinfo_cur_freq`
* intel NUC
* `sudo apt-get install cpufrequtils`
* `watch -n 1 'cpufreq-info | grep "current CPU frequency"'`
* [Disable snapd](https://www.addictivetips.com/ubuntu-linux-tips/disable-snaps-ubuntu/)
* `sudo snap list`
* Remove all snaps
* `sudo snap remove lxd`
* `sudo snap remove core18`
* `sudo snap remove snapd`
* `sudo apt autoremove --purge snapd`
### tangent
* 研究一下 ubuntu for raspberry pi 的 initial boot sequence 是如何進行的?
* cloud-init(!)