最近把树莓派3B出了买了块OrangePi Zero2,正要折腾的时候发现OrangePi的官方镜像不像树莓派一样有个方便修改的boot.txt,而且官方也不像树莓派一样有一个能修改开机配置的烧录器。于是乎基本都是建议你开机用ttl或者连有线来配置wifi。但是这样很麻烦,非常不利于我这种一天格几次盘的折腾选手,于是我就开始琢磨有没有第一次开机就自动连wifi的方法。
经过一番搜寻,我发现boot里面有个orangepi_first_run.txt.template文件(在armbian里是armbian_first_run.txt.template)里面大概长这样:

#-----------------------------------------------------------------
# Orange Pi first run configuration
# Set optional end user configuration
#    - Rename this file from /boot/orangepi_first_run.txt.template to /boot/orangepi_first_run.txt
#    - Settings below will be applied only on 1st run of Orange Pi
#-----------------------------------------------------------------

#-----------------------------------------------------------------
# General:
# 1 = delete this file, after first run setup is completed.

FR_general_delete_this_file_after_completion=1

#-----------------------------------------------------------------
#Networking:
# Change default network settings
# Set to 1 to apply any network related settings below

FR_net_change_defaults=0

# Enable WiFi or Ethernet.
#    NB: If both are enabled, WiFi will take priority and Ethernet will be disabled.

FR_net_ethernet_enabled=1
FR_net_wifi_enabled=0

#Enter your WiFi creds
#    SECURITY WARN: Your wifi keys will be stored in plaintext, no encryption.

FR_net_wifi_ssid='MySSID'
FR_net_wifi_key='MyWiFiKEY'

#    Country code to enable power ratings and channels for your country. eg: GB US DE | https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2

FR_net_wifi_countrycode='GB'

#If you want to use a static ip, set it here

FR_net_use_static=0
FR_net_static_ip='192.168.0.100'
FR_net_static_mask='255.255.255.0'
FR_net_static_gateway='192.168.0.1'
FR_net_static_dns='8.8.8.8 8.8.4.4' #2 entries max, seperated by a space.
#-----------------------------------------------------------------

诶哟这不就来了吗,填完信息改完配置我才发现,windows不支持ext4,没法编辑img文件里的内容。那就只能通过wsl来编辑这个img了。
这里要用到parted这个包来读取img的起始地址,wsl的系统默认是没有的,需要安装一下。

root@M1saka-Laptop:~# cd /mnt/d/香橙派
root@M1saka-Laptop:/mnt/d/香橙派# ls
Armbian_22.11.3_Orangepizero2_bullseye_legacy_4.9.318.img  Orangepizero2_3.0.6_debian_bullseye_server_linux5.16.17.img
debian11.img                                               OrangePi_Zero2_Android10_v1.1.tar.gz
Orangepizero2_2.2.0_debian_buster_server_linux4.9.170.img
root@M1saka-Laptop:/mnt/d/香橙派# mkdir /mnt/img
root@M1saka-Laptop:/mnt/d/香橙派# parted debian11.img
GNU Parted 3.4
Using /mnt/d/香橙派/debian11.img
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) unit b
(parted) print
Model:  (file)
Disk /mnt/d/香橙派/debian11.img: 1870659584B
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start     End          Size         Type     File system  Flags
 1      4194304B  1870659583B  1866465280B  primary  ext4

(parted) ^C

root@M1saka-Laptop:/mnt/d/香橙派# mount -o loop,offset=4194304 debian11.img  /mnt/img/
root@M1saka-Laptop:/mnt/d/香橙派# cd /mnt/img
root@M1saka-Laptop:/mnt/img# ls
bin  boot  dev  etc  home  lib  lost+found  media  mnt  opt  proc  root  run  sbin  selinux  srv  sys  tmp  usr  var
root@M1saka-Laptop:/mnt/img# cd
root@M1saka-Laptop:~# umount /mnt/img/
root@M1saka-Laptop:~#

在挂载上后,甚至可以直接在windows自带的文件管理器里修改镜像的文件,把orangepi_first_run.txt.template里面的内容替换成自己的之后把名字改成orangepi_first_run.txt即可。然后把镜像写入sd卡里,开机就可以自动连接wifi了。

Last modification:February 6, 2023
If you think my article is useful to you, please feel free to appreciate