Skip to content

Instantly share code, notes, and snippets.

@johnnymillergh
Last active June 19, 2023 04:40
Show Gist options
  • Save johnnymillergh/434469089a5f4c0a0b0cfbd64dc1c9d3 to your computer and use it in GitHub Desktop.
Save johnnymillergh/434469089a5f4c0a0b0cfbd64dc1c9d3 to your computer and use it in GitHub Desktop.
Raspberry Pi OS Initialization

Raspberry Pi OS Initialization

These steps were validated on Raspberry Pi 4B. (Thu 6 Oct 15:05:21 HKT 2022)

         _,met$$$$$gg.           pi@raspberrypi4b
      ,g$$$$$$$$$$$$$$$P.        OS: Debian 11 bullseye
    ,g$$P""       """Y$$.".      Kernel: aarch64 Linux 5.15.61-v8+
   ,$$P'              `$$$.      Uptime: 20m
  ',$$P       ,ggs.     `$$b:    Packages: 1427
  `d$$'     ,$P"'   .    $$$     Shell: zsh 5.8
   $$P      d$'     ,    $$P     Disk: 4.4G / 33G (14%)
   $$:      $$.   -    ,d$$'     CPU: BCM2835 @ 4x 1.8GHz
   $$\;      Y$b._   _,d$P'      GPU:
   Y$$.    `.`"Y$$$$P"'          RAM: 834MiB / 7636MiB
   `$$b      "-.__
    `Y$$
     `Y$$.
       `$$b.
         `Y$$b.
            `"Y$b._
                `""""

References:

  1. What about aarch64?

    The repository at piwheels.org does not currently support the 64-bit version of the Raspberry Pi OS (currently in beta). We have plans to support it in future, but this requires a significant amount of work, and then rebuilding all wheels on the new architecture. Read more on the blog and issue #220.

Table of Contents

[TOC]

Wi-Fi and SSH Configuration for Headless

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=US

network={
     ssid="wifi-name"
     psk="wifi-password"
     key_mgmt=WPA-PSK
}

Update Raspberry Pi Configuration

$ sudo raspi-config
  • File system expansion, to make sure the SD card is writable
  • GPU ram, 256 mb +
  • Hostname

After updating, reboot Raspberry Pi immediately.

Docker Installation

Install Docker Engine on Debian

Set up the repository

  1. Update the apt package index and install packages to allow apt to use a repository over HTTPS:

    $ sudo apt-get update
    
    $ sudo apt-get install \
        ca-certificates \
        curl \
        gnupg \
        lsb-release
  2. Add Docker’s official GPG key:

    $ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
  3. Use the following command to set up the stable repository. To add the nightly or test repository, add the word nightly or test (or both) after the word stable in the commands below. Learn about nightly and test channels.

    $ echo \
      "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \
      $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Install Docker Engine

This procedure works for Debian on x86_64 / amd64, armhf, arm64, and Raspbian.

  1. Update the apt package index, and install the latest version of Docker Engine and containerd, or go to the next step to install a specific version:

     $ sudo apt-get update
     $ sudo apt-get install docker-ce docker-ce-cli containerd.io
    

    Got multiple Docker repositories?

    If you have multiple Docker repositories enabled, installing or updating without specifying a version in the apt-get install or apt-get update command always installs the highest possible version, which may not be appropriate for your stability needs.

  2. To install a specific version of Docker Engine, list the available versions in the repo, then select and install:

    a. List the versions available in your repo:

    $ apt-cache madison docker-ce
    
      docker-ce | 5:18.09.1~3-0~debian-stretch | https://download.docker.com/linux/debian stretch/stable amd64 Packages
      docker-ce | 5:18.09.0~3-0~debian-stretch | https://download.docker.com/linux/debian stretch/stable amd64 Packages
      docker-ce | 18.06.1~ce~3-0~debian        | https://download.docker.com/linux/debian stretch/stable amd64 Packages
      docker-ce | 18.06.0~ce~3-0~debian        | https://download.docker.com/linux/debian stretch/stable amd64 Packages

    b. Install a specific version using the version string from the second column, for example, 5:18.09.1~3-0~debian-stretch .

    $ sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io
    
  3. Verify that Docker Engine is installed correctly by running the hello-world image.

    $ sudo docker run hello-world
    

    This command downloads a test image and runs it in a container. When the container runs, it prints a message and exits.

Docker Engine is installed and running. The docker group is created but no users are added to it. You need to use sudo to run Docker commands. Continue to Linux postinstall to allow non-privileged users to run Docker commands and for other optional configuration steps.

Upgrade Docker Engine

To upgrade Docker Engine, first run sudo apt-get update, then follow the installation instructions, choosing the new version you want to install.

Add current user to docker group

$ sudo gpasswd -a $USER docker

$ newgrp docker

Poitainer CE Installation

Portainer Official Docker Image

$ docker run \
  --name portainer \
  -p 8000:8000 \
  -p 9000:9000 \
  --restart "always" \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v ~/docker-file-mapping/portainer-ce:/data \
  -d portainer/portainer-ce:2.15.1-alpine

Network for China

Docker Hub - v2rayA

$ docker run -d \
     --restart=always \
     --privileged \
     --network=host \
     --name v2raya \
     -v /lib/modules:/lib/modules:ro \
     -v /etc/resolv.conf:/etc/resolv.conf \
     -v /etc/v2raya:/etc/v2raya \
     mzz2017/v2raya:1.5.4

Installation

$ sudo apt install proxychains -y

Configuration

$ sudo nano /etc/proxychains.conf
socks4     127.0.0.1 20170

Proxychains Validation

$ proxychains curl http://google.com

If you can access Google, the output should be like,

ProxyChains-3.1 (http://proxychains.sf.net)
|DNS-request| google.com
|S-chain|-<>-127.0.0.1:20170-<><>-4.2.2.2:53-<><>-OK
|DNS-response| google.com is 142.250.206.174
|S-chain|-<>-127.0.0.1:20170-<><>-142.250.206.174:80-<><>-OK
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>

ZSH + Oh My Zsh + Powerlevel10k

Install Zsh

Install zsh

$ sudo apt update && sudo apt upgrade -y
$ sudo apt install zsh -y

Set zsh as default

$ chsh -s $(which zsh)

Validate zsh

$ echo $0

Install On My Zsh

https://segmentfault.com/a/1190000040307253

# curl
$ sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

# wget
$ sh -c "$(wget https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"

Install Powerlevel10k

$ git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

# gitee.com
$ git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

Set oh-my-zsh theme

$ nano ~/.zshrc
ZSH_THEME="powerlevel10k/powerlevel10k"

Install font

# Download fontface into current directory
$ proxychains wget https://github.com/ryanoasis/nerd-fonts/raw/master/patched-fonts/Hack/Regular/HackNerdFontMono-Regular.ttf

# Copy to system font directory
$ sudo cp Hack\ Regular\ Nerd\ Font\ Complete.ttf /usr/share/fonts/truetype

Configure Oh My Zsh Plugins

Install plugins:

$ git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

$ git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
plugins=(
git
history
common-aliases
zsh-autosuggestions
zsh-syntax-highlighting
)

zsh oh-my-zsh 插件推荐

zsh-autosuggestions

zsh-syntax-highlighting

Configure Gateway (router) and DNS

Modify /etc/dhcpcd.conf

$ sudo nano /etc/dhcpcd.conf

With

static routers=192.168.31.51
static domain_name_servers=192.168.31.51

And then restart service

$ sudo service dhcpcd restart

Enter the following into the terminal:

$ sudo apt update
$ sudo apt install snapd

You will also need to reboot your device. This can be accomplished from the terminal (and from the desktop), but make sure you save any open documents first:

$ sudo reboot

After this, install the core snap in order to get the latest snapd.

$ sudo snap install core
core 16-2.45.2 from Canonical✓ installed

And then make snap zsh aware.

I can't use snap packages, even if installed

Modify oh-my-zsh profile

$ nano ~/.zshrc

Add this below,

# Make snapd zsh aware
emulate sh -c "source /etc/profile"

Morikko commented on Jan 31

I followed the answer here: https://stackoverflow.com/a/50958615/7186064I just commented the line. Now, I have no more messages and nextcloud works.

$ sudo nano /etc/ld.so.preload

And then,

# /usr/lib/arm-linux-gnueabihf/libarmmem-${PLATAFORM}.so

Necessary Softwares

  1. Visual Studio Code installation with apt
  2. PyCharm
  3. SDKMAN
  4. Node.js installation with apt
  5. tldr installation with apt

Install Python on Raspberry Pi

sh-python-installer

Command '('lsb_release', '-a')' returned non-zero exit status 1

https://stackoverflow.com/a/66474609/9728243

I had this same problem with python 3.6 and python 3.7 on Raspberry Pi, but I thing it shall work anywhere.

The only thing that works like a charm was to move the lsb_release to a backup file.

 sudo mv /usr/bin/lsb_release /usr/bin/lsb_release_back

The complete doc can be found here: [readthedocs.io].[1]https://neoctobers.readthedocs.io/en/latest/rpi/install_python3.html

Check link

$ ls -l /usr/bin | grep python

Modify link

# ln -snf TARGET LINK_NAME
$ sudo ln -snf /usr/bin/python3.7 /usr/bin/python3

If you end up using pip to install OpenCV on your Raspberry Pi, rest assured, you’re using the optimized version.

Install prerequisites on your Raspberry Pi

The Raspberry Pi requires that you install a few system packages before you get started:

$ sudo apt-get install libhdf5-dev libhdf5-serial-dev libhdf5-103
$ sudo apt-get install libqtgui4 libqtwebkit4 libqt4-test python3-pyqt5
$ sudo apt-get install libatlas-base-dev
$ sudo apt-get install libjasper-dev

Change Access Permissions

If following error (UNPROTECTED PRIVATE KEY) occurs,

$ git clone [email protected]:johnnymillergh/home_guardian.git -b develop
Cloning into 'home_guardian'...
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/home/pi/.ssh/id_ed25519' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "/home/pi/.ssh/id_ed25519": bad permissions
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Fix the issue by following command,

# Fix file permission for GitHub SSH keypair
$ chmod 400 ~/.ssh/id_ed25519 ~/.ssh/id_ed25519.pub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment