Skip to content

Instantly share code, notes, and snippets.

@kjuq
Last active December 22, 2023 23:06
Show Gist options
  • Select an option

  • Save kjuq/35488192340443d74e1550fbbf2eac48 to your computer and use it in GitHub Desktop.

Select an option

Save kjuq/35488192340443d74e1550fbbf2eac48 to your computer and use it in GitHub Desktop.

Initial setup

Download an OS image

Check device name of USB or SDcard

  • diskutil list

Unmount it

  • sudo diskutil umount /dev/disk8s1

Burn it

  • sudo dd bs=4M if=./2023-05-03-raspios-bullseye-arm64.img of=/dev/disk8 status=progress conv=fsync
    • Don't forget to extract the file if it's compressed

Wi-Fi, SSH, and Password

  • cd /Volumes/bootfs
  • touch ssh
  • nvim wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=JP
network={
    ssid="<SSID>"
    psk="<Password>"
}
  • nvim userconf.txt
kjuq:<ENCRYPTED_PASSWORD>

ENCRYPTED_PASSWORD is from pass {DEVICES_PASSWD} | openssl passwd -6 -stdin | pbcopy

userconf.txt should be like kjuq:$6$4FAIAmyeuggAn71w$BJLctNwvql1tndL3yPkjWp/h0xY21VrBTkQUALw5cE6lbFJ/k7EDpxBXbKw9uU9I7rfQGol2FFfjxhVI0LJHf0

Connect

  • ssh kjuq@raspberrypi.local

If locale error occers

  • locale
  • localectl list-locales
  • sudo localedef -f UTF-8 -i en_US en_US.UTF-8
  • localectl list-locales
  • locale

APT Update

  • sudo apt update
  • sudo apt upgrade

Enable USB boot

  • vcgencmd otp_dump | grep 17:
    • If the output is 17:1020000a, USB boot is disabled.
  • echo "program_usb_boot_mode=1" | sudo tee -a /boot/config.txt
  • echo "program_usb_boot_timeout=1" | sudo tee -a /boot/config.txt
  • sudo reboot
  • vcgencmd otp_dump | grep 17:
    • If the output is 17:3020000a, USB boot is enabled.

Change host name

  • sudo vi /etc/hostname
  • sudo vi /etc/hosts
  • sudo reboot

Extend Storage Life

Disable swap

  • free # Check current swap size
  • sudo apt autoremove -y dphys-swapfile
  • free # Swap size is now zero

Disable RamDisk

  • df -h # Check current file system
  • sudo vi /etc/fstab
  • Add 3 rows below to the end of the file
    • CAUTION: If /var/log is RAMDISK-nized, nginx may cause errors
  • sudo reboot
  • df -h # These directories are now mounted

/etc/fstab

tmpfs /tmp     tmpfs defaults,size=256m,noatime,mode=1777 0 0
tmpfs /var/tmp tmpfs defaults,size=16m,noatime,mode=1777  0 0
tmpfs /var/log tmpfs defaults,size=32m,noatime,mode=0755  0 0

SQ (df -h)

Filesystem      Size  Used Avail Use% Mounted on
udev            328M     0  328M   0% /dev
tmpfs            93M  944K   92M   1% /run
/dev/mmcblk0p2   29G  1.6G   26G   6% /
tmpfs           461M     0  461M   0% /dev/shm
tmpfs           5.0M   12K  5.0M   1% /run/lock
/dev/mmcblk0p1  510M   94M  417M  19% /boot/firmware
tmpfs            93M     0   93M   0% /run/user/1000

AP (df -h)

Filesystem      Size  Used Avail Use% Mounted on
udev            328M     0  328M   0% /dev
tmpfs            93M  2.5M   90M   3% /run
/dev/mmcblk0p2   29G  1.6G   26G   6% /
tmpfs           461M     0  461M   0% /dev/shm
tmpfs           5.0M   12K  5.0M   1% /run/lock
tmpfs           256M     0  256M   0% /tmp
tmpfs            32M  8.0K   32M   1% /var/log
tmpfs            16M     0   16M   0% /var/tmp
/dev/mmcblk0p1  510M   94M  417M  19% /boot/firmware
tmpfs            93M     0   93M   0% /run/user/1000

Tailscale

Install

sudo apt install apt-transport-https
curl -fsSL https://pkgs.tailscale.com/stable/raspbian/bullseye.noarmor.gpg | sudo tee /usr/share/keyrings/tailscale-archive-keyring.gpg > /dev/null
curl -fsSL https://pkgs.tailscale.com/stable/raspbian/bullseye.tailscale-keyring.list | sudo tee /etc/apt/sources.list.d/tailscale.list
sudo apt update
sudo apt install tailscale

Subnet router, Exit node, and SSH

sudo tailscale up --ssh --advertise-exit-node

Check your own ip address and subnet mask

Fix IP Address

  • ifconfig # Check ip address and device name (such as eth0, enp4s0)
  • ip route show # Check default gateway
  • cat /etc/resolv.conf # Check DNS server

(When using NetworkManager)

  • sudo nmcli connection show
  • sudo nmcli connection modify 'Wired connection 1' ipv4.method manual ipv4.addresses 192.168.11.100/24 ipv4.gateway 192.168.11.1 ipv4.dns 100.100.100.100
  • sudo reboot

Wake on LAN

Bluetooth PAN

  • sudo apt install bluez-tools

Remember current network

ifconfig

Create configurations of network

  • sudo nvim /etc/systemd/network/pan0.netdev
[NetDev]
Name=pan0
Kind=bridge
  • sudo nvim /etc/systemd/network/pan0.network
[Match]
Name=pan0

[Network]
Address=172.20.1.1/24 # private ip address you like
DHCPServer=yes

Create configurations of service

  • sudo nano /etc/systemd/system/bt-agent.service
[Unit]
Description=Bluetooth Auth Agent

[Service]
ExecStart=/usr/bin/bt-agent -c NoInputNoOutput
Type=simple

[Install]
WantedBy=multi-user.target

sudo nano /etc/systemd/system/bt-network.service

[Unit]
Description=Bluetooth NEP PAN
After=pan0.network

[Service]
ExecStart=/usr/bin/bt-network -s nap pan0
Type=simple

[Install]
WantedBy=multi-user.target

Enable and launch services created

  • sudo systemctl enable systemd-networkd
  • sudo systemctl enable bt-agent
  • sudo systemctl enable bt-network
  • sudo systemctl start systemd-networkd
  • sudo systemctl start bt-agent
  • sudo systemctl start bt-network

Check if the new network is created

  • ifconfig
pan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.20.1.1  netmask 255.255.255.0  broadcast 172.20.1.255
        inet6 fe80::4d9:21ff:fe82:921e  prefixlen 64  scopeid 0x20<link>
        ether 06:d9:21:82:92:1e  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 32  bytes 4410 (4.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Make discoverable on

  • sudo bluetoothctl
  • [bluetooth]# discoverable on

Connect from clients

  • ssh pi@172.20.1.1

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment