我们可以在树莓派的官网看到两种镜像:NOOBS和Raspbian。NOOBS是树莓派官方发布的工具,其实是集成了安装程序、恢复程序和镜像等。NOOBS对初次接触树莓派的人非常友好,下载好NOOBS的镜像,把内容解压到SD卡根目录,给树莓派插上 SD卡、键盘、鼠标、屏幕,上电即可,之后根据提示即可完成系统的安装。由于本次我们不单独给树莓派配备屏幕等配件,所以选择安装Raspbian,Raspbian有“lite”、“desktop”或者“desktop and recommended software”几个版本。我是程序猿,我想装逼,我不需要图形界面,所以就选择“lite”了。开玩笑啦,其实,毕竟Zero的性能有限,我不需要使用它的图形界面做一些其他事,只想在上面跑一些python脚本。当然也可以选择“desktop”或者“desktop and recommended software”版本的镜像,安装好之后可以使用VNC连接Zero,不过这不是本篇文章讨论的内容。
scarleastdeMacBook-Pro:~ scarleast$ diskutil list /dev/disk0 (internal, physical): #: TYPE NAME SIZE IDENTIFIER 0: GUID_partition_scheme *500.3 GB disk0 1: EFI EFI 314.6 MB disk0s1 2: Apple_APFS Container disk1 500.0 GB disk0s2
/dev/disk1 (synthesized): #: TYPE NAME SIZE IDENTIFIER 0: APFS Container Scheme - +500.0 GB disk1 Physical Store disk0s2 1: APFS Volume Macintosh HD - 数据 107.9 GB disk1s1 2: APFS Volume Preboot 82.4 MB disk1s2 3: APFS Volume Recovery 528.9 MB disk1s3 4: APFS Volume VM 3.2 GB disk1s4 5: APFS Volume Macintosh HD 10.6 GB disk1s5
/dev/disk2 (external, physical): #: TYPE NAME SIZE IDENTIFIER 0: FDisk_partition_scheme *15.9 GB disk2 1: Windows_FAT_32 BOOT 15.9 GB disk2s1
2.2 为烧写镜像做准备
确定了SD卡的磁盘后,需要卸载SD卡,为烧写镜像做准备,使用diskutil unmountDisk /dev/disk<disk# from diskutil>即可,这里注意,需要自行替换/dev/disk<disk# from diskutil>为SD卡实际的设备名,如下所示(我的为/dev/disk2):
1 2
scarleastdeMacBook-Pro:~ scarleast$ diskutil unmountDisk /dev/disk2 Unmount of all volumes on disk2 was successful
2.3 烧写镜像
使用sudo dd bs=1m if=image.img of=/dev/rdisk<disk# from diskutil> conv=sync,即可将镜像烧录到SD卡中,几个参数的含义:
scarleastdeMacBook-Pro:~ scarleast$ sudo dd bs=1m if=~/Desktop/2019-09-26-raspbian-buster-lite.img of=/dev/rdisk2 conv=sync load: 1.98 cmd: dd 6571 uninterruptible 0.00u 0.05s 48+0 records in 47+0 records out 49283072 bytes transferred in 2.859712 secs (17233578 bytes/sec) load: 1.98 cmd: dd 6571 uninterruptible 0.00u 0.07s 73+0 records in 72+0 records out 75497472 bytes transferred in 4.517975 secs (16710467 bytes/sec) load: 1.98 cmd: dd 6571 uninterruptible 0.01u 0.08s 85+0 records in 84+0 records out 88080384 bytes transferred in 5.720841 secs (15396405 bytes/sec) load: 1.98 cmd: dd 6571 uninterruptible 0.01u 0.10s 98+0 records in 97+0 records out 101711872 bytes transferred in 6.617933 secs (15369130 bytes/sec) 2144+0 records in 2144+0 records out 2248146944 bytes transferred in 165.306870 secs (13599840 bytes/sec)
scarleastdeMacBook-Pro:~ scarleast$ ssh pi@192.168.0.153 The authenticity of host '192.168.0.153 (192.168.0.153)' can't be established. ECDSA key fingerprint is SHA256:w8A0kgEd0oZDCF08dfoRYy2YYPA+Q+r8SObvsmETL2w. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.0.153' (ECDSA) to the list of known hosts. pi@192.168.0.153's password: Linux raspberrypi 4.19.75+ #1270 Tue Sep 24 18:38:54 BST 2019 armv6l
The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law.
SSH is enabled and the default password for the 'pi' user has not been changed. This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.