树莓派wordpress网站无法解析 php文件问题

树莓派最新64位系统安装wordpress后发现apache2可以正常运行,但无法解析php,网站显示的是php源代码

解决方案:
1.安装lib文件
sudo apt-get install libapache2-mod-php7.4 #大版本保持一致就好
2.修改配置文件

cd /etc/apache2/mods-enabled
sudo nano php7.4.conf #这个地方改成你对应的版本


在set handler 里面的require all denied改为granted
以及下面的 php|ar一串正则也改为granted

3.重启apche2

sudo service apache2 restart

piaware in raspberrypi

https://github.com/flightaware/piaware/blob/master/Building-and-installing-PiAware-from-source.mediawiki

Table of Contents
Upgrade Raspberry Pi software to the latest
Obtain, build and install the RTL-SDR libraries
Obtain, build and install dump1090
Obtain, build and install piaware
Upgrade Raspberry Pi software to the latest
 sudo apt-get update
 sudo apt-get upgrade
 sudo rpi-update
If rpi-update reported that it downloaded firmware and said you need to reboot for it to take effect, reboot:
 sudo reboot
Obtain, build and install the RTL-SDR libraries
This is the software that can talk to the software defined radio in the RTL-SDR dongle...
 sudo apt-get install git git-core cmake libusb-1.0-0-dev build-essential
 mkdir src
 cd src
 git clone git://git.osmocom.org/rtl-sdr.git
 cd rtl-sdr
 mkdir build
 cd build
 cmake ../ -DINSTALL_UDEV_RULES=ON
 make
 sudo make install
 sudo ldconfig
 sudo cp rtl-sdr.rules /etc/udev/rules.d
Keep the system from thinking that the RTL-SDR dongle is for watching TV... cat </tmp/no-rtl.conf
 blacklist dvb_usb_rtl28xxu
 blacklist rtl2832
 blacklist rtl2830
 EOF
 sudo mv /tmp/no-rtl.conf /etc/modprobe.d/
 sudo reboot
Obtain, build and install dump1090
This is for the FlightAware version. The main difference is that the FA version of dump1090 can emit "FlightAware" format directly, avoiding piaware having to run the faup1090 translation program. Other than that it's the same as dump1090 from Malcolm Robb.
Should you want to build the FlightAware version, please follow the build/install instructions at https://github.com/flightaware/dump1090_mr/blob/master/README.md#building
Obtain, build and install piaware
Follow the instructions for building and installing PiAware from source at https://github.com/flightaware/piaware#building-and-installing-piaware-from-source
Table of ContentsUpgrade Raspberry Pi software to the latestObtain, build and install the RTL-SDR librariesObtain, build and install dump1090Obtain, build and install piaware

install

Upgrade Raspberry Pi software to the latest

 sudo apt-get update
 sudo apt-get upgrade
 sudo rpi-update

If rpi-update reported that it downloaded firmware and said you need to reboot for it to take effect, reboot:

 sudo reboot

Obtain, build and install the RTL-SDR libraries

This is the software that can talk to the software defined radio in the RTL-SDR dongle…

 sudo apt-get install git git-core cmake libusb-1.0-0-dev build-essential
 mkdir src
 cd src
 git clone git://git.osmocom.org/rtl-sdr.git
 cd rtl-sdr
 mkdir build
 cd build
 cmake ../ -DINSTALL_UDEV_RULES=ON
 make
 sudo make install
 sudo ldconfig
 sudo cp rtl-sdr.rules /etc/udev/rules.d

Keep the system from thinking that the RTL-SDR dongle is for watching TV… cat </tmp/no-rtl.conf

 blacklist dvb_usb_rtl28xxu
 blacklist rtl2832
 blacklist rtl2830
 EOF
 sudo mv /tmp/no-rtl.conf /etc/modprobe.d/
 sudo reboot

Obtain, build and install dump1090

This is for the FlightAware version. The main difference is that the FA version of dump1090 can emit “FlightAware” format directly, avoiding piaware having to run the faup1090 translation program. Other than that it’s the same as dump1090 from Malcolm Robb.

Should you want to build the FlightAware version, please follow the build/install instructions at https://github.com/flightaware/dump1090_mr/blob/master/README.md#building

Obtain, build and install piaware

Follow the instructions for building and installing PiAware from source at https://github.com/flightaware/piaware#building-and-installing-piaware-from-source

https://zh.flightaware.com/adsb/piaware/build/

树莓派安装piware

https://zh.flightaware.com/adsb/piaware/install

您想将您的Raspberry Pi与 dump1090 链接到 FlightAware 吗?

如果您在 Raspberry Pi 上运行带有 dump1090 的 ADS-B 接收器,那么您可以安装 PiAware 软件包以将您的 ADS-B 接收器数据传输到 FlightAware。

PiAware 用户可以同时使用运行 dump1090 的 Raspberry Pi 中的数据,还可以通过 PiAware 将飞行数据发送到 FlightAware。与 FlightAware 共享数据的用户自动有资格免费升级到企业帐户。

什么是 PiAware?

PiAware 是一个 FlightAware 客户端程序,在 Raspberry Pi 上运行,可将 dump1090 ADS-B 和 Mode S 数据安全地传输到 FlightAware。PiAware 适用于已经使用 ADS-B 接收器和 dump1090 运行自己的 Raspberry Pi 的人。

上手又快又容易。

使用下面的简单步骤,您可以配置您的 Raspberry Pi 以提供 FlightAware。该过程需要两到三分钟。

已经在运行 PiAware?

查看

PiAware 升级页面以更新到最新版本。

1需要什么

您应该已经安装了 Raspbian 的 Raspberry Pi,并且对使用它有一定的了解。

如果您不熟悉使用 Pi 或需要从头开始构建接收器,请参阅这些说明!

2下载并安装 PiAware

下载并安装 PiAware 存储库包,它会告诉您的 Pi 的包管理器 (apt) 除了 Raspbian 提供的包之外,如何找到 FlightAware 的软件包。

对于在Raspbian Bullseye OS 上运行的 Raspberry Pi ,请从命令行执行以下命令:

wget https://zh.flightaware.com/adsb/piaware/files/packages/pool/piaware/p/piaware-support/piaware-repository_7.2_all.deb
sudo dpkg -i piaware-repository_7.2_all.deb

对于在

Raspbian Buster OS上运行的 Raspberry Pi ,请单击

此处 这将在您的 Raspberry Pi 上下载并安装 PiAware 和所需的依赖项。

sudo apt-get update
sudo apt-get install piaware

这将启用自动和手动(基于 Web,根据您的请求)PiAware 软件更新。默认情况下禁用这些更新。要禁用更新,请跳过此步骤。

sudo piaware-config allow-auto-updates yes
sudo piaware-config allow-manual-updates yes
3下载并安装 dump1090

如果您还没有安装dump1090等ADS-B接收机软件,那么您可以通过执行以下命令安装FlightAware的dump1090版本。

sudo apt-get install dump1090-fa
4下载并安装dump978
sudo apt-get install dump978-fa

有关为 978 UAT 配置接收器的更多说明,请访问我们的

高级配置页面。

5重启你的 Pi

完成安装和配置软件包后,重新启动 Raspberry Pi 以确保一切正常启动。

sudo reboot
6在 FlightAware.com上绑定您的PiAware客户端。

您可能需要等待 PiAware 启动大约四或五分钟,然后可以将您的 PiAware 设备关联您的 FlightAware 帐户来获取免费的企业级账号。

在 FlightAware.com上绑定您的PiAware客户端。

如果5分钟后您的设备还未显示为已绑定,请重新启动设备,如果这仍然不起作用,请重新确认Wi-Fi设置(如果使用Wi-Fi)正确无误。最后,您还可以通过ADSBsupport@FlightAware.com与我们联系。请检查您的统计信息页面(见以下链接)以确认其是否绑定。

7查看您的ADS-B统计数据
  1. 查看您的 ADS-B 数据统计:https://zh.flightaware.com/adsb/stats
    • FlightAware会立即处理您的数据,并在30分钟内显示统计信息。
    • 或者在登录以后点击标题栏里的“我的ADS-B”。这个链接只会在站点开始发送数据30分钟以后才会显示。
  2. 通过点击位于站点名称右侧的齿轮图标,在统计信息页面配置您的位置和天线高度。
    • 多点定位,也称为MLAT,可以使用从飞机接收消息的站点的位置来精确定位飞机的位置。
  3. FlightAware统计页面还会显示您设备的本地IP地址,并提供用于直接连接的链接。在这里您可以点击SkyAware的链接并通过这个门户网站在地图上查看接收器正在接收消息的航班。

相关链接 (PiAware, Raspberry Pi, dump1090, and more)

您想将您的Raspberry Pi与 dump1090 链接到 FlightAware 吗?
如果您在 Raspberry Pi 上运行带有 dump1090 的 ADS-B 接收器,那么您可以安装 PiAware 软件包以将您的 ADS-B 接收器数据传输到 FlightAware。
PiAware 用户可以同时使用运行 dump1090 的 Raspberry Pi 中的数据,还可以通过 PiAware 将飞行数据发送到 FlightAware。与 FlightAware 共享数据的用户自动有资格免费升级到企业帐户。
什么是 PiAware?
PiAware 是一个 FlightAware 客户端程序,在 Raspberry Pi 上运行,可将 dump1090 ADS-B 和 Mode S 数据安全地传输到 FlightAware。PiAware 适用于已经使用 ADS-B 接收器和 dump1090 运行自己的 Raspberry Pi 的人。
上手又快又容易。
使用下面的简单步骤,您可以配置您的 Raspberry Pi 以提供 FlightAware。该过程需要两到三分钟。
已经在运行 PiAware?
查看PiAware 升级页面以更新到最新版本。
1需要什么
您应该已经安装了 Raspbian 的 Raspberry Pi,并且对使用它有一定的了解。
如果您不熟悉使用 Pi 或需要从头开始构建接收器,请参阅这些说明!
树莓派
已安装Raspbian Bullseye 或 Bullseye Lite操作系统
网络连接
通过网络或使用连接的键盘和显示器访问 Pi 上的命令行 shell
必须在 Raspberry Pi 上启用 SSH 访问才能进行远程访问。有关启用 SSH 的信息,请参阅Raspberry Pi SSH 文档。
2下载并安装 PiAware
下载并安装 PiAware 存储库包,它会告诉您的 Pi 的包管理器 (apt) 除了 Raspbian 提供的包之外,如何找到 FlightAware 的软件包。
对于在Raspbian Bullseye OS 上运行的 Raspberry Pi ,请从命令行执行以下命令:
wget https://zh.flightaware.com/adsb/piaware/files/packages/pool/piaware/p/piaware-support/piaware-repository_7.2_all.deb
sudo dpkg -i piaware-repository_7.2_all.deb
对于在Raspbian Buster OS上运行的 Raspberry Pi ,请单击此处 这将在您的 Raspberry Pi 上下载并安装 PiAware 和所需的依赖项。
sudo apt-get update
sudo apt-get install piaware
这将启用自动和手动(基于 Web,根据您的请求)PiAware 软件更新。默认情况下禁用这些更新。要禁用更新,请跳过此步骤。
sudo piaware-config allow-auto-updates yes
sudo piaware-config allow-manual-updates yes
3下载并安装 dump1090
如果您还没有安装dump1090等ADS-B接收机软件,那么您可以通过执行以下命令安装FlightAware的dump1090版本。
sudo apt-get install dump1090-fa
4下载并安装dump978
sudo apt-get install dump978-fa
有关为 978 UAT 配置接收器的更多说明,请访问我们的高级配置页面。
5重启你的 Pi
完成安装和配置软件包后,重新启动 Raspberry Pi 以确保一切正常启动。
sudo reboot
6在 FlightAware.com上绑定您的PiAware客户端。
您可能需要等待 PiAware 启动大约四或五分钟,然后可以将您的 PiAware 设备关联您的 FlightAware 帐户来获取免费的企业级账号。
在 FlightAware.com上绑定您的PiAware客户端。
如果5分钟后您的设备还未显示为已绑定,请重新启动设备,如果这仍然不起作用,请重新确认Wi-Fi设置(如果使用Wi-Fi)正确无误。最后,您还可以通过ADSBsupport@FlightAware.com与我们联系。请检查您的统计信息页面(见以下链接)以确认其是否绑定。
7查看您的ADS-B统计数据
查看您的 ADS-B 数据统计:https://zh.flightaware.com/adsb/stats
FlightAware会立即处理您的数据,并在30分钟内显示统计信息。
统计页面
或者在登录以后点击标题栏里的“我的ADS-B”。这个链接只会在站点开始发送数据30分钟以后才会显示。
页眉中的我的 ADS-B
通过点击位于站点名称右侧的齿轮图标,在统计信息页面配置您的位置和天线高度。
多点定位,也称为MLAT,可以使用从飞机接收消息的站点的位置来精确定位飞机的位置。
统计页面齿轮图标位置
FlightAware统计页面还会显示您设备的本地IP地址,并提供用于直接连接的链接。在这里您可以点击SkyAware的链接并通过这个门户网站在地图上查看接收器正在接收消息的航班。
统计页面 SkyAware 链接位置
FlightAware PiAware:SkyAware ADS-B 软件网页界面
相关链接 (PiAware, Raspberry Pi, dump1090, and more)

piaware

Howto Install Piaware 3.8.1 on Ubuntu Server 20.04 arm64 / Pi4 – FlightAware / ADS-B Flight Tracking – FlightAware Discussions


https://github.com/abcd567a/piaware-ubuntu20-amd64/blob/master/README.md
Automated Installation of piaware 7.2, dump1090-fa 7.2, piaware-web 7.2, and dump978-fa 7.2 (by building packages from source code), on following OS:
(1) Ubuntu 20 - amd64
(2) Debian 11 - amd64
(3) Kali-linux 2021 - amd64
(4) On RPI Model 3 & 4 (32-bit & 64-bit / armv7l & aarch64) Raspberry Pi OS Bullseye, DietPi OS Bullseye, Ubuntu-20 for RPi, and Kali-2021 for RPi
(1) DUMP1090-FA
Copy-paste following command in SSH console and press Enter key. The script will install dump1090-fa.
sudo bash -c "$(wget -O - https://raw.githubusercontent.com/abcd567a/piaware-ubuntu20-amd64/master/install-dump1090-fa.sh)"
(2) PIAWARE
Copy-paste following command in SSH console and press Enter key. The script will install piaware.
sudo bash -c "$(wget -O - https://raw.githubusercontent.com/abcd567a/piaware-ubuntu20-amd64/master/install-piaware.sh)"
(3) PIAWARE-WEB
Copy-paste following command in SSH console and press Enter key. The script will install piaware-web.
sudo bash -c "$(wget -O - https://raw.githubusercontent.com/abcd567a/piaware-ubuntu20-amd64/master/install-piaware-web.sh)"
(4) DUMP978-FA (For USA ONLY. Requires 2nd Dongle)
If you want to receive both ES1090 and UAT978, then two dongles are required, one for 1090 MHz and other for 978 MHz.
(4.1) Copy-paste following command in SSH console and press Enter key. The script will install dump978-fa and skyaware978:
sudo bash -c "$(wget -O - https://raw.githubusercontent.com/abcd567a/piaware-ubuntu20-amd64/master/install-dump978-fa.sh)"
(4.2) Serialize dongles as follows
If you want to receive both ES1090 and UAT978, then two dongles are required, one for 1090 MHz and other for 978 MHz. In this case you will have to serialize dongles so that correct dongle+antenna sets are used by dump1090-fa and dump978-fa.
For 1090 Mhz dongle: use serial # 00001090
For 978 Mhz dongle : use serial # 00000978
(4.1.1) Issue following command to install serialization software:
sudo apt install rtl-sdr
(4.1.2) Unplug ALL DVB-T dongles from RPi
(4.1.3) Plugin only that DVB-T dongle which you want to use for dump1090-fa. All other dongles should be unplugged.
(4.1.4) Issue following command. Say yes when asked for confirmation to chang serial number.
rtl_eeprom -s 00001090
(4.1.5) Unplug 1090 dongle
(4.1.6) Plugin only that DVB-T dongle which you want to use for dump978-fa. All other dongles should be unplugged.
(4.1.7) Issue following command. Say yes when asked for confirmation to chang serial number.
rtl_eeprom -s 00000978
(4.1.8) Unplug 978 dongle
IMPORTANT: After completing above commands, unplug and then replug both dongles.
(4.3) - Configure dump1090-fa & dump978-fa to use dongles of assigned serial numbers
sudo sed -i 's/^RECEIVER_SERIAL=.*/RECEIVER_SERIAL=00001090/' /etc/default/dump1090-fa
sudo sed -i 's/driver=rtlsdr[^ ]* /driver=rtlsdr,serial=00000978 /' /etc/default/dump978-fa
(4.4) - Reboot so that dump1090-fa & dump978-fa can pick their assigned dongles at boot
sudo reboot
 

树莓派系统备份并传输

一键备份


建立文件backup.sh

sudo nano backup.sh

#!/bin/bash
set -e #当命令以非零状态退出时,则退出shell
Color_End="\033[0m"
Color_Red="\033[31m"
Color_Green="\033[32m"
if [ `id -un` != "root" ];then
    echo -e "$Color_Red权限不足,退出脚本! $Color_End"
    exit 1
fi
# 设置文件存放目录
BACKUP_DIR=`pwd`
BACK_UP_DIR=$BACKUP_DIR/raspi-backup
FILE=$BACK_UP_DIR/raspi-backup.img  #备份后的img文件名
mkdir $BACK_UP_DIR
#安装必要的软件安装包
echo -e "$Color_Green安装必要的软件...$Color_End"
apt-get install -qq -y dosfstools dump parted kpartx rsync
apt-get clean
#创建镜像img文件
echo -e "$Color_Green创建img文件...$Color_End"
ROOT=`df -P | grep /dev/root | awk '{print $3}'`   #获取 ROOT的文件大小
MMCBLK0P1=`df -P | grep /dev/mmcblk0p1 | awk '{print $2}'`  #获取主目录的文件大小
ALL=`echo $ROOT $MMCBLK0P1 | awk '{print int(($1+$2)*1.1)}'`  #生成一个比原文件大200M的IMG文件
echo "预计生成文件大小:$(($ALL/1024))MB"
echo "root 大小是 $(($ROOT/1024))MB"
echo "boot 大小是 $(($MMCBLK0P1/1024))MB"
echo "文件路径是 $FILE"
dd if=/dev/zero of=$FILE bs=1K count=$ALL status=progress
#格式化分区
echo -e "$Color_Green格式化root和boot...$Color_End"
P1_START=`fdisk -l /dev/mmcblk0 | grep /dev/mmcblk0p1 | awk '{print $2}'`
P1_END=`fdisk -l /dev/mmcblk0 | grep /dev/mmcblk0p1 | awk '{print $3}'`
P2_START=`fdisk -l /dev/mmcblk0 | grep /dev/mmcblk0p2 | awk '{print $2}'`
echo "boot_start is :$P1_START .boot_end is : $P1_END  .rootfs_start is :$P2_START"
parted $FILE --script -- mklabel msdos
parted $FILE --script -- mkpart primary fat32 ${P1_START}s ${P1_END}s
parted $FILE --script -- mkpart primary ext4 ${P2_START}s -1
parted $FILE --script -- quit
# mount
echo -e "$Color_Green挂载分区...$Color_End"
loopdevice_dst=`losetup -f --show $FILE`
echo "loop分区在 $loopdevice_dst"
PART_BOOT="/dev/dm-0"
PART_ROOT="/dev/dm-1"
sleep 1
device_dst=`kpartx -va $loopdevice_dst | sed -E 's/.*(loop[0-9])p.*/\1/g' | head -1`
sleep 1
device_dst="/dev/mapper/${device_dst}"
sleep 1
mkfs.vfat ${device_dst}p1 -n boot
sleep 1
mkfs.ext4 ${device_dst}p2 -L rootfs
sleep 1
# 复制文件到img
echo -e "$Color_Green复制文件到img...$Color_End"
echo "备份分区 /dev/boot"
dst_boot_path=$BACK_UP_DIR/dst_boot
mkdir  $dst_boot_path
mount -t vfat ${device_dst}p1 $dst_boot_path
cp -rfp /boot/* $dst_boot_path
echo "备份boot完成"
echo "备份分区 /dev/root"
dst_root_path=$BACK_UP_DIR/dst_root
mkdir  $dst_root_path
sleep 1
mount -t ext4 ${device_dst}p2 $dst_root_path
cd $dst_root_path
chmod 777 $dst_root_path/
#通过rsync复制根目录文件到IMG镜像中,排除了一些不需要同步的文件
rsync -ax --info=progress2 --no-inc-recursive \
    --exclude="$FILE" \
    --exclude=$BACK_UP_DIR  \
    --exclude=$BACKUP_DIR/$0  \
    --exclude=/sys/* \
    --exclude=/proc/*  \
    --exclude=/tmp/* /  $dst_root_path/
echo "备份root完成"
# 设置自动扩展空间
echo -e "$Color_Green设置自动扩展空间 ...$Color_End"
sed -i 's/exit 0/sudo bash \/expand-rootfs.sh \&/' $dst_root_path/etc/rc.local
echo "exit 0" >> $dst_root_path/etc/rc.local
cat > $dst_root_path/expand-rootfs.sh << EOF
#!/bin/bash
sed -i '/sudo bash \/expand-rootfs.sh &/d' /etc/rc.local
rm "\`pwd\`/\$0"
echo -e "\033[33m两秒后扩展分区空间!\033[0m"
sleep 2
raspi-config --expand-rootfs
echo -e "\033[33my一秒后重启系统!\033[0m"
sleep 1
reboot
EOF
#返回目录 $BACKUP_DIR
cd $BACKUP_DIR
sync
#替换PARTUUID 这步非常重要,liunx启动时会对PARTUUID有特定的指定,备份的时候是把旧的也同步过来,需要根据新的IMG文件来更新PARTUUID
echo -e "$Color_Green替换PARTUUID ...$Color_End"
opartuuidb=`blkid -o export /dev/mmcblk0p1 | grep PARTUUID`
opartuuidr=`blkid -o export /dev/mmcblk0p2| grep PARTUUID`
npartuuidb=`blkid -o export ${device_dst}p1 | grep PARTUUID`
npartuuidr=`blkid -o export ${device_dst}p2 | grep PARTUUID`
echo "BOOT uuid $opartuuidb 替换为 $npartuuidb"
echo "ROOT uuid $opartuuidr 替换为 $npartuuidr"
sed -i "s/$opartuuidr/$npartuuidr/g" $dst_boot_path/cmdline.txt
sed -i "s/$opartuuidb/$npartuuidb/g" $dst_root_path/etc/fstab
sed -i "s/$opartuuidr/$npartuuidr/g" $dst_root_path/etc/fstab
#清理释放装载的文件夹
echo -e "$Color_Green清理释放装载的文件夹...$Color_End"
umount $dst_boot_path
umount $dst_root_path
kpartx -d ${device_dst}p1
kpartx -d ${device_dst}p2
kpartx -d $loopdevice_dst
losetup -d $loopdevice_dst
rm -rf  $dst_boot_path
rm -rf  $dst_root_path
chmod 766 $FILE
mv $FILE $BACKUP_DIR
rm -rf $BACK_UP_DIR
echo -e "$Color_Green备份完成。$Color_End"
exit 0

给文件权限并执行

chmod +x backup.sh
sudo bash backup.sh

执行后将在当前路径生成备份文件:raspi-backup.img

参考链接:https://github.com/mghcool/Raspberry-backup

另一种方案(未验证)

https://github.com/nanhantianyi/rpi-backup

处理大文件无法拷贝传输问题

磁盘需要格式化为exFAT32格式,其它格式未验证,但fat32对于超过4g的文件肯定不行

https://linux.cn/article-11682-1.html

树莓派侧执行文件分割命令

# split -b1000M raspi-backup.img
split -b1G --verbose raspi-backup.img rpibackup.

远程侧执行如下指令

rsync "pi@192.168.1.2:/home/pi/rpibackup.??" /Volumes/BACKUPDISK/mixdiy.com/backup 

传输完成后执行合并指令

cat rpibackup.?? > raspi-backup.img

如遇权限问题可执行以下命令

sudo sh -c 'rpibackup.?? > raspi-backup.img'

注意:

如果将系统盘格式化为exfat32再烧入镜像,则系统无法启动

树莓派系统备份为img的最好方法

http://blog.dngz.net/813.htm

首先,不要用Win32DiskImager备份,不然备份出来文件超大。

用下面这个脚本备份文件才比实际使用空间大一点点。

将如下脚本保存为/tmp/back2img.sh

#!/bin/bash
if [ `whoami` != "root" ];then
    echo "This script must be run as root!"
    exit 1
fi
# install software
#apt update
apt install -y dosfstools parted kpartx rsync
echo ""
echo "software is ready"
file="rpi-`date +%Y%m%d%H%M%S`.img"
if [ "x$1" != "x" ];then
    file="$1"
fi
# boot mount point
boot_mnt=`findmnt -n /dev/mmcblk0p1 | awk '{print $1}'`
root_info=`df -PT / | tail -n 1`
root_type=`echo $root_info | awk '{print $2}'`
dr=`echo $root_info | awk '{print $4}'`
db=`df -P | grep /dev/mmcblk0p1 | awk '{print $2}'`
ds=`echo $dr $db |awk '{print int(($1+$2)*1.2)}'`
echo "create $file ..."
dd if=/dev/zero of=$file bs=1K count=0 seek=$ds
#truncate -s ${ds}k $file
start=`fdisk -l /dev/mmcblk0| awk 'NR==9 {print $2}'`
end=`fdisk -l /dev/mmcblk0| awk 'NR==9 {print $3}'`
if [ "$start" == "*" ];then
    start=`fdisk -l /dev/mmcblk0| awk 'NR==9 {print $3}'`
    end=`fdisk -l /dev/mmcblk0| awk 'NR==9 {print $4}'`
fi
start=`echo $start's'`
end=`echo $end's'`
end2=`fdisk -l /dev/mmcblk0| awk 'NR==10 {print $2}'`
end2=`echo $end2's'`
echo "start=$start"
echo "end=$end"
echo "end2=$end2"
parted $file --script -- mklabel msdos
parted $file --script -- mkpart primary fat32 $start $end
parted $file --script -- mkpart primary ext4 $end2 -1
loopdevice=`losetup -f --show $file`
device=`kpartx -va $loopdevice | sed -E 's/.*(loop[0-9])p.*/\1/g' | head -1`
device="/dev/mapper/${device}"
echo "device=$device"
partBoot="${device}p1"
partRoot="${device}p2"
echo "partBoot=$partBoot"
echo "partRoot=$partRoot"
sleep 5s
opartuuidb=`blkid -o export /dev/mmcblk0p1 | grep PARTUUID`
opartuuidr=`blkid -o export /dev/mmcblk0p2 | grep PARTUUID`
npartuuidb=`blkid -o export ${partBoot} | grep PARTUUID`
npartuuidr=`blkid -o export ${partRoot} | grep PARTUUID`
boot_label=`dosfslabel /dev/mmcblk0p1 | tail -n 1`
root_label=`e2label /dev/mmcblk0p2 | tail -n 1`
mkfs.vfat -F 32 -n "$boot_label" $partBoot
echo "$partBoot format success"
mkfs.ext4 $partRoot
e2label $partRoot $root_label
echo "$partRoot format success"
mount -t vfat $partBoot /mnt
cp -rfp ${boot_mnt}/* /mnt/
sed -i "s/$opartuuidr/$npartuuidr/g" /mnt/cmdline.txt
sync
umount /mnt
mount -t ext4 $partRoot /mnt
if [ -f /etc/dphys-swapfile ]; then
    SWAPFILE=`cat /etc/dphys-swapfile | grep ^CONF_SWAPFILE | cut -f 2 -d=`
    if [ "$SWAPFILE" = "" ]; then
        SWAPFILE=/var/swap
    fi
    EXCLUDE_SWAPFILE="--exclude $SWAPFILE"
fi
cd /mnt
rsync --force -rltWDEgop --delete --stats --progress \
    $EXCLUDE_SWAPFILE \
    --exclude ".gvfs" \
    --exclude "$boot_mnt" \
    --exclude "/dev" \
    --exclude "/media" \
    --exclude "/mnt" \
    --exclude "/proc" \
    --exclude "/run" \
    --exclude "/snap" \
    --exclude "/sys" \
    --exclude "/tmp" \
    --exclude "lost\+found" \
    --exclude "$file" \
    / ./
if [ ! -d $boot_mnt ]; then
    mkdir $boot_mnt
fi
if [ -d /snap ]; then
    mkdir /mnt/snap
fi
for i in boot dev media mnt proc run sys boot; do
    if [ ! -d /mnt/$i ]; then
        mkdir /mnt/$i
    fi
done
if [ ! -d /mnt/tmp ]; then
    mkdir /mnt/tmp
    chmod a+w /mnt/tmp
fi
cd
sed -i "s/$opartuuidb/$npartuuidb/g" /mnt/etc/fstab
sed -i "s/$opartuuidr/$npartuuidr/g" /mnt/etc/fstab
sync
umount /mnt
kpartx -d $loopdevice
losetup -d $loopdevice

用法,直接运行:
cd /tmp/
sudo ./back2img.sh blog.dngz.net.img

注意:如果TF卡剩余空间不够的话就挂载外部硬盘或U盘,将备份的img直接保存在外部磁盘中,并且外部磁盘请挂载到 /media 目录下,不要挂载到 /mnt!
因为脚本会对/mnt目录进行备份操作,会导致不断循环的递归备份,导致磁盘爆满。
总之记住一定不要挂载到/mnt目录!

运行时的备份日志:

Reading package lists... Done
Building dependency tree
Reading state information... Done
dosfstools is already the newest version (4.1-2).
parted is already the newest version (3.2-25).
rsync is already the newest version (3.1.3-6).
The following NEW packages will be installed:
  kpartx
0 upgraded, 1 newly installed, 0 to remove and 12 not upgraded.
Need to get 37.8 kB of archives.
After this operation, 86.0 kB of additional disk space will be used.
Get:1 https://mirrors.tuna.tsinghua.edu.cn/debian buster/main arm64 kpartx arm64 0.7.9-3+deb10u1 [37.8 kB]
Fetched 37.8 kB in 1s (47.2 kB/s)
Selecting previously unselected package kpartx.
(Reading database ... 49050 files and directories currently installed.)
Preparing to unpack .../kpartx_0.7.9-3+deb10u1_arm64.deb ...
Unpacking kpartx (0.7.9-3+deb10u1) ...
Setting up kpartx (0.7.9-3+deb10u1) ...
Processing triggers for man-db (2.8.5-2) ...
software is ready
create blog.dngz.net.img ...
0+0 records in
0+0 records out
0 bytes copied, 0.00126612 s, 0.0 kB/s
start=8192s
end=532479s
end2=532480s
device=/dev/mapper/loop0
partBoot=/dev/mapper/loop0p1
partRoot=/dev/mapper/loop0p2
mkfs.fat 4.1 (2017-01-24)
mkfs.fat: warning - lowercase labels might not work properly with DOS or Windows
/dev/mapper/loop0p1 format success
mke2fs 1.44.5 (15-Dec-2018)
Discarding device blocks: done
Creating filesystem with 739328 4k blocks and 185104 inodes
Filesystem UUID: ed9bf852-cd2f-4c1b-a9f6-d1e00bd20844
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
/dev/mapper/loop0p2 format success
sending incremental file list
rsync同步数据日志省略...
Number of files: 62,378 (reg: 48,951, dir: 5,618, link: 7,809)
Number of created files: 62,376 (reg: 48,951, dir: 5,616, link: 7,809)
Number of deleted files: 0
Number of regular files transferred: 48,951
Total file size: 2,260,121,595 bytes
Total transferred file size: 2,259,998,604 bytes
Literal data: 2,259,998,604 bytes
Matched data: 0 bytes
File list size: 1,703,776
File list generation time: 0.008 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 2,264,157,862
Total bytes received: 990,956
sent 2,264,157,862 bytes  received 990,956 bytes  6,214,400.05 bytes/sec
total size is 2,260,121,595  speedup is 1.00

备份后blog.dngz.net.img 显示3.1G(实际占用2.4G),用7z极限压缩后仅为630M。

https://zhuanlan.zhihu.com/p/66853949#:~:text=如果你有一台树莓派,你可能需要了解一个名为%20PiShrink%20的%20bash,脚本,该脚本可使树莓派镜像更小%E3%80%82%20PiShrink%20将自动缩小镜像,然后在启动时将其调整为%20SD%20卡的最大大小%E3%80%82

安装 PiShrink

要在 Linux 机器上安装 PiShrink,请先使用以下命令下载最新版本:

$ wget https://raw.githubusercontent.com/Drewsif/PiShrink/master/pishrink.sh

接下来,将下载的 PiShrink 变成二进制可执行文件:

$ chmod +x pishrink.sh

最后,移动到目录:

$ sudo mv pishrink.sh /usr/local/bin/

使树莓派镜像更小

你可能已经知道,Raspbian 是所有树莓派型号的官方操作系统。树莓派基金会为 PC 和 Mac 开发了树莓派桌面版本。你可以创建一个 live CD,并在虚拟机中运行它,甚至也可以将其安装在桌面上。树莓派也有少量非官方​​操作系统镜像。为了测试,我从官方下载页面下载了官方的 Raspbian 系统。

解压下载的系统镜像:

$ unzip 2019-04-08-raspbian-stretch-lite.zip

上面的命令将提取当前目录中 2019-04-08-raspbian-stretch-lite.zip 文件的内容。

让我们看下提取文件的实际大小:

$ du -h 2019-04-08-raspbian-stretch-lite.img
1.7G 2019-04-08-raspbian-stretch-lite.img

如你所见,提取的树莓派系统镜像大小为 1.7G。

现在,使用 PiShrink 缩小此文件的大小,如下所示:

$ sudo pishrink.sh 2019-04-08-raspbian-stretch-lite.img

示例输出:

Creating new /etc/rc.local
rootfs: 39795/107072 files (0.1% non-contiguous), 239386/428032 blocks
resize2fs 1.45.0 (6-Mar-2019)
resize2fs 1.45.0 (6-Mar-2019)
Resizing the filesystem on /dev/loop1 to 280763 (4k) blocks.
Begin pass 3 (max = 14)
Scanning inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 4 (max = 3728)
Updating inode references XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/loop1 is now 280763 (4k) blocks long.
Shrunk 2019-04-08-raspbian-stretch-lite.img from 1.7G to 1.2G

正如你在上面的输出中看到的,树莓派镜像的大小已减少到 1.2G。

你还可以使用 -s 标志跳过该过程的自动扩展部分。

$ sudo pishrink.sh -s 2019-04-08-raspbian-stretch-lite.img newpi.img

这将创建一个源镜像文件(即 2019-04-08-raspbian-stretch-lite.img)的副本到一个新镜像文件(newpi.img)并进行处理。有关更多详细信息,请查看最后给出的官方 GitHub 页面。

无法访问raw.githubusercontent.com的解决

我们难免不会访问raw.githubusercontent.com,但因种种因素,国内很难访问这个站点,以下方法可能帮助到你:
https://ip.cn/ip/raw.githubusercontent.com.html
查找到ip为185.199.108.133
sudo nano /etc/hosts
添加
185.199.110.133 raw.githubusercontent.com

注:

如果是windows系统,则修改

C:\Windows\System32\drivers\etc
hosts文件

python图像边缘检测并生成svg图像

https://zhuanlan.zhihu.com/p/398237689

from typing import Iterable, List, Tuple, Union
import cv2
import matplotlib.pyplot as plt
import numpy as np
from xml.dom import minidom as md
from queue import Queue
import warnings
def look_shape(a : Iterable) -> Tuple:
    # for debug
    return np.array(a).shape
def length_within_points(a : Iterable, empty_value : Union[int, float] = 0) -> int:
    """
        a simple instance:
            array : [empty_value, empty_value, empty_value, 1, empty_value, 0, 1, 2, empty_value]
            Then length_within_points(array) will return index diff between 1 and 2, which is 5
    """
    a = list(a)
    l_pivot, r_pivot = -1, -2
    for index, (l_val, r_val) in enumerate(zip(a[::1], a[::-1])):
        if l_val != empty_value and l_pivot == -1:
            l_pivot = index
        if r_val != empty_value and r_pivot == -2:
            r_pivot = len(a) - index
    return r_pivot - l_pivot + 1
def dump_rings_from_image(image : np.ndarray, output_path : str, plot_dict : dict = {"color" : "k", "linewidth" : 0.3}, default_height : float = 8) -> List[np.ndarray]:
    # regular operation, no more explainations
    blur = cv2.GaussianBlur(image, (3, 3), 0)
    gray = cv2.cvtColor(blur, cv2.COLOR_BGR2GRAY)
    edge = cv2.Canny(gray, 50, 150)
    # get ratio between width and height to adjust the final output
    valid_width = length_within_points(edge.sum(axis=0))
    valid_height = length_within_points(edge.sum(axis=1))
    true_ratio = valid_width / valid_height
    # get contour of the edge image
    contour_tuple = cv2.findContours(edge, mode=cv2.RETR_TREE, method=cv2.CHAIN_APPROX_NONE)
    contours = contour_tuple[0]
    rings = [np.array(c).reshape([-1, 2]) for c in contours]
    # adjust coordinate system to the image coordinate system
    max_x, max_y, min_x, min_y = 0, 0, 0, 0
    for ring in rings:
        max_x = max(max_x, ring.max(axis=0)[0])
        max_y = max(max_y, ring.max(axis=0)[1])
        min_x = max(min_x, ring.min(axis=0)[0])
        min_y = max(min_y, ring.min(axis=0)[1])
    # adjust ratio
    plt.figure(figsize=[default_height * true_ratio, default_height])
    # plot to the matplotlib
    for _, ring in enumerate(rings):
        close_ring = np.vstack((ring, ring[0]))
        xx = close_ring[..., 0]
        yy = max_y - close_ring[..., 1]
        plt.plot(xx, yy, **plot_dict)
    plt.axis("off")
    plt.savefig(output_path)
def remove_matplotlib_background(svg_file : str, bg_node_name : str = "patch_1") -> None:
    dom_tree : md.Document = md.parse(svg_file)
    svg_node = None
    # select the svg tag
    for node in dom_tree.childNodes:
        if node.nodeName == "svg":
            svg_node : md.Element = node
    if svg_node is None:
        raise ValueError("not find a svg node in {}".format(svg_file))
    # bfs svg node to find the background node
    q = Queue()
    q.put(svg_node)
    target_node = None  # we will remove the target node
    while not q.empty():
        cur : md.Node = q.get()
        if cur.hasChildNodes():
            for node in cur.childNodes:
                q.put(node)
        if hasattr(cur, "getAttribute"):
            # this is the id of the background node
            if cur.getAttribute("id") == bg_node_name:
                target_node = cur
    if target_node is None:
        warnings.warn("background node is not found, please ensure whether bg_node_name is correct")
    else:       # remove and write
        target_node.parentNode.removeChild(target_node)
        with open(svg_file, "w", encoding="utf-8") as fp:
            dom_tree.writexml(
                writer=fp,
                indent="\t"
            )
def bitmap_to_contour_svg(input_bitmap_path : str, output_svg_path : str):
    img = cv2.imread(input_bitmap_path)
    dump_rings_from_image(img, output_path=output_svg_path)
    remove_matplotlib_background(output_svg_path)
if __name__ == '__main__':
    bitmap_to_contour_svg(
        input_bitmap_path="555.png",
        output_svg_path="abc.svg"
    )

一个简单方式

from PIL import Image, ImageFilter
img = Image.open('abc.jpg')  # 打开图片文件
newimg = img.filter(ImageFilter.CONTOUR)  # 设置图片轮廓筛选器
newimg.save('轮廓效果.png', 'png')  # 保存轮廓效果的图片