个人技术空间

树莓派安装和初始化

最近好久没折腾树莓派,重新拿出来玩玩。
发现2014年写的树莓派安装的过程已经不适用了。
于是这次重新写一遍安装的过程。
当然现在玩也是纯命令行的操作了,也不接显示器了。

一、写入镜像到SD卡

下载树莓派的系统镜像
https://www.raspberrypi.org/downloads/raspbian/
我这里下载的是精简版

Raspbian Buster Lite
Minimal image based on Debian Buster
Version: February 2020
Release date: 2020-02-05
Kernel version: 4.19
Size: 433 MB

然后用Win32DiskImager将IMG后缀的镜像写入到SD卡中
写入镜像

二、开启SSH服务

在推出SD卡之前,在SD卡的BOOT分区中创建一个空的文件,名字为SSH
这样树莓派在第一次启动的时候就会自动开启SSH服务了

三、SSH连接树莓派

接下来就把SD卡插入树莓派,并且插入网线和电源线就可以启动了。
在第一次启动的时候IP是DHCP自动获取的,那应该如何知道它的初始IP是什么呢?
有几种方法
1.接上显示器操作。
2.登陆路由器查看树莓派分配的IP地址
3.树莓派支持multicast DNS 协议,直接ping一下raspberrypi.local就能解析出地址
我这里直接通过ping raspberrypi.local就成功得到了IP地址
然后通过SSH就能登陆了
默认的账号为:pi
默认的密码为:raspberry
登陆之后系统会提示要把默认的密码修改掉,使用passwd命令就可以修改了

四、设置VIM为默认编辑器

编辑器还是用Vim比较顺手

sudo apt-get install vim -y
sudo update-alternatives --config editor
There are 4 choices for the alternative editor (providing /usr/bin/editor).
Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /bin/nano            40        auto mode
1            /bin/ed             -100       manual mode
2            /bin/nano            40        manual mode
3            /usr/bin/vim.basic   30        manual mode
4            /usr/bin/vim.tiny    15        manual mode
Press  to keep the current choice[*], or type selection number: 3
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/editor (editor) in manual mode

输入3,回车

五、修改默认源

把默认源换成国内阿里云的源,加快下载速度。
编辑 /etc/apt/sources.list 文件,删除原文件所有内容,用以下内容取代:

deb https://mirrors.aliyun.com/raspbian/raspbian/ buster main non-free contrib
deb-src https://mirrors.aliyun.com/raspbian/raspbian/ buster main non-free contrib

参考:https://developer.aliyun.com/mirror/raspbian

六、修改时区

sudo cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

七、设置静态IP

sudo vim /etc/dhcpcd.conf
interface eth0
static ip_address=192.168.0.4/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1

使用sudo reboot重启

版权声明:署名-非商业性使用-禁止演绎 3.0 未本地化版本 (CC BY-NC-ND 3.0)