Raspberry Pi/Zero 2W/Ubuntu/24.04

From Chorke Wiki
Jump to navigation Jump to search
lsblk
:'
sdb           8:16   1  29.8G  0 disk 
├─sdb1        8:17   1   512M  0 part /media/shahed/system-boot
└─sdb2        8:18   1  29.3G  0 part /media/shahed/writable
'
ls -alh /media/${USER}/system-boot/{ssh,{config,cmdline}.txt}
:'
-rw-r--r-- 1 shahed shahed  170 Dec 30 01:03 /media/shahed/system-boot/cmdline.txt
-rw-r--r-- 1 shahed shahed 1.8K Dec 29 21:13 /media/shahed/system-boot/config.txt
-rw-r--r-- 1 shahed shahed    0 Dec 29 17:45 /media/shahed/system-boot/ssh
'
ls -lah /media/${USER}/writable/etc/netplan/
:'
total 12K
drwxr-xr-x   2 root root 4.0K Dec 30 08:29 .
drwxr-xr-x 108 root root 4.0K Dec 29 20:55 ..
-rw-------   1 root root  262 Dec 29 17:22 50-cloud-init.yaml
'
ls -lah /media/${USER}/writable/etc/udev/rules.d/
:'
total 72K
drwxr-xr-x 2 root root 4.0K Aug  6 01:00 .
drwxr-xr-x 4 root root 4.0K Dec 29 20:47 ..
-rw-r--r-- 1 root root  62K Aug  6 01:00 70-snap.snapd.rules
'

system-boot » config.txt

cat /media/${USER}/system-boot/config.txt && echo
<<-'TXT'
[all]
arm_64bit=1
kernel=vmlinuz
cmdline=cmdline.txt
initramfs initrd.img followkernel

# Enable the audio output, I2C and SPI interfaces on the GPIO header. As these
# parameters related to the base device-tree they must appear *before* any
# other dtoverlay= specification
dtparam=audio=on
dtparam=i2c_arm=on
dtparam=spi=on

# Comment out the following line if the edges of the desktop appear outside
# the edges of your display
disable_overscan=1

# If you have issues with audio, you may try uncommenting the following line
# which forces the HDMI output into HDMI mode instead of DVI (which doesn't
# support audio output)
#hdmi_drive=2

# Enable the KMS ("full" KMS) graphics overlay, leaving GPU memory as the
# default (the kernel is in control of graphics memory with full KMS)
dtoverlay=vc4-kms-v3d
disable_fw_kms_setup=1

# Enable the serial pins
enable_uart=1

# Autoload overlays for any recognized cameras or displays that are attached
# to the CSI/DSI ports. Please note this is for libcamera support, *not* for
# the legacy camera stack
camera_auto_detect=1
display_auto_detect=1

# Config settings specific to arm64
dtoverlay=dwc2

[pi4]
max_framebuffers=2
arm_boost=1

[pi3+]
# Use a smaller contiguous memory area, specifically on the 3A+ to avoid an
# OOM oops on boot. The 3B+ is also affected by this section, but it shouldn't
# cause any issues on that board
dtoverlay=vc4-kms-v3d,cma-128

[pi02]
# The Zero 2W is another 512MB board which is occasionally affected by the same
# OOM oops on boot.
dtoverlay=vc4-kms-v3d,cma-128

[cm4]
# Enable the USB2 outputs on the IO board (assuming your CM4 is plugged into
# such a board)
dtoverlay=dwc2,dr_mode=host

[all]
TXT

system-boot » cmdline.txt

cat /media/${USER}/system-boot/cmdline.txt && echo
:'
console=serial0,115200 multipath=off dwc_otg.lpm_enable=0 console=tty1 root=LABEL=writable rootfstype=ext4 rootwait fixrtc cfg80211.ieee80211_regdom=MY
'

SD Card » Pre-Boot

SD Card » Pre-Boot

system-boot » config.txt

cat <<'INI' | tee -a /media/${USER}/system-boot/config.txt >/dev/null
dtoverlay=dwc2

# Enable Heartbeat LED
dtparam=pwr_led_trigger=heartbeat
dtparam=act_led_trigger=heartbeat
INI
lsmod | grep -E 'dwc2|g_ether'
dmesg | grep -E 'dwc2'




sudo dtoverlay dwc2

system-boot » cmdline.txt

# modules-load=dwc2

cat <<'INI' | tee /media/${USER}/system-boot/cmdline.txt >/dev/null
console=serial0,115200 multipath=off dwc_otg.lpm_enable=0 console=tty1 root=LABEL=writable rootfstype=ext4 rootwait modules-load=dwc2 fixrtc cfg80211.ieee80211_regdom=MY
INI
# modules-load=dwc2,g_ether

cat <<'INI' | tee /media/${USER}/system-boot/cmdline.txt >/dev/null
console=serial0,115200 multipath=off dwc_otg.lpm_enable=0 console=tty1 root=LABEL=writable rootfstype=ext4 rootwait modules-load=dwc2,g_ether fixrtc cfg80211.ieee80211_regdom=MY
INI
# modules-load=dwc2,g_ether
# g_ether.host_addr=12:a5:cf:42:92:fd
# g_ether.dev_addr=5e:bc:ca:27:92:b1

cat <<'INI' | tee /media/${USER}/system-boot/cmdline.txt >/dev/null
console=serial0,115200 multipath=off dwc_otg.lpm_enable=0 console=tty1 root=LABEL=writable rootfstype=ext4 rootwait modules-load=dwc2,g_ether fixrtc cfg80211.ieee80211_regdom=MY g_ether.host_addr=12:a5:cf:42:92:fd g_ether.dev_addr=5e:bc:ca:27:92:b1
INI

writable » 10-usb-wan.yaml

ls -lah            /media/${USER}/writable/etc/netplan/
cat <<'YML' | sudo /media/${USER}/writable/etc/netplan/10-usb-wan.yaml >/dev/null
---
network:
  version: 2
  renderer: networkd
  ethernets:
    usb0:
      dhcp4: false
      addresses:
        - 192.168.10.2/24
      routes:
        - to: default
          via: 192.168.10.1
      nameservers:
        addresses:
          - 192.168.10.1
          - 8.8.8.8
      optional: true
YML
sudo chmod 600 /media/${USER}/writable/etc/netplan/10-usb-wan.yaml
sudo netplan try --timeout 60
sudo netplan generate
sudo netplan apply















sudo ip add show usb0
ping -c3 192.168.10.1
ping -c3 192.168.10.2

writable » 99-usb-gadget.yaml

ls -lah                /media/${USER}/writable/etc/netplan/
cat <<'YML' | sudo tee /media/${USER}/writable/etc/netplan/99-usb-gadget.yaml >/dev/null
---
network:
  version: 2
  renderer: networkd
  ethernets:
    usb0:
      dhcp4: no
      addresses:
        - 192.168.8.2/24
      optional: true
YML
sudo chmod 600 /media/${USER}/writable/etc/netplan/99-usb-gadget.yaml
sudo netplan try --timeout 60
sudo netplan generate
sudo netplan apply

sudo ip add show usb0
ping -c3 192.168.8.1

ETH_USB0="$(ip -o link show | grep '12:a5:cf:42:92:fd' | awk -F': ' '{print $2}')"
sudo ip addr add 192.168.8.1/24 dev "${ETH_USB0}"
sudo ip link set  "${ETH_USB0}" up
sudo ip addr show "${ETH_USB0}"

ping -c3 192.168.8.2
ping -c3 192.168.8.1

writable » 70-usb-gadget-net.rules

ls -lah                /media/${USER}/writable/etc/udev/rules.d/
cat <<'INI' | sudo tee /media/${USER}/writable/etc/udev/rules.d/70-usb-gadget-net.rules >/dev/null
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="5e:bc:ca:27:92:b1", NAME="usb0"
INI

sudo chmod 644 /media/${USER}/writable/etc/udev/rules.d/70-usb-gadget-net.rules
sudo udevadm control --reload
sudo udevadm trigger


sudo ip add show usb0
ping -c3 192.168.8.1

SD Card » Post-Boot

SD Card » Post-Boot

Post-Boot » Swapfile

cat <<'EXE' | sudo bash
swapoff /swapfile
fallocate -l 1G /swapfile
ls -lh /swapfile && mkswap /swapfile
chmod 0600 /swapfile && swapon /swapfile && swapon --show && free -th
EXE
cat << FST | sudo tee -a /etc/fstab >/dev/null
# Loopback Swap Space » 512Mi + 512Mi 
/swapfile              none            swap    sw              0       0
FST

sudo mount -a

Post-Boot » 10-usb-wan.yaml

ls -lah            /etc/netplan/
cat <<'YML' | sudo /etc/netplan/10-usb-wan.yaml >/dev/null
---
network:
  version: 2
  renderer: networkd
  ethernets:
    usb0:
      dhcp4: false
      addresses:
        - 192.168.10.2/24
      routes:
        - to: default
          via: 192.168.10.1
      nameservers:
        addresses:
          - 192.168.10.1
          - 8.8.8.8
      optional: true
YML
sudo chmod 600 /etc/netplan/10-usb-wan.yaml
sudo netplan try --timeout 60
sudo netplan generate
sudo netplan apply















sudo ip add show usb0
ping -c3 192.168.10.1
ping -c3 192.168.10.2

Post-Boot » 99-usb-gadget.yaml

ls -lah                /etc/netplan/
cat <<'YML' | sudo tee /etc/netplan/99-usb-gadget.yaml >/dev/null
---
network:
  version: 2
  renderer: networkd
  ethernets:
    usb0:
      dhcp4: no
      addresses:
        - 192.168.8.2/24
      optional: true
YML
sudo chmod 600 /etc/netplan/99-usb-gadget.yaml
sudo netplan try --timeout 60
sudo netplan generate
sudo netplan apply

sudo ip add show usb0
ping -c3 192.168.8.1

ETH_USB0="$(ip -o link show | grep '12:a5:cf:42:92:fd' | awk -F': ' '{print $2}')"
sudo ip addr add 192.168.8.1/24 dev "${ETH_USB0}"
sudo ip link set  "${ETH_USB0}" up
sudo ip addr show "${ETH_USB0}"

ping -c3 192.168.8.2
ping -c3 192.168.8.1

Post-Boot » 70-usb-gadget-net.rules

ls -lah                /etc/udev/rules.d/
cat <<'INI' | sudo tee /etc/udev/rules.d/70-usb-gadget-net.rules >/dev/null
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="5e:bc:ca:27:92:b1", NAME="usb0"
INI

sudo chmod 644 /etc/udev/rules.d/70-usb-gadget-net.rules
sudo udevadm control --reload
sudo udevadm trigger


sudo ip add show usb0
ping -c3 192.168.8.1

Host » Ethernet » USB0

Host » Ethernet » USB0

Host » 70-pi-usb-net.rules

ls -lah                /etc/udev/rules.d/
cat <<'INI' | sudo tee /etc/udev/rules.d/70-pi-usb-net.rules >/dev/null
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="12:a5:cf:42:92:fd", NAME="usb0"
INI

sudo chmod 644 /etc/udev/rules.d/70-pi-usb-net.rules
sudo udevadm control --reload
sudo udevadm trigger


sudo ip add show usb0
ping -c3 192.168.8.1

Host » 20-usb0.network » Match » MAC

ls -lah                /etc/systemd/network/
cat <<'INI' | sudo tee /etc/systemd/network/20-usb0.network >/dev/null
[Match]
MACAddress=12:a5:cf:42:92:fd

[Network]
Address=192.168.8.1/24
INI
sudo chown root:root /etc/systemd/network/20-usb0.network
sudo chmod 644       /etc/systemd/network/20-usb0.network
ls -l /etc/systemd/network/20-usb0.network
sudo systemctl restart systemd-networkd
networkctl status usb0
ip addr show usb0
networkctl list



ping -c3 192.168.10.1
ping -c3 192.168.10.2

Host » 20-usb0.network » Match » Name

ls -lah                /etc/systemd/network/
cat <<'INI' | sudo tee /etc/systemd/network/20-usb0.network >/dev/null
[Match]
Name=usb0

[Link]
MACAddress=12:a5:cf:42:92:fd

[Network]
Address=192.168.8.1/24
INI
sudo chown root:root /etc/systemd/network/20-usb0.network
sudo chmod 644       /etc/systemd/network/20-usb0.network
ls -l /etc/systemd/network/20-usb0.network
sudo systemctl restart systemd-networkd
networkctl status usb0
ip addr show usb0
networkctl list






ping -c3 192.168.10.1
ping -c3 192.168.10.2

Utility » Install

Utility » Install

Install » LXD

cat << EXE | sudo bash
snap install lxd --channel=6/stable
usermod -aG lxd shahed
EXE
echo 'id -nG' | sudo -i -u shahed bash
systemctl status ufw
sudo iptables -S
sudo ufw status
sudo ufw enable

cat << EXE | sudo bash
ufw       allow OpenSSH
ufw       allow in  on lxdbr0
ufw route allow in  on lxdbr0
ufw route allow out on lxdbr0
EXE

sudo ufw status numbered
sudo iptables -S
cat << EXE | sudo bash
snap restart  lxd
snap services lxd
EXE
lxc image ls images:alpine
lxc launch   images:alpine/3.23 academia
lxc exec academia -- sh -c 'ping -c5 chorke.org'
lxc exec academia -- sh -c 'ping -c5 shahed.biz'
cat <<'YML' | sudo lxd init --preseed
---
config: {}
networks:
- config:
    ipv4.address: 10.20.0.1/24
    ipv4.nat: "true"
    ipv6.address: auto
  description: ""
  name: lxdbr0
  type: ""
  project: default
storage_pools:
- config:
    size: 5GiB
  description: ""
  name: lxd-zfs-pool-aa
  driver: zfs
storage_volumes: []
profiles:
- config: {}
  description: ""
  devices:
    eth0:
      name: eth0
      network: lxdbr0
      type: nic
    root:
      path: /
      pool: lxd-zfs-pool-aa
      type: disk
  name: default
projects: []
cluster: null
YML

Install » Docker

curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
| sudo tee /etc/apt/keyrings/docker.asc >/dev/null

DISTRIBUTION=$(. /etc/os-release && echo "${VERSION_CODENAME}")
cat << SRC | sudo tee /etc/apt/sources.list.d/docker.list >/dev/null
deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu ${DISTRIBUTION}  stable
SRC
cat << EXE | sudo bash
apt-get update;echo
apt-cache policy docker-ce
apt list -a --upgradable;apt-get upgrade -y;echo
apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
apt-get clean cache && find /tmp -type f,s -atime +10 -delete
EXE
cat << EOF | sudo tee /etc/docker/daemon.json >/dev/null
{
    "bip"  : "10.20.13.1/24",
    "mtu"  : 1500,
    "dns"  : [
        "1.1.1.1",
        "8.8.8.8"
    ],
    "debug": true
}
EOF
cat << EXE | sudo bash
systemctl stop  docker.socket
systemctl stop  docker.service
systemctl start docker.service

usermod -aG docker shahed
EXE
docker network ls
echo 'id -nG' | sudo -i -u shahed bash
cat <<'EXE'   | docker run --rm -i alpine sh
echo
cat /etc/resolv.conf ;echo
ping -c3 chorke.org  ;echo
EXE

Install » Pi-hole

ssh -i ~/.ssh/cid.chorke.org_ed25519 -qt shahed@192.168.10.2 bash
sudo su

cd /opt/ && wget -O basic-install.sh https://install.pi-hole.net
sudo bash basic-install.sh
ls -ahl /opt/pihole/
pihole setpassword
cat << EXE | sudo bash
ufw allow 80/tcp
ufw allow 443/tcp


ufw status numbered 
EXE

References

References