Skip to main content

Posts about raspberrypi

wireguard on raspberryrpi

I tried to install wireguard with pivpn on 64bit Raspberry pi OS (buster, 4B), but it failed

$ cat << END > /tmp/pivpn_options.conf                                                                                                                                           
IPv4dev=xx
install_user=pi
VPN=wireguard
pivpnNET=10.x.x.0
subnetClass=24
ALLOWED_IPS="10.x.x.0/24, 192.168.y.0/24"
pivpnMTU=1420
pivpnPORT=51820
pivpnDNS1=1.1.1.1
pivpnHOST=myname.example.com
pivpnPERSISTENTKEEPALIVE=25
UNATTUPG=1
END

$ curl -L https://install.pivpn.io > /tmp/pivpn_install.sh
$ chmod +x /tmp/pivpn_install.sh
$ /tmp/pivpn_install.sh --noipv6 --unattended /tmp/pivpn_options.conf                                                                                                     


:: wireguard is not a supported VPN protocol on arm64 Debian, only 'openvpn' is

I was not able to select wireguard in intereractive interface. It select openvpn automatically.

$ /tmp/pivpn_install.sh --noipv6

Though I successed it on 32bit Raspberry pi OS (bullseye, 3B+) It needs NAPT settings to your pi to make a connection from outside wireguard peer.

I'd like to try it on bookwarm 32bit/64bit when it will be released on the next version of the pi :)

kvm on raspberrypi

kvm On Raspberry Pi OS (64bit) beta test version

related packages

$ sudo apt install --no-install-recommends qemu-system-arm qemu-utils kpartx

boot alpine linux

get kernel and initra from the iso file

$ sudo mount -o loop alpine-standard-3.12.0-aarch64.iso /media/tmp
$ sudo cp /media/tmp/boot/initramfs-lts .
$ sudo cp /media/tmp/boot/vmlinuz-lts .
$ sudo umount /media/tmp

boot

$ sudo qemu-system-aarch64 -cpu host -enable-kvm -machine virt -nographic -m 512 \
> -kernel vmlinuz-lts -initrd initramfs-lts \
> -drive if=none,id=image,file=alpine-standard-3.12.0-aarch64.iso -device virtio-blk-device,drive=image \
> -netdev user,id=user0 -device virtio-net-device,netdev=user0 \
> -monitor telnet:localhost:10025,server,nowait

install debian10

download kernel and initrd file and create an empty virtual image file.

$ wget -O linux http://ftp.jp.debian.org/debian/dists/buster/main/installer-arm64/current/images/netboot/debian-installer/arm64/linux
$ wget -O initrd.gz http://ftp.jp.debian.org/debian/dists/buster/main/installer-arm64/current/images/netboot/debian-installer/arm64/initrd.gz
$ qemu-img create -f qcow2 hda.qcow2 16G

boot the installer with downloaded kernel and initrd file and install to the virtual image file.

$ sudo qemu-system-aarch64 -cpu host -enable-kvm -machine virt -m 512 \
> -kernel linux -initrd initrd.gz \
> -drive if=none,id=image,file=debian10.qcow2 -device virtio-blk-device,drive=image \
> -netdev user,id=user0 -device virtio-net-device,netdev=user0 \
> -monitor telnet:localhost:10025,server,nowait \
> -no-reboot -vnc :1

$ vncviewer xxx.xxx.xxx.xxx:5901

get kernel and initrd file from qcow2 file

$ lsmod | grep nbd
$ sudo modprobe nbd
$ sudo qemu-nbd -c /dev/nbd0 debian10.qcow2
$ sudo kpartx -av /dev/nbd0
$ sudo mount /dev/mapper/nbd0p1 /media/tmp

$ cp /media/tmp/initrd.img-4.19.0-11-arm64 .
$ cp /media/tmp/vmlinuz-4.19.0-11-arm64 .

$ sudo umount /media/tmp
$ sudo kpartx -dv /dev/nbd0
$ sudo qemu-nbd -d /dev/nbd0
$ sudo rmmod nbd

boot

$ sudo qemu-system-aarch64 -cpu host -enable-kvm -machine virt -m 512 \
> -kernel vmlinuz-4.19.0-11-arm64 -initrd initrd.img-4.19.0-11-arm64 \
> -append 'root=/dev/vda2' \
> -drive if=none,id=image,file=debian10.qcow2 -device virtio-blk-device,drive=image \
> -netdev user,id=user0 -device virtio-net-device,netdev=user0 \
> -monitor telnet:localhost:10025,server,nowait \
> -nographic

docker on raspberrypi

Install docker on Raspberry Pi OS (64bit) beta test version We can download the iso images from https://downloads.raspberrypi.org/raspios_arm64/images/

Also we can use torrent to download them

make a script to stop transmission when download finished (in this case, the script name is stop_torrent.sh)

sleep 10
kill $(ps -ef | grep transmission | grep -v grep | awk '{print $2}')

then start download

transmissIon-cli --download-dir (fullpath) --uplimit (kbps) --downlimit (kbps) --encryption-required --finish (fullpath)/stop_torrent.sh https://(fqdn)/(path)/(filename).torrent

How to install

$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh --dry-run
$ sudo sh get-docker.sh
$ systemctl is-active docker
$ systemctl is-enabled docker
$ sudo docker version

change the docker root directory where we store the images and containers.

$ sudo docker info | grep Root
$ sudo systemctl stop docker
$ sudo mv /var/lib/docker /path/to/
$ sudo ln -s /path/to/docker /var/lib/docker
$ sudo systemctl start docker
$ sudo docker run --rm hello-world

confirm the result

$ sudo docker run --rm -it alpine
/ #
/ # uptime
 03:17:44 up 1 day,  2:47,  load average: 0.02, 0.05, 0.01
/ #
/ # uname -a
Linux 4db177a44a14 5.4.42-v8+ #1319 SMP PREEMPT Wed May 20 14:18:56 BST 2020 aarch64 Linux
/ #
/ # free -m
              total        used        free      shared  buff/cache   available
Mem:           7816         315        6339           2        1161        7460
Swap:          8191           0        8191

install docker-compose

$ http_proxy=http://192.168.xxx.xxx:3142/ sudo -E apt install libffi-dev libssl-dev
$ sudo pip3 install docker-compose
$ pip3 show docker-compose
$ docker-compose version

commands of docker-compose

config # Validate and view the Compose file
ps # List containers
images # List images
build # (Re)Build services
create # Create services
up # Create and start containers
start # Start services
stop # Stop services
rm -f # Remove stopped containers
down # Stop and remove containers
version # Show version information
help # Show help messages

When update docker-compose.yml, no need to rebuild the image.

docker-compose up -d

When update Dockerfile or edit any source codes, need to rebuild the image.

docker-compose build
docker-compose up -d

cpu governor on raspbian

configure cpu governor

cpu情報の確認

cat /proc/cpuinfo

cpuクロック関連ツール導入

apt-get install cpufrequtils

現在のクロックやガバナの表示

cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_max_freq
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_min_freq
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

状態確認

cpufreq-info
cpufreq-info -p

ガバナの変更

cpufreq-set -g ondemand

os起動時のガバナの指定

cp -pi /usr/share/doc/cpufrequtils/examples/cpufrequtils.sample /etc/default/cpufrequtils
vi /etc/default/cpufrequtils

service cpufrequtils restart

Disable swap on raspbian buster

systemctl status dphys-swapfile

systemctl stop dphys-swapfile
systemctl is-active dphys-swapfile

systemctl disable dphys-swapfile
systemctl is-enabled dphys-swapfile

rm /var/swap

Use tmpfs

mount -t tmpfs tmpfs <mount point>

or

cat << END >> /etc/fstab
tmpfs           /tmp            tmpfs   defaults,size=256m,noatime,mode=1777  0       0
END
mount /tmp